Created
August 16, 2018 08:22
-
-
Save zeloc/4a0ee7a29f0bfb4c4020f87aa74d2fc4 to your computer and use it in GitHub Desktop.
Gets the product ids for bundle products that have options, that is more then one where a customer has to choose an option
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_once('abstract.php'); | |
class Space48_Shell_ProductIds extends Mage_Shell_Abstract | |
{ | |
/** | |
* Entry point | |
*/ | |
public function run() | |
{ | |
$products = Mage::getModel('catalog/product')->getCollection(); | |
foreach($products as $product){ | |
$this->getOptions($product); | |
} | |
} | |
public function getIds() | |
{ | |
if(!$sku = $this->getArg('sku')){ | |
die('no sku'); | |
} | |
$id = Mage::getModel('catalog/product')->loadByAttribute('sku',$sku)->getId(); | |
echo 'sku: ' . $sku . ' product id = ' . $id; | |
} | |
public function getOptions($product) | |
{ | |
if($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE){ | |
$typeInstance = $product->getTypeInstance(true); | |
$typeInstance->setStoreFilter($product->getStoreId(), $product); | |
$optionCollection = $typeInstance->getOptionsCollection($product); | |
$selectionCollection = $typeInstance->getSelectionsCollection( | |
$typeInstance->getOptionsIds($product), | |
$product | |
); | |
/** @var $optionCollection Mage_Bundle_Model_Resource_Option_Collection */ | |
$options = $optionCollection->appendSelections($selectionCollection, false, | |
true | |
); | |
foreach($options as $option){ | |
$optionSelection = $option->getData('selections'); | |
if(is_array($optionSelection) && count($optionSelection) > 1){ | |
Mage::log('id: ' . $product->getId() . ' sku: ' . $product->getSku(), 6, 'debug.log', true); | |
break; | |
} | |
} | |
return $options; | |
} | |
} | |
} | |
$ids = new Space48_Shell_ProductIds(); | |
$ids->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment