- Posts: 202
- Thank you received: 2
Force a shopper to pick a product from a category
15 years 7 months ago #9623
by momentis
Force a shopper to pick a product from a category was created by momentis
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 or Create an account to join the conversation.
15 years 7 months ago #9629
by nicolas
Replied by nicolas on topic Re: Force a shopper to pick a product from a category
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 or Create an account to join the conversation.
15 years 5 months ago #14597
by momentis
Replied by momentis on topic Re: Force a shopper to pick a product from a category
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?
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 or Create an account to join the conversation.
15 years 5 months ago #14602
by momentis
Replied by momentis on topic Re: Force a shopper to pick a product from a category
I am going to add this to the front-end Checkout->Step view. What I was thinking was to include something like the following:
if($this->step=0) {
TEST IF CATEGORY ID 24 IS IN CART
If not, do not display the NEXT button
}
If it is
{echo $this->cart->displayButton(JText::_('Back'),'back',$this->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!!!
if($this->step=0) {
TEST IF CATEGORY ID 24 IS IN CART
If not, do not display the NEXT button
}
If it is
{echo $this->cart->displayButton(JText::_('Back'),'back',$this->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 or Create an account to join the conversation.
15 years 5 months ago #14606
by momentis
Replied by momentis on topic Re: Force a shopper to pick a product from a category
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 or Create an account to join the conversation.
15 years 5 months ago #14607
by nicolas
Replied by nicolas on topic Re: Force a shopper to pick a product from a category
Not tested:
Code:
$ids=array();
foreach($this->rows as $i => $row){
$ids[]=(int)$row->product_id;
}
$db =& JFactory::getDBO();
$db->setQuery('SELECT category_id FROM '.hikashop::table('product_category').' WHERE product_id IN ('.implode(',',$ids).') AND category_id=24');
$result = $db->loadResult();
if(!empty($result)){
//category is there
}else{
//category not in the cart
}
Please Log in or Create an account to join the conversation.
15 years 5 months ago #14608
by momentis
Replied by momentis on topic Re: Force a shopper to pick a product from a category
Thanks!!
Please Log in or Create an account to join the conversation.
15 years 5 months ago #14615
by momentis
Replied by momentis on topic Re: Force a shopper to pick a product from a category
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:
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:
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:
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?
Code:
if($this->step==3){
echo $this->cart->displayButton(JText::_('PLACE_ORDER_BUTTON'),'next',$this->params,hikashop::completeLink('checkout&task=step&step='.$this->step+1),'document.forms[\'hikashop_checkout_form\'].submit(); return false; ','id="hikashop_checkout_next_button"');
}else{
echo $this->cart->displayButton(JText::_('NEXT'),'next',$this->params,hikashop::completeLink('checkout&task=step&step='.$this->step+1),'document.forms[\'hikashop_checkout_form\'].submit(); return false;','id="hikashop_checkout_next_button"');
}
if($this->step!=0){
echo $this->cart->displayButton(JText::_('Back'),'back',$this->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->step=0){
$ids=array();
foreach($this->rows as $i => $row){
$ids[]=(int)$row->product_id;
}
$db =& JFactory::getDBO();
$db->setQuery('SELECT category_id FROM '.hikashop::table('product_category').' WHERE product_id IN ('.implode(',',$ids).') AND category_id=24');
$result = $db->loadResult();
if(!empty($result)){
if($this->step==3){
echo $this->cart->displayButton(JText::_('PLACE_ORDER_BUTTON'),'next',$this->params,hikashop::completeLink('checkout&task=step&step='.$this->step+1),'document.forms[\'hikashop_checkout_form\'].submit(); return false; ','id="hikashop_checkout_next_button"');
}else{
echo $this->cart->displayButton(JText::_('NEXT'),'next',$this->params,hikashop::completeLink('checkout&task=step&step='.$this->step+1),'document.forms[\'hikashop_checkout_form\'].submit(); return false;','id="hikashop_checkout_next_button"');
}
if($this->step!=1){
echo $this->cart->displayButton(JText::_('Back'),'back',$this->params,hikashop::currentUrl(),'history.back();return false;','id="hikashop_checkout_next_button"');
}
}else{
echo '<div style="float: right; text-align: right; color: #ff0000; font-weight: bold;">'.JText::_('REQD_CAT_MISSING','Cart must include a Paper Stock').'</div>';
}
}
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->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 or Create an account to join the conversation.
15 years 5 months ago #14618
by nicolas
Replied by nicolas on topic Re: Force a shopper to pick a product from a category
$this->step=1 is always true. You wanted to write $this->step==1 or $this->step!=1
Please Log in or Create an account to join the conversation.
15 years 5 months ago #14619
by momentis
Replied by momentis on topic Re: Force a shopper to pick a product from a category
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 or Create an account to join the conversation.
15 years 5 months ago #14620
by momentis
Replied by momentis on topic Re: Force a shopper to pick a product from a category
Done, and working GREAT!!
Please Log in or Create an account to join the conversation.
Time to create page: 0.269 seconds