Skip to content

Commit 4f07c61

Browse files
committed
Merge branch '2.2-develop' into fix/2.2-issue-18904-missing-asterisk-for-admin-required-fields
2 parents 7d2dd65 + e9b525a commit 4f07c61

File tree

56 files changed

+711
-59
lines changed

Some content is hidden

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

56 files changed

+711
-59
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/Attribute/Backend/Sku.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ protected function _generateUniqueSku($object)
9797
public function beforeSave($object)
9898
{
9999
$this->_generateUniqueSku($object);
100+
$this->trimValue($object);
100101
return parent::beforeSave($object);
101102
}
102103

@@ -127,4 +128,17 @@ protected function _getLastSimilarAttributeValueIncrement($attribute, $object)
127128
$data = $connection->fetchOne($select, $bind);
128129
return abs((int)str_replace($value, '', $data));
129130
}
131+
132+
/**
133+
* @param Product $object
134+
* @return void
135+
*/
136+
private function trimValue($object)
137+
{
138+
$attrCode = $this->getAttribute()->getAttributeCode();
139+
$value = $object->getData($attrCode);
140+
if ($value) {
141+
$object->setData($attrCode, trim($value));
142+
}
143+
}
130144
}

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: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,7 +1803,8 @@ protected function _productLimitationJoinWebsite()
18031803
}
18041804
$conditions[] = $this->getConnection()->quoteInto(
18051805
'product_website.website_id IN(?)',
1806-
$filters['website_ids']
1806+
$filters['website_ids'],
1807+
'int'
18071808
);
18081809
} elseif (isset(
18091810
$filters['store_id']
@@ -1815,7 +1816,7 @@ protected function _productLimitationJoinWebsite()
18151816
) {
18161817
$joinWebsite = true;
18171818
$websiteId = $this->_storeManager->getStore($filters['store_id'])->getWebsiteId();
1818-
$conditions[] = $this->getConnection()->quoteInto('product_website.website_id = ?', $websiteId);
1819+
$conditions[] = $this->getConnection()->quoteInto('product_website.website_id = ?', $websiteId, 'int');
18191820
}
18201821

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

20122013
$conditions = [
20132014
'cat_index.product_id=e.entity_id',
2014-
$this->getConnection()->quoteInto('cat_index.store_id=?', $filters['store_id']),
2015+
$this->getConnection()->quoteInto('cat_index.store_id=?', $filters['store_id'], 'int'),
20152016
];
20162017
if (isset($filters['visibility']) && !isset($filters['store_table'])) {
2017-
$conditions[] = $this->getConnection()->quoteInto('cat_index.visibility IN(?)', $filters['visibility']);
2018+
$conditions[] = $this->getConnection()->quoteInto('cat_index.visibility IN(?)', $filters['visibility'], 'int');
20182019
}
2019-
$conditions[] = $this->getConnection()->quoteInto('cat_index.category_id=?', $filters['category_id']);
2020+
$conditions[] = $this->getConnection()->quoteInto('cat_index.category_id=?', $filters['category_id'], 'int');
20202021
if (isset($filters['category_is_anchor'])) {
20212022
$conditions[] = $this->getConnection()->quoteInto('cat_index.is_parent=?', $filters['category_is_anchor']);
20222023
}

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use Magento\Ui\DataProvider\Mapper\FormElement as FormElementMapper;
3333
use Magento\Ui\DataProvider\Mapper\MetaProperties as MetaPropertiesMapper;
3434
use Magento\Eav\Model\ResourceModel\Entity\Attribute\CollectionFactory as AttributeCollectionFactory;
35+
use \Magento\Catalog\Model\Product\Type as ProductType;
3536

3637
/**
3738
* Class Eav
@@ -398,7 +399,7 @@ public function modifyData(array $data)
398399

399400
foreach ($attributes as $attribute) {
400401
if (null !== ($attributeValue = $this->setupAttributeData($attribute))) {
401-
if ($attribute->getFrontendInput() === 'price' && is_scalar($attributeValue)) {
402+
if ($this->isPriceAttribute($attribute, $attributeValue)) {
402403
$attributeValue = $this->formatPrice($attributeValue);
403404
}
404405
$data[$productId][self::DATA_SOURCE_DEFAULT][$attribute->getAttributeCode()] = $attributeValue;
@@ -409,6 +410,32 @@ public function modifyData(array $data)
409410
return $data;
410411
}
411412

413+
/**
414+
* Obtain if given attribute is a price
415+
*
416+
* @param \Magento\Catalog\Api\Data\ProductAttributeInterface $attribute
417+
* @param string|integer $attributeValue
418+
* @return bool
419+
*/
420+
private function isPriceAttribute(ProductAttributeInterface $attribute, $attributeValue)
421+
{
422+
return $attribute->getFrontendInput() === 'price'
423+
&& is_scalar($attributeValue)
424+
&& !$this->isBundleSpecialPrice($attribute);
425+
}
426+
427+
/**
428+
* Obtain if current product is bundle and given attribute is special_price
429+
*
430+
* @param \Magento\Catalog\Api\Data\ProductAttributeInterface $attribute
431+
* @return bool
432+
*/
433+
private function isBundleSpecialPrice(ProductAttributeInterface $attribute)
434+
{
435+
return $this->locator->getProduct()->getTypeId() === ProductType::TYPE_BUNDLE
436+
&& $attribute->getAttributeCode() === ProductAttributeInterface::CODE_SPECIAL_PRICE;
437+
}
438+
412439
/**
413440
* Resolve data persistence
414441
*

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/General.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,8 @@ protected function customizeNameListeners(array $meta)
373373
$skuPath . static::META_CONFIG_PATH,
374374
$meta,
375375
[
376-
'autoImportIfEmpty' => true
376+
'autoImportIfEmpty' => true,
377+
'validation' => ['no-marginal-whitespace' => true]
377378
]
378379
);
379380

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/CatalogImportExport/Model/Import/Product/Validator.php

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

88
use Magento\CatalogImportExport\Model\Import\Product;
99
use Magento\Framework\Validator\AbstractValidator;
10+
use Magento\Catalog\Model\Product\Attribute\Backend\Sku;
1011

1112
/**
1213
* Class Validator
@@ -69,6 +70,8 @@ protected function textValidation($attrCode, $type)
6970
$val = $this->string->cleanString($this->_rowData[$attrCode]);
7071
if ($type == 'text') {
7172
$valid = $this->string->strlen($val) < Product::DB_MAX_TEXT_LENGTH;
73+
} else if ($attrCode == Product::COL_SKU) {
74+
$valid = $this->string->strlen($val) <= SKU::SKU_MAX_LENGTH;
7275
} else {
7376
$valid = $this->string->strlen($val) < Product::DB_MAX_VARCHAR_LENGTH;
7477
}

0 commit comments

Comments
 (0)