Thank you for your reply Nicolas,
I have managed to write some code that gives the functionality that i want and added the code to quantity.php as you instructed.
global $Itemid;
$database = JFactory::getDBO();
$url_itemid = '';
$app = JFactory::getApplication();
$class = hikashop_get('class.cart');
$cart_type = 'cart';
$cart_id =$app->getUserState( HIKASHOP_COMPONENT.'.'.$cart_type.'_id', 0, 'int' );
$class->get($cart_id,true,$cart_type);
$full = $class->loadFullCart(true,true,true);
$rows = $full->products;
$cat= array();
$cart_cat = array();
$found=false;
foreach ($this->categories as $category){
array_push($cat, $category->category_id); //categories of the current product
}
var_dump($this->categories);
foreach($rows as $row){
$query = 'SELECT b.category_id FROM '.hikashop_table('product_category').' AS a LEFT JOIN '.hikashop_table('category').' AS b ON a.category_id = b.category_id WHERE a.product_id = '.(int)$row->product_id.' ORDER BY a.product_category_id ASC';
$database->setQuery($query);
$categories = $database->loadObjectList();
$this->assignRef('categories',$categories);//categories of the products that are already in cart
foreach ($categories as $category){
if (in_array($category->category_id, $cat)){ //if there is a product in the cart with same category as the current product
$found=true;
break;
}
}
if ($found){
break;
}
}
if ($found){
echo 'hide add to cart';
}
else{
echo ' show add to cart';
}
I have created categories for my products and at version 1 of the code i check the categories of the products at the cart and if the current product has the same category i hide the add to cart button.
I have 2 problems.
First one is that when i add a product to the cart from a product listing and then i press continue shopping(thats what i want the user to able to do) the page does not refresh so my code is not run.
Secondly the var_dump($this->categories); always return null for the first product in product listing but if i enter the product view of the said product it displays my array correctly. It is always null for the first product in product listing. Where is the error in my logic?