2

What is the best way to Collection of all configurable products (which has children) with sku using script?

How to do that?

2
  • Please specify magento version. M1 or M2?
    – Nits
    Commented Jan 9, 2018 at 10:46
  • in magento1 and please create script so i have easily use.
    – meet
    Commented Jan 9, 2018 at 10:48

2 Answers 2

5

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);
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.