Skip to content

Commit ea8eed3

Browse files
author
Mariana Lashch
committed
Merge branch '2.2-develop' of github.com:magento/magento2ce into mpi-fix-1810
2 parents 38164c3 + 8648f52 commit ea8eed3

File tree

53 files changed

+682
-121
lines changed

Some content is hidden

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

53 files changed

+682
-121
lines changed

app/code/Magento/Catalog/Model/Api/SearchCriteria/CollectionProcessor/ConditionProcessor/ProductCategoryCondition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ private function getCategoryIds(Filter $filter): array
102102
}
103103
}
104104

105-
return array_unique(array_merge($categoryIds, ...$childCategoryIds));
105+
return array_map('intval', array_unique(array_merge($categoryIds, ...$childCategoryIds)));
106106
}
107107

108108
/**

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
}

app/code/Magento/Catalog/Model/ProductCategoryList.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ public function getCategoryIds($productId)
8181
Select::SQL_UNION_ALL
8282
);
8383

84-
$this->categoryIdList[$productId] = $this->productResource->getConnection()->fetchCol($unionSelect);
84+
$this->categoryIdList[$productId] = array_map(
85+
'intval',
86+
$this->productResource->getConnection()->fetchCol($unionSelect)
87+
);
8588
}
8689

8790
return $this->categoryIdList[$productId];

app/code/Magento/Catalog/Model/ProductRepository.php

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Magento\Framework\DB\Adapter\ConnectionException;
1919
use Magento\Framework\DB\Adapter\DeadlockException;
2020
use Magento\Framework\DB\Adapter\LockWaitException;
21+
use Magento\Framework\EntityManager\Operation\Read\ReadExtensions;
2122
use Magento\Framework\Exception\CouldNotSaveException;
2223
use Magento\Framework\Exception\InputException;
2324
use Magento\Framework\Exception\LocalizedException;
@@ -26,6 +27,7 @@
2627
use Magento\Framework\Exception\ValidatorException;
2728

2829
/**
30+
* Product Repository.
2931
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3032
* @SuppressWarnings(PHPMD.TooManyFields)
3133
*/
@@ -155,6 +157,11 @@ class ProductRepository implements \Magento\Catalog\Api\ProductRepositoryInterfa
155157
*/
156158
private $serializer;
157159

160+
/**
161+
* @var ReadExtensions
162+
*/
163+
private $readExtensions;
164+
158165
/**
159166
* ProductRepository constructor.
160167
* @param ProductFactory $productFactory
@@ -180,6 +187,7 @@ class ProductRepository implements \Magento\Catalog\Api\ProductRepositoryInterfa
180187
* @param CollectionProcessorInterface $collectionProcessor [optional]
181188
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
182189
* @param int $cacheLimit [optional]
190+
* @param ReadExtensions|null $readExtensions
183191
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
184192
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
185193
*/
@@ -206,7 +214,8 @@ public function __construct(
206214
\Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $extensionAttributesJoinProcessor,
207215
CollectionProcessorInterface $collectionProcessor = null,
208216
\Magento\Framework\Serialize\Serializer\Json $serializer = null,
209-
$cacheLimit = 1000
217+
$cacheLimit = 1000,
218+
ReadExtensions $readExtensions = null
210219
) {
211220
$this->productFactory = $productFactory;
212221
$this->collectionFactory = $collectionFactory;
@@ -229,10 +238,12 @@ public function __construct(
229238
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
230239
->get(\Magento\Framework\Serialize\Serializer\Json::class);
231240
$this->cacheLimit = (int)$cacheLimit;
241+
$this->readExtensions = $readExtensions ?: \Magento\Framework\App\ObjectManager::getInstance()
242+
->get(ReadExtensions::class);
232243
}
233244

234245
/**
235-
* {@inheritdoc}
246+
* @inheritdoc
236247
*/
237248
public function get($sku, $editMode = false, $storeId = null, $forceReload = false)
238249
{
@@ -249,11 +260,12 @@ public function get($sku, $editMode = false, $storeId = null, $forceReload = fal
249260
$this->cacheProduct($cacheKey, $product);
250261
$cachedProduct = $product;
251262
}
263+
252264
return $cachedProduct;
253265
}
254266

255267
/**
256-
* {@inheritdoc}
268+
* @inheritdoc
257269
*/
258270
public function getById($productId, $editMode = false, $storeId = null, $forceReload = false)
259271
{
@@ -272,6 +284,7 @@ public function getById($productId, $editMode = false, $storeId = null, $forceRe
272284
}
273285
$this->cacheProduct($cacheKey, $product);
274286
}
287+
275288
return $this->instancesById[$productId][$cacheKey];
276289
}
277290

@@ -292,6 +305,7 @@ protected function getCacheKey($data)
292305
}
293306
}
294307
$serializeData = $this->serializer->serialize($serializeData);
308+
295309
return sha1($serializeData);
296310
}
297311

@@ -349,6 +363,8 @@ protected function initializeProductData(array $productData, $createNew)
349363
}
350364

351365
/**
366+
* Assign product to websites.
367+
*
352368
* @param \Magento\Catalog\Model\Product $product
353369
* @return void
354370
*/
@@ -418,11 +434,12 @@ private function processLinks(ProductInterface $product, $newLinks)
418434
}
419435

420436
$product->setProductLinks($newLinks);
437+
421438
return $this;
422439
}
423440

424441
/**
425-
* {@inheritdoc}
442+
* @inheritdoc
426443
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
427444
* @SuppressWarnings(PHPMD.NPathComplexity)
428445
*/
@@ -494,7 +511,7 @@ public function save(ProductInterface $product, $saveOptions = false)
494511
}
495512

496513
/**
497-
* {@inheritdoc}
514+
* @inheritdoc
498515
*/
499516
public function delete(ProductInterface $product)
500517
{
@@ -513,20 +530,22 @@ public function delete(ProductInterface $product)
513530
}
514531
$this->removeProductFromLocalCache($sku);
515532
unset($this->instancesById[$productId]);
533+
516534
return true;
517535
}
518536

519537
/**
520-
* {@inheritdoc}
538+
* @inheritdoc
521539
*/
522540
public function deleteById($sku)
523541
{
524542
$product = $this->get($sku);
543+
525544
return $this->delete($product);
526545
}
527546

528547
/**
529-
* {@inheritdoc}
548+
* @inheritdoc
530549
*/
531550
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
532551
{
@@ -543,6 +562,7 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr
543562
$collection->load();
544563

545564
$collection->addCategoryIds();
565+
$this->addExtensionAttributes($collection);
546566
$searchResult = $this->searchResultsFactory->create();
547567
$searchResult->setSearchCriteria($searchCriteria);
548568
$searchResult->setItems($collection->getItems());
@@ -553,7 +573,7 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr
553573
$this->getCacheKey(
554574
[
555575
false,
556-
$product->hasData(\Magento\Catalog\Model\Product::STORE_ID) ? $product->getStoreId() : null
576+
$product->getStoreId()
557577
]
558578
),
559579
$product
@@ -563,6 +583,21 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr
563583
return $searchResult;
564584
}
565585

586+
/**
587+
* Add extension attributes to loaded items.
588+
*
589+
* @param Collection $collection
590+
* @return Collection
591+
*/
592+
private function addExtensionAttributes(Collection $collection): Collection
593+
{
594+
foreach ($collection->getItems() as $item) {
595+
$this->readExtensions->execute($item);
596+
}
597+
598+
return $collection;
599+
}
600+
566601
/**
567602
* Helper function that adds a FilterGroup to the collection.
568603
*
@@ -608,6 +643,8 @@ public function cleanCache()
608643
}
609644

610645
/**
646+
* Retrieve media gallery processor.
647+
*
611648
* @return ProductRepository\MediaGalleryProcessor
612649
*/
613650
private function getMediaGalleryProcessor()
@@ -616,6 +653,7 @@ private function getMediaGalleryProcessor()
616653
$this->mediaGalleryProcessor = \Magento\Framework\App\ObjectManager::getInstance()
617654
->get(ProductRepository\MediaGalleryProcessor::class);
618655
}
656+
619657
return $this->mediaGalleryProcessor;
620658
}
621659

@@ -632,6 +670,7 @@ private function getCollectionProcessor()
632670
'Magento\Catalog\Model\Api\SearchCriteria\ProductCollectionProcessor'
633671
);
634672
}
673+
635674
return $this->collectionProcessor;
636675
}
637676

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,6 +1422,11 @@ protected function _addUrlRewrite()
14221422
['cu' => $this->getTable('catalog_url_rewrite_product_category')],
14231423
'u.url_rewrite_id=cu.url_rewrite_id'
14241424
)->where('cu.category_id IN (?)', $this->_urlRewriteCategory);
1425+
} else {
1426+
$select->joinLeft(
1427+
['cu' => $this->getTable('catalog_url_rewrite_product_category')],
1428+
'u.url_rewrite_id=cu.url_rewrite_id'
1429+
)->where('cu.url_rewrite_id IS NULL');
14251430
}
14261431

14271432
// more priority is data with category id
@@ -1803,7 +1808,8 @@ protected function _productLimitationJoinWebsite()
18031808
}
18041809
$conditions[] = $this->getConnection()->quoteInto(
18051810
'product_website.website_id IN(?)',
1806-
$filters['website_ids']
1811+
$filters['website_ids'],
1812+
'int'
18071813
);
18081814
} elseif (isset(
18091815
$filters['store_id']
@@ -1815,7 +1821,7 @@ protected function _productLimitationJoinWebsite()
18151821
) {
18161822
$joinWebsite = true;
18171823
$websiteId = $this->_storeManager->getStore($filters['store_id'])->getWebsiteId();
1818-
$conditions[] = $this->getConnection()->quoteInto('product_website.website_id = ?', $websiteId);
1824+
$conditions[] = $this->getConnection()->quoteInto('product_website.website_id = ?', $websiteId, 'int');
18191825
}
18201826

18211827
$fromPart = $this->getSelect()->getPart(\Magento\Framework\DB\Select::FROM);
@@ -2011,12 +2017,12 @@ protected function _applyProductLimitations()
20112017

20122018
$conditions = [
20132019
'cat_index.product_id=e.entity_id',
2014-
$this->getConnection()->quoteInto('cat_index.store_id=?', $filters['store_id']),
2020+
$this->getConnection()->quoteInto('cat_index.store_id=?', $filters['store_id'], 'int'),
20152021
];
20162022
if (isset($filters['visibility']) && !isset($filters['store_table'])) {
2017-
$conditions[] = $this->getConnection()->quoteInto('cat_index.visibility IN(?)', $filters['visibility']);
2023+
$conditions[] = $this->getConnection()->quoteInto('cat_index.visibility IN(?)', $filters['visibility'], 'int');
20182024
}
2019-
$conditions[] = $this->getConnection()->quoteInto('cat_index.category_id=?', $filters['category_id']);
2025+
$conditions[] = $this->getConnection()->quoteInto('cat_index.category_id=?', $filters['category_id'], 'int');
20202026
if (isset($filters['category_is_anchor'])) {
20212027
$conditions[] = $this->getConnection()->quoteInto('cat_index.is_parent=?', $filters['category_is_anchor']);
20222028
}

app/code/Magento/Catalog/etc/adminhtml/system.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@
8383
<backend_model>Magento\Catalog\Model\Indexer\Product\Flat\System\Config\Mode</backend_model>
8484
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
8585
</field>
86-
<field id="default_sort_by" translate="label" type="select" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
86+
<field id="default_sort_by" translate="label comment" type="select" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
8787
<label>Product Listing Sort by</label>
88+
<comment>Applies to category pages</comment>
8889
<source_model>Magento\Catalog\Model\Config\Source\ListSort</source_model>
8990
</field>
9091
<field id="list_allow_all" translate="label comment" type="select" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="1">

app/code/Magento/CatalogSearch/Model/Indexer/Fulltext/Action/DataProvider.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,20 @@ public function getSearchableAttributes($backendType = null)
316316
/** @var \Magento\Eav\Model\Entity\Attribute[] $attributes */
317317
$attributes = $productAttributes->getItems();
318318

319+
/**
320+
* @deprecated Event argument catelogsearch_searchable_attributes_load_after.
321+
* @see catalogsearch_searchable_attributes_load_after instead.
322+
*/
319323
$this->eventManager->dispatch(
320324
'catelogsearch_searchable_attributes_load_after',
321325
['engine' => $this->engine, 'attributes' => $attributes]
322326
);
323327

328+
$this->eventManager->dispatch(
329+
'catalogsearch_searchable_attributes_load_after',
330+
['engine' => $this->engine, 'attributes' => $attributes]
331+
);
332+
324333
$entity = $this->eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getEntity();
325334

326335
foreach ($attributes as $attribute) {

0 commit comments

Comments
 (0)