[Skip to main content](#vessel-content)

#   Cart update triggers after a second page reload

##

- **[Rixters](/forum/user/28762-rixters "View Rixters's Profile")**
- [![Rixters's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar28762.jpg)](/forum/user/28762-rixters "View Rixters's Profile") Topic Author
- [ Offline](/forum/user/28762-rixters)

Less More

- Posts: 209
- Thank you received: 14
-
-
-
- [](http://www.r2h.nl)
-

9 years 4 months ago -  9 years 4 months ago [\#273709](#273709) by [Rixters](/forum/user/28762-rixters "View Rixters's Profile")  *[Cart update triggers after a second page reload](/forum/31-development/891086-cart-update-triggers-after-a-second-page-reload#273709 "-- HikaShop version -- : 3.1.1 &#91;1707101222&#93; 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 &quot;onAfterCartShippingLoad&quot; 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&#95;get('class.cart'); $classCart-&gt;update($params-&gt;productId, $params-&gt;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?")* was created by *[Rixters](/forum/user/28762-rixters "View Rixters's Profile")*

-- 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-&gt;update($params-&gt;productId, $params-&gt;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: 9 years 4 months ago by [Rixters](/forum/user/28762-rixters "View Rixters's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg5MTA4Ni1jYXJ0LXVwZGF0ZS10cmlnZ2Vycy1hZnRlci1hLXNlY29uZC1wYWdlLXJlbG9hZD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Jerome](/forum/user/80-jerome "View Jerome's Profile")**
- [![Jerome's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar80.png)](/forum/user/80-jerome "View Jerome's Profile")
- [ Offline](/forum/user/80-jerome)
- HikaShop core developer

Less More

- Posts: 26400
- Thank you received: 4079
-
- [](http://obsi.dev)
-

9 years 4 months ago [\#273711](#273711) by [Jerome](/forum/user/80-jerome "View Jerome's Profile")  Replied by *[Jerome](/forum/user/80-jerome "View Jerome's Profile")* on topic *[Cart update triggers after a second page reload](/forum/31-development/891086-cart-update-triggers-after-a-second-page-reload#273711 "-- HikaShop version -- : 3.1.1 &#91;1707101222&#93; 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 &quot;onAfterCartShippingLoad&quot; 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&#95;get('class.cart'); $classCart-&gt;update($params-&gt;productId, $params-&gt;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?")*

Hello,

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

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

Where $products is an array of "products". Code:

$products = array( array('id' =&gt; $product_id, 'qty' =&gt; $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 &amp; HikaSerial developer / HikaShop core dev team.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg5MTA4Ni1jYXJ0LXVwZGF0ZS10cmlnZ2Vycy1hZnRlci1hLXNlY29uZC1wYWdlLXJlbG9hZD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.047 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
