gpt4 book ai didi

Magento 1 - 从产品 ID 中获取类别 ID

转载 作者:行者123 更新时间:2023-12-04 14:06:18 26 4
gpt4 key购买 nike

在 magento 中如何从每个产品的产品 ID 中获取每个产品的类别 ID。

   $items    = $request->getAllItems();
$c = count($items);

for ($i = 0; $i < $c; $i++) {
if ($items[$i]->getProduct() instanceof Mage_Catalog_Model_Product) {

if ($items[$i]->getProduct()->getId()) {
$this->_dhlAllowed = false;
}
}
}

这里 $items[$i]->getProduct()->getId()返回产品 ID。我想要它的类别 ID。

最佳答案

public function getProductCategory() {
/* @var $product Mage_Catalog_Model_Product */
$product = Mage::registry('current_product');
if ($product->getId()) {
$categoryIds = $product->getCategoryIds();
if (is_array($categoryIds) and count($categoryIds) >= 1) {
return Mage::getModel('catalog/category')->load($categoryIds[0]);
};
}
return false;
}

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com