在magento中,可以通过使用以下调用获得与可配置产品关联的简单产品:
$childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null, $product);
我在保存可配置产品后尝试调用此函数,以便我可以获得它使用的简单产品的新列表 . 所以我从 catalog_product_save_after
事件触发的方法进行上述调用 . 但是,在调用之后 $childProducts
存储了与保存操作之前的 $product
关联的简单产品,而不是它之后 .
如何在保存操作后获得与 $product
关联的简单产品?
在此先感谢,任何建议表示赞赏 .
1 回答
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文档而导致的错误 .让我告诉你这个方法的前几行: -
此方法有2个参数 - “
$requiredAttributeIds
" (Configurable Attribute IDs) & "$product
”(可配置的产品对象) .调用此方法时,您将传递“
null
" for the parameter "$requiredAttributeIds
", but you are providing the correct Configurable Product object "$product
” .此类具有属性“
_usedProducts
”(用于维护子简单产品的数据),该属性是为每个可配置产品对象设置的 . 如果之前已设置此值,则Magento将向您返回已有的值 . 这是您在更新可配置产品之前获取子产品的主要原因 .因此,您可以做的是清除完整的缓存存储,同时刷新所有缓存进程 . 可能那时你的结果会起作用,因为内部Magento将所有这些用过的产品数据存储在缓存中 .
希望能帮助到你 .