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

#   How to use do parameter of onBeforeCartUpdate ?

##

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

Less More

- Posts: 64
- Thank you received: 0
-
-

13 years 3 months ago -  13 years 3 months ago [\#112361](#112361) by [irfanhanfi](/forum/user/23811-irfanhanfi "View irfanhanfi's Profile")  *[How to use do parameter of onBeforeCartUpdate ?](/forum/2-general-talk-about-hikashop/84622-how-to-use-do-parameter-of-onbeforecartupdate#112361 "I am using onBeforeCartUpdate to check that if product meets some condition than max quantity should be one.So now I am doing this.  Now the problem is, if I set quantity more than one in cart module it works fine.but if quantity is set more than one from checkout page and after clicking on update(refresh) button it goes to thank you page.")* was created by *[irfanhanfi](/forum/user/23811-irfanhanfi "View irfanhanfi's Profile")*

I am using onBeforeCartUpdate to check that if product meets some condition than max quantity should be one.So now I am doing this.
Code:

function onBeforeCartUpdate($class, &amp;$cart, $product_id, $quantity, $add, $type,$resetCartWhenUpdate,$force,&amp;$do){ $isPro = Helper::isMyProduct($product_id); if($isPro){ if($quantity&gt;1){ $do = false; } } }

Now the problem is, if I set quantity more than one in cart module it works fine.but if quantity is set more than one from checkout page and after clicking on update(refresh) button it goes to thank you page.

Last edit: 13 years 3 months ago by [irfanhanfi](/forum/user/23811-irfanhanfi "View irfanhanfi's Profile").

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

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86289
- Thank you received: 14265
-
-

13 years 3 months ago [\#112427](#112427) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[How to use do parameter of onBeforeCartUpdate ?](/forum/2-general-talk-about-hikashop/84622-how-to-use-do-parameter-of-onbeforecartupdate#112427 "I am using onBeforeCartUpdate to check that if product meets some condition than max quantity should be one.So now I am doing this.  Now the problem is, if I set quantity more than one in cart module it works fine.but if quantity is set more than one from checkout page and after clicking on update(refresh) button it goes to thank you page.")*

Hi,

the format of the data is different on the checkout as all the products are updated at the same time.
So you actually have in $product_id an array of cart_product_id=&gt;new quantity.
Simply do a vardump of $product_id and you will see what I mean.

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

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

Less More

- Posts: 64
- Thank you received: 0
-
-

13 years 3 months ago [\#112435](#112435) by [irfanhanfi](/forum/user/23811-irfanhanfi "View irfanhanfi's Profile")  Replied by *[irfanhanfi](/forum/user/23811-irfanhanfi "View irfanhanfi's Profile")* on topic *[How to use do parameter of onBeforeCartUpdate ?](/forum/2-general-talk-about-hikashop/84622-how-to-use-do-parameter-of-onbeforecartupdate#112435 "I am using onBeforeCartUpdate to check that if product meets some condition than max quantity should be one.So now I am doing this.  Now the problem is, if I set quantity more than one in cart module it works fine.but if quantity is set more than one from checkout page and after clicking on update(refresh) button it goes to thank you page.")*

This is what I have done.
Code:

function onBeforeCartUpdate($class, &amp;$cart, $product_id, $quantity, $add, $type,$resetCartWhenUpdate,$force,&amp;$do){ $msg= 'msg'; $user = JFactory::getUser(); $userId = $user-&gt;get('id'); if($type=='product'){ $myProduct = Helper::isMyProduct($product_id); if($myProduct){ if($quantity&gt;1){ $do = false; JFactory::getApplication()-&gt;enqueueMessage($msg, 'error'); } } }elseif($type=='item'){ //Array([37] =&gt; Array([cart_product_quantity] =&gt; 2))//via cart module //Array([37] =&gt; 2)//checkout foreach($product_id as $carProdId=&gt;$detail){ $prod_id = $this-&gt;getProductId($carProdId); if(is_array($detail)){ $qnty = $detail['cart_product_quantity']; }else{ $qnty = $detail; } $myProduct = Helper::isMyProduct($prod_id); if($myProduct){ if($qnty&gt;1){ $do = false; JFactory::getApplication()-&gt;enqueueMessage($msg, 'error'); } } } } return true; }

The problem is, if quantity is changed in checkout page and if condition goes $do=false it takes to thank you page but works for cart module.
Thanks for your help.

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

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86289
- Thank you received: 14265
-
-

13 years 3 months ago [\#112439](#112439) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[How to use do parameter of onBeforeCartUpdate ?](/forum/2-general-talk-about-hikashop/84622-how-to-use-do-parameter-of-onbeforecartupdate#112439 "I am using onBeforeCartUpdate to check that if product meets some condition than max quantity should be one.So now I am doing this.  Now the problem is, if I set quantity more than one in cart module it works fine.but if quantity is set more than one from checkout page and after clicking on update(refresh) button it goes to thank you page.")*

Yes, if you do a $do=false in the onBeforeCartUpdate trigger, it means that you don't want the cart to be updated.
And on the checkout, when the cart is not updated on a step, it goes to the next step automatically.

Instead of the trigger onBeforeCartUpdate, I would recommend to implement onAfterProductQuantityCheck(&amp;$product, &amp;$wantedQuantity,&amp;$quantity, &amp;$cartContent, &amp;$cart_product_id_for_product, &amp;$displayErrors)

Instead of allowing you to cancel the cart update, it allows you to modify the $quantity variable that will be updated for one product.
You get the new quantity requested by the user in $wantedQuantity.
And the format of the variables is the same regardless if you add a product to the cart or modify the quantities in the checkout.

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

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

Less More

- Posts: 64
- Thank you received: 0
-
-

13 years 3 months ago -  13 years 3 months ago [\#112444](#112444) by [irfanhanfi](/forum/user/23811-irfanhanfi "View irfanhanfi's Profile")  Replied by *[irfanhanfi](/forum/user/23811-irfanhanfi "View irfanhanfi's Profile")* on topic *[How to use do parameter of onBeforeCartUpdate ?](/forum/2-general-talk-about-hikashop/84622-how-to-use-do-parameter-of-onbeforecartupdate#112444 "I am using onBeforeCartUpdate to check that if product meets some condition than max quantity should be one.So now I am doing this.  Now the problem is, if I set quantity more than one in cart module it works fine.but if quantity is set more than one from checkout page and after clicking on update(refresh) button it goes to thank you page.")*

I used **onAfterProductQuantityCheck** event but this did not fire.I have used it similar to **onBeforeCartUpdate** event.

Thanks.

Last edit: 13 years 3 months ago by [irfanhanfi](/forum/user/23811-irfanhanfi "View irfanhanfi's Profile").

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

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86289
- Thank you received: 14265
-
-

13 years 3 months ago [\#112449](#112449) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[How to use do parameter of onBeforeCartUpdate ?](/forum/2-general-talk-about-hikashop/84622-how-to-use-do-parameter-of-onbeforecartupdate#112449 "I am using onBeforeCartUpdate to check that if product meets some condition than max quantity should be one.So now I am doing this.  Now the problem is, if I set quantity more than one in cart module it works fine.but if quantity is set more than one from checkout page and after clicking on update(refresh) button it goes to thank you page.")*

Then you probably have an old version of HikaShop where that event doesn't exist.
It is triggered by the line:
$dispatcher-&gt;trigger('onAfterProductQuantityCheck', array(&amp;$product, &amp;$wantedQuantity,&amp;$quantity, &amp;$cartContent, &amp;$cart_product_id_for_product, &amp;$displayErrors) );

in the file administrator/components/com_hikashop/classes/cart.php

If you don't have it, then it means that you don't have the latest version of HikaShop.

The following user(s) said Thank You: [irfanhanfi](/forum/user/23811-irfanhanfi "View irfanhanfi's Profile")

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

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

Less More

- Posts: 64
- Thank you received: 0
-
-

13 years 3 weeks ago [\#126095](#126095) by [irfanhanfi](/forum/user/23811-irfanhanfi "View irfanhanfi's Profile")  Replied by *[irfanhanfi](/forum/user/23811-irfanhanfi "View irfanhanfi's Profile")* on topic *[How to use do parameter of onBeforeCartUpdate ?](/forum/2-general-talk-about-hikashop/84622-how-to-use-do-parameter-of-onbeforecartupdate#126095 "I am using onBeforeCartUpdate to check that if product meets some condition than max quantity should be one.So now I am doing this.  Now the problem is, if I set quantity more than one in cart module it works fine.but if quantity is set more than one from checkout page and after clicking on update(refresh) button it goes to thank you page.")*

I have some custom validation for cart.I want that user must not go to next step until he enters all the information.Is it possible to stop user from moving into the next step until all conditions are fulfilled in previous step? Is there any event that I can use for validation?

Thanks,

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

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86289
- Thank you received: 14265
-
-

13 years 3 weeks ago [\#126117](#126117) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[How to use do parameter of onBeforeCartUpdate ?](/forum/2-general-talk-about-hikashop/84622-how-to-use-do-parameter-of-onbeforecartupdate#126117 "I am using onBeforeCartUpdate to check that if product meets some condition than max quantity should be one.So now I am doing this.  Now the problem is, if I set quantity more than one in cart module it works fine.but if quantity is set more than one from checkout page and after clicking on update(refresh) button it goes to thank you page.")*

With the latest version of Hikashop, you now have the possibility to add custom views on the checkout with the trigger onCheckoutStepList and then you can plug yourself on the controller of the checkout with the onAfterCheckoutStep trigger which will be called when the user click on the next button of the step where your view is on your checkout workflow.
There is no documentation yet for these triggers on our website as they are brand new, but it will allow you to do what you want.

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

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

[](#top)
