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 | |
$addRamdomProductToCategory = function($n, $arrCategoryId) { | |
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); | |
$productModel = Mage::getModel('catalog/product'); | |
$productIds = Mage::getModel('catalog/product')->getCollection()->getAllIds(); | |
foreach($arrCategoryId as $catId) { | |
$arrProductIdIndexs = array_rand($productIds, $n); |
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 | |
/** | |
* RootCategoryName is the name of root for store. | |
* Level: Level 1 child of root, Level2 child of level 1, Level is relative with rootCategoryLevel | |
* Display Mode: | |
* | |
* @param $rootCategoryName | |
* @param $level | |
* @param $displayMode |
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 | |
$getAllIdOfRootCategory = function($catname) { | |
$rootCategoryObj = Mage::getModel('catalog/category')->loadByAttribute('name', $catname); | |
$collection = Mage::getModel('catalog/category') | |
->getCollection() | |
->addPathsFilter($rootCategoryObj->getPath().'/'); | |
$arr = array(); | |
foreach($collection as $catObj) { |
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 | |
/** | |
* Note that this function do not support: | |
* - Create root category if it is not exits | |
* - The category name must do not duplicate in same root category | |
* - The name of root category must unique | |
* @param $arrKey | |
* @param $rootCategoryName | |
* @throws Exception | |
*/ |
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 | |
$deleteAllCatChildren = function($catname) { | |
$rootCategoryObj = Mage::getModel('catalog/category')->loadByAttribute('name', $catname); | |
$collection = Mage::getModel('catalog/category') | |
->getCollection() | |
->addPathsFilter($rootCategoryObj->getPath().'/'); | |
foreach($collection as $catObj) { |
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 | |
$swapEqualWithResult = function($arr, $total) { | |
$result = array(); | |
for($i = 0; $i < count($arr); $i++) { | |
for($j = 0; $j < count($arr); $j++) { | |
for($k = 0; $k < count($arr); $k++) { | |
if($arr[$i] + $arr[$j] + $arr[$k] === $total) | |
{ | |
$result = array($arr[$i], $arr[$j], $arr[$k]); |
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 | |
$deleteAllProduct = function() { | |
$products = Mage::getModel('catalog/product')->getCollection(); | |
foreach ($products as $product) { | |
try { | |
$product->delete(); | |
} catch(Exception $e) { | |
echo "Product #".$product->getId()." could not be remvoved: ".$e->getMessage(); | |
} |
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 | |
$updateAttributeOptionValue = function() { | |
$attribute_model = Mage::getModel('eav/entity_attribute'); | |
$attribute_id = $attribute_model->getIdByCode('catalog_product', 'color'); | |
$attribute = $attribute_model->load($attribute_id); | |
$arrColor = array( | |
'Brown', |
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 | |
$createAttributeSet = function($arrAttributeSetName) { | |
$entityTypeId = Mage::getModel('catalog/product')->getResource()->getTypeId(); | |
$attributeSetDefault = Mage::getModel('eav/entity_attribute_set')->getCollection() | |
->addFieldToFilter('attribute_set_name', 'Default') | |
->addFieldToFilter('entity_type_id', $entityTypeId) | |
->setPageSize(1)->getFirstItem(); |
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 | |
$createCategory = function() { | |
$data = array(); | |
$arrKey = array( | |
'Men', | |
'Men/Shirts', | |
'Men/New Arrivals', | |
'Men/Tees, Knits and Polos', |