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

#   onAfterCartUpdate infinite loop

##

- **[Head](/forum/user/32682-head "View Head's Profile")**
- [![Head's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/32682-head "View Head's Profile") Topic Author
- [ Offline](/forum/user/32682-head)

Less More

- Posts: 18
- Thank you received: 2
-
-

11 years 5 months ago -  11 years 5 months ago [\#202335](#202335) by [Head](/forum/user/32682-head "View Head's Profile")  *[onAfterCartUpdate infinite loop](/forum/25-install-update/877082-onaftercartupdate-infinite-loop#202335 "-- HikaShop version -- : 2.3.4 -- Joomla version -- : 3.4.1 -- PHP version -- : 5.5.x  Hello,  this is probably very easy for you developers of Hikashop, but I'am stuck.  We've written a very simple Plugin to automaticaly add a product on after the cart gets updated, that creates an infinite loop :(  EDIT: Sorry for not setting the right forum category.")* was created by *[Head](/forum/user/32682-head "View Head's Profile")*

-- HikaShop version -- : 2.3.4
-- Joomla version -- : 3.4.1
-- PHP version -- : 5.5.x

Hello,

this is probably very easy for you developers of Hikashop, but I'am stuck.

We've written a very simple Plugin to automaticaly add a product on after the cart gets updated, that creates an infinite loop ![:(](/media/kunena/emoticons/5.png ":(")
Code:

public function onAfterCartUpdate(&amp;$cartClass,&amp;$cart,$product_id,$quantity,$add,$type,$resetCartWhenUpdate,$force){ //die(print_r($product_id)); //if( $product_id != '17962' ){ Does not work because $product_id is an Array, and the id is either the "real" product id, or the id from the table "hikashop_cart_product", which I do not know $c = $cartClass-&gt;loadFullCart(); if( count($c-&gt;products) ){ $sum = 0; foreach($c-&gt;products as $i =&gt; $product){ if( !empty($product-&gt;length) ){ // if product has custom field "length" $sum += $product-&gt;cart_product_quantity - 1; // that "- 1" is willed... } } $cartClass-&gt;update('17962', $sum); // infinite loop } //} }

EDIT: Sorry for not setting the right forum category.

Last edit: 11 years 5 months ago by [Head](/forum/user/32682-head "View Head's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI1LWluc3RhbGwtdXBkYXRlLzg3NzA4Mi1vbmFmdGVyY2FydHVwZGF0ZS1pbmZpbml0ZS1sb29wP3RtcGw9bWFya2Rvd24=) 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: 26394
- Thank you received: 4078
-
- [](http://obsi.dev)
-

11 years 5 months ago [\#202345](#202345) by [Jerome](/forum/user/80-jerome "View Jerome's Profile")  Replied by *[Jerome](/forum/user/80-jerome "View Jerome's Profile")* on topic *[onAfterCartUpdate infinite loop](/forum/25-install-update/877082-onaftercartupdate-infinite-loop#202345 "-- HikaShop version -- : 2.3.4 -- Joomla version -- : 3.4.1 -- PHP version -- : 5.5.x  Hello,  this is probably very easy for you developers of Hikashop, but I'am stuck.  We've written a very simple Plugin to automaticaly add a product on after the cart gets updated, that creates an infinite loop :(  EDIT: Sorry for not setting the right forum category.")*

Hi,

It will be better to use the "onBeforeCareUpdate" in order to be able to modify the quantity dynamically before the cart is updated in the database.

Regards,

---

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

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI1LWluc3RhbGwtdXBkYXRlLzg3NzA4Mi1vbmFmdGVyY2FydHVwZGF0ZS1pbmZpbml0ZS1sb29wP3RtcGw9bWFya2Rvd24=) 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.115 seconds

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

[](#top)
