Skip to content

Instantly share code, notes, and snippets.

@enis-ismail
Last active July 18, 2017 07:55
Show Gist options
  • Save enis-ismail/9206023 to your computer and use it in GitHub Desktop.
Save enis-ismail/9206023 to your computer and use it in GitHub Desktop.
Magento: Get all configurable products' children from a category
<?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