简体   繁体   中英

Magento: How to pass custom product attribute to order

Using Magento CE 1.8.x and I'm trying to get a custom product attribute to pass to order items to use behind the scenes. I've created the custom product attribute, qb_product_id in catalog > attributes > manage attributes

And then I created the following module:

config.xml

<?xml version="1.0"?>
<config>
<modules>
    <Nellys_QBProductID>
        <version>0.1.0</version>   
    </Nellys_QBProductID>
</modules>

<global>
<fieldsets>
    <sales_convert_quote_item>
        <qb_product_id>
            <to_order_item>*</to_order_item>
        </qb_product_id>
    </sales_convert_quote_item>

    <sales_convert_order_item>
        <qb_product_id>
            <to_quote_item>*</to_quote_item>
        </qb_product_id>
    </sales_convert_order_item>
</fieldsets>

<sales>
    <quote>
        <item>
            <product_attributes>
                <qb_product_id />
            </product_attributes>
        </item>
    </quote>
</sales>

<events>
    <sales_quote_item_set_product>
        <observers>
            <Nellys_QBProductID>
                <class>Nellys_QBProductID_Model_Observer</class>
                <method>setQbProductId</method>
            </Nellys_QBProductID>
        </observers>
    </sales_quote_item_set_product>
</events>
</global>

</config>

Observer.php

<?php
class Nellys_QBProductID_Model_Observer extends Varien_Event_Observer
{
public function setQbProductId(Varien_Event_Observer $observer) {
    $item = $observer->getQuoteItem();
    $product = $observer->getProduct();
    $item->setQbProductId($product->getQbProductId());
    return $this;
}
}

?>

It doesn't seem to be outputting qb_invoice_id when I dump the order items information. Any idea where I went wrong? I've cleared my var/cache folder and reindexed everything, but still not showing up on the order items.

Possibly need to install the attribute on the sales_order_table?

Adding custom attribute to order in Magento is same as we do for customer and category. The difference is we will use different setup class AND we will not need attribute set, group and attribute input type now. We will create a quick module which will do exactly what we want and nothing more than that. So yo need to create module for that. Please visit below URLs.

http://ka.lpe.sh/2013/05/10/magento-add-attribute-to-order/

https://www.atwix.com/magento/custom-product-attribute-quote-order-item/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM