Skip to content

Commit 1bcebfe

Browse files
committed
Merge remote-tracking branch 'origin/develop' into MAGETWO-59405
2 parents ed0884a + 1b719ef commit 1bcebfe

File tree

134 files changed

+1972
-394
lines changed

Some content is hidden

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

134 files changed

+1972
-394
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/MassStatus.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ public function execute()
8484
$productIds = $collection->getAllIds();
8585
$storeId = (int) $this->getRequest()->getParam('store', 0);
8686
$status = (int) $this->getRequest()->getParam('status');
87+
$filters = (array)$this->getRequest()->getParam('filters', []);
88+
89+
if (isset($filters['store_id'])) {
90+
$storeId = (int)$filters['store_id'];
91+
}
8792

8893
try {
8994
$this->_validateMassStatus($productIds, $status);

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/Test/Unit/Controller/Adminhtml/Product/MassStatusTest.php

Lines changed: 102 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,74 @@
66
*/
77
namespace Magento\Catalog\Test\Unit\Controller\Adminhtml\Product;
88

9+
use Magento\Ui\Component\MassAction\Filter;
10+
use Magento\Backend\Model\View\Result\Redirect;
11+
use Magento\Catalog\Model\Indexer\Product\Price\Processor;
12+
use Magento\Catalog\Controller\Adminhtml\Product\Builder;
13+
use Magento\Framework\Data\Collection\AbstractDb;
14+
use Magento\Catalog\Model\Product\Action;
15+
16+
/**
17+
* Class MassStatusTest
18+
*
19+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
20+
*/
921
class MassStatusTest extends \Magento\Catalog\Test\Unit\Controller\Adminhtml\ProductTest
1022
{
1123
/**
12-
* @var \PHPUnit_Framework_MockObject_MockObject
24+
* @var Processor|\PHPUnit_Framework_MockObject_MockObject
1325
*/
14-
protected $priceProcessor;
26+
private $priceProcessorMock;
1527

16-
/** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Backend\Model\View\Result\Redirect */
17-
protected $resultRedirect;
28+
/**
29+
* @var Redirect|\PHPUnit_Framework_MockObject_MockObject
30+
*/
31+
private $resultRedirectMock;
32+
33+
/**
34+
* @var Filter|\PHPUnit_Framework_MockObject_MockObject
35+
*/
36+
private $filterMock;
37+
38+
/**
39+
* @var Builder|\PHPUnit_Framework_MockObject_MockObject
40+
*/
41+
private $productBuilderMock;
42+
43+
/**
44+
* @var AbstractDb|\PHPUnit_Framework_MockObject_MockObject
45+
*/
46+
private $abstractDbMock;
47+
48+
/**
49+
* @var Action|\PHPUnit_Framework_MockObject_MockObject
50+
*/
51+
private $actionMock;
1852

1953
protected function setUp()
2054
{
21-
$this->priceProcessor = $this->getMockBuilder(\Magento\Catalog\Model\Indexer\Product\Price\Processor::class)
55+
$this->priceProcessorMock = $this->getMockBuilder(Processor::class)
2256
->disableOriginalConstructor()->getMock();
57+
$this->productBuilderMock = $this->getMockBuilder(Builder::class)
58+
->setMethods(['build'])
59+
->disableOriginalConstructor()
60+
->getMock();
2361

24-
$productBuilder = $this->getMockBuilder(
25-
\Magento\Catalog\Controller\Adminhtml\Product\Builder::class
26-
)->setMethods(['build'])->disableOriginalConstructor()->getMock();
27-
28-
$product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)->disableOriginalConstructor()
29-
->setMethods(['getTypeId', 'getStoreId', '__sleep', '__wakeup'])->getMock();
30-
$product->expects($this->any())->method('getTypeId')->will($this->returnValue('simple'));
31-
$product->expects($this->any())->method('getStoreId')->will($this->returnValue('1'));
32-
$productBuilder->expects($this->any())->method('build')->will($this->returnValue($product));
62+
$productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
63+
->disableOriginalConstructor()
64+
->setMethods(['getTypeId', 'getStoreId', '__sleep', '__wakeup'])
65+
->getMock();
66+
$productMock->expects($this->any())
67+
->method('getTypeId')
68+
->willReturn('simple');
69+
$productMock->expects($this->any())
70+
->method('getStoreId')
71+
->willReturn('1');
72+
$this->productBuilderMock->expects($this->any())
73+
->method('build')
74+
->willReturn($productMock);
3375

34-
$this->resultRedirect = $this->getMockBuilder(\Magento\Backend\Model\View\Result\Redirect::class)
76+
$this->resultRedirectMock = $this->getMockBuilder(\Magento\Backend\Model\View\Result\Redirect::class)
3577
->disableOriginalConstructor()
3678
->getMock();
3779
$resultFactory = $this->getMockBuilder(\Magento\Framework\Controller\ResultFactory::class)
@@ -41,47 +83,71 @@ protected function setUp()
4183
$resultFactory->expects($this->atLeastOnce())
4284
->method('create')
4385
->with(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT)
44-
->willReturn($this->resultRedirect);
86+
->willReturn($this->resultRedirectMock);
4587

46-
$abstractDbMock = $this->getMockBuilder(\Magento\Framework\Data\Collection\AbstractDb::class)
88+
$this->abstractDbMock = $this->getMockBuilder(AbstractDb::class)
4789
->disableOriginalConstructor()
4890
->setMethods(['getAllIds', 'getResource'])
4991
->getMock();
50-
$abstractDbMock->expects($this->any())
51-
->method('getAllIds')
52-
->willReturn([]);
53-
54-
$filterMock = $this->getMockBuilder(\Magento\Ui\Component\MassAction\Filter::class)
92+
$this->filterMock = $this->getMockBuilder(\Magento\Ui\Component\MassAction\Filter::class)
5593
->disableOriginalConstructor()
5694
->setMethods(['getCollection'])
5795
->getMock();
58-
$filterMock->expects($this->any())
59-
->method('getCollection')
60-
->willReturn($abstractDbMock);
61-
62-
$collectionFactoryMock = $this->getMockBuilder(
63-
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory::class
64-
)
96+
$this->actionMock = $this->getMockBuilder(Action::class)
97+
->disableOriginalConstructor()
98+
->getMock();
99+
100+
$collectionFactoryMock =
101+
$this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory::class)
65102
->disableOriginalConstructor()
66103
->setMethods(['create'])
67104
->getMock();
68105
$collectionFactoryMock->expects($this->any())
69106
->method('create')
70-
->willReturn($abstractDbMock);
107+
->willReturn($this->abstractDbMock);
108+
109+
$additionalParams = [
110+
'resultFactory' => $resultFactory
111+
];
112+
/** @var \Magento\Backend\App\Action\Context $context */
113+
$context = $this->initContext($additionalParams, [[Action::class, $this->actionMock]]);
71114

72-
$additionalParams = ['resultFactory' => $resultFactory];
73115
$this->action = new \Magento\Catalog\Controller\Adminhtml\Product\MassStatus(
74-
$this->initContext($additionalParams),
75-
$productBuilder,
76-
$this->priceProcessor,
77-
$filterMock,
116+
$context,
117+
$this->productBuilderMock,
118+
$this->priceProcessorMock,
119+
$this->filterMock,
78120
$collectionFactoryMock
79121
);
80122
}
81123

82124
public function testMassStatusAction()
83125
{
84-
$this->priceProcessor->expects($this->once())->method('reindexList');
126+
$storeId = 1;
127+
$status = \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED;
128+
$filters = [
129+
'store_id' => 2,
130+
];
131+
132+
$this->filterMock->expects($this->once())
133+
->method('getCollection')
134+
->willReturn($this->abstractDbMock);
135+
$this->abstractDbMock->expects($this->once())
136+
->method('getAllIds')
137+
->willReturn([3]);
138+
$this->request->expects($this->exactly(3))
139+
->method('getParam')
140+
->willReturnMap([
141+
['store', 0, $storeId],
142+
['status', null, $status],
143+
['filters', [], $filters]
144+
]);
145+
$this->actionMock->expects($this->once())
146+
->method('updateAttributes')
147+
->with([3], ['status' => $status], 2);
148+
$this->priceProcessorMock->expects($this->once())
149+
->method('reindexList');
150+
85151
$this->action->execute();
86152
}
87153
}

0 commit comments

Comments
 (0)