问题出在addStoreFilter()
in中getUsedProductCollection()
:
public function getUsedProductCollection($product = null)
{
$collection = Mage::getResourceModel('catalog/product_type_configurable_product_collection')
->setFlag('require_stock_items', true)
->setFlag('product_children', true)
->setProductFilter($this->getProduct($product));
if (!is_null($this->getStoreFilter($product))) {
$collection->addStoreFilter($this->getStoreFilter($product));
}
return $collection;
}
这将添加过滤器以仅显示当前商店中可销售的产品。
如果$configurable
是可配置产品的类型实例,则可以在调用之前取消设置商店过滤器,如下所示getUsedProductCollection()
:
$configurable->setStoreFilter(null);
完整的解决方案:
$configurable = $product->getTypeInstance();
$configurable->setStoreFilter(null);
$simpleCollection = $configurable->getUsedProductCollection()
->addAttributeToSelect('*')
->addFilterByRequiredOptions();
foreach ($simpleCollection as $simple) {
//$simple->getName();
}