What is the best way to Collection of all configurable products (which has children) with sku using script?
How to do that?
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityWhat is the best way to Collection of all configurable products (which has children) with sku using script?
How to do that?
Try following code:
<?php
require_once('app/Mage.php');
umask(0);
Mage::app();
$products = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('sku')
->addFieldToFilter('type_id','configurable');
$data = array();
foreach ($products as $product) {
$childProducts = Mage::getModel('catalog/product_type_configurable')
->getUsedProducts(null, $product);
if (count($childProducts)) {
foreach($childProducts as $childProduct) {
if (isset($data[$product->getSku()]) && $data[$product->getSku()]) {
$data[$product->getSku()] .= " || ".$childProduct->getSku();
} else {
$data[$product->getSku()] = $childProduct->getSku();
}
}
}
}
echo "<pre>";print_r($data);
This should work:
error_reporting(E_ALL | E_STRICT);
define('MAGENTO_ROOT', getcwd());
$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
require_once $mageFilename;
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
Mage::app();
$_productCollection1 = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect('*')
->addAttributeToFilter('type_id','configurable');
foreach ($_productCollection1 as $product1) {
echo $product1->getName();
$childIds = Mage::getModel('catalog/product_type_configurable')->getChildrenIds($product1->getId());
or
$childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null,$product1);
}
Please let me know if you have any query or question.