开发者

How to get a Magento product collection as a comma separated list of SKU's

开发者 https://www.devze.com 2022-12-24 23:48 出处:网络
I have a custom module I made for Magento. From the admin, there is a multi-select list of store products. The selected products from this are output in the form of a comma separated list of SKU\'s -

I have a custom module I made for Magento. From the admin, there is a multi-select list of store products. The selected products from this are output in the form of a comma separated list of SKU's - for example:

// Get Featured Products from list
    $configData = Mage::getStoreConfig('featured_products');
    $featuredlist = $configData['settings']['featuredlist'];

This gives the output in the following format if I < ?php echo $featuredlist ?>:

cn,asc,ken,steve,nine,ecco,ana

Is it possible to output a collection from a category in the same way, as a comma separated list of SKU's? I currently use the following to get a collection:

$_productCollection = Mage::getResourceModel('reports/product_collection')
    ->addAttributeToSelect('*')
    ->addAttributeToFilter('visibility', $visibi开发者_StackOverflowlity)
    ->addCategoryFilter($_category);
    $_productCollection->load()


You can iterate a product collection and collect the SKU's of each as an array:

$sku= array();
foreach ($_productCollection as $product) {
 $sku[]= $product->getSku();
}
return implode(',', $sku);

I use this for collections returned by Mage::getModel('catalog/product')->getCollection();. YMMV with the reports/product_collection model.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号