首页 文章

获得属于可配置产品的简单产品AFTER可配置产品保存

提问于
浏览
9

在magento中,可以通过使用以下调用获得与可配置产品关联的简单产品:

$childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null, $product);

我在保存可配置产品后尝试调用此函数,以便我可以获得它使用的简单产品的新列表 . 所以我从 catalog_product_save_after 事件触发的方法进行上述调用 . 但是,在调用之后 $childProducts 存储了与保存操作之前的 $product 关联的简单产品,而不是它之后 .

如何在保存操作后获得与 $product 关联的简单产品?

在此先感谢,任何建议表示赞赏 .

1 回答

  • 7

    Magento的OOP系统非常好,这种优点有时会给尚未深入其结构的人带来麻烦 .

    如果您密切关注方法“ getUsedProducts() " in the class " Mage_Catalog_Model_Product_Type_Configurable ", you will see that there are some " if " logics provided, along with the usage of its properties (like " _usedProducts ", " _configurableAttributes ”) . 这些阻碍了您获得实际结果,但故障不是Magento,而是由于缺少Magento文档而导致的错误 .

    让我告诉你这个方法的前几行: -

    Varien_Profiler::start('CONFIGURABLE:'.__METHOD__);
    if (!$this->getProduct($product)->hasData($this->_usedProducts)) {
        if (is_null($requiredAttributeIds) and is_null($this->getProduct($product)->getData($this->_configurableAttributes))) {
            // If used products load before attributes, we will load attributes.
            $this->getConfigurableAttributes($product);
            // After attributes loading products loaded too.
            Varien_Profiler::stop('CONFIGURABLE:'.__METHOD__);
            return $this->getProduct($product)->getData($this->_usedProducts);
        }
        ....
    

    此方法有2个参数 - “ $requiredAttributeIds " (Configurable Attribute IDs) & " $product ”(可配置的产品对象) .

    调用此方法时,您将传递“ null " for the parameter " $requiredAttributeIds ", but you are providing the correct Configurable Product object " $product ” .

    此类具有属性“ _usedProducts ”(用于维护子简单产品的数据),该属性是为每个可配置产品对象设置的 . 如果之前已设置此值,则Magento将向您返回已有的值 . 这是您在更新可配置产品之前获取子产品的主要原因 .

    因此,您可以做的是清除完整的缓存存储,同时刷新所有缓存进程 . 可能那时你的结果会起作用,因为内部Magento将所有这些用过的产品数据存储在缓存中 .

    希望能帮助到你 .

相关问题