Last active
          July 18, 2017 07:55 
        
      - 
      
- 
        Save enis-ismail/9206023 to your computer and use it in GitHub Desktop. 
    Magento: Get all configurable products' children from a category
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <?php | |
| require_once 'app/Mage.php'; | |
| Mage::app(); | |
| $categoryId = 86; | |
| $products = Mage::getModel('catalog/product')->getCollection() | |
| ->addAttributeToSelect('*') | |
| ->addAttributeToFilter('type_id', 'configurable') | |
| ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left') | |
| ->addAttributeToFilter('category_id', array( | |
| array('finset' => $categoryId) | |
| )); | |
| $ids = array(); | |
| $skus = array(); | |
| foreach($products as $product) { | |
| $childProducts = Mage::getModel('catalog/product_type_configurable') | |
| ->getUsedProducts(null, $product); | |
| foreach($childProducts as $child) { | |
| $ids[] = $child->getId(); | |
| $skus[] = $child->getSku(); | |
| } | |
| } | |
| $ids = implode(', ', $ids); | |
| $skus = implode(', ',$skus); | |
| Zend_Debug::dump($ids); | |
| Zend_Debug::dump($skus); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment