Warning: Cannot modify header information - headers already sent by (output started at /www/wwwroot/sbboke.com/wp-content/plugins/wordpress-seo/src/integrations/front-end-integration.php:409) in /www/wwwroot/sbboke.com/wp-content/themes/pacify/content-single.php on line 5

Magento:如何获得可配置产品的所有关联子产品?

配置产品可以具有与其关联的多个其他产品。本文介绍了如何获取与可配置产品关联的所有子产品。

这是代码:

/**
 * 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('*');

希望这可以帮助。谢谢。

相关文章

0 0 投票数
文章评分
订阅评论
提醒
0 评论
内联反馈
查看所有评论