The events catalog_product_type_prepare_full_options
and catalog_product_type_prepare_lite_options
1. create config /app/code/community/Magespy/Cart/etc/config.xml
<config>
<modules>
<Magespy_Cart>
<version>0.1.0</version>
</Magespy_Cart>
</modules>
<frontend>
<events>
<catalog_product_type_prepare_full_options>
<observers>
<magespy_cart_catalog_product_type_prepare>
<class>Magespy_Cart_Model_Observer</class>
<method>catalogProductTypePrepare</method>
</magespy_cart_catalog_product_type_prepare>
</observers>
</catalog_product_type_prepare_full_options>
</events>
</frontend>
</config>
2.Create observer /app/code/community/Magespy/Cart/Model/Observer.php
<?php
class Magespy_Cart_Model_Observer extends Varien_Object
{
public function catalogProductTypePrepare($observer)
{
$quote = Mage::getSingleton(‘checkout/session’)->getQuote();
if($quote->getItemsCount()>=1){
Mage::throwException(‘You can only buy one product at a time.’);
}
}
}
and catalog_product_type_prepare_lite_options
1. create config /app/code/community/Magespy/Cart/etc/config.xml
<config>
<modules>
<Magespy_Cart>
<version>0.1.0</version>
</Magespy_Cart>
</modules>
<frontend>
<events>
<catalog_product_type_prepare_full_options>
<observers>
<magespy_cart_catalog_product_type_prepare>
<class>Magespy_Cart_Model_Observer</class>
<method>catalogProductTypePrepare</method>
</magespy_cart_catalog_product_type_prepare>
</observers>
</catalog_product_type_prepare_full_options>
</events>
</frontend>
</config>
2.Create observer /app/code/community/Magespy/Cart/Model/Observer.php
<?php
class Magespy_Cart_Model_Observer extends Varien_Object
{
public function catalogProductTypePrepare($observer)
{
$quote = Mage::getSingleton(‘checkout/session’)->getQuote();
if($quote->getItemsCount()>=1){
Mage::throwException(‘You can only buy one product at a time.’);
}
}
}
I just tried this and I'm still able to add more than more item in my magento cart. I"m running V1.9.2.3
ReplyDeleteProvide us your mail address and store front url.
ReplyDelete