Created
December 30, 2013 17:13
-
-
Save tegansnyder/8184936 to your computer and use it in GitHub Desktop.
Get a list of skus in a category ID comma separated in Magento
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'; | |
| umask(0); | |
| Mage::app('default'); | |
| $cat_id = 2117; | |
| $skus = array(); | |
| $category = Mage::getModel('catalog/category')->load($cat_id); | |
| $collection = $category->getProductCollection()->addAttributeToSort('position'); | |
| Mage::getModel('catalog/layer')->prepareProductCollection($collection); | |
| foreach ($collection as $product) { | |
| $product_id = $product->getId(); | |
| $_product = Mage::getModel('catalog/product')->load($product_id); | |
| $skus[] = $_product->getSku(); | |
| } | |
| $sku_list = implode(',', $skus); | |
| echo $sku_list; |
Can you write the same code for magneto 2 ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You should not run product model load inside a loop like this as it would cause performance issue.
Not sure if the SKU is already available inside the loop in your example without loading the model.
If not, try