php - ERROR: Call to a member function getProducts() on a non-object -


i getting error:

fatal error: call member function getproducts() on non-object in /var/www/vhosts/designsense.net.au/gypsy/public_html/catalog/controller/module/cart.php on line 23

this code using.

    class controllermodulecart extends controller {      protected function index() {     $this->language->load('module/cart');      $this->data['heading_title'] = $this->language->get('heading_title');     $this->data['text_subtotal'] = $this->language->get('text_subtotal');     $this->data['text_empty'] = $this->language->get('text_empty');     $this->data['text_remove'] = $this->language->get('text_remove');     $this->data['text_confirm'] = $this->language->get('text_confirm');     $this->data['text_cart'] = $this->language->get('text_cart');     $this->data['text_checkout'] = $this->language->get('text_checkout');     $this->data['button_checkout'] = $this->language->get('button_checkout');     $this->data['button_remove'] = $this->language->get('button_remove');     $this->data['text_cart'] = $this->language->get('text_cart');      $this->data['cart'] = $this->url->link('checkout/cart');     $this->data['checkout'] = $this->url->link('checkout/checkout', '', 'ssl');      // cart products     $this->data['products'] = array();      foreach ($this->cart->getproducts() $result) {          $option_data = array();          foreach ($result['option'] $option) {             $option_data[] = array(                 'name'  => $option['name'],                 'value' => (strlen($option['option_value']) > 20 ? substr($option['option_value'], 0, 20) . '..' : $option['option_value'])             );         } 

any suggestions on causing this?

you cant use $this->cart->getproducts(); in foreach loop.

so need assign value variable

$products = $this->cart->getproducts();

this little line of code important in makes call function getproducts core procedure located in system/library/cart.php. variable $products has entire cart array + possible options , can “iterated” through. iterate means sift through array, gathering it’s contents or loop through. let’s take @ happening in function getproducts(); in system/library/cart.php find function towards top: use in foreach loop

foreach ($products $product)  {    //your code here } 

this code foreach() loop set go through array set in system/library/cart.php. responsible displaying of content seen in shopping cart page along product options. below foreach ($products $product) { repeat many times necessary until products have been dealt in array.

this work fine.

read article well

edit 01

public function getproducts() {     if ( !$this->data )     {         foreach ( $this->session->data['cart'] $key => $quantity )         {             $product = explode(':', $key);             $product_id = $product[0];             $stock = true;// options             if ( isset($product[1]) )             {                 $options = unserialize(base64_decode($product[1]));             }             else             {                 $options = array();             }         }     } } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -