Created
June 25, 2019 05:55
-
-
Save ZusZus/d68943de1e0b0def488bddcdf4ada4c9 to your computer and use it in GitHub Desktop.
How to do selected single product should be purchase alone?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<config> | |
<modules> | |
<Brst_Test> | |
<version>1.0.0.0</version> | |
</Brst_Test> | |
</modules> | |
<global> | |
<models> | |
<brst_test> | |
<class>Brst_Test_Model</class> | |
</brst_test> | |
</models> | |
</global> | |
<frontend> | |
<events> | |
<controller_action_predispatch_checkout_cart_add> | |
<observers> | |
<brst_test_log_cart_add> | |
<class>brst_test/observer</class> | |
<method>logCartAdd</method> | |
</brst_test_log_cart_add> | |
</observers> | |
</controller_action_predispatch_checkout_cart_add> | |
</events> | |
</frontend> | |
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
Mage::log('Hy observer called', null, 'logfile.log'); | |
class Brst_Test_Model_Observer | |
{ | |
//Put any event as per your requirement | |
public function logCartAdd() { | |
$product = Mage::getModel('catalog/product') | |
->load(Mage::app()->getRequest()->getParam('product', 0)); | |
$cart_qty = (int) Mage::getModel('checkout/cart')->getQuote()->getItemsQty(); | |
if ($product->getId()==31588 && cart_qty > 0) { | |
Mage::throwException("You can not add This special Product, empty cart before add it"); | |
} | |
// $quote = Mage::getSingleton('checkout/session')->getQuote(); | |
// if ($quote->hasProductId(2)) { | |
// Mage::getSingleton("core/session")->addError("Cart has Special Product you can not add another"); | |
// return; | |
// } | |
$quote = Mage::getModel('checkout/cart')->getQuote(); | |
foreach ($quote->getAllItems() as $item) { | |
$productId = $item->getProductId(); | |
if($productId==2){ | |
Mage::throwException("Cart has Special Product you can not add another"); | |
} | |
} | |
} | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<config> | |
<modules> | |
<Brst_Test> | |
<active>true</active> | |
<codePool>community</codePool> | |
</Brst_Test> | |
</modules> | |
</config> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment