Get All simple product from a Configurable Product in Magento Product View

后端 未结 6 1559
轮回少年
轮回少年 2021-01-31 09:55

How can I get all the simple products associated with a configurable product? I found how to do the opposite (get a product configurable from a simple product) but that\'s not w

6条回答
  •  情话喂你
    2021-01-31 10:03

    A configurable product can have multiple other products associated to it.

    Here is the code to fetch all the children products that are associated with a configurable product.

    Here goes the code :)

    /**
     * Load product by product id
     */
    $product = Mage::getModel('catalog/product')->load(YOUR_PRODUCT_ID);
    
    /**
     * Get child products id and such (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);
    

    Source: http://blog.chapagain.com.np/magento-how-to-get-all-associated-children-product-of-a-configurable-product/

提交回复
热议问题