0

I have created the custom column from sales/order_item and sales/quote_item table. But when I have set the values it's not saving. I don't know what happening. There is no Error logs also.

My code is

mysql4-installer-1.0.0.php

<?php

$installer = $this;
$installer->startSetup();

$this->_conn->addColumn($this->getTable('sales_flat_quote_item'), 'vendor', 'text');
$this->_conn->addColumn($this->getTable('sales_flat_order_item'), 'vendor', 'text');

$installer->endSetup();

?>

config.xml file

<events>

            <sales_order_save_before>
                <observers>
                    <save_before>
                        <type>model</type>
                        <class>vendor/observer</class>
                        <method>SaveBefore</method>
                    </save_before>
                </observers>
            </sales_order_save_before>
            <sales_quote_save_before>
                <observers>
                    <save_quote_before>
                        <type>model</type>
                        <class>vendor/observer</class>
                        <method>SaveQuoteBefore</method>
                    </save_quote_before>
                </observers>
            </sales_quote_save_before>
        </events>

Observer.php file

<?php
    class Easylife_Vendor_Model_Observer
    {               

        public function SaveBefore(Varien_Event_Observer $observer){
            $order = $observer->getEvent()->getOrder();

            $order_item = $order->getAllVisibleItems();
            foreach($order_item as $order_items){
                $product= Mage::getModel('catalog/product')->load($order_items->getProductId());
                $product->setVendor('Admin');

            }

        }

        public function SaveQuoteBefore(Varien_Event_Observer $observer){
            $quote = $observer->getEvent()->getQuote();
            foreach($quote->getAllItems() as $item){
                $Product = $item->getProduct();
                $Product->setVendor('Admin');
                $Product->save();
            }
        }

    }

Is this method is correct or wrong?

Suggest me how to save this value to those tables..

Thanks.

  • Why are you using setDropShipVendor (not setVendor) when you add column 'vendor'? – michael Dec 22 '14 at 6:52
  • @michael, Actually I forget, Previously i have used that field now see I have changed. till not working... – Manoj Kumar Dec 22 '14 at 6:56
2

Please try with this code in Observer.php:

public function SaveQuoteBefore($observer){
    $quote = $observer->getEvent()->getQuote();
    foreach($quote->getAllItems() as $item){
        $item->setVendor('Admin');
    }
}

and remove function SaveBefore.In config.xml remove <sales_order_save_before> and add this code in <global>:

<fieldsets>
    <sales_convert_quote_item>
        <vendor>
            <to_order_item>*</to_order_item>
        </vendor>
    </sales_convert_quote_item>
</fieldsets>

Don't forget to Flush Cache and maybe Reindex before using it.

Only recommendation - it's better to not use full table name but $this->getTable('sales/quote_item') and $this->getTable('sales/order_item').

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.