Skip to content

Commit 0822bd7

Browse files
authored
Merge pull request #3416 from magento-tsg-csl3/2.2-develop-pr8
[TSG-CSL3] 2.2-develop (pr8)
2 parents 87c76df + fe08289 commit 0822bd7

File tree

10 files changed

+441
-113
lines changed

10 files changed

+441
-113
lines changed

app/code/Magento/Catalog/Helper/Data.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Catalog\Api\CategoryRepositoryInterface;
99
use Magento\Catalog\Api\ProductRepositoryInterface;
10+
use Magento\Store\Model\ScopeInterface;
1011
use Magento\Customer\Model\Session as CustomerSession;
1112
use Magento\Framework\Exception\NoSuchEntityException;
1213
use Magento\Framework\Pricing\PriceCurrencyInterface;
@@ -269,7 +270,8 @@ public function setStoreId($store)
269270

270271
/**
271272
* Return current category path or get it from current category
272-
* and creating array of categories|product paths for breadcrumbs
273+
*
274+
* Creating array of categories|product paths for breadcrumbs
273275
*
274276
* @return array
275277
*/
@@ -378,6 +380,7 @@ public function getLastViewedUrl()
378380

379381
/**
380382
* Split SKU of an item by dashes and spaces
383+
*
381384
* Words will not be broken, unless this length is greater than $length
382385
*
383386
* @param string $sku
@@ -406,14 +409,15 @@ public function getAttributeHiddenFields()
406409
/**
407410
* Retrieve Catalog Price Scope
408411
*
409-
* @return int
412+
* @return int|null
410413
*/
411414
public function getPriceScope()
412415
{
413-
return $this->scopeConfig->getValue(
416+
$priceScope = $this->scopeConfig->getValue(
414417
self::XML_PATH_PRICE_SCOPE,
415-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
418+
ScopeInterface::SCOPE_STORE
416419
);
420+
return isset($priceScope) ? (int)$priceScope : null;
417421
}
418422

419423
/**
@@ -449,7 +453,7 @@ public function isUrlDirectivesParsingAllowed()
449453
{
450454
return $this->scopeConfig->isSetFlag(
451455
self::CONFIG_PARSE_URL_DIRECTIVES,
452-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
456+
ScopeInterface::SCOPE_STORE,
453457
$this->_storeId
454458
);
455459
}
@@ -466,19 +470,22 @@ public function getPageTemplateProcessor()
466470

467471
/**
468472
* Whether to display items count for each filter option
473+
*
469474
* @param int $storeId Store view ID
470475
* @return bool
471476
*/
472477
public function shouldDisplayProductCountOnLayer($storeId = null)
473478
{
474479
return $this->scopeConfig->isSetFlag(
475480
self::XML_PATH_DISPLAY_PRODUCT_COUNT,
476-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
481+
ScopeInterface::SCOPE_STORE,
477482
$storeId
478483
);
479484
}
480485

481486
/**
487+
* Convert tax address array to address data object with country id and postcode
488+
*
482489
* @param array $taxAddress
483490
* @return \Magento\Customer\Api\Data\AddressInterface|null
484491
*/

app/code/Magento/Catalog/Model/Product/Attribute/Backend/TierPrice/UpdateHandler.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ public function execute($entity, $arguments = [])
8282
__('Tier prices data should be array, but actually other type is received')
8383
);
8484
}
85-
$websiteId = $this->storeManager->getStore($entity->getStoreId())->getWebsiteId();
85+
$websiteId = (int)$this->storeManager->getStore($entity->getStoreId())->getWebsiteId();
8686
$isGlobal = $attribute->isScopeGlobal() || $websiteId === 0;
8787
$identifierField = $this->metadataPoll->getMetadata(ProductInterface::class)->getLinkField();
88-
$productId = $entity->getData($identifierField);
88+
$productId = (int)$entity->getData($identifierField);
8989

9090
// prepare original data to compare
9191
$origPrices = $entity->getOrigData($attribute->getName());
92-
$old = $this->prepareOriginalDataToCompare($origPrices, $isGlobal);
92+
$old = $this->prepareOldTierPriceToCompare($origPrices);
9393
// prepare data for save
9494
$new = $this->prepareNewDataForSave($priceRows, $isGlobal);
9595

@@ -262,19 +262,18 @@ private function isWebsiteGlobal(int $websiteId): bool
262262
}
263263

264264
/**
265+
* Prepare old data to compare.
266+
*
265267
* @param array|null $origPrices
266-
* @param bool $isGlobal
267268
* @return array
268269
*/
269-
private function prepareOriginalDataToCompare($origPrices, $isGlobal = true): array
270+
private function prepareOldTierPriceToCompare($origPrices): array
270271
{
271272
$old = [];
272273
if (is_array($origPrices)) {
273274
foreach ($origPrices as $data) {
274-
if ($isGlobal === $this->isWebsiteGlobal((int)$data['website_id'])) {
275-
$key = $this->getPriceKey($data);
276-
$old[$key] = $data;
277-
}
275+
$key = $this->getPriceKey($data);
276+
$old[$key] = $data;
278277
}
279278
}
280279

app/code/Magento/Catalog/view/frontend/web/js/product/provider.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55

66
define([
77
'underscore',
8+
'jquery',
89
'mageUtils',
910
'uiElement',
1011
'Magento_Catalog/js/product/storage/storage-service',
11-
'Magento_Customer/js/customer-data'
12-
], function (_, utils, Element, storage, customerData) {
12+
'Magento_Customer/js/customer-data',
13+
'Magento_Catalog/js/product/view/product-ids-resolver'
14+
], function (_, $, utils, Element, storage, customerData, productResolver) {
1315
'use strict';
1416

1517
return Element.extend({
@@ -135,11 +137,16 @@ define([
135137
*/
136138
filterIds: function (ids) {
137139
var _ids = {},
138-
currentTime = new Date().getTime() / 1000;
140+
currentTime = new Date().getTime() / 1000,
141+
currentProductIds = productResolver($('#product_addtocart_form'));
139142

140143
_.each(ids, function (id) {
141-
if (currentTime - id['added_at'] < ~~this.idsStorage.lifetime) {
144+
if (
145+
currentTime - id['added_at'] < ~~this.idsStorage.lifetime &&
146+
!_.contains(currentProductIds, id['product_id'])
147+
) {
142148
_ids[id['product_id']] = id;
149+
143150
}
144151
}, this);
145152

app/code/Magento/ConfigurableProduct/Model/Product/Configuration/Item/ItemProductResolver.php

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
use Magento\Catalog\Model\Product\Configuration\Item\ItemResolverInterface;
1414
use Magento\Framework\App\Config\ScopeConfigInterface;
1515
use Magento\Catalog\Model\Product;
16+
use Magento\Store\Model\ScopeInterface;
1617

1718
/**
18-
* {@inheritdoc}
19+
* Resolves the product from a configured item.
1920
*/
2021
class ItemProductResolver implements ItemResolverInterface
2122
{
@@ -38,28 +39,22 @@ public function __construct(ScopeConfigInterface $scopeConfig)
3839
}
3940

4041
/**
41-
* {@inheritdoc}
42+
* Get the final product from a configured item by product type and selection.
43+
*
44+
* @param ItemInterface $item
45+
* @return ProductInterface
4246
*/
4347
public function getFinalProduct(ItemInterface $item): ProductInterface
4448
{
4549
/**
4650
* Show parent product thumbnail if it must be always shown according to the related setting in system config
4751
* or if child thumbnail is not available.
4852
*/
49-
$parentProduct = $item->getProduct();
50-
$finalProduct = $parentProduct;
53+
$finalProduct = $item->getProduct();
5154
$childProduct = $this->getChildProduct($item);
5255

53-
if ($childProduct !== $parentProduct) {
54-
$configValue = $this->scopeConfig->getValue(
55-
self::CONFIG_THUMBNAIL_SOURCE,
56-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
57-
);
58-
$childThumb = $childProduct->getData('thumbnail');
59-
$finalProduct =
60-
($configValue == Thumbnail::OPTION_USE_PARENT_IMAGE) || (!$childThumb || $childThumb == 'no_selection')
61-
? $parentProduct
62-
: $childProduct;
56+
if ($childProduct !== null && $this->isUseChildProduct($childProduct)) {
57+
$finalProduct = $childProduct;
6358
}
6459

6560
return $finalProduct;
@@ -69,17 +64,30 @@ public function getFinalProduct(ItemInterface $item): ProductInterface
6964
* Get item configurable child product.
7065
*
7166
* @param ItemInterface $item
72-
* @return Product
67+
* @return Product|null
7368
*/
74-
private function getChildProduct(ItemInterface $item): Product
69+
private function getChildProduct(ItemInterface $item)
7570
{
7671
$option = $item->getOptionByCode('simple_product');
77-
$product = $item->getProduct();
7872

79-
if ($option) {
80-
$product = $option->getProduct();
81-
}
73+
return $option ? $option->getProduct() : null;
74+
}
8275

83-
return $product;
76+
/**
77+
* Is need to use child product
78+
*
79+
* @param Product $childProduct
80+
* @return bool
81+
*/
82+
private function isUseChildProduct(Product $childProduct): bool
83+
{
84+
$configValue = $this->scopeConfig->getValue(
85+
self::CONFIG_THUMBNAIL_SOURCE,
86+
ScopeInterface::SCOPE_STORE
87+
);
88+
$childThumb = $childProduct->getData('thumbnail');
89+
return $configValue !== Thumbnail::OPTION_USE_PARENT_IMAGE
90+
&& $childThumb !== null
91+
&& $childThumb !== 'no_selection';
8492
}
8593
}

0 commit comments

Comments
 (0)