Magento:使用getModel获取产品和类别 [英] Magento: using getModel to get product and category

查看:61
本文介绍了Magento:使用getModel获取产品和类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码返回一系列包含url_path的产品详细信息.要创建到该产品的链接,我必须知道该产品的类别和子类别.不幸的是,此方法无法将所有数据返回类别或子类别.

I have some code that returns an array of product details including a url_path. To create a link to this product I have to know the category and subcategory of the product. Unfortunately out all the data this method returns neither the category or sub category are pulled out.

这是我得到产品的代码:

Here is the code I have that gets a product:

$product_id = array(231, 230,229,228);

foreach ($product_id as $id){
    $productDetails = Mage::getModel('catalog/product')->load($id)->getData();
    echo $productDetails['url_path'].'<br />';
}

是否可以获取每种产品的类别和子类别?

Is it possible to get the category and subcategory for each product?

推荐答案

您正在寻找的

foreach ($product_id as $id){
    $categoryIds = Mage::getModel('catalog/product')->load($id)->getCategoryIds();    
}

它将返回您产品所属的类别ID的数组.

which will return you an array of category ids that the product belongs to.

这篇关于Magento:使用getModel获取产品和类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆