Post by webiscore » Wed Mar 21, 2018 12:19 am

I'm using Opencart version 1.5.2.1 connecting API to it. I'm facing an issue while adding item to cart.

When Adding an item to the cart then hovering over the mini cart at the header it becomes empty and shows a message "Your shopping cart is empty!".

To make it simpler I was using the code below:

Code: Select all

      <file name="system/library/customer.php">
        <operation>
          <search position="after" offset="2"><![CDATA[
            $this->session->data['customer_id'] . "' AND status = '1'");
          ]]></search>
          <add ><![CDATA[
                /**
                 * Mobile App code
                 */

                if ($customer_query->row['cart'] && is_string($customer_query->row['cart'])) {
                  $cart = unserialize($customer_query->row['cart']);
                  $this->session->data['cart'] = $cart;
                }
This code was emptying the cart after adding the item. I replaced the above code with the below one.

Code: Select all

      <file name="system/library/customer.php">
        <operation>
          <search position="after" offset="2"><![CDATA[
            $this->session->data['customer_id'] . "' AND status = '1'");
          ]]></search>
          <add ><![CDATA[
                /**
                 * Mobile App code
                 */

				if ($customer_query->row['cart'] && is_string($customer_query->row['cart'])) {
					$cart = unserialize($customer_query->row['cart']);
					
					foreach ($cart as $key => $value) {
						if (!array_key_exists($key, $this->session->data['cart'])) {
							$this->session->data['cart'][$key] = $value;
						} else {
							$this->session->data['cart'][$key] += $value;
						}
					}			
				}
Now I can add the item(s) to the cart and it's not emptied but when hovering over the minicart at the top header the quantity keeps doubling till infinity.

Anyone can help me please, thank you!

New member

Posts

Joined
Mon Jan 30, 2012 9:49 am
Who is online

Users browsing this forum: No registered users and 66 guests