【问题标题】:I need a dropdown brands filter for Silvershop我需要 Silvershop 的下拉品牌过滤器
【发布时间】:2017-10-12 02:42:41
【问题描述】:

如何过滤模板中 AdditionalCategories 上的 $Product?

我试过了:

$Product.filter('AdditionalCategories', $MyFilter)

但是数据库中 Product 上没有 AdditionalCategories 列

【问题讨论】:

    标签: silverstripe silvershop


    【解决方案1】:

    在@3dgoo 的帮助下,

    看来我需要以下内容:

    <% loop $Products.filter('Product_ProductCategories.ProductCategoryID', $MyFilter) %>
    

    【讨论】:

      【解决方案2】:

      ProductProductCategory 具有多对多关系,称为 ProductCategories

      如果我们想根据类别关系过滤产品,我们会调用以下代码:

      $Product.filter('ProductCategories.ID', 5)
      

      我建议在控制器的函数中编写此过滤器。像这样的:

      public function getFilteredProducts() {
          return Product::get()->filter('ProductCategories.Title', 'my-filter');
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-05-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-05-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多