Skip to content

Commit 276a9ab

Browse files
committed
MC-15250: Explicit product sorting in PageBuilder Products Content type
1 parent c4dfa5d commit 276a9ab

File tree

16 files changed

+189
-464
lines changed

16 files changed

+189
-464
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\PageBuilder\Model\Catalog\Sorting;
10+
11+
use Magento\Framework\DB\Select;
12+
13+
/**
14+
* Class for sorting by specified attribute
15+
*/
16+
class Attribute implements SortInterface
17+
{
18+
/**
19+
* @var string
20+
*/
21+
private $label;
22+
23+
/**
24+
* @var string
25+
*/
26+
private $sort_direction;
27+
28+
/**
29+
* @var string
30+
*/
31+
private $attribute_field;
32+
33+
/**
34+
* @param string $label
35+
* @param string $sort_direction
36+
* @param string $attribute_field
37+
*/
38+
public function __construct(
39+
string $label,
40+
string $sort_direction,
41+
string $attribute_field
42+
) {
43+
$this->label = $label;
44+
$this->sort_direction = $sort_direction;
45+
$this->attribute_field = $attribute_field;
46+
}
47+
48+
/**
49+
* @inheritdoc
50+
*/
51+
public function sort(
52+
\Magento\Catalog\Model\ResourceModel\Product\Collection $collection
53+
): \Magento\Catalog\Model\ResourceModel\Product\Collection {
54+
$collection->getSelect()->reset(Select::ORDER);
55+
$collection->addOrder($this->attribute_field, $this->sort_direction);
56+
return $collection;
57+
}
58+
59+
/**
60+
* @inheritdoc
61+
*/
62+
public function getLabel(): \Magento\Framework\Phrase
63+
{
64+
return __($this->label);
65+
}
66+
}

app/code/Magento/PageBuilder/Model/Catalog/Sorting/AttributeAbstract.php

Lines changed: 0 additions & 42 deletions
This file was deleted.

app/code/Magento/PageBuilder/Model/Catalog/Sorting/Date/NewestTop.php

Lines changed: 0 additions & 41 deletions
This file was deleted.

app/code/Magento/PageBuilder/Model/Catalog/Sorting/Date/OldestTop.php

Lines changed: 0 additions & 41 deletions
This file was deleted.

app/code/Magento/PageBuilder/Model/Catalog/Sorting/Name/Ascending.php

Lines changed: 0 additions & 41 deletions
This file was deleted.

app/code/Magento/PageBuilder/Model/Catalog/Sorting/Name/Descending.php

Lines changed: 0 additions & 41 deletions
This file was deleted.

app/code/Magento/PageBuilder/Model/Catalog/Sorting/PriceAbstract.php renamed to app/code/Magento/PageBuilder/Model/Catalog/Sorting/Price.php

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,31 @@
1111
use Magento\Framework\DB\Select;
1212

1313
/**
14-
* Class PriceAbstract
14+
* Class for sorting by price
1515
*/
16-
abstract class PriceAbstract extends SortAbstract implements SortInterface
16+
class Price implements SortInterface
1717
{
1818
/**
19-
* @inheritdoc
19+
* @var string
20+
*/
21+
private $label;
22+
23+
/**
24+
* @var string
2025
*/
21-
abstract protected function getSortDirection();
26+
private $sort_direction;
27+
28+
/**
29+
* @param string $label
30+
* @param string $sort_direction
31+
*/
32+
public function __construct(
33+
string $label,
34+
string $sort_direction
35+
) {
36+
$this->label = $label;
37+
$this->sort_direction = $sort_direction;
38+
}
2239

2340
/**
2441
* @inheritdoc
@@ -29,8 +46,16 @@ public function sort(
2946
$collection->joinAttribute('sorting_price', 'catalog_product/price', 'entity_id', null, 'left');
3047
$collection->getSelect()
3148
->reset(Select::ORDER)
32-
->order('sorting_price '.$this->getSortDirection());
49+
->order('sorting_price '.$this->sort_direction);
3350

3451
return $collection;
3552
}
53+
54+
/**
55+
* @inheritdoc
56+
*/
57+
public function getLabel(): \Magento\Framework\Phrase
58+
{
59+
return __($this->label);
60+
}
3661
}

app/code/Magento/PageBuilder/Model/Catalog/Sorting/Price/HighToLow.php

Lines changed: 0 additions & 33 deletions
This file was deleted.

app/code/Magento/PageBuilder/Model/Catalog/Sorting/Price/LowToHigh.php

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)