Skip to content

Commit e6e6725

Browse files
authored
Merge pull request #5253 from magento-chaika/Chaika-PR24-2020-01-22
Chaika-PR24-2020-01-22
2 parents 2c553dd + 771ce44 commit e6e6725

File tree

18 files changed

+92
-229
lines changed

18 files changed

+92
-229
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/LinkedProductSelectBuilderByIndexPrice.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515
use Magento\Store\Model\Indexer\WebsiteDimensionProvider;
1616
use Magento\Framework\Search\Request\IndexScopeResolverInterface;
1717

18+
/**
19+
* Class LinkedProductSelectBuilderByIndexPrice
20+
*
21+
* Provide Select object for retrieve product id by index price.
22+
*
23+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
24+
*/
1825
class LinkedProductSelectBuilderByIndexPrice implements LinkedProductSelectBuilderInterface
1926
{
2027
/**
@@ -83,13 +90,13 @@ public function __construct(
8390
}
8491

8592
/**
86-
* {@inheritdoc}
93+
* @inheritdoc
8794
*/
88-
public function build($productId)
95+
public function build(int $productId, int $storeId) : array
8996
{
9097
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
9198
$productTable = $this->resource->getTableName('catalog_product_entity');
92-
$websiteId = $this->storeManager->getStore()->getWebsiteId();
99+
$websiteId = $this->storeManager->getStore($storeId)->getWebsiteId();
93100
$customerGroupId = $this->customerSession->getCustomerGroupId();
94101

95102
$priceSelect = $this->resource->getConnection()->select()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function __construct(
7474
/**
7575
* @inheritdoc
7676
*/
77-
public function build($productId)
77+
public function build(int $productId, int $storeId) : array
7878
{
7979
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
8080
$priceAttribute = $this->eavConfig->getAttribute(Product::ENTITY, 'price');
@@ -104,7 +104,7 @@ public function build($productId)
104104

105105
if (!$this->catalogHelper->isPriceGlobal()) {
106106
$priceSelectStore = clone $priceSelect;
107-
$priceSelectStore->where('t.store_id = ?', $this->storeManager->getStore()->getId());
107+
$priceSelectStore->where('t.store_id = ?', $storeId);
108108
$selects[] = $priceSelectStore;
109109
}
110110

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
use Magento\Store\Model\Store;
1313

1414
/**
15+
* LinkedProductSelectBuilderBySpecialPrice
16+
*
17+
* Provide Select object for retrieve product id by special price
18+
*
1519
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1620
*/
1721
class LinkedProductSelectBuilderBySpecialPrice implements LinkedProductSelectBuilderInterface
@@ -88,16 +92,16 @@ public function __construct(
8892
}
8993

9094
/**
91-
* {@inheritdoc}
95+
* @inheritdoc
9296
*/
93-
public function build($productId)
97+
public function build(int $productId, int $storeId) : array
9498
{
9599
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
96100
$connection = $this->resource->getConnection();
97101
$specialPriceAttribute = $this->eavConfig->getAttribute(Product::ENTITY, 'special_price');
98102
$specialPriceFromDate = $this->eavConfig->getAttribute(Product::ENTITY, 'special_from_date');
99103
$specialPriceToDate = $this->eavConfig->getAttribute(Product::ENTITY, 'special_to_date');
100-
$timestamp = $this->localeDate->scopeTimeStamp($this->storeManager->getStore());
104+
$timestamp = $this->localeDate->scopeTimeStamp($this->storeManager->getStore($storeId));
101105
$currentDate = $this->dateTime->formatDate($timestamp, false);
102106
$productTable = $this->resource->getTableName('catalog_product_entity');
103107

@@ -145,7 +149,7 @@ public function build($productId)
145149

146150
if (!$this->catalogHelper->isPriceGlobal()) {
147151
$priceSelectStore = clone $specialPrice;
148-
$priceSelectStore->where('t.store_id = ?', $this->storeManager->getStore()->getId());
152+
$priceSelectStore->where('t.store_id = ?', $storeId);
149153
$selects[] = $priceSelectStore;
150154
}
151155

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,19 @@
99
use Magento\Framework\App\ObjectManager;
1010
use Magento\Framework\DB\Select;
1111

12+
/**
13+
* LinkedProductSelectBuilderByTierPrice
14+
*
15+
* Provide Select object for retrieve product id by tier price
16+
*
17+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
18+
*/
1219
class LinkedProductSelectBuilderByTierPrice implements LinkedProductSelectBuilderInterface
1320
{
1421
/**
1522
* Default website id
23+
*
24+
* Constant represents default website id
1625
*/
1726
const DEFAULT_WEBSITE_ID = 0;
1827

@@ -72,9 +81,9 @@ public function __construct(
7281
}
7382

7483
/**
75-
* {@inheritdoc}
84+
* @inheritdoc
7685
*/
77-
public function build($productId)
86+
public function build(int $productId, int $storeId) : array
7887
{
7988
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
8089
$productTable = $this->resource->getTableName('catalog_product_entity');
@@ -103,7 +112,7 @@ public function build($productId)
103112

104113
if (!$this->catalogHelper->isPriceGlobal()) {
105114
$priceSelectStore = clone $priceSelect;
106-
$priceSelectStore->where('t.website_id = ?', $this->storeManager->getStore()->getWebsiteId());
115+
$priceSelectStore->where('t.website_id = ?', $this->storeManager->getStore($storeId)->getWebsiteId());
107116
$selects[] = $priceSelectStore;
108117
}
109118

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
namespace Magento\Catalog\Model\ResourceModel\Product;
88

9+
/**
10+
* Collect Select object for list of products
11+
*/
912
class LinkedProductSelectBuilderComposite implements LinkedProductSelectBuilderInterface
1013
{
1114
/**
@@ -22,14 +25,15 @@ public function __construct($linkedProductSelectBuilder)
2225
}
2326

2427
/**
25-
* {@inheritdoc}
28+
* @inheritdoc
2629
*/
27-
public function build($productId)
30+
public function build(int $productId, int $storeId) : array
2831
{
2932
$selects = [];
3033
foreach ($this->linkedProductSelectBuilder as $productSelectBuilder) {
31-
$selects = array_merge($selects, $productSelectBuilder->build($productId));
34+
$selects[] = $productSelectBuilder->build($productId, $storeId);
3235
}
36+
$selects = array_merge(...$selects);
3337

3438
return $selects;
3539
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
interface LinkedProductSelectBuilderInterface
1212
{
1313
/**
14+
* Build Select objects
15+
*
1416
* @param int $productId
17+
* @param int $storeId
1518
* @return \Magento\Framework\DB\Select[]
1619
*/
17-
public function build($productId);
20+
public function build(int $productId, int $storeId) : array;
1821
}

app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/Indexer/LinkedProductSelectBuilderByIndexPriceTest.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,21 @@ class LinkedProductSelectBuilderByIndexPriceTest extends \PHPUnit\Framework\Test
3737
*/
3838
private $baseSelectProcessorMock;
3939

40+
/**
41+
* @var \Magento\Framework\Search\Request\IndexScopeResolverInterface|\PHPUnit\Framework\MockObject\MockObject
42+
*/
43+
private $indexScopeResolverMock;
44+
45+
/**
46+
* @var \Magento\Framework\Indexer\Dimension|\PHPUnit\Framework\MockObject\MockObject
47+
*/
48+
private $dimensionMock;
49+
50+
/**
51+
* @var \Magento\Framework\Indexer\DimensionFactory|\PHPUnit\Framework\MockObject\MockObject
52+
*/
53+
private $dimensionFactoryMock;
54+
4055
/**
4156
* @var \Magento\Catalog\Model\ResourceModel\Product\Indexer\LinkedProductSelectBuilderByIndexPrice
4257
*/
@@ -85,6 +100,7 @@ protected function setUp()
85100
public function testBuild()
86101
{
87102
$productId = 10;
103+
$storeId = 1;
88104
$metadata = $this->getMockBuilder(\Magento\Framework\EntityManager\EntityMetadataInterface::class)
89105
->disableOriginalConstructor()
90106
->getMockForAbstractClass();
@@ -108,6 +124,6 @@ public function testBuild()
108124
$metadata->expects($this->once())->method('getLinkField')->willReturn('row_id');
109125
$this->resourceMock->expects($this->any())->method('getTableName');
110126
$this->baseSelectProcessorMock->expects($this->once())->method('process')->willReturnSelf();
111-
$this->model->build($productId);
127+
$this->model->build($productId, $storeId);
112128
}
113129
}

app/code/Magento/CatalogInventory/Model/Quote/Item/QuantityValidator.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,11 @@ private function checkOptionsQtyIncrements(Item $quoteItem, array $options): voi
222222
{
223223
$removeErrors = true;
224224
foreach ($options as $option) {
225+
$optionValue = $option->getValue();
226+
$optionQty = $quoteItem->getData('qty') * $optionValue;
225227
$result = $this->stockState->checkQtyIncrements(
226228
$option->getProduct()->getId(),
227-
$quoteItem->getData('qty'),
229+
$optionQty,
228230
$option->getProduct()->getStore()->getWebsiteId()
229231
);
230232
if ($result->getHasError()) {

app/code/Magento/CatalogRule/Model/ResourceModel/Product/LinkedProductSelectBuilderByCatalogRulePrice.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ public function __construct(
8686
/**
8787
* @inheritdoc
8888
*/
89-
public function build($productId)
89+
public function build(int $productId, int $storeId) : array
9090
{
91-
$timestamp = $this->localeDate->scopeTimeStamp($this->storeManager->getStore());
91+
$timestamp = $this->localeDate->scopeTimeStamp($this->storeManager->getStore($storeId));
9292
$currentDate = $this->dateTime->formatDate($timestamp, false);
9393
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
9494
$productTable = $this->resource->getTableName('catalog_product_entity');
@@ -108,7 +108,7 @@ public function build($productId)
108108
sprintf('t.product_id = %s.%s', BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS, $linkField),
109109
[]
110110
)->where('parent.entity_id = ?', $productId)
111-
->where('t.website_id = ?', $this->storeManager->getStore()->getWebsiteId())
111+
->where('t.website_id = ?', $this->storeManager->getStore($storeId)->getWebsiteId())
112112
->where('t.customer_group_id = ?', $this->customerSession->getCustomerGroupId())
113113
->where('t.rule_date = ?', $currentDate)
114114
->order('t.rule_price ' . Select::SQL_ASC)

app/code/Magento/ConfigurableProduct/Model/ResourceModel/Product/LinkedProductSelectBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ public function __construct(
3939
}
4040

4141
/**
42-
* {@inheritdoc}
42+
* @inheritdoc
4343
*/
44-
public function build($productId)
44+
public function build(int $productId, int $storeId) : array
4545
{
46-
$selects = $this->linkedProductSelectBuilder->build($productId);
46+
$selects = $this->linkedProductSelectBuilder->build($productId, $storeId);
4747

4848
foreach ($selects as $select) {
4949
$this->baseSelectProcessor->process($select);

0 commit comments

Comments
 (0)