【问题标题】:Magento - Update Prices Script - Multiple StoresMagento - 更新价格脚本 - 多个商店
【发布时间】:2012-10-27 13:28:29
【问题描述】:

我正在尝试将一些(但不是全部)价格从一家商店更新到另一家商店。比如一件衬衫应该是第二家店价格的1.2倍

我只想根据实体标签更新一些项目组,但我正在努力从 magento 中提取所有数据(除了我可以在下面的代码中得到的数据)。我缺少的是价格和实体标签。我知道他们住在哪些表中,但不确定访问它们的正确 magento 语法,例如 Mage::getModel('catalog/product') 我正在尝试使用 Magento 友好代码而不是查询来实现这一点

使用企业 1.11,现阶段不考虑购买插件,非常感谢任何建议

$mageFilename = 'app/Mage.php';
require_once $mageFilename;
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); #important
$product_id = '8782';
$collection = Mage::getModel('catalog/product')
         ->load($product_id);
        echo "Collection: " . $collection->getName();
        echo "<br>";
        echo "Attribute Set: " . $collection->getAttributeSetId() . " SKU: " . $collection->getSku();
        echo "<br>"; 
        echo "Entity ID: " . $collection->getEntity_id() . " Product Type (Attribute Label): " . $collection->getProducttype();

【问题讨论】:

    标签: php magento


    【解决方案1】:

    澄清一下:

    在您展示的示例中,$collection 对象并不是真正的“集合”。 它是一个“目录/产品”对象的实例。

    要修改一个目录/产品对象的价格,您会考虑执行以下操作:

    $product = Mage::getModel('catalog/product')->load($product_id);
    $product->setPrice($product->getPrice() * 1.2)
            ->save();
    

    如果您想对一堆产品执行此操作,您可能需要使用一组 “目录/产品”对象,并应用一些属性过滤器(归结为添加 最终生成的 SQL 的 WHERE 子句)。 (Here's one summary 的 magento 集合查询 语法。)

    我不确定您所说的“实体标签”是什么意思。这是您附加到产品的自定义属性吗?

    一个通用示例,将此价格更改应用于具有特定 SKU 的所有产品:

    $product_collection = Mage::getModel('catalog/product')->getCollection()
                                                           ->addAttributeToFilter('sku', array('like' => 'FOO01-%'));
    
    foreach($product_collection as $product) {
    
        $new_price = calcNewPrice($product->getPrice());
        $product->setPrice($new_price)
                ->save(); 
    
    }     
    

    如果您要跨商店进行价格计算,“calcNewPrice”可能看起来像这样:

    function calcNewPrice($product) {
        $other_store_product = Mage::getModel('catalog/product')->setStoreId($other_store_id)
                                                                ->load($product->getId());
        if ($other_store_product) {
            return $other_store_product->getPrice() * 1.2;
        }
        // else ???
    }
    

    希望这会有所帮助。

    【讨论】:

    • 谢谢,让我更近了 3 步。我的意思是属性标签,而不是实体,对不起,它位于后端目录/属性/管理属性下。它位于 eav_attribute_option_value 表和价值标题下,如果我可以访问该数据,我可以将其用作分组来编辑价格 非常感谢您到目前为止的帮助
    • 在搜索论坛后找到了我正在寻找的 2 个值,结果证明这返回了正确的值 echo "Attribute Text:" 。 $collection->getAttributeText('producttype') 。 “选项 ID:”。 $collection->getData('producttype');从这里我希望使用 getAttributeText 来查找产品组,使用相应的 Option Id,将其与 catalog_product_index_eav 表中的商店 id 匹配以获取 entity_id 并使用这些值来更新 catalog_product_entity_decimal 表中的价格。有人看到这有什么潜在的问题吗?
    • 他们是否可以通过任何方式更新/创建每个网站或每个商店的数量?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-13
    • 1970-01-01
    • 1970-01-01
    • 2019-05-07
    • 2011-07-11
    相关资源
    最近更新 更多