Skip to content

Commit e5b76f9

Browse files
committed
Merge remote-tracking branch 'mainline/develop' into jsunit
2 parents 53f18a0 + 1b719ef commit e5b76f9

File tree

50 files changed

+1202
-237
lines changed

Some content is hidden

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

50 files changed

+1202
-237
lines changed

app/code/Magento/Catalog/Block/Adminhtml/Helper/Form/Wysiwyg/Content.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
use Magento\Backend\Block\Widget\Form;
1515
use Magento\Backend\Block\Widget\Form\Generic;
1616

17+
/**
18+
* Class Content
19+
*
20+
* @deprecated
21+
* @see \Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Eav
22+
*/
1723
class Content extends Generic
1824
{
1925
/**

app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Save.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ public function execute()
101101
}
102102
$model->save();
103103
$this->messageManager->addSuccess(__('You saved the attribute set.'));
104+
} catch (\Magento\Framework\Exception\AlreadyExistsException $e) {
105+
$this->messageManager->addErrorMessage($e->getMessage());
106+
$hasError = true;
104107
} catch (\Magento\Framework\Exception\LocalizedException $e) {
105108
$this->messageManager->addError($e->getMessage());
106109
$hasError = true;

app/code/Magento/Catalog/Model/Product/Attribute/Backend/Sku.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,12 @@ protected function _generateUniqueSku($object)
7373
{
7474
$attribute = $this->getAttribute();
7575
$entity = $attribute->getEntity();
76-
$increment = $this->_getLastSimilarAttributeValueIncrement($attribute, $object);
7776
$attributeValue = $object->getData($attribute->getAttributeCode());
77+
$increment = null;
7878
while (!$entity->checkAttributeUniqueValue($attribute, $object)) {
79+
if ($increment === null) {
80+
$increment = $this->_getLastSimilarAttributeValueIncrement($attribute, $object);
81+
}
7982
$sku = trim($attributeValue);
8083
if (strlen($sku . '-' . ++$increment) > self::SKU_MAX_LENGTH) {
8184
$sku = substr($sku, 0, -strlen($increment) - 1);

app/code/Magento/Catalog/Model/Product/Gallery/CreateHandler.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ class CreateHandler implements ExtensionInterface
5858
*/
5959
protected $fileStorageDb;
6060

61+
/**
62+
* @var array
63+
*/
64+
private $mediaAttributeCodes;
65+
6166
/**
6267
* @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
6368
* @param \Magento\Catalog\Api\ProductAttributeRepositoryInterface $attributeRepository
@@ -145,9 +150,11 @@ public function execute($product, $arguments = [])
145150
}
146151

147152
/* @var $mediaAttribute \Magento\Catalog\Api\Data\ProductAttributeInterface */
148-
foreach ($this->mediaConfig->getMediaAttributeCodes() as $mediaAttrCode) {
153+
foreach ($this->getMediaAttributeCodes() as $mediaAttrCode) {
149154
$attrData = $product->getData($mediaAttrCode);
150-
155+
if (empty($attrData) && empty($clearImages) && empty($newImages) && empty($existImages)) {
156+
continue;
157+
}
151158
if (in_array($attrData, $clearImages)) {
152159
$product->setData($mediaAttrCode, 'no_selection');
153160
}
@@ -394,4 +401,17 @@ protected function copyImage($file)
394401
);
395402
}
396403
}
404+
405+
/**
406+
* Get Media Attribute Codes cached value
407+
*
408+
* @return array
409+
*/
410+
private function getMediaAttributeCodes()
411+
{
412+
if ($this->mediaAttributeCodes === null) {
413+
$this->mediaAttributeCodes = $this->mediaConfig->getMediaAttributeCodes();
414+
}
415+
return $this->mediaAttributeCodes;
416+
}
397417
}

app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ public function __construct(
4040
Link $linkResource,
4141
ProductLinkRepositoryInterface $productLinkRepository
4242
) {
43-
4443
$this->metadataPool = $metadataPool;
4544
$this->linkResource = $linkResource;
4645
$this->productLinkRepository = $productLinkRepository;
@@ -54,12 +53,18 @@ public function __construct(
5453
*/
5554
public function execute($entityType, $entity)
5655
{
57-
/** @var \Magento\Catalog\Api\Data\ProductInterface $entity*/
58-
foreach ($this->productLinkRepository->getList($entity) as $link) {
59-
$this->productLinkRepository->delete($link);
56+
$link = $entity->getData($this->metadataPool->getMetadata($entityType)->getLinkField());
57+
if ($this->linkResource->hasProductLinks($link)) {
58+
/** @var \Magento\Catalog\Api\Data\ProductInterface $entity*/
59+
foreach ($this->productLinkRepository->getList($entity) as $link) {
60+
$this->productLinkRepository->delete($link);
61+
}
6062
}
61-
foreach ($entity->getProductLinks() as $link) {
62-
$this->productLinkRepository->save($link);
63+
$productLinks = $entity->getProductLinks();
64+
if (count($productLinks) > 0) {
65+
foreach ($entity->getProductLinks() as $link) {
66+
$this->productLinkRepository->save($link);
67+
}
6368
}
6469
return $entity;
6570
}

app/code/Magento/Catalog/Model/ResourceModel/Category.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,9 @@ protected function _beforeSave(\Magento\Framework\DataObject $object)
238238
if (!$object->getChildrenCount()) {
239239
$object->setChildrenCount(0);
240240
}
241-
241+
$object->setAttributeSetId(
242+
$object->getAttributeSetId() ?: $this->getEntityType()->getDefaultAttributeSetId()
243+
);
242244
if ($object->isObjectNew()) {
243245
if ($object->getPosition() === null) {
244246
$object->setPosition($this->_getMaxPosition($object->getPath()) + 1);

app/code/Magento/Catalog/Model/ResourceModel/Eav/Attribute.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -351,14 +351,11 @@ public function getStoreId()
351351
*/
352352
public function getApplyTo()
353353
{
354-
if ($this->getData(self::APPLY_TO)) {
355-
if (is_array($this->getData(self::APPLY_TO))) {
356-
return $this->getData(self::APPLY_TO);
357-
}
358-
return explode(',', $this->getData(self::APPLY_TO));
359-
} else {
360-
return [];
354+
$applyTo = $this->_getData(self::APPLY_TO) ?: [];
355+
if (!is_array($applyTo)) {
356+
$applyTo = explode(',', $applyTo);
361357
}
358+
return $applyTo;
362359
}
363360

364361
/**

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,30 @@ public function getProductLinkId($parentId, $linkedProductId, $typeId)
9696
return $connection->fetchOne($select, $bind);
9797
}
9898

99+
/**
100+
* Check if product has links.
101+
*
102+
* @param int $parentId ID of product
103+
* @return bool
104+
*/
105+
public function hasProductLinks($parentId)
106+
{
107+
$connection = $this->getConnection();
108+
$select = $connection->select()->from(
109+
$this->getMainTable(),
110+
['count' => new \Zend_Db_Expr('COUNT(*)')]
111+
)->where(
112+
'product_id = :product_id'
113+
) ;
114+
115+
return $connection->fetchOne(
116+
$select,
117+
[
118+
'product_id' => $parentId
119+
]
120+
) > 0;
121+
}
122+
99123
/**
100124
* Save Product Links process
101125
*

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,10 @@ private function customizeWysiwyg(ProductAttributeInterface $attribute, array $m
754754
$meta['arguments']['data']['config']['wysiwyg'] = true;
755755
$meta['arguments']['data']['config']['wysiwygConfigData'] = [
756756
'add_variables' => false,
757-
'add_widgets' => false
757+
'add_widgets' => false,
758+
'add_directives' => true,
759+
'use_container' => true,
760+
'container_class' => 'hor-scroll',
758761
];
759762

760763
return $meta;

app/code/Magento/CatalogImportExport/Model/Export/Product.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
namespace Magento\CatalogImportExport\Model\Export;
77

8-
use Magento\Framework\DB\Ddl\Table;
98
use Magento\ImportExport\Model\Import;
109
use \Magento\Store\Model\Store;
1110
use \Magento\CatalogImportExport\Model\Import\Product as ImportProduct;
@@ -850,6 +849,24 @@ public function export()
850849
return $writer->getContents();
851850
}
852851

852+
/**
853+
* {@inheritdoc}
854+
*/
855+
protected function _prepareEntityCollection(\Magento\Eav\Model\Entity\Collection\AbstractCollection $collection)
856+
{
857+
$exportFilter = !empty($this->_parameters[\Magento\ImportExport\Model\Export::FILTER_ELEMENT_GROUP]) ?
858+
$this->_parameters[\Magento\ImportExport\Model\Export::FILTER_ELEMENT_GROUP] : [];
859+
860+
if (isset($exportFilter['category_ids'])
861+
&& trim($exportFilter['category_ids'])
862+
&& $collection instanceof \Magento\Catalog\Model\ResourceModel\Product\Collection
863+
) {
864+
$collection->addCategoriesFilter(['in' => explode(',', $exportFilter['category_ids'])]);
865+
}
866+
867+
return parent::_prepareEntityCollection($collection);
868+
}
869+
853870
/**
854871
* Get export data for collection
855872
*

0 commit comments

Comments
 (0)