Created
January 13, 2014 01:16
-
-
Save willboudle/8393139 to your computer and use it in GitHub Desktop.
Add Products to category by sku programmatically
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 | |
| // USAGE http://www.site.com/updategroupprice.php?price=14.95&sku=SKU123X | |
| require_once '../app/Mage.php'; | |
| umask(0); | |
| //Mage::app('admin'); | |
| Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); | |
| $sku = $_GET['sku']; | |
| $id = $_GET['id']; | |
| $categoryId = $_GET['catid']; | |
| // get my products | |
| $productcollection = Mage::getResourceModel('catalog/product_collection'); | |
| $productcollection->addAttributeToFilter('sku', array('like' => $sku.'%')); | |
| $productcollection->addAttributeToFilter("visibility", array("eq" => 4)); | |
| //Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($productcollection); | |
| foreach ($productcollection as $product){ | |
| $product->setCategoryIds(array($categoryId)); | |
| $product->save(); | |
| echo $product->getSku()." has been added to Category ID: ". $categoryId ."<br>"; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment