Skip to content

Commit d372d2b

Browse files
committed
Merge remote-tracking branch 'edenduong/2.4-bugfix/date_login_customer_issue30328' into 2.4-bugfix/date_login_customer_issue30328
2 parents ef72f80 + 8ddd329 commit d372d2b

File tree

89 files changed

+2328
-726
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+2328
-726
lines changed

app/code/Magento/Catalog/Model/Indexer/Product/Price/Action/Rows.php

Lines changed: 92 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,82 @@
55
*/
66
namespace Magento\Catalog\Model\Indexer\Product\Price\Action;
77

8+
use Magento\Directory\Model\CurrencyFactory;
9+
use Magento\Catalog\Model\Indexer\Product\Price\DimensionCollectionFactory;
10+
use Magento\Catalog\Model\Indexer\Product\Price\TableMaintainer;
11+
use Magento\Catalog\Model\Product\Type;
12+
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\DefaultPrice;
13+
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\Factory;
14+
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\TierPrice;
15+
use Magento\Framework\App\Config\ScopeConfigInterface;
16+
use Magento\Framework\Stdlib\DateTime;
17+
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
18+
use Magento\Store\Model\StoreManagerInterface;
19+
820
/**
921
* Class Rows reindex action for mass actions
1022
*
23+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) to preserve compatibility with parent class
1124
*/
1225
class Rows extends \Magento\Catalog\Model\Indexer\Product\Price\AbstractAction
1326
{
27+
/**
28+
* Default batch size
29+
*/
30+
private const BATCH_SIZE = 100;
31+
32+
/**
33+
* @var int
34+
*/
35+
private $batchSize;
36+
37+
/**
38+
* @param ScopeConfigInterface $config
39+
* @param StoreManagerInterface $storeManager
40+
* @param CurrencyFactory $currencyFactory
41+
* @param TimezoneInterface $localeDate
42+
* @param DateTime $dateTime
43+
* @param Type $catalogProductType
44+
* @param Factory $indexerPriceFactory
45+
* @param DefaultPrice $defaultIndexerResource
46+
* @param TierPrice|null $tierPriceIndexResource
47+
* @param DimensionCollectionFactory|null $dimensionCollectionFactory
48+
* @param TableMaintainer|null $tableMaintainer
49+
* @param int|null $batchSize
50+
* @SuppressWarnings(PHPMD.NPathComplexity) Added to backward compatibility with abstract class
51+
* @SuppressWarnings(PHPMD.CyclomaticComplexity) Added to backward compatibility with abstract class
52+
* @SuppressWarnings(PHPMD.ExcessiveParameterList) Added to backward compatibility with abstract class
53+
*/
54+
public function __construct(
55+
ScopeConfigInterface $config,
56+
StoreManagerInterface $storeManager,
57+
CurrencyFactory $currencyFactory,
58+
TimezoneInterface $localeDate,
59+
DateTime $dateTime,
60+
Type $catalogProductType,
61+
Factory $indexerPriceFactory,
62+
DefaultPrice $defaultIndexerResource,
63+
TierPrice $tierPriceIndexResource = null,
64+
DimensionCollectionFactory $dimensionCollectionFactory = null,
65+
TableMaintainer $tableMaintainer = null,
66+
?int $batchSize = null
67+
) {
68+
parent::__construct(
69+
$config,
70+
$storeManager,
71+
$currencyFactory,
72+
$localeDate,
73+
$dateTime,
74+
$catalogProductType,
75+
$indexerPriceFactory,
76+
$defaultIndexerResource,
77+
$tierPriceIndexResource,
78+
$dimensionCollectionFactory,
79+
$tableMaintainer
80+
);
81+
$this->batchSize = $batchSize ?? self::BATCH_SIZE;
82+
}
83+
1484
/**
1585
* Execute Rows reindex
1686
*
@@ -24,10 +94,28 @@ public function execute($ids)
2494
if (empty($ids)) {
2595
throw new \Magento\Framework\Exception\InputException(__('Bad value was supplied.'));
2696
}
27-
try {
28-
$this->_reindexRows($ids);
29-
} catch (\Exception $e) {
30-
throw new \Magento\Framework\Exception\LocalizedException(__($e->getMessage()), $e);
97+
$currentBatch = [];
98+
$i = 0;
99+
100+
foreach ($ids as $id) {
101+
$currentBatch[] = $id;
102+
if (++$i === $this->batchSize) {
103+
try {
104+
$this->_reindexRows($currentBatch);
105+
} catch (\Exception $e) {
106+
throw new \Magento\Framework\Exception\LocalizedException(__($e->getMessage()), $e);
107+
}
108+
$i = 0;
109+
$currentBatch = [];
110+
}
111+
}
112+
113+
if (!empty($currentBatch)) {
114+
try {
115+
$this->_reindexRows($currentBatch);
116+
} catch (\Exception $e) {
117+
throw new \Magento\Framework\Exception\LocalizedException(__($e->getMessage()), $e);
118+
}
31119
}
32120
}
33121
}

app/code/Magento/Catalog/Model/ResourceModel/Product/Relation.php

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,38 @@
55
*/
66
namespace Magento\Catalog\Model\ResourceModel\Product;
77

8+
use Magento\Framework\App\ObjectManager;
9+
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
10+
use Magento\Framework\Model\ResourceModel\Db\Context;
11+
use Magento\Framework\EntityManager\MetadataPool;
12+
use Magento\Catalog\Api\Data\ProductInterface;
13+
814
/**
915
* Catalog Product Relations Resource model
1016
*
1117
* @author Magento Core Team <core@magentocommerce.com>
1218
*/
13-
class Relation extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
19+
class Relation extends AbstractDb
1420
{
21+
/**
22+
* @var MetadataPool
23+
*/
24+
private $metadataPool;
25+
26+
/**
27+
* @param Context $context
28+
* @param string $connectionName
29+
* @param MetadataPool $metadataPool
30+
*/
31+
public function __construct(
32+
Context $context,
33+
$connectionName = null,
34+
MetadataPool $metadataPool = null
35+
) {
36+
parent::__construct($context, $connectionName);
37+
$this->metadataPool = $metadataPool ?: ObjectManager::getInstance()->get(MetadataPool::class);
38+
}
39+
1540
/**
1641
* Initialize resource model and define main table
1742
*
@@ -109,4 +134,27 @@ public function removeRelations($parentId, $childIds)
109134
}
110135
return $this;
111136
}
137+
138+
/**
139+
* Finds parent relations by given children ids.
140+
*
141+
* @param array $childrenIds Child products entity ids.
142+
* @return array Parent products entity ids.
143+
*/
144+
public function getRelationsByChildren(array $childrenIds): array
145+
{
146+
$connection = $this->getConnection();
147+
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)
148+
->getLinkField();
149+
$select = $connection->select()
150+
->from(
151+
['cpe' => $this->getTable('catalog_product_entity')],
152+
'entity_id'
153+
)->join(
154+
['relation' => $this->getTable('catalog_product_relation')],
155+
'relation.parent_id = cpe.' . $linkField
156+
)->where('relation.child_id IN(?)', $childrenIds);
157+
158+
return $connection->fetchCol($select);
159+
}
112160
}

app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Price/Action/RowsTest.php

Lines changed: 167 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,189 @@
77

88
namespace Magento\Catalog\Test\Unit\Model\Indexer\Product\Price\Action;
99

10+
use Magento\Store\Model\StoreManagerInterface;
11+
use Magento\Directory\Model\CurrencyFactory;
12+
use Magento\Catalog\Model\Product\Type;
13+
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\Factory;
14+
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\DefaultPrice;
15+
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\TierPrice;
16+
use Magento\Catalog\Model\Indexer\Product\Price\DimensionCollectionFactory;
17+
use Magento\Catalog\Model\Indexer\Product\Price\TableMaintainer;
1018
use Magento\Catalog\Model\Indexer\Product\Price\Action\Rows;
11-
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
19+
use Magento\Framework\App\Config\ScopeConfigInterface;
20+
use Magento\Framework\Stdlib\DateTime;
21+
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
22+
use Magento\Framework\DB\Adapter\AdapterInterface;
23+
use Magento\Framework\DB\Select;
24+
use Magento\Framework\Indexer\MultiDimensionProvider;
1225
use PHPUnit\Framework\TestCase;
26+
use PHPUnit\Framework\MockObject\MockObject;
1327

28+
/**
29+
* Test coverage for the rows action
30+
*
31+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) to preserve compatibility with parent class
32+
*/
1433
class RowsTest extends TestCase
1534
{
1635
/**
1736
* @var Rows
1837
*/
19-
protected $_model;
38+
private $actionRows;
39+
40+
/**
41+
* @var ScopeConfigInterface|MockObject
42+
*/
43+
private $config;
44+
45+
/**
46+
* @var StoreManagerInterface|MockObject
47+
*/
48+
private $storeManager;
49+
50+
/**
51+
* @var CurrencyFactory|MockObject
52+
*/
53+
private $currencyFactory;
54+
55+
/**
56+
* @var TimezoneInterface|MockObject
57+
*/
58+
private $localeDate;
59+
60+
/**
61+
* @var DateTime|MockObject
62+
*/
63+
private $dateTime;
64+
65+
/**
66+
* @var Type|MockObject
67+
*/
68+
private $catalogProductType;
69+
70+
/**
71+
* @var Factory|MockObject
72+
*/
73+
private $indexerPriceFactory;
74+
75+
/**
76+
* @var DefaultPrice|MockObject
77+
*/
78+
private $defaultIndexerResource;
79+
80+
/**
81+
* @var TierPrice|MockObject
82+
*/
83+
private $tierPriceIndexResource;
84+
85+
/**
86+
* @var DimensionCollectionFactory|MockObject
87+
*/
88+
private $dimensionCollectionFactory;
89+
90+
/**
91+
* @var TableMaintainer|MockObject
92+
*/
93+
private $tableMaintainer;
2094

2195
protected function setUp(): void
2296
{
23-
$objectManager = new ObjectManager($this);
24-
$this->_model = $objectManager->getObject(Rows::class);
97+
$this->config = $this->getMockBuilder(ScopeConfigInterface::class)
98+
->getMockForAbstractClass();
99+
$this->storeManager = $this->getMockBuilder(StoreManagerInterface::class)
100+
->getMockForAbstractClass();
101+
$this->currencyFactory = $this->getMockBuilder(CurrencyFactory::class)
102+
->disableOriginalConstructor()
103+
->getMock();
104+
$this->localeDate = $this->getMockBuilder(TimezoneInterface::class)
105+
->getMockForAbstractClass();
106+
$this->dateTime = $this->getMockBuilder(DateTime::class)
107+
->disableOriginalConstructor()
108+
->getMock();
109+
$this->catalogProductType = $this->getMockBuilder(Type::class)
110+
->disableOriginalConstructor()
111+
->getMock();
112+
$this->indexerPriceFactory = $this->getMockBuilder(Factory::class)
113+
->disableOriginalConstructor()
114+
->getMock();
115+
$this->defaultIndexerResource = $this->getMockBuilder(DefaultPrice::class)
116+
->disableOriginalConstructor()
117+
->getMock();
118+
$this->tierPriceIndexResource = $this->getMockBuilder(TierPrice::class)
119+
->disableOriginalConstructor()
120+
->getMock();
121+
$this->dimensionCollectionFactory = $this->getMockBuilder(DimensionCollectionFactory::class)
122+
->disableOriginalConstructor()
123+
->getMock();
124+
$this->tableMaintainer = $this->getMockBuilder(TableMaintainer::class)
125+
->disableOriginalConstructor()
126+
->getMock();
127+
$batchSize = 2;
128+
129+
$this->actionRows = new Rows(
130+
$this->config,
131+
$this->storeManager,
132+
$this->currencyFactory,
133+
$this->localeDate,
134+
$this->dateTime,
135+
$this->catalogProductType,
136+
$this->indexerPriceFactory,
137+
$this->defaultIndexerResource,
138+
$this->tierPriceIndexResource,
139+
$this->dimensionCollectionFactory,
140+
$this->tableMaintainer,
141+
$batchSize
142+
);
25143
}
26144

27145
public function testEmptyIds()
28146
{
29147
$this->expectException('Magento\Framework\Exception\InputException');
30148
$this->expectExceptionMessage('Bad value was supplied.');
31-
$this->_model->execute(null);
149+
$this->actionRows->execute(null);
150+
}
151+
152+
public function testBatchProcessing()
153+
{
154+
$ids = [1, 2, 3, 4];
155+
$select = $this->getMockBuilder(Select::class)
156+
->disableOriginalConstructor()
157+
->getMock();
158+
$select->expects($this->any())->method('from')->willReturnSelf();
159+
$select->expects($this->any())->method('where')->willReturnSelf();
160+
$select->expects($this->any())->method('join')->willReturnSelf();
161+
$adapter = $this->getMockBuilder(AdapterInterface::class)->getMockForAbstractClass();
162+
$adapter->expects($this->any())->method('select')->willReturn($select);
163+
$this->defaultIndexerResource->expects($this->any())
164+
->method('getConnection')
165+
->willReturn($adapter);
166+
$adapter->expects($this->any())
167+
->method('fetchAll')
168+
->with($select)
169+
->willReturn([]);
170+
$adapter->expects($this->any())
171+
->method('fetchPairs')
172+
->with($select)
173+
->willReturn([]);
174+
$multiDimensionProvider = $this->getMockBuilder(MultiDimensionProvider::class)
175+
->disableOriginalConstructor()
176+
->getMock();
177+
$this->dimensionCollectionFactory->expects($this->exactly(2))
178+
->method('create')
179+
->willReturn($multiDimensionProvider);
180+
$iterator = new \ArrayIterator([]);
181+
$multiDimensionProvider->expects($this->exactly(2))
182+
->method('getIterator')
183+
->willReturn($iterator);
184+
$this->catalogProductType->expects($this->any())
185+
->method('getTypesByPriority')
186+
->willReturn([]);
187+
$adapter->expects($this->exactly(2))
188+
->method('getIndexList')
189+
->willReturn(['entity_id'=>['COLUMNS_LIST'=>['test']]]);
190+
$adapter->expects($this->exactly(2))
191+
->method('getPrimaryKeyName')
192+
->willReturn('entity_id');
193+
$this->actionRows->execute($ids);
32194
}
33195
}

app/code/Magento/CatalogGraphQl/DataProvider/Product/LayeredNavigation/Builder/Price.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function build(AggregationInterface $aggregation, ?int $storeId): array
7272
);
7373
}
7474

75-
return [$result];
75+
return [self::PRICE_BUCKET => $result];
7676
}
7777

7878
/**

0 commit comments

Comments
 (0)