0
votes

Is there any chance to check if product is already in cart if is used direct link to add product do cart? For example, we send to customer link, he/she click on it one time and than by mystake click again. Result is, that in cart is 2 times more pieces.

We use one product option, text field, which is unique (in this example - options[8]=AX587AD9) for each order/customer, maybe there is a way to check it by this via API.

We can also use any mechanim to check it before Magento frontend, and then redirect to cart or use link to add product to cart...

Example of direct link: http://www.example.com/checkout/cart/add?product=161&qty=1&options[8]=AX587AD9

Thanks for every suggestion, Igor

1

1 Answers

1
votes

You can check if product is in cart or not using event observer.

You can use checkout_cart_product_add_before event to check if this product is already in your cart. your config file is look like this

<config>
...
<frontend>
    ...
    <events>
        <checkout_cart_product_add_after>
            <observers>
                <unique_event_name>
                    <class>{{modulename}}/observer</class>
                    <method>CheckItem</method>
                </unique_event_name>
            </observers>
        </checkout_cart_product_add_after>
    </events>
    ...
</frontend>
...

And in your observer check your logic if something is in cart or not

 class <namespace>_<modulename>_Model_Observer
{

        public function CheckItem(Varien_Event_Observer $obs)
        {
            // Get the quote item
            $item = $obs->getQuoteItem();
            //and put your logic here
            // condition matched then redirect back customer with some message

        }



    }