简体   繁体   English

如何在 magento 中导入 csv 文件期间或之后更改产品价格?

[英]How to change product price during or after import csv file in magento?

I have 1000 Jewelry products.我有 1000 件珠宝产品。 When I upload CSV file using Magento import functionality, so at that time products price will be changed automatically with my custom calculation formula.当我使用 Magento 导入功能上传 CSV 文件时,届时产品价格将使用我的自定义计算公式自动更改。

Ex: csv product price = 100 but after import product price will be 150.例如:csv 产品价格 = 100 但导入后产品价格将为 150。

Please help me how can I implement this functionality.请帮助我如何实现此功能。

I got the solution for above problem.我得到了上述问题的解决方案。 I am using hooking below is my code.我在下面使用钩子是我的代码。

<adminhtml>
        <events>
            <catalog_product_import_finish_before>
                <observers>
                    <test_module1_catalog_product_import_after>
                        <type>singleton</type>
                        <class>gold_pricechange/observer</class>
                        <method>afterImportProductData</method>
                    </test_module1_catalog_product_import_after>
                </observers>
            </catalog_product_import_finish_before>
        </events>
    </adminhtml>

public function afterImportProductData(Varien_Event_Observer $observer)
    {       
        $adapter = $observer->getEvent()->getAdapter();
        $affectedEntityIds = $adapter->getAffectedEntityIds();

        for($i=0;$i<count($affectedEntityIds);$i++)
        {
            $product_id = $affectedEntityIds[$i];
            $product = Mage::getModel('catalog/product')->load($product_id);
            $product->setPrice($product->getPrice() * 1.2); //1.2 will come from my calculation function

            $product->save();
            $product->clearInstance();
        }       
    }

Sorry if my question was wrong.对不起,如果我的问题错了。

Thank you for great help.谢谢你的大力帮助。

您可以使用此扩展价格导入

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

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