Cart update triggers after a second page reload

  • Posts: 189
  • Thank you received: 11
  • Hikashop Business
7 years 4 months ago #273709

-- HikaShop version -- : 3.1.1 [1707101222] Business
-- Joomla version -- : 3.7.3
-- PHP version -- : 7.0.20
-- Browser(s) name and version -- : Chrome 59

I'm developing a plugin that adds a free product based on the current shipping zone. This works, however, it will only show the added product in the cart after a second reload. Changing the amount of initial products triggers it, but it does not show the newly added product in the cart. It's the same when removing the product again after changing the initial product amount back to a lower case (which is outside the shipping rules; the shipping changes when I change the amount of products).

The cart does update correctly whenever I update the amount of a product using a POST (pressing return/enter); it does not when I use the AJAX refresh button.

I'm using the event "onAfterCartShippingLoad" but I've tried other events aswell loading the cart dynamicly using the cart class. I'm using the following code to add to the cart;

$classCart = hikashop_get('class.cart');
$classCart->update($params->productId, $params->quantity);

This adds the new product to the database and the right card id, however, it does not show the product in the cart the first time its loaded. Are there any events that will trigger before showing the cart products but after the shipping has been updated?

Last edit: 7 years 4 months ago by Rixters.

Please Log in or Create an account to join the conversation.

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
7 years 4 months ago #273711

Hello,

If you're developing for HikaShop 3.x ; please use the new cart function instead.

public function addProduct($cart_id, $products, $options = array())

Where $products is an array of "products".
$products = array(
  array('id' => $product_id, 'qty' => $product_quantity),
);
But you can simply put the product_id and the function will convert it into the internal format with the default 1 quantity.

Afterwards, depending the context of usage ; you might need to call some functions in order to clean the Checkout cache system. But we would need a lot of details about how you processing your tests (HikaShop configuration, etc).

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

Time to create page: 0.056 seconds
Powered by Kunena Forum