set different carts for different product cat...

  • Posts: 251
  • Thank you received: 2
13 years 7 months ago #13256

It is possible to set different carts for different product categories and therefore be able to buy only products from that specific category?

Please Log in or Create an account to join the conversation.

  • Posts: 82864
  • Thank you received: 13372
  • MODERATOR
13 years 7 months ago #13277

There is no such option but could you explain a bit more what you're trying to do ?

Please Log in or Create an account to join the conversation.

  • Posts: 251
  • Thank you received: 2
13 years 7 months ago #13282

OK, I try to explain.
I have Products A in Category A and Product B in Category B.
If I'm buying Product A I can't buy Product B in the same order, but first I have to complete the order of Product A of Category A and then I will be able to buy Product B.

Please Log in or Create an account to join the conversation.

  • Posts: 82864
  • Thank you received: 13372
  • MODERATOR
13 years 7 months ago #13295

It's not possible with an option but if you change a bit the code of the file show of the view product, you could load the categories of the products in the cart and only display the add to cart button when the category of the current product is the same as the products in the cart.

Please Log in or Create an account to join the conversation.

  • Posts: 251
  • Thank you received: 2
13 years 7 months ago #13300

Uhmmm... Ok! I think I've understood! I'm going to study the code, but... if you want to post an example it would be wonderful.

You're great! ;)
Anyway, thank you so much!

Please Log in or Create an account to join the conversation.

  • Posts: 82864
  • Thank you received: 13372
  • MODERATOR
13 years 7 months ago #13326

Something like that (not tested):

$cart = hikashop::get('class.cart');
$products = $cart->get();
if(!empty($products)){
 $ids = array();
 foreach($products as $k => $row){
  $ids[]=$row->product_id;
 }
 $db =& JFactory::getDBO();
 $db->setQuery('SELECT category_id FROM '.hikashop::table('product_category').' WHERE product_id ='.$this->element->category_id);
 $current_category_id = $db->loadResult();
 $db->setQuery('SELECT category_id FROM '.hikashop::table('product_category').' WHERE product_id IN ('.implode(',',$ids).')');
 $category_id = $db->loadResult();
 if($category_id==$current_category_id){
   //display add to cart
 }
}

Please Log in or Create an account to join the conversation.

  • Posts: 251
  • Thank you received: 2
13 years 7 months ago #13419

Thank you Nicolas

Please Log in or Create an account to join the conversation.

Time to create page: 0.065 seconds
Powered by Kunena Forum