Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can try the following. This will check if the quantity is bigger than 1. If this is the situation then we will update the quantity to 1. We also add a notice message so the user is informed about the quantity change.</p> <pre><code>&lt;checkout_cart_product_add_after&gt; &lt;observers&gt; &lt;company_module_name&gt; &lt;type&gt;singleton&lt;/type&gt; &lt;class&gt;Company_Module_Model_Observer&lt;/class&gt; &lt;method&gt;checkItem&lt;/method&gt; &lt;/company_module_name&gt; &lt;/observers&gt; </code></pre> <p></p> <pre><code>public function checkItem($obj) { //check if qty is more then 1 if($obj-&gt;getProduct()-&gt;getQty() &gt; 1) { //set notice to inform the visitor that there is a maximum Mage::getSingleton('core/session')-&gt;addNotice('The maximum quantity allowed for purchase is 1.'); //get the event $event = $obj-&gt;getEvent(); //get the product we have added $product = $event-&gt;getProduct(); //get the quote item $quoteItem = $event-&gt;getQuoteItem(); //change the qty to 1 allowed $quoteItem-&gt;setQty(1); //recalc totals $quoteItem-&gt;getQuote()-&gt;collectTotals(); //save the item $quoteItem-&gt;getQuote()-&gt;save(); } </code></pre> <p>===== EDIT ======</p> <p>Another option would be:</p> <pre><code>&lt;controller_action_predispatch_checkout_cart_add&gt; &lt;observers&gt; &lt;aquait_aquait_name&gt; &lt;type&gt;singleton&lt;/type&gt; &lt;class&gt;Aquait_Aquait_Model_Observer&lt;/class&gt; &lt;method&gt;checkfunction&lt;/method&gt; &lt;/aquait_aquait_name&gt; &lt;/observers&gt; &lt;/controller_action_predispatch_checkout_cart_add&gt; public function checkfunction($observer) { if ($observer-&gt;getEvent()-&gt;getControllerAction()-&gt;getFullActionName() == 'checkout_cart_add') { $productId = Mage::app()-&gt;getRequest()-&gt;getParam('product'); $product = Mage::getModel('catalog/product')-&gt;load($productId); if (Mage::app()-&gt;getRequest()-&gt;getParam('qty') &gt; 1) { Mage::getSingleton('core/session')-&gt;addNotice('The maximum quantity allowed for purchase is 1.'); Mage::app()-&gt;getResponse()-&gt;setRedirect($product-&gt;getProductUrl()); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload