How to add condition in add-to-cart button function? Magento 1.9How to do selected single product should be purchase alone?PHP else: statements in addtocart.phtml - Adding conditions to the Add To Cart button on product pageMagento 2 add to cart button validationCustomise “add to cart” buttonHow to exclude products being added to cart based on products attributes?How can I get the product details (like SKU) on JS when “Add to Cart” button is clicked?How can i give condition Shopping Cart Price Rules like if selected attribute products present in the cart, no other products allowed to add cartHow can i show USPS Media Mail Only For Books not for other Products?Change add to cart button based on customer groupHow to customize Add to cart functionality based on product categories in Magento 2?How to do selected single product should be purchase alone?

How can I smooth the top side of this ring?

What is the meaning of "it" in "as luck would have it"?

Is there a connection between representation theory and PDEs?

Reaction mechanism of rearrangement

Existence of infinite set of positive integers s.t sum of reciprocals is rational and set of primes dividing an element is infinite

Advantages of using bra-ket notation

Sentences with no verb, but an ablative

What prevents a US state from colonizing a smaller state?

SQL Server Ignoring Instance name when using port number of different instance

GFCI versus circuit breaker

Finding an optimal set without forbidden subsets

Can combing bent evaporator coil fins damage it?

Why is my 401k manager recommending me to save more?

Odd PCB Layout for Voltage Regulator

Wings for orbital transfer bioships?

Is it OK to say "The situation is pregnant with a crisis"?

How far can gerrymandering go?

Does the Grothendieck group of finitely generated modules form a commutative ring where the multiplication structure is induced from tensor product?

What does this Pokemon Trainer mean by saying the player is "SHELLOS"?

Confusion in understanding the behavior of inductor in RL circuit with DC source

How to extract coefficients of a generating function like this one, using a computer?

Variable declaration inside main loop

How soon after takeoff can you recline your airplane seat?

Why is quantum gravity non-renormalizable?



How to add condition in add-to-cart button function? Magento 1.9


How to do selected single product should be purchase alone?PHP else: statements in addtocart.phtml - Adding conditions to the Add To Cart button on product pageMagento 2 add to cart button validationCustomise “add to cart” buttonHow to exclude products being added to cart based on products attributes?How can I get the product details (like SKU) on JS when “Add to Cart” button is clicked?How can i give condition Shopping Cart Price Rules like if selected attribute products present in the cart, no other products allowed to add cartHow can i show USPS Media Mail Only For Books not for other Products?Change add to cart button based on customer groupHow to customize Add to cart functionality based on product categories in Magento 2?How to do selected single product should be purchase alone?













1















How to Add PHP script in add-to-cart function like if other products are trying to add add-to-cart, supposed selected id based products[restricted products] already available in add-to-cart here restrict and show message like not allowed to add-to-cart, please purchase alone, if already some other products available in cart condition like you need to purchase this product alone.



Using Magento add-to-cart button Function how to achieve my above condition?










share|improve this question
























  • magento.stackexchange.com/questions/279094/…

    – Ketan Borada
    Jun 24 at 9:40















1















How to Add PHP script in add-to-cart function like if other products are trying to add add-to-cart, supposed selected id based products[restricted products] already available in add-to-cart here restrict and show message like not allowed to add-to-cart, please purchase alone, if already some other products available in cart condition like you need to purchase this product alone.



Using Magento add-to-cart button Function how to achieve my above condition?










share|improve this question
























  • magento.stackexchange.com/questions/279094/…

    – Ketan Borada
    Jun 24 at 9:40













1












1








1


2






How to Add PHP script in add-to-cart function like if other products are trying to add add-to-cart, supposed selected id based products[restricted products] already available in add-to-cart here restrict and show message like not allowed to add-to-cart, please purchase alone, if already some other products available in cart condition like you need to purchase this product alone.



Using Magento add-to-cart button Function how to achieve my above condition?










share|improve this question
















How to Add PHP script in add-to-cart function like if other products are trying to add add-to-cart, supposed selected id based products[restricted products] already available in add-to-cart here restrict and show message like not allowed to add-to-cart, please purchase alone, if already some other products available in cart condition like you need to purchase this product alone.



Using Magento add-to-cart button Function how to achieve my above condition?







magento-1.9 addtocart restriction






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 24 at 8:51









Asad Khan

6881 silver badge17 bronze badges




6881 silver badge17 bronze badges










asked Jun 24 at 8:49









zuszus

301 silver badge20 bronze badges




301 silver badge20 bronze badges












  • magento.stackexchange.com/questions/279094/…

    – Ketan Borada
    Jun 24 at 9:40

















  • magento.stackexchange.com/questions/279094/…

    – Ketan Borada
    Jun 24 at 9:40
















magento.stackexchange.com/questions/279094/…

– Ketan Borada
Jun 24 at 9:40





magento.stackexchange.com/questions/279094/…

– Ketan Borada
Jun 24 at 9:40










1 Answer
1






active

oldest

votes


















0














Create an event observer for event sales_quote_merge_before. Create a custom module and put this in config.xml.



<events>
<sales_quote_merge_before>
<observers>
<cart_validation>
<class>MyModule_CartValidation_Model_Observer</class>
<method>quoteMergeBefore</method>
</cart_update>
</observers>
</sales_quote_merge_before>

</events>


Create Observer.php in [MyModule]/[CartValidation]/Model and put this code.



class MyModule_CartValidation_Model_Observer 
public function quoteMergeBefore($observer)
// Get Existing Cart Items
$quoteItem = Mage::getSingleton('checkout/cart') - > getQuote() - > getItemsCollection();

//Get current product trying to be added
$product = Mage::getModel('catalog/product')
- > load(Mage::app() - > getRequest() - > getParam('product', 0));

/*
* Your code logic to see restricted items in cart
*
*/
$isRestricted = $this - > hasRestrictedItems($quoteItem, $product);
if ($isRestricted)
Mage::getSingleton("core/session") - > addError("You can not add this product");
return;






Make sure you implement your restricted products logic in hasRestrictedItems().






share|improve this answer























  • Join with chat.stackexchange.com/rooms/95367/…

    – zus
    Jun 25 at 5:27













Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f279362%2fhow-to-add-condition-in-add-to-cart-button-function-magento-1-9%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Create an event observer for event sales_quote_merge_before. Create a custom module and put this in config.xml.



<events>
<sales_quote_merge_before>
<observers>
<cart_validation>
<class>MyModule_CartValidation_Model_Observer</class>
<method>quoteMergeBefore</method>
</cart_update>
</observers>
</sales_quote_merge_before>

</events>


Create Observer.php in [MyModule]/[CartValidation]/Model and put this code.



class MyModule_CartValidation_Model_Observer 
public function quoteMergeBefore($observer)
// Get Existing Cart Items
$quoteItem = Mage::getSingleton('checkout/cart') - > getQuote() - > getItemsCollection();

//Get current product trying to be added
$product = Mage::getModel('catalog/product')
- > load(Mage::app() - > getRequest() - > getParam('product', 0));

/*
* Your code logic to see restricted items in cart
*
*/
$isRestricted = $this - > hasRestrictedItems($quoteItem, $product);
if ($isRestricted)
Mage::getSingleton("core/session") - > addError("You can not add this product");
return;






Make sure you implement your restricted products logic in hasRestrictedItems().






share|improve this answer























  • Join with chat.stackexchange.com/rooms/95367/…

    – zus
    Jun 25 at 5:27















0














Create an event observer for event sales_quote_merge_before. Create a custom module and put this in config.xml.



<events>
<sales_quote_merge_before>
<observers>
<cart_validation>
<class>MyModule_CartValidation_Model_Observer</class>
<method>quoteMergeBefore</method>
</cart_update>
</observers>
</sales_quote_merge_before>

</events>


Create Observer.php in [MyModule]/[CartValidation]/Model and put this code.



class MyModule_CartValidation_Model_Observer 
public function quoteMergeBefore($observer)
// Get Existing Cart Items
$quoteItem = Mage::getSingleton('checkout/cart') - > getQuote() - > getItemsCollection();

//Get current product trying to be added
$product = Mage::getModel('catalog/product')
- > load(Mage::app() - > getRequest() - > getParam('product', 0));

/*
* Your code logic to see restricted items in cart
*
*/
$isRestricted = $this - > hasRestrictedItems($quoteItem, $product);
if ($isRestricted)
Mage::getSingleton("core/session") - > addError("You can not add this product");
return;






Make sure you implement your restricted products logic in hasRestrictedItems().






share|improve this answer























  • Join with chat.stackexchange.com/rooms/95367/…

    – zus
    Jun 25 at 5:27













0












0








0







Create an event observer for event sales_quote_merge_before. Create a custom module and put this in config.xml.



<events>
<sales_quote_merge_before>
<observers>
<cart_validation>
<class>MyModule_CartValidation_Model_Observer</class>
<method>quoteMergeBefore</method>
</cart_update>
</observers>
</sales_quote_merge_before>

</events>


Create Observer.php in [MyModule]/[CartValidation]/Model and put this code.



class MyModule_CartValidation_Model_Observer 
public function quoteMergeBefore($observer)
// Get Existing Cart Items
$quoteItem = Mage::getSingleton('checkout/cart') - > getQuote() - > getItemsCollection();

//Get current product trying to be added
$product = Mage::getModel('catalog/product')
- > load(Mage::app() - > getRequest() - > getParam('product', 0));

/*
* Your code logic to see restricted items in cart
*
*/
$isRestricted = $this - > hasRestrictedItems($quoteItem, $product);
if ($isRestricted)
Mage::getSingleton("core/session") - > addError("You can not add this product");
return;






Make sure you implement your restricted products logic in hasRestrictedItems().






share|improve this answer













Create an event observer for event sales_quote_merge_before. Create a custom module and put this in config.xml.



<events>
<sales_quote_merge_before>
<observers>
<cart_validation>
<class>MyModule_CartValidation_Model_Observer</class>
<method>quoteMergeBefore</method>
</cart_update>
</observers>
</sales_quote_merge_before>

</events>


Create Observer.php in [MyModule]/[CartValidation]/Model and put this code.



class MyModule_CartValidation_Model_Observer 
public function quoteMergeBefore($observer)
// Get Existing Cart Items
$quoteItem = Mage::getSingleton('checkout/cart') - > getQuote() - > getItemsCollection();

//Get current product trying to be added
$product = Mage::getModel('catalog/product')
- > load(Mage::app() - > getRequest() - > getParam('product', 0));

/*
* Your code logic to see restricted items in cart
*
*/
$isRestricted = $this - > hasRestrictedItems($quoteItem, $product);
if ($isRestricted)
Mage::getSingleton("core/session") - > addError("You can not add this product");
return;






Make sure you implement your restricted products logic in hasRestrictedItems().







share|improve this answer












share|improve this answer



share|improve this answer










answered Jun 24 at 10:29









Abdul PathanAbdul Pathan

1637 bronze badges




1637 bronze badges












  • Join with chat.stackexchange.com/rooms/95367/…

    – zus
    Jun 25 at 5:27

















  • Join with chat.stackexchange.com/rooms/95367/…

    – zus
    Jun 25 at 5:27
















Join with chat.stackexchange.com/rooms/95367/…

– zus
Jun 25 at 5:27





Join with chat.stackexchange.com/rooms/95367/…

– zus
Jun 25 at 5:27

















draft saved

draft discarded
















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f279362%2fhow-to-add-condition-in-add-to-cart-button-function-magento-1-9%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Grendel Contents Story Scholarship Depictions Notes References Navigation menu10.1093/notesj/gjn112Berserkeree

Area configuration aggregation error after install Porto themeMagento 2.1 CE Installed but front/backend not loading/workingCSS not loading on page within Magento 2 pageCannot install module in Magento 2no commands defined in the “setup” namespace. in Magento2Magento 2: Static files are present but shows 404Why do i have to always run the commands to clean cache in Magento 2.1.8?Failure reason: 'Unable to unserialize value.'Error 500 after magento migrationIn production mode the site does not loadMagento 2 : Error 500 after installing

Middle Expansion Olielle Resaix Definition: Uttering songs of triumph shouting with joy triumphant exulting Sejunction Journal 붙다 달 고급 품목 외출 The stretch trades the screeching tin. Definition: The act of speaking with a drawl a drawl Cough Sand Definition: An uproar a quarrel a noisy outbreak Shake Iron Publicize Horse House Baby 사과 Resaix Flaggy Jelly Temporary Unequaled Puppet A drop in the bucket Shrew 성격 회원 성질 미팅 The burn frames the tacky quality. Materialistic The smoke reduces the way. Yammoe Nondescript Cheek 얼굴 배 약하다 날리다 타다 The illegal country shows the iron. Help Rule Drearien Smoke Teaching Meaty Wasp Abraham Lincoln Jaws 진심 수리하다 Size Cork Idea Convert Think Lark John Lennon 거울 청소 군 추천하다 아이스크림