0

I'm needing to save an additional parameter when the customer click in "addToCart". In the product page I added a box with some data to fill. When the customer click on "addToCart" these data should be saved in a column created in sales_flat_quote_item called "passengers_data". But I can't save in my custom column.

I've created a Event to catch the custom parameters. Here is my config.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<config>
    <modules>
        <DevXIII_CpfPlus>
            <version>0.1.0</version>
        </DevXIII_CpfPlus>
    </modules>

    <global>

        <models>
            <cpfplus>
                <class>DevXIII_CpfPlus_Model</class>
            </cpfplus>
        </models>


        <events>
            <checkout_cart_add_product_complete>
                <observers>
                    <cpfplus>
                        <type>singleton</type>
                        <class>cpfplus/observer</class>
                        <method>convertPassengers</method>
                    </cpfplus>
                </observers>
            </checkout_cart_add_product_complete>
        </events> 

        <resources>
            <cpfplus_setup>

                <setup>
                    <module>DevXIII_CpfPlus</module>
                    <class>DevXIII_CpfPlus_Model_Resource_Setup</class>
                </setup>
                <connection>
                    <use>directory_setup</use>
                </connection>

            </cpfplus_setup>
        </resources>
    </global>

    <frontend>

        <!-- Begin: Sobrescrevendo o controller do checkout -->
        <routers>
            <checkout>
                <args>
                    <modules>
                        <DevXIII_CpfPlus before="Mage_Checkout">DevXIII_CpfPlus</DevXIII_CpfPlus>
                    </modules>
                </args>
            </checkout>
        </routers>
        <!-- End: Sobrescrevendo o controller do checkout -->

        <layout>
            <updates>
                <cpfplus>
                    <file>cpfplus.xml</file>
                </cpfplus>
            </updates>
        </layout>
    </frontend>
</config>

And here is my Model/Observer.php:

<?php

class DevXIII_CpfPlus_Model_Observer
{

    public function convertPassengers( $observer )
    {
        $item = $observer->getQuoteItem();
        $product = $observer->getProduct();

        $params = $observer->getRequest()->getParams();

    }

}

The idea is save these data to display for each product saved in order, but I don't know how I can do this.

Thanks!!!

  • Well, you only use getters. You should call setPassengerData() on the quote item. Then the question remains if you have the right event. I think this is dispatched after save(), but I may be mistaken. – Melvyn Nov 20 '14 at 18:30
  • Yes, I made a test and it saves after save()... the variable $item is empty( I used print_r() ). So I need to dispatch before save() aaand, with my custom data. – erick.bruno Nov 20 '14 at 20:27
  • Have you achieved this functionality ? – Suresh Chikani Aug 31 '16 at 12:36
0

That event doesn't have the quote item. In 1.8.0.0:

        Mage::dispatchEvent('checkout_cart_add_product_complete',
            array('product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse())
        );

It isn't in there. You want the checkout_cart_product_add_after event. For two reasons:

  1. It has a quote item
  2. It's called before the cart->save() in the checkout_cart_add_product_complete event.

So your event XML should be:

        <checkout_cart_product_add_after>
            <observers>
                <cpfplus>
                    <type>singleton</type>
                    <class>cpfplus/observer</class>
                    <method>convertPassengers</method>
                </cpfplus>
            </observers>
        </checkout_cart_product_add_after>

And your observer handler:

public function convertPassengers( $observer )
{
    $item = $observer->getQuoteItem();
    $params = Mage::app()->getRequest()->getParams();

    $item->setPassengerData($this->doSomethingWith($params));
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.