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

#   Force a shopper to pick a product from a category

##

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

Less More

- Posts: 202
- Thank you received: 2
-
-

15 years 8 months ago [\#9623](#9623) by [momentis](/forum/user/364-momentis "View momentis's Profile")  *[Force a shopper to pick a product from a category](/forum/4-how-to/9623-force-a-shopper-to-pick-a-product-from-a-category#9623 "I want to have a category in my store that every shopper MUST select a product from before submitting their cart. Is there a way to do this that you know of?")* was created by *[momentis](/forum/user/364-momentis "View momentis's Profile")*

I want to have a category in my store that every shopper MUST select a product from before submitting their cart. Is there a way to do this that you know of?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzk2MjMtZm9yY2UtYS1zaG9wcGVyLXRvLXBpY2stYS1wcm9kdWN0LWZyb20tYS1jYXRlZ29yeT90bXBsPW1hcmtkb3du) 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?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86561
- Thank you received: 14307
-
-

15 years 8 months ago [\#9629](#9629) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Re: Force a shopper to pick a product from a category](/forum/4-how-to/9623-force-a-shopper-to-pick-a-product-from-a-category#9629 "I want to have a category in my store that every shopper MUST select a product from before submitting their cart. Is there a way to do this that you know of?")*

You will have to edit one of the views (a checkout view or the cart file of the view product) to not display the "proceed to checkout" or "next" button when a product from that category is not in the cart and display an error message.

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

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

Less More

- Posts: 202
- Thank you received: 2
-
-

15 years 6 months ago [\#14597](#14597) by [momentis](/forum/user/364-momentis "View momentis's Profile")  Replied by *[momentis](/forum/user/364-momentis "View momentis's Profile")* on topic *[Re: Force a shopper to pick a product from a category](/forum/4-how-to/9623-force-a-shopper-to-pick-a-product-from-a-category#14597 "I want to have a category in my store that every shopper MUST select a product from before submitting their cart. Is there a way to do this that you know of?")*

nicolas,

I am ready to implement this. Assuming I have one category in particular I want to force, what would I use to find whether that particular category is in the cart?

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

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

Less More

- Posts: 202
- Thank you received: 2
-
-

15 years 6 months ago [\#14602](#14602) by [momentis](/forum/user/364-momentis "View momentis's Profile")  Replied by *[momentis](/forum/user/364-momentis "View momentis's Profile")* on topic *[Re: Force a shopper to pick a product from a category](/forum/4-how-to/9623-force-a-shopper-to-pick-a-product-from-a-category#14602 "I want to have a category in my store that every shopper MUST select a product from before submitting their cart. Is there a way to do this that you know of?")*

I am going to add this to the front-end Checkout-&gt;Step view. What I was thinking was to include something like the following:

if($this-&gt;step=0) {

TEST IF CATEGORY ID 24 IS IN CART

If not, do not display the NEXT button

}

If it is

{echo $this-&gt;cart-&gt;displayButton(JText::_('Back'),'back',$this-&gt;params,hikashop::currentUrl(),'history.back();return false;','id="hikashop_checkout_next_button"');
}

I can get the IF's correct, if I just know what to use to see if that category exists in the cart.

I hope I am making sense!!!

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

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

Less More

- Posts: 202
- Thank you received: 2
-
-

15 years 6 months ago [\#14606](#14606) by [momentis](/forum/user/364-momentis "View momentis's Profile")  Replied by *[momentis](/forum/user/364-momentis "View momentis's Profile")* on topic *[Re: Force a shopper to pick a product from a category](/forum/4-how-to/9623-force-a-shopper-to-pick-a-product-from-a-category#14606 "I want to have a category in my store that every shopper MUST select a product from before submitting their cart. Is there a way to do this that you know of?")*

Thinking about this, the ideal situation would be to have the check performed on the "Proceed to Checkout" function, with a pop-up message indicating the need to add a product from this category to the cart, then redirecting to that category instead of the checkout.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzk2MjMtZm9yY2UtYS1zaG9wcGVyLXRvLXBpY2stYS1wcm9kdWN0LWZyb20tYS1jYXRlZ29yeT90bXBsPW1hcmtkb3du) 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?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86561
- Thank you received: 14307
-
-

15 years 6 months ago [\#14607](#14607) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Re: Force a shopper to pick a product from a category](/forum/4-how-to/9623-force-a-shopper-to-pick-a-product-from-a-category#14607 "I want to have a category in my store that every shopper MUST select a product from before submitting their cart. Is there a way to do this that you know of?")*

Not tested: Code:

$ids=array(); foreach($this-&gt;rows as $i =&gt; $row){ $ids[]=(int)$row-&gt;product_id; } $db =&amp; JFactory::getDBO(); $db-&gt;setQuery('SELECT category_id FROM '.hikashop::table('product_category').' WHERE product_id IN ('.implode(',',$ids).') AND category_id=24'); $result = $db-&gt;loadResult(); if(!empty($result)){ //category is there }else{ //category not in the cart }

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

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

Less More

- Posts: 202
- Thank you received: 2
-
-

15 years 6 months ago [\#14608](#14608) by [momentis](/forum/user/364-momentis "View momentis's Profile")  Replied by *[momentis](/forum/user/364-momentis "View momentis's Profile")* on topic *[Re: Force a shopper to pick a product from a category](/forum/4-how-to/9623-force-a-shopper-to-pick-a-product-from-a-category#14608 "I want to have a category in my store that every shopper MUST select a product from before submitting their cart. Is there a way to do this that you know of?")*

Thanks!!

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

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

Less More

- Posts: 202
- Thank you received: 2
-
-

15 years 6 months ago [\#14615](#14615) by [momentis](/forum/user/364-momentis "View momentis's Profile")  Replied by *[momentis](/forum/user/364-momentis "View momentis's Profile")* on topic *[Re: Force a shopper to pick a product from a category](/forum/4-how-to/9623-force-a-shopper-to-pick-a-product-from-a-category#14615 "I want to have a category in my store that every shopper MUST select a product from before submitting their cart. Is there a way to do this that you know of?")*

The code you sent works PERFECTLY! I am having a small issue with the Step number. Before the changes you sent me, the area of step.php I am changing looked like this:
Code:

if($this-&gt;step==3){ echo $this-&gt;cart-&gt;displayButton(JText::_('PLACE_ORDER_BUTTON'),'next',$this-&gt;params,hikashop::completeLink('checkout&amp;task=step&amp;step='.$this-&gt;step+1),'document.forms[\'hikashop_checkout_form\'].submit(); return false; ','id="hikashop_checkout_next_button"'); }else{ echo $this-&gt;cart-&gt;displayButton(JText::_('NEXT'),'next',$this-&gt;params,hikashop::completeLink('checkout&amp;task=step&amp;step='.$this-&gt;step+1),'document.forms[\'hikashop_checkout_form\'].submit(); return false;','id="hikashop_checkout_next_button"'); } if($this-&gt;step!=0){ echo $this-&gt;cart-&gt;displayButton(JText::_('Back'),'back',$this-&gt;params,hikashop::currentUrl(),'history.back();return false;','id="hikashop_checkout_next_button"'); }

I had it like that so that it would display a BACK button on all steps except the first (#0), and the NEXT button would be replaced with PLACE ORDER in the last step (#3).

I changed this section of code to:
Code:

if($this-&gt;step=0){ $ids=array(); foreach($this-&gt;rows as $i =&gt; $row){ $ids[]=(int)$row-&gt;product_id; } $db =&amp; JFactory::getDBO(); $db-&gt;setQuery('SELECT category_id FROM '.hikashop::table('product_category').' WHERE product_id IN ('.implode(',',$ids).') AND category_id=24'); $result = $db-&gt;loadResult(); if(!empty($result)){ if($this-&gt;step==3){ echo $this-&gt;cart-&gt;displayButton(JText::_('PLACE_ORDER_BUTTON'),'next',$this-&gt;params,hikashop::completeLink('checkout&amp;task=step&amp;step='.$this-&gt;step+1),'document.forms[\'hikashop_checkout_form\'].submit(); return false; ','id="hikashop_checkout_next_button"'); }else{ echo $this-&gt;cart-&gt;displayButton(JText::_('NEXT'),'next',$this-&gt;params,hikashop::completeLink('checkout&amp;task=step&amp;step='.$this-&gt;step+1),'document.forms[\'hikashop_checkout_form\'].submit(); return false;','id="hikashop_checkout_next_button"'); } if($this-&gt;step!=1){ echo $this-&gt;cart-&gt;displayButton(JText::_('Back'),'back',$this-&gt;params,hikashop::currentUrl(),'history.back();return false;','id="hikashop_checkout_next_button"'); } }else{ echo '&lt;div style="float: right; text-align: right; color: #ff0000; font-weight: bold;"&gt;'.JText::_('REQD_CAT_MISSING','Cart must include a Paper Stock').'&lt;/div&gt;'; } }

I have the first IF looking to see if the checkout step is the first (#0). However, nothing displays at the bottom of the page in this case. Not the NEXT button or the text I want to display. If I change the first IF to:
Code:

if($this-&gt;step=1){

then it displays correctly on the first step in the checkout process, and works absolutely correctly. However, clicking NEXT causes an error on the nest step, because it is evaluating the IF statement again as step #1. It's like I somehow messed with the step numbers. Any idea why?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzk2MjMtZm9yY2UtYS1zaG9wcGVyLXRvLXBpY2stYS1wcm9kdWN0LWZyb20tYS1jYXRlZ29yeT90bXBsPW1hcmtkb3du) 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?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86561
- Thank you received: 14307
-
-

15 years 6 months ago [\#14618](#14618) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Re: Force a shopper to pick a product from a category](/forum/4-how-to/9623-force-a-shopper-to-pick-a-product-from-a-category#14618 "I want to have a category in my store that every shopper MUST select a product from before submitting their cart. Is there a way to do this that you know of?")*

$this-&gt;step=1 is always true. You wanted to write $this-&gt;step==1 or $this-&gt;step!=1

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

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

Less More

- Posts: 202
- Thank you received: 2
-
-

15 years 6 months ago [\#14619](#14619) by [momentis](/forum/user/364-momentis "View momentis's Profile")  Replied by *[momentis](/forum/user/364-momentis "View momentis's Profile")* on topic *[Re: Force a shopper to pick a product from a category](/forum/4-how-to/9623-force-a-shopper-to-pick-a-product-from-a-category#14619 "I want to have a category in my store that every shopper MUST select a product from before submitting their cart. Is there a way to do this that you know of?")*

Darn it - I saw that as I read through my post! I just couldn't get back on here quick enough!!! Sorry, and thanks!

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

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

Less More

- Posts: 202
- Thank you received: 2
-
-

15 years 6 months ago [\#14620](#14620) by [momentis](/forum/user/364-momentis "View momentis's Profile")  Replied by *[momentis](/forum/user/364-momentis "View momentis's Profile")* on topic *[Re: Force a shopper to pick a product from a category](/forum/4-how-to/9623-force-a-shopper-to-pick-a-product-from-a-category#14620 "I want to have a category in my store that every shopper MUST select a product from before submitting their cart. Is there a way to do this that you know of?")*

Done, and working GREAT!!

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

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