私はオンラインストアのウェブサイトで働いており、その国に基づいていくつかの製品を隠すためのフィルターが必要です。 「Hide
in
Europe」という名前のlightswitchフィールド(デフォルトはfalse)を作成し、それをカテゴリに追加し、テストする一部の製品でtrueに設定しました。
これは、製品をフィルタリングするためのクエリパラメータを作成するコードブロックです。
<!-- START QUERYPARAMS -->
<!-- Initialize query paramaters array -->
{% set queryParams = {} %}
<!-- Add sale parameter to query paramaters array if searching for sale items -->
{% if craft.request.getSegment(2) == "sale" %}
{% set queryParams = queryParams|merge({ hasSales: true }) %}
{% endif %}
<!-- If on new arrivals page, add new arrivals to query parameters array -->
{% if craft.request.getSegment(2) == "new-arrivals" %}
{% set queryParams = queryParams|merge({ newArrival: true }) %}
{% endif %}
<!-- If order parameter passed in, merge it to the query parameters array -->
{% if craft.request.getParam('order') != "" and craft.request.getParam('order') != "default-sorting" %}
{% set queryParams = queryParams|merge({ order: craft.request.getParam('order') }) %}
{% endif %}
<!-- Initiating rate variable -->
{% set rate = 0 %}
<!-- Setting rate according to current currency -->
{% for currency in craft.commerce.paymentCurrencies %}
{% if currency == cart.paymentCurrency %}
{% set rate = currency.rate %}
{% endif %}
{% endfor %}
<!-- Set price variables to default values if none are passed in -->
{% if (craft.request.getParam('lowPrice') != "" and craft.request.getParam('highPrice')) != "" %}
{% set lowPrice = (craft.request.getParam('lowPrice'))/rate %}
{% set highPrice = (craft.request.getParam('highPrice'))/rate %}
{% else %}
{% set lowPrice = 0 %}
{% set highPrice = 1500 * rate %}
{% endif %}
<!-- Add price paramaters to queryParams array -->
{% set queryParams = queryParams|merge({
defaultPrice: [
'and',
'>= ' ~ lowPrice,
'<= ' ~ highPrice,
]
})
%}
{% set queryParams = queryParams|merge({ hideInEurope: false }) %}
<!-- END QUERYPARAMS -->
<!-- Perform query and store results in results array -->
{% paginate craft.commerce.products(queryParams).type(typesArray).search(queryString ~ (q is defined ? ' ~ ' ~ q : '')).limit(productLimit) as pageInfo, products %}
ご覧のとおり、
{% set queryParams = queryParams|merge({ hideInEurope: false }) %}
しかし何らかの理由で、私がTRUEと設定した製品はまだリストに掲載されています。一方、
hideInEurope:true
を設定すると、フィールドをtrueに設定した製品だけが表示されるため、動作しているようです。 paramをfalseに設定すると、
“無視される”ように見えます。何か不足していますか?
ベストアンサー
答えを見つけました。クエリのwhere節を作成するときには、 empty($
をチェックする行があるので、falseのブール値を渡すと、PHPは空文字列として解釈します。作成した。だから私は
str)
hideInEurope: 'false'
にクエリのパラメータを変更することでそれを修正しました。