我正在使用下面的代码
$configurable= Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
$simpleCollection = $configurable->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();
$productAttributeOptions = $_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product);
$attributeOptions = array();
foreach ($productAttributeOptions as $productAttribute) {
foreach ($productAttribute['values'] as $attribute) {
$attributeOptions[$productAttribute['label']][] =
array('id' => $attribute['value_index'],
'label' => $attribute['label'],
'mainId' => $productAttribute['attribute_id'] );
}
}
return $attributeOptions;
但它给了我所有简单产品的清单,即使那些库存不可用。 我只想要一份有库存的可配置产品的简单产品清单。 我怎样才能获得可配置产品的库存产品
答案 0 :(得分:0)
您可以查看商品库存状态0
- 没有库存或1
- 库存
$configurable= Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
$simpleCollection = $configurable->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();
/* -------- Add this ------- */
$simpleCollection->getSelect()->join('cataloginventory_stock_status', 'cataloginventory_stock_status.product_id = e.entity_id', array('stock_status'));
$simpleCollection->getSelect()->where("`cataloginventory_stock_status`.`stock_status` = 1");
$productAttributeOptions = $_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product);
$attributeOptions = array();
foreach ($productAttributeOptions as $productAttribute) {
foreach ($productAttribute['values'] as $attribute) {
$attributeOptions[$productAttribute['label']][] =
array('id' => $attribute['value_index'],
'label' => $attribute['label'],
'mainId' => $productAttribute['attribute_id'] );
}
}
return $attributeOptions;