可配置产品可以具有与其关联的多个其他产品。本文介绍了如何获取与可配置产品关联的所有子产品。
这是代码:
/**
* Load product by product id
*/
$product = Mage::getModel('catalog/product')
->load(YOUR_PRODUCT_ID);
/**
* Get child products id (only ids)
*/
$childIds = Mage::getModel('catalog/product_type_configurable')
->getChildrenIds($product->getId());
/**
* Get children products (all associated children products data)
*/
$childProducts = Mage::getModel('catalog/product_type_configurable')
->getUsedProducts(null, $product);
/**
* Get children products as collection
* And, select all attributes like name, description, price, etc.
*/
$childProducts = Mage::getModel('catalog/product_type_configurable')
->getUsedProductCollection($product)
->addAttributeToSelect('*');
希望这可以帮助。谢谢。