As the title says. I need to be able to disable adding to cart if a product sku or shipping type already exists in the cart. Any way this can be done?
Created checkout_stop.xml
in app/etc/modules with below code
<?xml version="1.0"?>
<config>
<modules>
<Checkout_Stop>
<codePool>local</codePool>
<active>true</active>
</Checkout_Stop>
</modules>
</config>
Created config.xml
in app/code/local/Checkout/Stop/etc with below code
<?xml version="1.0"?>
<config>
<modules>
<Checkout_Stop>
<version>0.1.0</version>
</Checkout_Stop>
</modules>
<global>
<models>
<checkout_stop>
<class>checkout_stop_Model</class>
</checkout_stop>
</models>
<events>
<checkout_cart_product_add_after>
<observers>
<checkout_stop_Model_Observer>
<type>singleton</type>
<class>checkout_stop_Model_Observer</class>
<method>addtocartEvent</method>
</checkout_stop_Model_Observer>
</observers>
</checkout_cart_product_add_after>
<review_save_before>
<observers>
<checkout_stop_Model_Observer>
<type>singleton</type>
<class>checkout_stop_Model_Observer</class>
<method>autoApproveReview</method>
</checkout_stop_Model_Observer>
</observers>
</review_save_before>
</events>
</global>
</config>
Created Observer.php
in app/code/local/Checkout/Stop/Model with below code
<?php
$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
foreach ($items as $item){
if ($item->getSku() == 'shoes1001'){
Mage::throwException(Mage::helper('checkout')->__('You cannot add that product to your cart');
}
}
?>