繁体   English   中英

如何在 sales->orders 中添加像自定义价格这样的文本并存储在数据库表 Magento 1.9 中?

[英]How can Add the text filed like custom price in sales->orders and store in database table Magento 1.9?

我想添加自定义产品描述之类的文本字段(请参阅屏幕截图)并将值存储在销售订单表中在此处输入图片说明

  1. 添加新的 catalog_product 属性并创建本地模块(yournamespace_customattribute)
  2. 通过设置脚本向订单项实体添加新属性

    $install = new Mage_Sales_Model_Resource_Setup('core_setup'); $options = array( 'type' => Varien_Db_Ddl_Table::TYPE_VARCHAR, 'visible' => true, 'required' => false ); $install->addAttribute('quote_item', 'custom_product_description', $options); $install->addAttribute('order_item', 'custom_product_description', $options); $install->endSetup();
  3. 在 config.xml 中添加属性

    <sales>
        <quote>
            <item>
                <product_attributes>
                    <custom_product_description />
                </product_attributes>
            </item>
        </quote>
    </sales>
  1. 在 config.xml 中添加观察者方法
    <sales_quote_item_set_product>
        <observers>
            <yournamespace_customattribute>
                <class>yournamespace_customattribute/observer</class>
                <method>salesQuoteItemSetCustomAttribute</method>
            </yournamespace_customattribute>
        </observers>
    </sales_quote_item_set_product>
  1. 将方法 salesQuoteItemSetCustomAttribute 添加到 Observer.php
    public function salesQuoteItemSetCustomAttribute($observer)
    {
        $quoteItem = $observer->getQuoteItem();
        $product = $observer->getProduct();
        $quoteItem->setCustomProductDescription($product->getCustomProductDescription());
    }
  1. 最后将值传递到销售平面表中,将其添加到 config.xml 中的全局
    <fieldsets>
        <sales_convert_quote_item>
            <custom_product_description>
                <to_order_item>*</to_order_item>
            </custom_product_description>
        </sales_convert_quote_item>
        <sales_convert_order_item>
            <custom_product_description>
                <to_quote_item>*</to_quote_item>
            </custom_product_description>
        </sales_convert_order_item>
    </fieldsets>

暂无
暂无

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

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