Skip to content

Commit 9cc1162

Browse files
committed
Merge remote-tracking branch 'mainline/develop' into MAGETWO-67106
2 parents 1fbeb2e + d4f730e commit 9cc1162

File tree

227 files changed

+6381
-1926
lines changed

Some content is hidden

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

227 files changed

+6381
-1926
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Bundle\Model\Sales\Order\Plugin;
8+
9+
/**
10+
* Plugin to calculate bundle item qty available for cancel
11+
*/
12+
class Item
13+
{
14+
/**
15+
* Retrieve item qty available for cancel
16+
*
17+
* @param \Magento\Sales\Model\Order\Item $subject
18+
* @param float|integer $result
19+
* @return float|integer
20+
*/
21+
public function afterGetQtyToCancel(\Magento\Sales\Model\Order\Item $subject, $result)
22+
{
23+
if ($subject->getProductType() === \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE || $subject->getParentItem()
24+
&& $subject->getParentItem()->getProductType() === \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE
25+
) {
26+
$qtyToCancel = $this->getQtyToCancelBundle($subject);
27+
return max($qtyToCancel, 0);
28+
}
29+
return $result;
30+
}
31+
32+
/**
33+
* Retrieve item qty available for ship
34+
*
35+
* @param \Magento\Sales\Model\Order\Item $subject
36+
* @param float|integer $result
37+
* @return bool
38+
*/
39+
public function afterIsProcessingAvailable(\Magento\Sales\Model\Order\Item $subject, $result)
40+
{
41+
if ($subject->getProductType() === \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE || $subject->getParentItem()
42+
&& $subject->getParentItem()->getProductType() === \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE
43+
) {
44+
return $subject->getSimpleQtyToShip() > $subject->getQtyToCancel();
45+
}
46+
return $result;
47+
}
48+
49+
/**
50+
* Retrieve Bundle child item qty available for cancel
51+
* getQtyToShip() always returns 0 for BundleItems that ship together
52+
*
53+
* @param \Magento\Sales\Model\Order\Item $item
54+
* @return float|integer
55+
*/
56+
private function getQtyToCancelBundle($item)
57+
{
58+
if ($item->isDummy(true)) {
59+
return min($item->getQtyToInvoice(), $item->getSimpleQtyToShip());
60+
}
61+
return min($item->getQtyToInvoice(), $item->getQtyToShip());
62+
}
63+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Bundle\Test\Unit\Model\Sales\Order\Plugin;
8+
9+
class ItemTest extends \PHPUnit_Framework_TestCase
10+
{
11+
private $plugin;
12+
13+
private $itemMock;
14+
15+
protected function setUp()
16+
{
17+
$this->itemMock = $this->getMockBuilder(\Magento\Sales\Model\Order\Item::class)
18+
->disableOriginalConstructor()
19+
->getMock();
20+
$this->plugin = new \Magento\Bundle\Model\Sales\Order\Plugin\Item();
21+
}
22+
23+
public function testAfterGetQtyToCancelIfProductIsBundle()
24+
{
25+
$qtyToCancel = 10;
26+
$result = 5;
27+
28+
$this->itemMock
29+
->expects($this->once())
30+
->method('getProductType')
31+
->willReturn(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE);
32+
$this->itemMock->expects($this->once())->method('isDummy')->willReturn(true);
33+
$this->itemMock->expects($this->once())->method('getQtyToInvoice')->willReturn(15);
34+
$this->itemMock->expects($this->once())->method('getSimpleQtyToShip')->willReturn($qtyToCancel);
35+
$this->assertEquals($qtyToCancel, $this->plugin->afterGetQtyToCancel($this->itemMock, $result));
36+
}
37+
38+
public function testAfterGetQtyToCancelIfParentProductIsBundle()
39+
{
40+
$qtyToCancel = 10;
41+
$result = 5;
42+
$parentItemMock = $this->getMockBuilder(\Magento\Sales\Model\Order\Item::class)
43+
->disableOriginalConstructor()
44+
->getMock();
45+
$this->itemMock
46+
->expects($this->once())
47+
->method('getProductType')
48+
->willReturn(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE);
49+
$this->itemMock->expects($this->any())->method('getParentItem')->willReturn($parentItemMock);
50+
$parentItemMock->expects($this->once())
51+
->method('getProductType')
52+
->willReturn(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE);
53+
$this->itemMock->expects($this->once())->method('isDummy')->willReturn(false);
54+
$this->itemMock->expects($this->once())->method('getQtyToInvoice')->willReturn(15);
55+
$this->itemMock->expects($this->once())->method('getQtyToShip')->willReturn($qtyToCancel);
56+
$this->assertEquals($qtyToCancel, $this->plugin->afterGetQtyToCancel($this->itemMock, $result));
57+
}
58+
public function testAfterGetQtyToCancelForSimpleProduct()
59+
{
60+
$result = 5;
61+
$this->itemMock
62+
->expects($this->once())
63+
->method('getProductType')
64+
->willReturn(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE);
65+
$this->itemMock->expects($this->any())->method('getParentItem')->willReturn(false);
66+
$this->itemMock->expects($this->never())->method('isDummy');
67+
$this->itemMock->expects($this->never())->method('getQtyToInvoice');
68+
$this->assertEquals($result, $this->plugin->afterGetQtyToCancel($this->itemMock, $result));
69+
}
70+
71+
public function testAfterIsProcessingAvailableForProductWithoutParent()
72+
{
73+
$this->itemMock->expects($this->once())->method('getParentItem')->willReturn(false);
74+
$this->assertFalse($this->plugin->afterIsProcessingAvailable($this->itemMock, false));
75+
}
76+
77+
public function testAfterIsProcessingAvailableForProductWhenParentIsBundle()
78+
{
79+
$parentItemMock = $this->getMockBuilder(\Magento\Sales\Model\Order\Item::class)
80+
->disableOriginalConstructor()
81+
->getMock();
82+
$this->itemMock->expects($this->any())->method('getParentItem')->willReturn($parentItemMock);
83+
$parentItemMock->expects($this->once())
84+
->method('getProductType')
85+
->willReturn(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE);
86+
$this->itemMock->expects($this->once())->method('getSimpleQtyToShip')->willReturn(10);
87+
$this->itemMock->expects($this->once())->method('getQtyToCancel')->willReturn(5);
88+
$this->assertTrue($this->plugin->afterIsProcessingAvailable($this->itemMock, false));
89+
}
90+
91+
public function testAfterIsProcessingAvailableForBundleProduct()
92+
{
93+
$this->itemMock->expects($this->once())
94+
->method('getProductType')
95+
->willReturn(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE);
96+
$this->itemMock->expects($this->once())->method('getSimpleQtyToShip')->willReturn(10);
97+
$this->itemMock->expects($this->once())->method('getQtyToCancel')->willReturn(5);
98+
$this->assertTrue($this->plugin->afterIsProcessingAvailable($this->itemMock, false));
99+
}
100+
}

app/code/Magento/Bundle/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@
8181
<type name="Magento\Catalog\Model\Product">
8282
<plugin name="bundle" type="Magento\Bundle\Model\Plugin\Product" sortOrder="100" />
8383
</type>
84+
<type name="Magento\Sales\Model\Order\Item">
85+
<plugin name="bundle" type="Magento\Bundle\Model\Sales\Order\Plugin\Item" sortOrder="100" />
86+
</type>
8487
<type name="Magento\Framework\EntityManager\Operation\ExtensionPool">
8588
<arguments>
8689
<argument name="extensionActions" xsi:type="array">

app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,17 +213,14 @@ public function execute()
213213
$category->save();
214214
$this->messageManager->addSuccess(__('You saved the category.'));
215215
} catch (\Magento\Framework\Exception\AlreadyExistsException $e) {
216-
var_dump($e->getMessage());
217216
$this->messageManager->addError($e->getMessage());
218217
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
219218
$this->_getSession()->setCategoryData($categoryPostData);
220219
} catch (\Magento\Framework\Exception\LocalizedException $e) {
221-
var_dump($e->getMessage());
222220
$this->messageManager->addError($e->getMessage());
223221
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
224222
$this->_getSession()->setCategoryData($categoryPostData);
225223
} catch (\Exception $e) {
226-
var_dump($e->getMessage());
227224
$this->messageManager->addError(__('Something went wrong while saving the category.'));
228225
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
229226
$this->_getSession()->setCategoryData($categoryPostData);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Model\Api\SearchCriteria\CollectionProcessor\FilterProcessor;
7+
8+
use Magento\Catalog\Model\ResourceModel\Product\Collection;
9+
use Magento\Framework\Api\Filter;
10+
use Magento\Framework\Api\SearchCriteria\CollectionProcessor\FilterProcessor\CustomFilterInterface;
11+
use Magento\Framework\Data\Collection\AbstractDb;
12+
13+
class ProductStoreFilter implements CustomFilterInterface
14+
{
15+
/**
16+
* Apply store Filter to Product Collection
17+
*
18+
* @param Filter $filter
19+
* @param AbstractDb $collection
20+
* @return bool Whether the filter is applied
21+
*/
22+
public function apply(Filter $filter, AbstractDb $collection)
23+
{
24+
/** @var Collection $collection */
25+
$collection->addStoreFilter($filter->getValue());
26+
return true;
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Model\Api\SearchCriteria\CollectionProcessor\FilterProcessor;
7+
8+
use Magento\Catalog\Model\ResourceModel\Product\Collection;
9+
use Magento\Framework\Api\Filter;
10+
use Magento\Framework\Api\SearchCriteria\CollectionProcessor\FilterProcessor\CustomFilterInterface;
11+
use Magento\Framework\Data\Collection\AbstractDb;
12+
13+
class ProductWebsiteFilter implements CustomFilterInterface
14+
{
15+
/**
16+
* Apply website Filter to Product Collection
17+
*
18+
* @param Filter $filter
19+
* @param AbstractDb $collection
20+
* @return bool Whether the filter is applied
21+
*/
22+
public function apply(Filter $filter, AbstractDb $collection)
23+
{
24+
$value = $filter->getValue();
25+
if (strpos($value, ',') !== false) {
26+
$value = explode(',', $value);
27+
}
28+
/** @var Collection $collection */
29+
$collection->addWebsiteFilter($value);
30+
return true;
31+
}
32+
}

app/code/Magento/Catalog/Model/Product/Copier.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,15 @@ public function copy(\Magento\Catalog\Model\Product $product)
5454
$product->getWebsiteIds();
5555
$product->getCategoryIds();
5656

57+
/** @var \Magento\Framework\EntityManager\EntityMetadataInterface $metadata */
58+
$metadata = $this->getMetadataPool()->getMetadata(ProductInterface::class);
59+
5760
/** @var \Magento\Catalog\Model\Product $duplicate */
5861
$duplicate = $this->productFactory->create();
5962
$duplicate->setData($product->getData());
6063
$duplicate->setOptions([]);
6164
$duplicate->setIsDuplicate(true);
62-
$duplicate->setOriginalId($product->getEntityId());
65+
$duplicate->setOriginalLinkId($product->getData($metadata->getLinkField()));
6366
$duplicate->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED);
6467
$duplicate->setCreatedAt(null);
6568
$duplicate->setUpdatedAt(null);
@@ -81,7 +84,6 @@ public function copy(\Magento\Catalog\Model\Product $product)
8184
}
8285
} while (!$isDuplicateSaved);
8386
$this->getOptionRepository()->duplicate($product, $duplicate);
84-
$metadata = $this->getMetadataPool()->getMetadata(ProductInterface::class);
8587
$product->getResource()->duplicate(
8688
$product->getData($metadata->getLinkField()),
8789
$duplicate->getData($metadata->getLinkField())

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ protected function duplicate($product)
297297
$this->resourceModel->duplicate(
298298
$this->getAttribute()->getAttributeId(),
299299
isset($mediaGalleryData['duplicate']) ? $mediaGalleryData['duplicate'] : [],
300-
$product->getOriginalId(),
300+
$product->getOriginalLinkId(),
301301
$product->getData($this->metadata->getLinkField())
302302
);
303303

app/code/Magento/Catalog/Model/Product/Type/AbstractType.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,8 +723,7 @@ public function save($product)
723723
protected function _removeNotApplicableAttributes($product)
724724
{
725725
$entityType = $product->getResource()->getEntityType();
726-
foreach ($this->_eavConfig->getEntityAttributeCodes($entityType, $product) as $attributeCode) {
727-
$attribute = $this->_eavConfig->getAttribute($entityType, $attributeCode);
726+
foreach ($this->_eavConfig->getEntityAttributes($entityType, $product) as $attribute) {
728727
$applyTo = $attribute->getApplyTo();
729728
if (is_array($applyTo) && count($applyTo) > 0 && !in_array($product->getTypeId(), $applyTo)) {
730729
$product->unsetData($attribute->getAttributeCode());

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,9 @@ public function save(\Magento\Catalog\Api\Data\ProductInterface $product, $saveO
564564
$this->resourceModel->getLinkField(),
565565
$existingProduct->getData($this->resourceModel->getLinkField())
566566
);
567+
if (!$product->hasData(Product::STATUS)) {
568+
$product->setStatus($existingProduct->getStatus());
569+
}
567570
} catch (NoSuchEntityException $e) {
568571
$existingProduct = null;
569572
}
@@ -679,9 +682,7 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr
679682
$collection = $this->collectionFactory->create();
680683
$this->extensionAttributesJoinProcessor->process($collection);
681684

682-
foreach ($this->metadataService->getList($this->searchCriteriaBuilder->create())->getItems() as $metadata) {
683-
$collection->addAttributeToSelect($metadata->getAttributeCode());
684-
}
685+
$collection->addAttributeToSelect('*');
685686
$collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner');
686687
$collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner');
687688

0 commit comments

Comments
 (0)