サブカテゴリの製品の並べ替えはどのように機能しますか?
質問
製品をカテゴリに追加すると、並べ替え順序値を指定できます。
イメージング現在、「Anchor」に設定されたカテゴリ「P」と、「P」のチャイルドであるさまざまなカテゴリ「C1」と「C2」があります。
これらの製品の順序はどのように定義されていますか?これはサブカテゴリにのみ含まれていますが、親カテゴリを開くときに表示されますか?
解決
を見てみましょう Mage_Catalog_Model_Resource_Category_Indexer_Product::_refreshAnchorRelations
特にこれらの行:
$position = 'MIN('.
$adapter->getCheckSql(
'cp.category_id = ce.entity_id',
'cp.position',
'(cc.position + 1) * ('.$adapter->quoteIdentifier('cc.level').' + 1) * 10000 + cp.position'
)
.')';
cc
と ce
同じだ catalog_category_entity
テーブルと cp
は catalog_category_product
テーブル。
製品は複数の子供カテゴリになる可能性があるため、製品の位置は複数の値間で最小です。
したがって、基本的に親カテゴリの製品位置は、テーブルからの各カテゴリに関連する位置間の最小です catalog_category_product
この式に従ってください:
(child category position + 1) * (child category level + 1) * 10000 + ( product position in catalog_category_product + 1)
編集
結論:ツリー内の位置が高いカテゴリの製品は、以下の製品の前に表示されます。
他のヒント
マリウスとアンドレアスが示唆したように、あなたは Mage_Catalog_Model_Resource_Category_Indexer_Product
のcomportementを変更するクラス _refreshAnchorRelations
と reindexAll
.
為に _refreshAnchorRelations
デフォルトで持っています
'(cc.position + 1) * ('.$adapter->quoteIdentifier('cc.level').' + 1) * 10000 + cp.position'
のために変更します
'cp.position + 10000'
為に reindexAll
デフォルトで持っています
'('.$idxAdapter->quoteIdentifier('ce.position').' + 1) * '
.'('.$idxAdapter->quoteIdentifier('ce.level').' + 1 * 10000)'
.' + '.$idxAdapter->quoteIdentifier('cp.position')
のために変更します
'('.$idxAdapter->quoteIdentifier('cp.position').' + 10000)'
したがって、最小製品の位置のみが必要です。私が追加しました + 10000
一部の顧客はネガティブな位置に入るからです。