php - 如何在 Magento 中获取产品的类别

标签 php magento

我正在尝试根据产品类别将 product_type 添加到我的 Magento Google Base 输出中,但我似乎无法做到。我有以下代码:

// Get categories from  product to include as product_type
$categoryIds = $object->getCategoryIds();
foreach($categoryIds as $categoryId) {
    $category = Mage::getModel('catalog/category')->load($categoryId);
    $this->_setAttribute('product_type', $category->getName(), 'text' );
}

问题是它返回所有 类别,而不仅仅是产品所在的类别。有人有解决方案吗?

最佳答案

使用上面 Rao 删除的源链接,我实际上找到了更好的答案:

$product = Mage::getModel('catalog/product')->load($productId);

$cats = $product->getCategoryIds();
foreach ($cats as $category_id) {
    $_cat = Mage::getModel('catalog/category')->load($category_id) ;
    echo $_cat->getName();
} 

关于php - 如何在 Magento 中获取产品的类别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5009861/

相关文章:

php - 将用户 ID 插入表单数据库提交 php

启用 ssl 后,Magento 站点重定向到主页

mysql - 如何使用 SQL 从单独的表中检索 'postcode'

css - 在 magento 中以 2 行显示更长的产品名称

php - 从 MySQL 数据库创建复选框,然后回显选择

php - 在 PHP 中合并两个 sql 查询的结果

php - 如何在zend框架中对表进行分页?

magento paypal 'PayPal response hasn' t 必填字段。'

themes - 如何在 Magento 中激活新的 adminhtml 主题?

javascript - 使用 PHP 和 Javascript 的正确登录屏幕