Created
January 8, 2013 13:45
-
-
Save dsueiro/4483931 to your computer and use it in GitHub Desktop.
Magento: Look up for 2 simple products associated to the same configurable but with same values for super attributes
This file contains 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 "app/Mage.php"; | |
$debug = false; | |
Mage::app(); | |
// Looking for 2 simple products associated to the same configurable but with same values for super attributes | |
$collectionConfigurable = Mage::getResourceModel('catalog/product_collection') | |
->addAttributeToFilter('type_id', array('eq' => 'configurable')); | |
foreach($collectionConfigurable as $product) { | |
$attributes = array(); | |
if ($debug) { | |
echo $product->getId(); | |
echo "\n"; | |
} | |
$configurable_class = Mage::getModel('catalog/product_type_configurable'); | |
foreach($configurable_class->getConfigurableAttributes($product) as $attribute) { | |
$attribute_code = $attribute->getProductAttribute()->getAttributeCode(); | |
$configurable_attributes[] = $attribute_code; | |
$attributes[] = $attribute_code; | |
if ($debug) echo "$attribute_code\n"; | |
} | |
$children = $configurable_class->getChildrenIds($product->getId()); | |
$simples = array(); | |
if (!empty($children) && !empty($children[0])) { | |
foreach($children[0] as $childId) { | |
$arr_id = array(); | |
$child = Mage::getModel('catalog/product')->load($childId); | |
foreach($attributes as $attribute) { | |
$arr_id[] = $child->getData($attribute); | |
} | |
$id = implode('_',$arr_id); | |
if (!isset($simples[$id])) { | |
$simples[$id] = $child->getId(); | |
} else { | |
echo "Conflict between {$child->getId()} and {$simples[$id]} in configurable {$product->getId()}\n"; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment