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);

app/code/Magento/ConfigurableProduct/Pricing/Price/LowestPriceOptionsProvider.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,16 @@ public function __construct(
6262
}
6363

6464
/**
65-
* {@inheritdoc}
65+
* @inheritdoc
6666
*/
6767
public function getProducts(ProductInterface $product)
6868
{
69-
$key = $this->storeManager->getStore()->getId() . '-' . $product->getId();
69+
$productId = $product->getId();
70+
$storeId = $product->getStoreId() ?: $this->storeManager->getStore()->getId();
71+
$key = $storeId . '-' . $productId;
7072
if (!isset($this->linkedProductMap[$key])) {
7173
$productIds = $this->resource->getConnection()->fetchCol(
72-
'(' . implode(') UNION (', $this->linkedProductSelectBuilder->build($product->getId())) . ')'
74+
'(' . implode(') UNION (', $this->linkedProductSelectBuilder->build($productId, $storeId)) . ')'
7375
);
7476

7577
$this->linkedProductMap[$key] = $this->collectionFactory->create()

app/code/Magento/ConfigurableProduct/Test/Unit/Model/ResourceModel/Product/LinkedProductSelectBuilderTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ protected function setUp()
5050
public function testBuild()
5151
{
5252
$productId = 42;
53+
$storeId = 1;
5354

5455
/** @var Select|\PHPUnit_Framework_MockObject_MockObject $selectMock */
5556
$selectMock = $this->getMockBuilder(Select::class)
@@ -67,6 +68,6 @@ public function testBuild()
6768
->method('process')
6869
->with($selectMock);
6970

70-
$this->assertEquals($expectedResult, $this->subject->build($productId));
71+
$this->assertEquals($expectedResult, $this->subject->build($productId, $storeId));
7172
}
7273
}

app/code/Magento/ConfigurableProduct/Test/Unit/Pricing/Price/LowestPriceOptionsProviderTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
namespace Magento\ConfigurableProduct\Test\Unit\Pricing\Price;
88

9+
use Magento\Catalog\Model\Product;
910
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
10-
use Magento\Catalog\Api\Data\ProductInterface;
1111
use Magento\Catalog\Model\ResourceModel\Product\LinkedProductSelectBuilderInterface;
1212
use Magento\Store\Model\StoreManagerInterface;
1313
use Magento\Store\Api\Data\StoreInterface;
@@ -102,9 +102,11 @@ protected function setUp()
102102
public function testGetProducts()
103103
{
104104
$productId = 1;
105+
$storeId = 1;
105106
$linkedProducts = ['some', 'linked', 'products', 'dataobjects'];
106-
$product = $this->getMockBuilder(ProductInterface::class)->disableOriginalConstructor()->getMock();
107+
$product = $this->createMock(Product::class);
107108
$product->expects($this->any())->method('getId')->willReturn($productId);
109+
$product->expects($this->any())->method('getStoreId')->willReturn($storeId);
108110
$this->linkedProductSelectBuilder->expects($this->any())->method('build')->with($productId)->willReturn([]);
109111
$this->productCollection
110112
->expects($this->once())

app/code/Magento/ProductAlert/Block/Email/AbstractEmail.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
namespace Magento\ProductAlert\Block\Email;
77

88
use Magento\Framework\Pricing\PriceCurrencyInterface;
9-
use Magento\Framework\App\ObjectManager;
10-
use Magento\ProductAlert\Block\Product\ImageProvider;
119

1210
/**
1311
* Product Alert Abstract Email Block
@@ -43,32 +41,23 @@ abstract class AbstractEmail extends \Magento\Framework\View\Element\Template
4341
*/
4442
protected $imageBuilder;
4543

46-
/**
47-
* @var ImageProvider
48-
*/
49-
private $imageProvider;
50-
5144
/**
5245
* @param \Magento\Framework\View\Element\Template\Context $context
5346
* @param \Magento\Framework\Filter\Input\MaliciousCode $maliciousCode
5447
* @param PriceCurrencyInterface $priceCurrency
5548
* @param \Magento\Catalog\Block\Product\ImageBuilder $imageBuilder
5649
* @param array $data
57-
* @param ImageProvider $imageProvider
5850
*/
5951
public function __construct(
6052
\Magento\Framework\View\Element\Template\Context $context,
6153
\Magento\Framework\Filter\Input\MaliciousCode $maliciousCode,
6254
PriceCurrencyInterface $priceCurrency,
6355
\Magento\Catalog\Block\Product\ImageBuilder $imageBuilder,
64-
array $data = [],
65-
ImageProvider $imageProvider = null
56+
array $data = []
6657
) {
6758
$this->imageBuilder = $imageBuilder;
6859
$this->priceCurrency = $priceCurrency;
6960
$this->_maliciousCode = $maliciousCode;
70-
$this->imageProvider = $imageProvider ?: ObjectManager::getInstance()->get(ImageProvider::class);
71-
7261
parent::__construct($context, $data);
7362
}
7463

@@ -173,6 +162,8 @@ protected function _getUrlParams()
173162
}
174163

175164
/**
165+
* Get Price Render
166+
*
176167
* @return \Magento\Framework\Pricing\Render
177168
*/
178169
protected function getPriceRender()
@@ -227,6 +218,6 @@ public function getProductPriceHtml(
227218
*/
228219
public function getImage($product, $imageId, $attributes = [])
229220
{
230-
return $this->imageProvider->getImage($product, $imageId, $attributes);
221+
return $this->imageBuilder->create($product, $imageId, $attributes);
231222
}
232223
}

0 commit comments

Comments
 (0)