简体   繁体   English

Magento:如何将自定义产品属性传递给订单

[英]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. 使用Magento CE 1.8.x,我正在尝试获取自定义产品属性以传递给在幕后使用的订单项。 I've created the custom product attribute, qb_product_id in catalog > attributes > manage attributes 我在catalog > attributes > manage attributes创建了自定义产品属性qb_product_id

And then I created the following module: 然后我创建了以下模块:

config.xml 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 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. 当我转储订单商品信息时,它似乎没有输出qb_invoice_id 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. 我已经清除了我的var / cache文件夹并重新编制了所有索引,但仍未显示订单项。

Possibly need to install the attribute on the sales_order_table? 可能需要在sales_order_table上安装该属性?

Adding custom attribute to order in Magento is same as we do for customer and category. 在Magento中为订单添加自定义属性与我们对客户和类别相同。 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/ http://ka.lpe.sh/2013/05/10/magento-add-attribute-to-order/

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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