お返事ありがとうございます。
ec-cube\src\Eccube\Repository\ProductRepository.php::getQueryBuilderBySearchData
上記ファイルで仮に価格高い順もしくは低い順が選択されていたとき
if (!empty($searchData['orderby']) && $searchData['orderby']->getId() == $config['eccube_product_order_price_lower']) {
//@see http://doctrine-orm.readthedocs.org/en/latest/reference/dql-doctrine-query-language.html
$qb->addSelect('MIN(pc.price02) as HIDDEN price02_min');
$qb->innerJoin('p.ProductClasses', 'pc');
$qb->andWhere('pc.visible = true');
$qb->groupBy('p.id');
$qb->orderBy('price02_min', 'ASC');
$qb->addOrderBy('p.id', 'DESC');
// 価格高い順
} elseif (!empty($searchData['orderby']) && $searchData['orderby']->getId() == $config['eccube_product_order_price_higher']) {
$qb->addSelect('MAX(pc.price02) as HIDDEN price02_max');
$qb->innerJoin('p.ProductClasses', 'pc');
$qb->andWhere('pc.visible = true');
$qb->groupBy('p.id');
$qb->orderBy('price02_max', 'DESC');
$qb->addOrderBy('p.id', 'DESC');
// 新着順
}
の処理が走りますが、もしMAX()を使わないとなると、規格が2つ存在する商品の場合、どちらのprice02を評価するか分からなくないですか?
それとMAX()指定をしたカラムはwhere文から参照できないみたいですね、なので今回は以下のように対応してみました。
// EccubeEvents::FRONT_PRODUCT_INDEX_SEARCHでのイベントフック
// $subを2回使おうとしましたが、別名の重複で出来ませんでした。
$sub = $this->ProductClassRepository->createQueryBuilder('sub1');
$sub
->select('MAX(sub1.price02)')
->where('sub1.Product = p.id')
;
$sub2 = $this->ProductClassRepository->createQueryBuilder('sub2');
$sub2
->select('MAX(sub2.price02)')
->where('sub2.Product = p.id')
;
$qb
->andWhere(sprintf('(%s)', $sub->getDQL()).' >= :price_min')
->andWhere(sprintf('(%s)', $sub2->getDQL()).' <= :price_max')
->setParameter('price_min', $min)
->setParameter('price_max', $max)
;
もっとスマートに出来ればいいんですが・・・。