Skip to content

Commit

Permalink
Optimised the query
Browse files Browse the repository at this point in the history
  • Loading branch information
royduin committed Dec 14, 2021
1 parent 082385b commit 6db9fe6
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/Models/Scopes/CrossselProductsScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@ class CrossselProductsScope implements Scope
public function apply(Builder $builder, Model $model): void
{
$builder->selectRaw('GROUP_CONCAT(DISTINCT related.entity_id) as amasty_crosssell_ids')
->leftJoin('quote_item as item', function ($join) {
$join->on('item.quote_id', '=', 'quote.entity_id')->whereNull('item.parent_item_id');
})
->leftJoin('amasty_mostviewed_product_index as mainrule', function ($join) {
$join->on('mainrule.entity_id', '=', 'item.product_id')
->leftJoin('amasty_mostviewed_product_index as mainrule', function ($join) {
$join->on('mainrule.entity_id', '=', 'quote_item.product_id')
->where('mainrule.relation', 'where_show')
->where('mainrule.position', 'cart_into_crosssel')
->where('mainrule.store_id', config('rapidez.store'));
})
})
->leftJoin('amasty_mostviewed_product_index as related', function ($join) {
$join->on('related.rule_id', '=', 'mainrule.rule_id')
->where('related.relation', 'what_show')
Expand Down

0 comments on commit 6db9fe6

Please sign in to comment.