【问题标题】:Magento - Updating the price of a configurable product optionMagento - 更新可配置产品选项的价格
【发布时间】:2013-11-03 04:51:12
【问题描述】:

Magento 版本 1.6.1.0。我正在尝试编写一些代码来动态更新可配置产品选项的价格。我的最终目标是编写一个模块,该模块将根据可配置产品的子产品价格更新可配置产品选项的价格。附加代码从目录中提取所有可配置产品,并将它们与产品选项和价格以及子产品的名称和价格一起显示。我计划计算出可配置产品和每个子产品之间的价格差异,并更新价格适当的选项以匹配。到目前为止,我一直无法弄清楚如何更新产品选项的价格。

短版:我只需要一种方法来更新可配置产品选项的价格。你知道怎么做吗?

<?php
require_once './app/Mage.php';
Mage::app();
Mage::app()->setCurrentStore(1);

// load in configurable products
$productConfig = Mage::getResourceModel('catalog/product_collection')->addAttributeToFilter('type_id', 'configurable');
foreach ($productConfig as $_product)
{
    // load the configurable product
    $_product = Mage::getModel('catalog/product')->load($_product->getId());
    echo 'Product Name';
    var_dump ($_product->getName());
    var_dump ($_product->getPrice());
    // Collect options applicable to the configurable product
    $productAttributeOptions = $_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product);
    $attributeOptions = array();
    foreach ($productAttributeOptions as $productAttribute)
        {
        var_dump($productAttribute['label']);
        foreach ($productAttribute['values'] as $attribute)
            {
            var_dump($attribute);
            }
        }

    // loop through the child products
    echo 'Child products';
    $col = Mage::getModel('catalog/product_type_configurable')->setProduct($_product)->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();
    foreach($col as $simple_product)
    {
        var_dump($simple_product->getName());
        var_dump($simple_product->getPrice());
    } 
}
echo '~fin';
?>

谢谢!

【问题讨论】:

    标签: magento product configurable


    【解决方案1】:

    好吧,经过一番摸索,我解决了这个问题。我不知道我做的是否“正确”。

    我通过手动运行一些 SQL 来调整 catalog_product_super_attribute_pricing 表中的定价来解决这个问题。如果您要执行此操作,则需要一个 product_super_attribute_id,如果您有产品 ID,可以从 catalog_product_super_attribute 表中获取。

    一个警告:如果后端中不存在选项的价格(如果选项存在,但在选择时会在产品价格中增加 0 英镑),catalog_product_super_attribute_pricing 中将不会记录该选项表,在这种情况下,您需要插入查询而不是更新。

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题,我开始做同样的事情:编写一个模块来更新可配置产品的选项。

      我最近在这里发布了它:Magento Configurable Auto Pricing

      我只使用 EE 1.12 对其进行了测试,但它也应该适用于 CE,如果有人想尝试它并给我任何反馈,或者甚至更好地编写他自己的修复并提交它们,我会很高兴 :)

      【讨论】:

        猜你喜欢
        • 2016-11-07
        • 2013-01-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-05-18
        • 1970-01-01
        • 2012-07-20
        相关资源
        最近更新 更多