3

並べ替えに関連して見つけたいくつかの投稿を調べましたが、必要な解決策が思いつきませんでした。

現在、次のコードを使用してカテゴリ ビュー フィールドで製品を並べ替え、デフォルトのオプションを上書きし、toolbar.phtml の属性で並べ替えています。

<option value="<?php echo $this->getOrderUrl('name', 'asc') ?>"<?php if($this->isOrderCurrent('name')): ?> selected="selected"<?php endif; ?>>
                 NAME
            </option>
            <option value="<?php echo $this->getOrderUrl('short_description', 'asc') ?>"<?php if($this->isOrderCurrent('short_description')): ?> selected="selected"<?php endif; ?>>
                 FRAGRANCE
            </option>
            <option value="<?php echo $this->getOrderUrl('price', 'asc') ?>"<?php if($this->isOrderCurrent('price') && $this->getCurrentDirection() == 'asc'): ?> selected="selected"<?php endif; ?>>
                 PRICE (Low to High)
            </option>
            <option value="<?php echo $this->getOrderUrl('price', 'desc') ?>"<?php if($this->isOrderCurrent('price') && $this->getCurrentDirection() == 'desc'): ?> selected="selected"<?php endif; ?>>
                 PRICE (High to Low)
            </option>

(カスタムフレグランス属性を追加する代わりに、誤って short_description 属性を使用しました)

今、私が必要とする機能は、これらのそれぞれが使用されるとき、たとえば価格でソートする場合、すでに行っている価格でソートした後、別のカスタム属性「範囲」で二次的にソートすることです。そのため、£3 のすべての製品を表示する必要がある場合は、現時点でランダムに見えるものではなく、各範囲の製品をまとめて表示します。

これは、ライブに移行するための最後の主要な障害であるため、どんな助けも大歓迎です。

toolbar.php の次の行を使用して、道路を少し通り抜けることができました。

if ($this->getCurrentOrder()) {
      $this->_collection->setOrder(array($this->getCurrentOrder(), 'range'), $this->getCurrentDirection());
 }

それに関する唯一の問題は、価格ではなく最初に範囲でソートされるように見えることです。つまり、すべての範囲 1 が価格順に並べられ、次に範囲 2 が価格順に並べられます。範囲で価格で注文する必要があるため、価格のサブオーダー

4

1 に答える 1

4

商品コレクションを呼び出すとsetOrder()、指定された属性がであるかどうかがチェックされ、そうである場合は代わりにprice使用されます。これは、価格での並べ替えには、一般的な方法addAttributeToSortで行われるものよりも具体的なコードが必要であるという事実によるものです。ただし、配列に合格すると、テストは失敗し、共通のコードが使用されるため、代わりに2つの呼び出し を分離してみることができます。sortOrder
setOrder()

if ($this->getCurrentOrder()) {
    $this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
    $this->_collection->setOrder('range', $this->getCurrentDirection());
 }
于 2012-07-16T09:53:30.040 に答える