我知道Magento类别可以通过 $categories = Mage::getResourceModel('catalog/category_collection')
获得,但是如何获得这些类别及其各自的项目SKU的列表?Magento获取类别中的SKU列表
4
A
回答
2
如果你仅仅需要包含类别ID和SKU的数组的数组...
$skuArray = array();
$categoryCollection = Mage::getModel('catalog/category')->getCollection();
foreach ($categoryCollection as $category) {
$skuArray[$category->getId()] = $category->getProductCollection()->getColumnValues('sku');
}
另外,一个新的字段添加到每个对象集合到包含的SKU ...
$categoryCollection = Mage::getModel('catalog/category')->getCollection();
foreach ($categoryCollection as $category) {
$skus = $category->getProductCollection()->getColumnValues('sku');
$category->setData('skus', $skus);
}
如果您稍后在代码中进一步处理集合,并且仍然需要访问产品sku数组,那么这将是一个选项。
foreach($categoryCollection as $category) {
$categorySkus = $category->getData('skus');
}
2
您可以使用:
$categories = Mage::getResourceModel('catalog/category_collection');
foreach ($categories as $category) {
$products = $category->getProductCollection();
foreach ($products as $product) {
$sku[$product->getId()] = $product->getSku();
}
}
我存储所有的SKU在$sku
作为数组。你的可能会有所不同。
相关问题
- 1. 如何从Magento获取类别列表?
- 2. 创建新的magento Rest api以获取magento中的类别列表
- 3. magento在产品列表页面中获取子子类别ID
- 4. Magento获取根类别url
- 5. 获取Magento Footer中的类别ID
- 6. 如何从Magento获取产品类别及其ID的列表?
- 7. Magento从订单中获得商品SKU列表
- 8. Magento类别列表为空
- 9. Magento Rest-Api类别列表
- 10. 获取Akeneo中的类别列表
- 11. 如何根据Magento中的类别id获取类别名称
- 12. 获取magento中根类别的特定/特定类别名称
- 13. 获取子类别页中的父类别ID - Magento
- 14. 获取已删除类别的ID [Magento]
- 15. 获取类别和此类别中的项目列表
- 16. 如何获得magento类别列表中的可扩展菜单
- 17. 使用基于SOAP的API在Magento中获取产品类别列表
- 18. Magento的显示在类别列表
- 19. 获取magento商店列表
- 20. Magento - 如何从根类别之外的类别获取产品
- 21. 在前端获取Magento类别属性
- 22. Magento API:从类别获取产品
- 23. 获取Magento当前顶级类别
- 24. 使用Azure Rest API获取Azure订阅的SKU和SKU容量列表
- 25. 找不到所需的列:SKU在Magento
- 26. 在magento中获取带类似查询的类别集合
- 27. Quickbook PHP API - 获取类别列表
- 28. Magento:从产品iD获取产品类别阵列
- 29. 如何从list.phtml中获取Magento中的类别名称
- 30. PHP codeigniter获取类别和子类别的逗号分隔子类别列表