根据产品所属的类别在产品视图页面上显示不同的信息
Display different info on the Product View page depending on the Category the product belongs to
我正在使用 Magento 1.9 创建一个网站。我有 2 个类别(例如鞋子和衣服)。类别中的每个产品都需要在产品视图中显示尺码指南。但我需要显示正确的尺寸指南,这取决于产品所属的类别
即
- 查看属于鞋子类别的产品时,在产品视图中显示鞋子尺码指南
- 并在查看属于服装类别的产品时在产品视图中显示服装尺码指南
尺码指南是 Bootstrap table。
谁能告诉我如何在“产品查看”页面上显示正确的产品类别尺寸指南?
你可以做到。
首先获取您的产品所属的所有类别的列表(因为您的两个类别,鞋子和衣服,可能是您的根类别的子类别,我们将获取您的产品所属的所有类别并将它们存储为 $categoryIds。
<?php $_helper = $this->helper('catalog/output'); ?>
<?php $_product = $this->getProduct(); ?>
<?php $categoryIds = $_product->getCategoryIds(); ?>
然后我们使用一些简单的php逻辑来决定调用哪一组代码。
现在检查您的鞋子和衣服类别的类别 ID。假设鞋子的 ID 为 5,衣服的 ID 为 10
<div class="sizeguide">
<?php if(in_array(5, $categoryIds)): ?>
// Code for shoes size guide
<?php elseif (in_array(10, $categoryIds)): ?>
// Code for clothes size guide
<?php endif ?>
</div>
将您的尺码 table 填入您的产品描述字段。它会自动显示。
我正在使用 Magento 1.9 创建一个网站。我有 2 个类别(例如鞋子和衣服)。类别中的每个产品都需要在产品视图中显示尺码指南。但我需要显示正确的尺寸指南,这取决于产品所属的类别
即
- 查看属于鞋子类别的产品时,在产品视图中显示鞋子尺码指南
- 并在查看属于服装类别的产品时在产品视图中显示服装尺码指南
尺码指南是 Bootstrap table。
谁能告诉我如何在“产品查看”页面上显示正确的产品类别尺寸指南?
你可以做到。 首先获取您的产品所属的所有类别的列表(因为您的两个类别,鞋子和衣服,可能是您的根类别的子类别,我们将获取您的产品所属的所有类别并将它们存储为 $categoryIds。
<?php $_helper = $this->helper('catalog/output'); ?>
<?php $_product = $this->getProduct(); ?>
<?php $categoryIds = $_product->getCategoryIds(); ?>
然后我们使用一些简单的php逻辑来决定调用哪一组代码。 现在检查您的鞋子和衣服类别的类别 ID。假设鞋子的 ID 为 5,衣服的 ID 为 10
<div class="sizeguide">
<?php if(in_array(5, $categoryIds)): ?>
// Code for shoes size guide
<?php elseif (in_array(10, $categoryIds)): ?>
// Code for clothes size guide
<?php endif ?>
</div>
将您的尺码 table 填入您的产品描述字段。它会自动显示。