0

I added two text columns to sales_flat_quote_item in order to store data and for other reasons When i add product to cart. my problem is that i cant save the data. i tried a lot of examples but without any success. Config.xml file :

 <events>
        <catalog_product_load_after>
            <observers>
                <iwp_package>
                    <type>model</type>
                    <class>iwp_package/observer</class>
                    <method>catalogProductLoadAfter</method>
                </iwp_package>
            </observers>
        </catalog_product_load_after>
    </events>

here i add the coulmns :

$installer = $this;
$connection = $installer->getConnection();
$installer->startSetup();
$installer->getConnection()
    ->addColumn($installer->getTable('sales/quote_item'),
    'pack_name',
    array(
        'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
        'nullable' => true,
        'default' => null,
        'comment' => 'pack_name'
    )
);
$installer->endSetup();

This is the code in my observer where i try to save the data :

$quote_item  = Mage::getModel('sales/quote_item')->load($quote->Id);
$quote_item->setPackName($string);
$quote_item->save();

any help?

4
  • Did you clear the cache after adding the 2 columns?
    – Marius
    Commented Jul 10, 2014 at 11:53
  • Yes, i even removed cleaned the cache folder. Commented Jul 10, 2014 at 12:28
  • What event is your observer running on? What does your config.xml file look like? Commented Jul 10, 2014 at 23:50
  • I updated the question with the event in my config file Commented Jul 11, 2014 at 10:08

1 Answer 1

0

try this event it gets triggered only when items gets added to cart

 <events>
        <checkout_cart_add_product_complete>
            <observers>
                <iwp_package>
                    <type>model</type>
                    <class>iwp_package/observer</class>
                    <method>catalogProductLoadAfter</method>
                </iwp_package>
            </observers>
        </checkout_cart_add_product_complete>
    </events>

EDIT

Am Assuming that $quote has quote object, so further you have to loop through all the items in cart.

For that you can try below code snippet

foreach ($quote->getAllItems() as $item) {
    $item->setPackName($string);
    $item->save();
}

OR

foreach ($quote->getAllItems() as $item) {
    $quote_item  = Mage::getModel('sales/quote_item')->load($item->getItemId());
    $quote_item->setPackName($string);
    $quote_item->save();
}
2
  • OK, but its not my big problem. why "$quote_item->setPackName($string);" not working for me? Commented Jul 11, 2014 at 11:12
  • @user3270551 refer to edit section Commented Jul 12, 2014 at 3:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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