【问题标题】:Magento - get product count for attribute optionMagento - 获取属性选项的产品数量
【发布时间】:2023-04-02 01:35:02
【问题描述】:

我有具有属性和选项的产品。 例如 Person 属性有 Man 和 Woman 选项。 在首页我有左栏列出这些选项=男人,女人 我想显示属于该选项的产品的选项数量。

例如 10 个产品在属性 Person 中选择了选项 Man,所以在首页我想要 Man (10)。

任何提示如何做到这一点?

谢谢

【问题讨论】:

  • 你为什么不使用现有的分层导航功能——它已经在那里实现了
  • 因为这是另一种情况.. 只是有属性选项列表并想在末尾添加产品数量。
  • 看看magento是怎么实现的?

标签: magento attributes count option product


【解决方案1】:

我在 cmets 中的建议,或自定义实现示例:

$person_counts = array();
foreach ($products as $product) {
  if (!isset($person_counts[$product->getPerson()])) {
    $person_counts[$product->getPerson()] = 0;
  }
  $person_counts[$product->getPerson()]++;
}

foreach ($person_counts as $attribute => $count) {
  echo "$attribute ($count)<br />";
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-02
    • 1970-01-01
    • 1970-01-01
    • 2016-03-29
    • 1970-01-01
    相关资源
    最近更新 更多