Welcome Guest, Not a member yet? Register   Sign In
Problem with adding products to a shopping cart
#1

[eluser]yuro[/eluser]
I works with the CodeIgniter Version 2.1.3

The Problem is, when i click at a product and go on "buy now", then i get the following error message:

Quote:----------------------------------------
Fatal error: Call to a member function updateWarenkorb() on a non-object in D:\xampp\htdocs\ci_shop\application\controllers\welcome.php on line 107
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Welcome::$Order_model
Filename: controllers/welcome.php
Line Number: 107
----------------------------------------


So, here is my code:


Code:
Model: Order_model.php


function updateWarenkorb($produktid,$gesamtprodukt) {
        //Zuerst in bestehenden Warenkorb ziehen
        $warenkorb = $_SESSION['warenkorb'];
        $summe = 0;
      
        if(count($gesamtprodukt)) {
            if(isset($warenkorb[$produktid])) {
                $prevwk = $warenkorb[$produktid]['count'];
                $prevname = $warenkorb[$produktid]['name'];
                $prevpreis = $warenkorb[$produktid]['preis'];
              
                $warenkorb[$produktid] = array(
                    'name'    => $prevname,
                    'preis'    => $prevpreis,
                    'count'    => $prevwk + 1
                );
            } else {
                $warenkorb[$produktid] = array(
                    'name'    => $gesamtprodukt['name'],
                    'preis'    => $gesamtprodukt['preis'],
                    'count'    => 1
                );      
            }
          
            foreach($warenkorb as $id => $produkt) {
                $summe += $produkt['preis'] * $produkt['count'];
            }
          
            $_SESSION['summe'] = $summe;
            $_SESSION['warenkorb'] = $warenkorb;
          
            $this->session->set_flashdata('conf_msg', "Das Produkt wurde Ihrem Warenkorb hinzugefĆ¼gt.");
        }
    }



Code:
Controller: welcome.php


function Welcome() {
        parent::__construct();
        session_start();  
}




function warenkorb($produktid) {
        if($produktid > 0) {
            $gesamtprodukt = $this->Produkte_model->getProdukt($produktid);
          
            $this->Order_model->updateWarenkorb($produktid, $gesamtprodukt); [b]<!-- Thats the Error?! Line 107[/b]
          
            redirect('welcome/produkt/' . $produktid, 'refresh');  
        } else {
            $data['title'] = "Bachelor Webshop | Warenkorb";
          
            if(count($_SESSION['warenkorb']) == true) {
                $data['main'] = 'wkorb';
                $data['navlist'] = $this->Kategorie_model->getKategorienNav();
              
                $this->load->vars($data);
                $this->load->view('template');
            } else {
                redirect('welcome/index', 'refresh');
            }
        }
    }

Code:
View: produkt.php


<?php
        if($this->session->flashdata('conf_msg')) {
            echo "<div class='message'>";
            echo $this->session->flashdata('conf_msg');  
            echo "</div>";
        }
    ?&gt;
#2

[eluser]TheFuzzy0ne[/eluser]
Where are you loading your Order_model?
#3

[eluser]yuro[/eluser]
I load all models with this variables:

$this->load->vars($data);
$this->load->view('template');

But I think that I have to put it in a variable. --&gt;$this->Order_model->updateWarenkorb($produktid, $gesamtprodukt); ??
#4

[eluser]TheFuzzy0ne[/eluser]
The way you are doing it is fine, but you are not assigning the return value to a variable, and the model clearly isn't loaded.

Models can be loaded in one of two ways:
1) $this->load->model('model_name');
2) Add it to ./application/config/autoload.php

There are other ways of doing it, but it makes no sense using them since the you have the two options above available to you.
#5

[eluser]yuro[/eluser]
Thankkkkssss fuzzy Smile

i'm so an idiot. I forgot to write the order model in the autoload.php file... thank you guy!!! Smile




Theme © iAndrew 2016 - Forum software by © MyBB