Skip to content

Commit eb0d499

Browse files
committed
Merge branch '2.2-develop' into ENGCOM-3271-magento-magento2-18808
2 parents f009a5f + 0822bd7 commit eb0d499

File tree

64 files changed

+1370
-253
lines changed

Some content is hidden

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

64 files changed

+1370
-253
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/Model/Product/Url.php

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

88
use Magento\UrlRewrite\Model\UrlFinderInterface;
99
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
1011

1112
/**
1213
* Product Url model
@@ -45,38 +46,37 @@ class Url extends \Magento\Framework\DataObject
4546
*/
4647
protected $urlFinder;
4748

49+
/**
50+
* @var ScopeConfigInterface
51+
*/
52+
private $scopeConfig;
53+
4854
/**
4955
* @param \Magento\Framework\UrlFactory $urlFactory
5056
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
5157
* @param \Magento\Framework\Filter\FilterManager $filter
5258
* @param \Magento\Framework\Session\SidResolverInterface $sidResolver
5359
* @param UrlFinderInterface $urlFinder
5460
* @param array $data
61+
* @param ScopeConfigInterface|null $scopeConfig
5562
*/
5663
public function __construct(
5764
\Magento\Framework\UrlFactory $urlFactory,
5865
\Magento\Store\Model\StoreManagerInterface $storeManager,
5966
\Magento\Framework\Filter\FilterManager $filter,
6067
\Magento\Framework\Session\SidResolverInterface $sidResolver,
6168
UrlFinderInterface $urlFinder,
62-
array $data = []
69+
array $data = [],
70+
ScopeConfigInterface $scopeConfig = null
6371
) {
6472
parent::__construct($data);
6573
$this->urlFactory = $urlFactory;
6674
$this->storeManager = $storeManager;
6775
$this->filter = $filter;
6876
$this->sidResolver = $sidResolver;
6977
$this->urlFinder = $urlFinder;
70-
}
71-
72-
/**
73-
* Retrieve URL Instance
74-
*
75-
* @return \Magento\Framework\UrlInterface
76-
*/
77-
private function getUrlInstance()
78-
{
79-
return $this->urlFactory->create();
78+
$this->scopeConfig = $scopeConfig ?:
79+
\Magento\Framework\App\ObjectManager::getInstance()->get(ScopeConfigInterface::class);
8080
}
8181

8282
/**
@@ -157,10 +157,19 @@ public function getUrl(\Magento\Catalog\Model\Product $product, $params = [])
157157
UrlRewrite::ENTITY_TYPE => \Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator::ENTITY_TYPE,
158158
UrlRewrite::STORE_ID => $storeId,
159159
];
160-
if ($categoryId) {
160+
$useCategories = $this->scopeConfig->getValue(
161+
\Magento\Catalog\Helper\Product::XML_PATH_PRODUCT_URL_USE_CATEGORY,
162+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
163+
);
164+
165+
if ($useCategories && $categoryId) {
161166
$filterData[UrlRewrite::METADATA]['category_id'] = $categoryId;
167+
} elseif (!$useCategories) {
168+
$filterData[UrlRewrite::METADATA]['category_id'] = '';
162169
}
170+
163171
$rewrite = $this->urlFinder->findOneByData($filterData);
172+
164173
if ($rewrite) {
165174
$requestPath = $rewrite->getRequestPath();
166175
$product->setRequestPath($requestPath);
@@ -194,6 +203,8 @@ public function getUrl(\Magento\Catalog\Model\Product $product, $params = [])
194203
$routeParams['_query'] = [];
195204
}
196205

197-
return $this->getUrlInstance()->setScope($storeId)->getUrl($routePath, $routeParams);
206+
$url = $this->urlFactory->create()->setScope($storeId);
207+
208+
return $url->getUrl($routePath, $routeParams);
198209
}
199210
}

0 commit comments

Comments
 (0)