Skip to content

Commit 5314307

Browse files
authored
Merge pull request #2955 from magento-tango/PR-0208
[tango] bugfixes-2.2
2 parents 5a04525 + 034b01a commit 5314307

File tree

12 files changed

+267
-14
lines changed

12 files changed

+267
-14
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ public function execute()
102102
$this->productBuilder->build($this->getRequest())
103103
);
104104
$this->productTypeManager->processProduct($product);
105-
106105
if (isset($data['product'][$product->getIdFieldName()])) {
107106
throw new \Magento\Framework\Exception\LocalizedException(__('Unable to save product'));
108107
}
109108

110109
$originalSku = $product->getSku();
110+
$canSaveCustomOptions = $product->getCanSaveCustomOptions();
111111
$product->save();
112112
$this->handleImageRemoveError($data, $product->getId());
113113
$this->getCategoryLinkManagement()->assignProductToCategories(
@@ -117,8 +117,9 @@ public function execute()
117117
$productId = $product->getEntityId();
118118
$productAttributeSetId = $product->getAttributeSetId();
119119
$productTypeId = $product->getTypeId();
120-
121-
$this->copyToStores($data, $productId);
120+
$extendedData = $data;
121+
$extendedData['can_save_custom_options'] = $canSaveCustomOptions;
122+
$this->copyToStores($extendedData, $productId);
122123

123124
$this->messageManager->addSuccessMessage(__('You saved the product.'));
124125
$this->getDataPersistor()->clear('catalog_product');
@@ -238,6 +239,7 @@ protected function copyToStores($data, $productId)
238239
->setStoreId($copyFrom)
239240
->load($productId)
240241
->setStoreId($copyTo)
242+
->setCanSaveCustomOptions($data['can_save_custom_options'])
241243
->setCopyFromView(true)
242244
->save();
243245
}

app/code/Magento/Reports/Block/Adminhtml/Grid/AbstractGrid.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ public function getCountTotals()
298298
);
299299

300300
$this->_addOrderStatusFilter($totalsCollection, $filterData);
301+
$this->_addCustomFilter($totalsCollection, $filterData);
301302

302303
if ($totalsCollection->load()->getSize() < 1 || !$filterData->getData('from')) {
303304
$this->setTotals(new \Magento\Framework\DataObject());
@@ -309,6 +310,7 @@ public function getCountTotals()
309310
}
310311
}
311312
}
313+
312314
return parent::getCountTotals();
313315
}
314316

@@ -407,7 +409,6 @@ protected function _addCustomFilter($collection, $filterData)
407409
}
408410

409411
/**
410-
*
411412
* @return array
412413
* @throws \Magento\Framework\Exception\LocalizedException
413414
*/
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Reports\Test\Unit\Block\Adminhtml\Sales\Coupons;
9+
10+
/**
11+
* Test for class \Magento\Reports\Block\Adminhtml\Sales\Coupons\Grid
12+
*/
13+
class GridTest extends \PHPUnit\Framework\TestCase
14+
{
15+
/**
16+
* @var \Magento\Reports\Block\Adminhtml\Sales\Coupons\Grid
17+
*/
18+
private $model;
19+
20+
/**
21+
* @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
22+
*/
23+
private $storeManagerMock;
24+
25+
/**
26+
* @var \Magento\Reports\Model\ResourceModel\Report\Collection\Factory|\PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
private $resourceFactoryMock;
29+
30+
protected function setUp()
31+
{
32+
$this->storeManagerMock = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
33+
->getMock();
34+
$this->resourceFactoryMock = $this
35+
->getMockBuilder(\Magento\Reports\Model\ResourceModel\Report\Collection\Factory::class)
36+
->disableOriginalConstructor()
37+
->getMock();
38+
$aggregatedColumns = [1 => 'SUM(value)'];
39+
40+
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
41+
$this->model = $objectManager->getObject(
42+
\Magento\Reports\Block\Adminhtml\Sales\Coupons\Grid::class,
43+
[
44+
'_storeManager' => $this->storeManagerMock,
45+
'_aggregatedColumns' => $aggregatedColumns,
46+
'resourceFactory' => $this->resourceFactoryMock,
47+
]
48+
);
49+
}
50+
51+
/**
52+
* @dataProvider getCountTotalsDataProvider
53+
*
54+
* @param string $reportType
55+
* @param int $priceRuleType
56+
* @param int $collectionSize
57+
* @param bool $expectedCountTotals
58+
*/
59+
public function testGetCountTotals(
60+
string $reportType,
61+
int $priceRuleType,
62+
int $collectionSize,
63+
bool $expectedCountTotals
64+
) {
65+
$filterData = new \Magento\Framework\DataObject();
66+
$filterData->setData('report_type', $reportType);
67+
$filterData->setData('period_type', 'day');
68+
$filterData->setData('from', '2000-01-01');
69+
$filterData->setData('to', '2000-01-30');
70+
$filterData->setData('store_ids', '1');
71+
$filterData->setData('price_rule_type', $priceRuleType);
72+
if ($priceRuleType) {
73+
$filterData->setData('rules_list', ['0,1']);
74+
}
75+
$filterData->setData('order_statuses', 'statuses');
76+
$this->model->setFilterData($filterData);
77+
78+
$resourceCollectionName = $this->model->getResourceCollectionName();
79+
$collectionMock = $this->buildBaseCollectionMock($filterData, $resourceCollectionName, $collectionSize);
80+
81+
$store = $this->getMockBuilder(\Magento\Store\Api\Data\StoreInterface::class)
82+
->getMock();
83+
$this->storeManagerMock->method('getStores')
84+
->willReturn([1 => $store]);
85+
$this->resourceFactoryMock->expects($this->once())
86+
->method('create')
87+
->willReturn($collectionMock);
88+
89+
$this->assertEquals($expectedCountTotals, $this->model->getCountTotals());
90+
}
91+
92+
/**
93+
* @return array
94+
*/
95+
public function getCountTotalsDataProvider(): array
96+
{
97+
return [
98+
['created_at_shipment', 0, 0, false],
99+
['created_at_shipment', 0, 1, true],
100+
['updated_at_order', 0, 1, true],
101+
['updated_at_order', 1, 1, true],
102+
];
103+
}
104+
105+
/**
106+
* @param \Magento\Framework\DataObject $filterData
107+
* @param string $resourceCollectionName
108+
* @param int $collectionSize
109+
* @return \PHPUnit_Framework_MockObject_MockObject
110+
*/
111+
private function buildBaseCollectionMock(
112+
\Magento\Framework\DataObject $filterData,
113+
string $resourceCollectionName,
114+
int $collectionSize
115+
): \PHPUnit_Framework_MockObject_MockObject {
116+
$collectionMock = $this->getMockBuilder($resourceCollectionName)
117+
->disableOriginalConstructor()
118+
->getMock();
119+
$collectionMock->expects($this->once())
120+
->method('setPeriod')
121+
->with($filterData->getData('period_type'))
122+
->willReturnSelf();
123+
$collectionMock->expects($this->once())
124+
->method('setDateRange')
125+
->with($filterData->getData('from'), $filterData->getData('to'))
126+
->willReturnSelf();
127+
$collectionMock->expects($this->once())
128+
->method('addStoreFilter')
129+
->with(\explode(',', $filterData->getData('store_ids')))
130+
->willReturnSelf();
131+
$collectionMock->expects($this->once())
132+
->method('setAggregatedColumns')
133+
->willReturnSelf();
134+
$collectionMock->expects($this->once())
135+
->method('isTotals')
136+
->with(true)
137+
->willReturnSelf();
138+
$collectionMock->expects($this->once())
139+
->method('addOrderStatusFilter')
140+
->with($filterData->getData('order_statuses'))
141+
->willReturnSelf();
142+
143+
if ($filterData->getData('price_rule_type')) {
144+
$collectionMock->expects($this->once())
145+
->method('addRuleFilter')
146+
->with(\explode(',', $filterData->getData('rules_list')[0]))
147+
->willReturnSelf();
148+
}
149+
150+
$collectionMock->expects($this->once())
151+
->method('load')
152+
->willReturnSelf();
153+
$collectionMock->expects($this->once())
154+
->method('getSize')
155+
->willReturn($collectionSize);
156+
if ($collectionSize) {
157+
$itemMock = $this->getMockBuilder(\Magento\Reports\Model\Item::class)
158+
->disableOriginalConstructor()
159+
->getMock();
160+
$collectionMock->expects($this->once())
161+
->method('getItems')
162+
->willReturn([$itemMock]);
163+
}
164+
165+
return $collectionMock;
166+
}
167+
}

app/code/Magento/Wishlist/Helper/Data.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ public function calculate()
570570
) {
571571
$count = $collection->getItemsQty();
572572
} else {
573-
$count = $collection->getSize();
573+
$count = $collection->count();
574574
}
575575
$this->_customerSession->setWishlistDisplayType(
576576
$this->scopeConfig->getValue(

app/code/Magento/Wishlist/Model/ResourceModel/Item/Collection.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ protected function _assignProducts()
307307

308308
$checkInStock = $this->_productInStock && !$this->stockConfiguration->isShowOutOfStock();
309309

310+
/** @var \Magento\Wishlist\Model\Item $item */
310311
foreach ($this as $item) {
311312
$product = $productCollection->getItemById($item->getProductId());
312313
if ($product) {
@@ -320,7 +321,7 @@ protected function _assignProducts()
320321
$item->setPrice($product->getPrice());
321322
}
322323
} else {
323-
$item->isDeleted(true);
324+
$this->removeItemByKey($item->getId());
324325
}
325326
}
326327

app/code/Magento/Wishlist/Model/Wishlist.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ public function setStore($store)
582582
*/
583583
public function getItemsCount()
584584
{
585-
return $this->getItemCollection()->getSize();
585+
return $this->getItemCollection()->count();
586586
}
587587

588588
/**

app/code/Magento/Wishlist/Test/Mftf/Test/StorefrontAddMultipleStoreProductsToWishlistTest.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,12 @@
8181
<click stepKey="ClickSwitchStoreButtonOnDefaultStore" selector="{{StorefrontFooterSection.SwitchStoreButton}}"/>
8282
<click stepKey="SelectSecondStoreToSwitchOn" selector="{{StorefrontFooterSection.StoreLink($$storeGroup.group[name]$$)}}"/>
8383
<!-- Verify that both products are visible in wishlist on both stores -->
84-
<see stepKey="seeProduct1InWishlist" userInput="$$product.name$$" selector="{{StorefrontCustomerWishlistSection.productItemNameText}}"/>
8584
<amOnPage url="$$secondProduct.name$$.html" stepKey="navigateToProductPageOnSecondStore"/>
8685
<see selector="{{StorefrontProductInfoMainSection.productName}}" userInput="$$secondProduct.name$$" stepKey="assertSecondProductNameTitle"/>
8786
<click stepKey="addSecondProductToWishlist" selector="{{StorefrontProductPageSection.addToWishlist}}"/>
88-
<see stepKey="seeProduct1InWishlistOnSecondStore" userInput="$$product.name$$" selector="{{StorefrontCustomerWishlistSection.productItemNameText}}"/>
8987
<see stepKey="seeProduct2InWishlistOnSecondStore" userInput="$$secondProduct.name$$" selector="{{StorefrontCustomerWishlistSection.productItemNameText}}"/>
9088
<click stepKey="ClickSwitchStoreButtonOnSecondStore" selector="{{StorefrontFooterSection.SwitchStoreButton}}"/>
9189
<click stepKey="SelectDefaultStoreToSwitchOn" selector="{{StorefrontFooterSection.StoreLink('Main Website Store')}}"/>
9290
<see stepKey="seeProduct1InWishlistOnDefaultStore" userInput="$$product.name$$" selector="{{StorefrontCustomerWishlistSection.productItemNameText}}"/>
93-
<see stepKey="seeProduct2InWishlistOnDefaultStore" userInput="$$secondProduct.name$$" selector="{{StorefrontCustomerWishlistSection.productItemNameText}}"/>
9491
</test>
9592
</tests>

dev/tests/integration/testsuite/Magento/Wishlist/Controller/IndexTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public function testAddActionProductNameXss()
122122
}
123123

124124
/**
125+
* @magentoDbIsolation disabled
125126
* @magentoDataFixture Magento/Wishlist/_files/wishlist_with_product_qty_increments.php
126127
*/
127128
public function testAllcartAction()

dev/tests/integration/testsuite/Magento/Wishlist/Model/WishlistTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Wishlist\Model;
77

88
use Magento\Catalog\Api\ProductRepositoryInterface;
9+
use Magento\Catalog\Model\Product\Attribute\Source\Status as ProductStatus;
910
use Magento\Framework\App\ObjectManager;
1011
use Magento\Framework\DataObject;
1112

@@ -85,4 +86,39 @@ public function testAddNewItemInvalidWishlistItemConfiguration()
8586
);
8687
$this->wishlist->addNewItem($product);
8788
}
89+
90+
/**
91+
* @magentoDbIsolation disabled
92+
* @magentoDataFixture Magento/Wishlist/_files/wishlist.php
93+
*/
94+
public function testGetItemCollection()
95+
{
96+
$productSku = 'simple';
97+
$customerId = 1;
98+
99+
$this->wishlist->loadByCustomerId($customerId, true);
100+
$itemCollection = $this->wishlist->getItemCollection();
101+
/** @var \Magento\Wishlist\Model\Item $item */
102+
$item = $itemCollection->getFirstItem();
103+
$this->assertEquals($productSku, $item->getProduct()->getSku());
104+
}
105+
106+
/**
107+
* @magentoDbIsolation disabled
108+
* @magentoDataFixture Magento/Wishlist/_files/wishlist.php
109+
*/
110+
public function testGetItemCollectionWithDisabledProduct()
111+
{
112+
$productSku = 'simple';
113+
$customerId = 1;
114+
115+
$productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
116+
$product = $productRepository->get($productSku);
117+
$product->setStatus(ProductStatus::STATUS_DISABLED);
118+
$productRepository->save($product);
119+
120+
$this->wishlist->loadByCustomerId($customerId, true);
121+
$itemCollection = $this->wishlist->getItemCollection();
122+
$this->assertEmpty($itemCollection->getItems());
123+
}
88124
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/** @var \Magento\Framework\ObjectManagerInterface $objectManager */
8+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
9+
10+
/** @var \Magento\Framework\Registry $registry */
11+
$registry = $objectManager->get(\Magento\Framework\Registry::class);
12+
$registry->unregister('isSecureArea');
13+
$registry->register('isSecureArea', true);
14+
15+
/** @var \Magento\Wishlist\Model\Wishlist $wishlist */
16+
$wishlist = $objectManager->create(\Magento\Wishlist\Model\Wishlist::class);
17+
$wishlist->loadByCustomerId(1);
18+
$wishlist->delete();
19+
20+
$registry->unregister('isSecureArea');
21+
$registry->register('isSecureArea', false);
22+
23+
require __DIR__ . '/../../../Magento/Catalog/_files/product_simple_rollback.php';
24+
require __DIR__ . '/../../../Magento/Customer/_files/customer_rollback.php';

0 commit comments

Comments
 (0)