【问题标题】:Detect multiple category ID of a product in Virtuemart在 Virtuemart 中检测产品的多个类别 ID
【发布时间】:2014-04-11 09:32:10
【问题描述】:

我们有这样一个声明,检查产品是否在这个类别中,然后显示一些 HTML,但问题是这个产品被放置在多个类别中,例如时尚、男士和销售:

fashion category id is 16
men category id is 12
and sale category is 64

我尝试确定产品是否也属于 SALE 类别,以便添加一些额外的 HTML,但它仅在我设置 if($this->product->virtuemart_category_id == 16) 时才有效

仅识别第一类的声明

if($this->product->virtuemart_category_id == 64){

   echo 'your Custom HTML';
}
else{
 //nothing
}

我们如何确定该产品是否也属于 SALE 类别?

【问题讨论】:

    标签: php joomla joomla2.5 joomla1.5 virtuemart


    【解决方案1】:

    试试这个,

    在 VM 中,您可以为一个产品添加多个类别,

    它会将类别 ID 作为数组提供,如下所示。

    print_r($this->product->categories );
    

    因此,如果您有需要自定义样式的预定义类别列表。

    if(in_array(16,$this->product->categories) || in_array(64,$this->product->categories) || in_array(12,$this->product->categories)){
    echo 'your styles';
    }
    

    为了更好的方法,你可以试试这样的方法

    $custom_cats          = array(12,16,64);//your custom categories that required additional styles
    $current_product_cats = $this->product->categories;
    $checkstatus          = array_intersect($custom_cats , $current_product_cats);
    
    if(sizeof($checkstatus)>0){ // check your first array element found in second array
    echo 'your custom styles';
    }
    

    希望它的作品..

    【讨论】:

      【解决方案2】:

      您可以使用定义为||or 运算符,如下所示:

      $cat_id = $this->product->virtuemart_category_id;
      if ($cat_id == 16 || $cat_id == 64) {
         echo 'your Custom HTML';
      }
      else {
         // do nothing
      }
      

      这会检测类别是 fashion 还是 sale

      如果要检测其他类别,只需添加|| $cat_id == ID,其中ID为类别ID

      希望对你有帮助

      【讨论】:

      • 它可以工作,但不幸的是它没有看到该产品属于 64 类
      • 不知道为什么,但产品可能只有一个 id 类别
      • 很有可能。我认为在 VirtueMart 中,您只能为一个产品分配一个类别,而不是多个类别
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-04
      • 1970-01-01
      • 2016-03-20
      • 1970-01-01
      • 2019-06-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多