Created
September 20, 2015 21:22
-
-
Save molotovbliss/6f20a8ce48de9baa3435 to your computer and use it in GitHub Desktop.
Options (colors) to Products
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'); | |
ob_implicit_flush(true); | |
umask(0); | |
set_time_limit(0); | |
ini_set('display_errors', 1); | |
Mage::app(); | |
Mage::setIsDeveloperMode(true); | |
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); | |
$attribute = Mage::getModel('eav/entity_attribute') | |
->loadByCode('catalog_product', 'color'); | |
$valuesCollection = Mage::getResourceModel('eav/entity_attribute_option_collection') | |
->setAttributeFilter($attribute->getData('attribute_id')) | |
->setStoreFilter(0, false); | |
$colors = array(); | |
foreach($valuesCollection as $value) { | |
$colors[$value->getOptionId()] = $value->getValue(); | |
} | |
if (count($colors)) { | |
echo "<h2>Colors</h2><ul>"; | |
foreach($colors as $optionId => $value) { | |
$products = Mage::getModel('catalog/product')->getCollection(); | |
$products->addAttributeToSelect('color'); | |
$products->addFieldToFilter(array( | |
array('attribute'=>'color', 'eq'=> $optionId | |
))); | |
echo "<li>" . $value . " - (" . $optionId . ") - (Products: ".count($products).")</li>"; | |
} | |
echo "</ul>"; | |
} | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment