Created
April 10, 2017 12:22
-
-
Save trabulium/c8ce94b1bfef007c559cfd77fffb2478 to your computer and use it in GitHub Desktop.
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 'abstract.php'; | |
class Mage_Shell_Simples_Category extends Mage_Shell_Abstract | |
{ | |
/** | |
* Run script | |
* | |
*/ | |
public function run() | |
{ | |
if ($this->getArg('associate')) { | |
/** MageAustralia_Simples_Category */ | |
$products = Mage::getModel('catalog/product')->getCollection() | |
->addAttributeToFilter('type_id', Mage_Catalog_Model_Product_Type::TYPE_SIMPLE) | |
->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left') | |
->addAttributeToFilter( | |
'status', | |
array('neq' => Mage_Catalog_Model_Product_Status::STATUS_DISABLED) | |
); | |
$products->getSelect()->group('e.entity_id'); | |
$products->load(); | |
foreach($products as $product) { | |
echo $product->getId() . "\n"; | |
//$groupedParentIds = Mage::getModel('catalog/product_type_grouped')->getParentIdsByChild($product->getId()); | |
$groupedParentIds = array(); | |
$configurableParentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId()); | |
$parentIds = array_merge($groupedParentIds, $configurableParentIds); | |
$categoryIds = array(47); | |
foreach($parentIds as $parentId) { | |
$parent = Mage::getModel('catalog/product')->load($parentId); | |
$intersect = array_intersect($categoryIds, $parent->getCategoryIds()); | |
if(!empty($intersect)){ | |
print_r($intersect); | |
$product->setCategoryIds($parent->getCategoryIds()); | |
$product->setVisibility(1); | |
print_r($parent->getCategoryIds()); | |
$product->save(); | |
continue; | |
} | |
} | |
} | |
} else { | |
echo $this->usageHelp(); | |
} | |
} | |
/** | |
* Retrieve Usage Help Message | |
* | |
*/ | |
public function usageHelp() | |
{ | |
return <<<USAGE | |
Usage: php -f category_simple_associate.php -- [options] | |
--associate associate simple products with grouped / configurable category | |
help This help | |
USAGE; | |
} | |
} | |
$shell = new Mage_Shell_Simples_Category(); | |
$shell->run(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment