在magento中,可以使用以下调用获得与可配置产品关联的简单产品:
$childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null, $product);
Run Code Online (Sandbox Code Playgroud)
我正在尝试在保存可配置产品后调用此函数,以便我可以获得它使用的简单产品的新列表.所以我从一个由catalog_product_save_after事件触发的方法进行上述调用.但是,在调用之后$childProducts存储$product与保存操作之前关联的简单产品,而不是它之后.
如何$product在保存操作后获得与之关联的简单产品?
在此先感谢,任何建议表示赞赏.
Magento的OOP系统非常好,这种优点有时会给尚未深入其结构的人带来麻烦.
如果你密切关注getUsedProducts()类" Mage_Catalog_Model_Product_Type_Configurable"中的方法" " ,你会看到if提供了一些" "逻辑,以及它的属性的用法(比如" _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);
}
....
Run Code Online (Sandbox Code Playgroud)
此方法有2个参数 - " $requiredAttributeIds"(可配置属性ID)和" $product"(可配置产品对象).
调用此方法时,您null将为参数" $requiredAttributeIds" 传递" " ,但您提供了正确的可配置产品对象" $product".
此类具有属性" _usedProducts"(用于维护子简单产品的数据),该属性是为每个可配置产品对象设置的.如果之前已设置此值,则Magento将向您返回已有的值.这是您在更新可配置产品之前获取子产品的主要原因.
因此,您可以做的是清除完整的缓存存储,同时刷新所有缓存进程.可能那时你的结果会起作用,因为内部Magento将所有这些用过的产品数据存储在缓存中.
希望能帮助到你.