News:

Support the VirtueMart project and become a member

Main Menu

Notify and disable user from adding different items to the cart?

Started by mailblade, February 06, 2018, 16:17:26 PM

Previous topic - Next topic

mailblade

Latest VM
Joomla 3.6


I basically need to disable a user from adding a product to the cart, IF another product with a different "customfield_value" than the one already in the cart, tries to be added by the user.

Let's assume we have colour as a customfield.

If a product with "blue" as a colour is in the cart, the user can not add another colour to the cart until they remove the one in the cart. They can then add red, and only red if they wish to. It may sound dumb, but it is required for my VirtueMart since this customfield can not be mixed with other types.

templates/mytemplate/html/com_virtuemart/cart/default_pricelist.php

<div id="cartcolour">
<?php  foreach($prow->customfields as $customfields){
   
    
   if(
$customfields->virtuemart_custom_id==3){  
   
   echo ( 
$customfields->customfield_value);
  
// var_dump($customfields);
   
}
};
?>

</div>



templates/mytemplate/html/com_virtuemart/category/default.php

<div id="colour">
<?php  //this code gives me the value of "colour" for each product. It is within a "foreach" element.

$db JFactory::getDbo();

$query $db->getQuery(true);

$query->select($db->quoteName(array('customfield_value''virtuemart_product_id')));
$query->from($db->quoteName('jos_virtuemart_product_customfields'));
$query->where($db->quoteName('virtuemart_custom_id') . ' LIKE '$db->quote('3'). ' AND '$db->quoteName('virtuemart_product_id') . 'LIKE ' $db->quote($product->virtuemart_product_id));


$db->setQuery($query);

$results $db->loadResult();
echo (
$results); 
 
?>

</div>


Now, this is what I was thinking of doing:

<?php 
            
            $carts
VirtueMartCart::getCart();
            foreach(
$carts->cartProductsData as $cartItem)
    {
     if($cartItem[$customfields->virtuemart_custom_id['3'] != $product-virtuemart_custom_id['3'] ){
 
      echo "Only the colour".$cartItem->virtuemart_custom_id['3']."  may be added to the cart. Please remove the other item if you wish to add this item to the cart.";
 
    }
?>