Jump to content

Cart ID is zero?


Recommended Posts

I have a module which displays a color / size matrix at the bottom of product pages for bulk ordering.  
Can be seen at the bottom of this page: http://allamericanswim.com/rise-aquatics-guard/39766-guard-poly-v-back-tankini.html

 

It was working great for the last couple weeks when a customer called and said the products where not adding to the cart when using the matrix layout.  So I tested it on another computer and indeed there is an issue.  My module needs the cart id to add the products into the cart.  But the cart id is zero, thus not adding to the cart.

 

If I already have a product in my cart, the module works fine and adds to the cart.  Why would cart id be zero?

 

The module uses hookDisplayFooterProduct to display the matrix.  To get the cart id, i use:

$context = Context::getContext();
$cartID = (int)$context->cookie->id_cart;

Sometimes this id_cart is zero.  Does prestashop not generate a cart_id on every visitor?  How can I get a cart_id to add products to the cart?

 

I have tried the following:   

 

 

if (!$cartID)
{
    $cart = new Cart();
   $cart->id_customer = (int)($context->cookie->id_customer);
    $cart->id_address_delivery = (int) (Address::getFirstCustomerAddressId($cart->id_customer));
    $cart->id_address_invoice = $cart->id_address_delivery;
    $cart->id_lang = (int)($context->cookie->id_lang);
    $cart->id_currency = (int)($ontext->cookie->id_currency);
    $cart->id_carrier = 1;
    $cart->recyclable = 0;
    $cart->gift = 0;
    $cart->save();
$cartID = $cart->id;
}
 
Which does indeed generate a cart_id but I don't think its saving to the sessions as no products are added to the cart either.  Plus when this code is used, multiple computers have the same cart_id.
 
Any pointers?  Thanks in advanced.

 

 

 

 

 

 

 

 

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More