Skip to content

Commit 5d27996

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-96016' into 2.3-develop-pr38
2 parents 0419965 + 51f1488 commit 5d27996

File tree

104 files changed

+2740
-444
lines changed

Some content is hidden

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

104 files changed

+2740
-444
lines changed

app/code/Magento/Backend/Test/Mftf/Page/AdminConfigurationStoresPage.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,7 @@
1414
<page name="WebConfigurationPage" url="admin/system_config/edit/section/web/" area="admin" module="Backend">
1515
<section name="WYSIWYGOptionsSection"/>
1616
</page>
17+
<page name="GeneralConfigurationPage" url="admin/system_config/edit/section/general/" area="admin" module="Backend">
18+
<section name="LocaleOptionsSection"/>
19+
</page>
1720
</pages>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
11+
<section name="LocaleOptionsSection">
12+
<element name="sectionHeader" type="text" selector="#general_locale-head"/>
13+
<element name="timezone" type="select" selector="#general_locale_timezone"/>
14+
</section>
15+
</sections>

app/code/Magento/Bundle/Model/OptionRepository.php

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function __construct(
9090
}
9191

9292
/**
93-
* {@inheritdoc}
93+
* @inheritdoc
9494
*/
9595
public function get($sku, $optionId)
9696
{
@@ -106,23 +106,24 @@ public function get($sku, $optionId)
106106

107107
$productLinks = $this->linkManagement->getChildren($product->getSku(), $optionId);
108108

109-
/** @var \Magento\Bundle\Api\Data\OptionInterface $option */
109+
/** @var \Magento\Bundle\Api\Data\OptionInterface $optionDataObject */
110110
$optionDataObject = $this->optionFactory->create();
111111
$this->dataObjectHelper->populateWithArray(
112112
$optionDataObject,
113113
$option->getData(),
114114
\Magento\Bundle\Api\Data\OptionInterface::class
115115
);
116-
$optionDataObject->setOptionId($option->getId())
117-
->setTitle($option->getTitle() === null ? $option->getDefaultTitle() : $option->getTitle())
118-
->setSku($product->getSku())
119-
->setProductLinks($productLinks);
116+
117+
$optionDataObject->setOptionId($option->getId());
118+
$optionDataObject->setTitle($option->getTitle() === null ? $option->getDefaultTitle() : $option->getTitle());
119+
$optionDataObject->setSku($product->getSku());
120+
$optionDataObject->setProductLinks($productLinks);
120121

121122
return $optionDataObject;
122123
}
123124

124125
/**
125-
* {@inheritdoc}
126+
* @inheritdoc
126127
*/
127128
public function getList($sku)
128129
{
@@ -131,6 +132,8 @@ public function getList($sku)
131132
}
132133

133134
/**
135+
* Return list of product options
136+
*
134137
* @param ProductInterface $product
135138
* @return \Magento\Bundle\Api\Data\OptionInterface[]
136139
*/
@@ -140,7 +143,7 @@ public function getListByProduct(ProductInterface $product)
140143
}
141144

142145
/**
143-
* {@inheritdoc}
146+
* @inheritdoc
144147
*/
145148
public function delete(\Magento\Bundle\Api\Data\OptionInterface $option)
146149
{
@@ -156,20 +159,19 @@ public function delete(\Magento\Bundle\Api\Data\OptionInterface $option)
156159
}
157160

158161
/**
159-
* {@inheritdoc}
162+
* @inheritdoc
160163
*/
161164
public function deleteById($sku, $optionId)
162165
{
163-
$product = $this->getProduct($sku);
164-
$optionCollection = $this->type->getOptionsCollection($product);
165-
$optionCollection->setIdFilter($optionId);
166-
$hasBeenDeleted = $this->delete($optionCollection->getFirstItem());
166+
/** @var \Magento\Bundle\Api\Data\OptionInterface $option */
167+
$option = $this->get($sku, $optionId);
168+
$hasBeenDeleted = $this->delete($option);
167169

168170
return $hasBeenDeleted;
169171
}
170172

171173
/**
172-
* {@inheritdoc}
174+
* @inheritdoc
173175
*/
174176
public function save(
175177
\Magento\Catalog\Api\Data\ProductInterface $product,
@@ -189,6 +191,9 @@ public function save(
189191
* @param \Magento\Catalog\Api\Data\ProductInterface $product
190192
* @param \Magento\Bundle\Api\Data\OptionInterface $option
191193
* @return $this
194+
* @throws InputException
195+
* @throws NoSuchEntityException
196+
* @throws \Magento\Framework\Exception\CouldNotSaveException
192197
*/
193198
protected function updateOptionSelection(
194199
\Magento\Catalog\Api\Data\ProductInterface $product,
@@ -228,9 +233,12 @@ protected function updateOptionSelection(
228233
}
229234

230235
/**
236+
* Retrieve product by SKU
237+
*
231238
* @param string $sku
232239
* @return \Magento\Catalog\Api\Data\ProductInterface
233-
* @throws \Magento\Framework\Exception\InputException
240+
* @throws InputException
241+
* @throws NoSuchEntityException
234242
*/
235243
private function getProduct($sku)
236244
{

app/code/Magento/Bundle/Test/Unit/Model/OptionRepositoryTest.php

Lines changed: 68 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\Bundle\Test\Unit\Model;
99

1010
use Magento\Bundle\Model\OptionRepository;
11+
use Magento\Framework\Exception\NoSuchEntityException;
1112

1213
/**
1314
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -84,7 +85,7 @@ protected function setUp()
8485
->getMock();
8586
$this->optionResourceMock = $this->createPartialMock(
8687
\Magento\Bundle\Model\ResourceModel\Option::class,
87-
['delete', '__wakeup', 'save', 'removeOptionSelections']
88+
['get', 'delete', '__wakeup', 'save', 'removeOptionSelections']
8889
);
8990
$this->storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
9091
$this->linkManagementMock = $this->createMock(\Magento\Bundle\Api\ProductLinkManagementInterface::class);
@@ -227,32 +228,92 @@ public function testDeleteThrowsExceptionIfCannotDelete()
227228
$this->model->delete($optionMock);
228229
}
229230

231+
/**
232+
* Test successful delete action for given $optionId
233+
*/
230234
public function testDeleteById()
231235
{
232236
$productSku = 'sku';
233237
$optionId = 100;
234-
$productMock = $this->createMock(\Magento\Catalog\Api\Data\ProductInterface::class);
238+
239+
$optionMock = $this->createMock(\Magento\Bundle\Model\Option::class);
240+
$optionMock->expects($this->exactly(2))
241+
->method('getId')
242+
->willReturn($optionId);
243+
244+
$optionMock->expects($this->once())
245+
->method('getData')
246+
->willReturn([
247+
'title' => 'Option title',
248+
'option_id' => $optionId
249+
]);
250+
251+
$this->optionFactoryMock->expects($this->once())
252+
->method('create')
253+
->willReturn($optionMock);
254+
255+
$productMock = $this->createPartialMock(
256+
\Magento\Catalog\Model\Product::class,
257+
['getTypeId', 'getTypeInstance', 'getStoreId', 'getPriceType', '__wakeup', 'getSku']
258+
);
235259
$productMock->expects($this->once())
236260
->method('getTypeId')
237261
->willReturn(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE);
238-
$this->productRepositoryMock->expects($this->once())
262+
$productMock->expects($this->exactly(2))->method('getSku')->willReturn($productSku);
263+
264+
$this->productRepositoryMock
265+
->expects($this->once())
239266
->method('get')
240267
->with($productSku)
241268
->willReturn($productMock);
242269

270+
$optCollectionMock = $this->createMock(\Magento\Bundle\Model\ResourceModel\Option\Collection::class);
271+
$optCollectionMock->expects($this->once())->method('getItemById')->with($optionId)->willReturn($optionMock);
272+
$this->typeMock->expects($this->once())
273+
->method('getOptionsCollection')
274+
->with($productMock)
275+
->willReturn($optCollectionMock);
276+
277+
$this->assertTrue($this->model->deleteById($productSku, $optionId));
278+
}
279+
280+
/**
281+
* Tests if NoSuchEntityException thrown when provided $optionId not found
282+
*/
283+
public function testDeleteByIdException()
284+
{
285+
$productSku = 'sku';
286+
$optionId = null;
287+
243288
$optionMock = $this->createMock(\Magento\Bundle\Model\Option::class);
289+
$optionMock->expects($this->exactly(1))
290+
->method('getId')
291+
->willReturn($optionId);
292+
293+
$productMock = $this->createPartialMock(
294+
\Magento\Catalog\Model\Product::class,
295+
['getTypeId', 'getTypeInstance', 'getStoreId', 'getPriceType', '__wakeup', 'getSku']
296+
);
297+
$productMock->expects($this->once())
298+
->method('getTypeId')
299+
->willReturn(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE);
300+
301+
$this->productRepositoryMock
302+
->expects($this->once())
303+
->method('get')
304+
->with($productSku)
305+
->willReturn($productMock);
244306

245307
$optCollectionMock = $this->createMock(\Magento\Bundle\Model\ResourceModel\Option\Collection::class);
308+
$optCollectionMock->expects($this->once())->method('getItemById')->with($optionId)->willReturn($optionMock);
246309
$this->typeMock->expects($this->once())
247310
->method('getOptionsCollection')
248311
->with($productMock)
249312
->willReturn($optCollectionMock);
250313

251-
$optCollectionMock->expects($this->once())->method('setIdFilter')->with($optionId)->willReturnSelf();
252-
$optCollectionMock->expects($this->once())->method('getFirstItem')->willReturn($optionMock);
314+
$this->expectException(NoSuchEntityException::class);
253315

254-
$this->optionResourceMock->expects($this->once())->method('delete')->with($optionMock)->willReturnSelf();
255-
$this->assertTrue($this->model->deleteById($productSku, $optionId));
316+
$this->model->deleteById($productSku, $optionId);
256317
}
257318

258319
/**

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
1515

1616
/**
17+
* Updates status for a batch of products.
1718
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1819
*/
1920
class MassStatus extends \Magento\Catalog\Controller\Adminhtml\Product implements HttpPostActionInterface
@@ -87,7 +88,7 @@ public function execute()
8788
$filterRequest = $this->getRequest()->getParam('filters', null);
8889
$status = (int) $this->getRequest()->getParam('status');
8990

90-
if (null !== $storeId && null !== $filterRequest) {
91+
if (null === $storeId && null !== $filterRequest) {
9192
$storeId = (isset($filterRequest['store_id'])) ? (int) $filterRequest['store_id'] : 0;
9293
}
9394

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

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

88
use Magento\Catalog\Api\CategoryRepositoryInterface;
99
use Magento\Catalog\Api\ProductRepositoryInterface;
10+
use Magento\Store\Model\ScopeInterface;
1011
use Magento\Customer\Model\Session as CustomerSession;
1112
use Magento\Framework\Exception\NoSuchEntityException;
1213
use Magento\Framework\Pricing\PriceCurrencyInterface;
@@ -273,7 +274,8 @@ public function setStoreId($store)
273274

274275
/**
275276
* Return current category path or get it from current category
276-
* and creating array of categories|product paths for breadcrumbs
277+
*
278+
* Creating array of categories|product paths for breadcrumbs
277279
*
278280
* @return array
279281
*/
@@ -382,6 +384,7 @@ public function getLastViewedUrl()
382384

383385
/**
384386
* Split SKU of an item by dashes and spaces
387+
*
385388
* Words will not be broken, unless this length is greater than $length
386389
*
387390
* @param string $sku
@@ -410,14 +413,15 @@ public function getAttributeHiddenFields()
410413
/**
411414
* Retrieve Catalog Price Scope
412415
*
413-
* @return int
416+
* @return int|null
414417
*/
415-
public function getPriceScope()
418+
public function getPriceScope(): ?int
416419
{
417-
return $this->scopeConfig->getValue(
420+
$priceScope = $this->scopeConfig->getValue(
418421
self::XML_PATH_PRICE_SCOPE,
419-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
422+
ScopeInterface::SCOPE_STORE
420423
);
424+
return isset($priceScope) ? (int)$priceScope : null;
421425
}
422426

423427
/**
@@ -439,7 +443,7 @@ public function isUsingStaticUrlsAllowed()
439443
{
440444
return $this->scopeConfig->isSetFlag(
441445
self::CONFIG_USE_STATIC_URLS,
442-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
446+
ScopeInterface::SCOPE_STORE
443447
);
444448
}
445449

@@ -454,7 +458,7 @@ public function isUrlDirectivesParsingAllowed()
454458
{
455459
return $this->scopeConfig->isSetFlag(
456460
self::CONFIG_PARSE_URL_DIRECTIVES,
457-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
461+
ScopeInterface::SCOPE_STORE,
458462
$this->_storeId
459463
);
460464
}
@@ -472,19 +476,22 @@ public function getPageTemplateProcessor()
472476

473477
/**
474478
* Whether to display items count for each filter option
479+
*
475480
* @param int $storeId Store view ID
476481
* @return bool
477482
*/
478483
public function shouldDisplayProductCountOnLayer($storeId = null)
479484
{
480485
return $this->scopeConfig->isSetFlag(
481486
self::XML_PATH_DISPLAY_PRODUCT_COUNT,
482-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
487+
ScopeInterface::SCOPE_STORE,
483488
$storeId
484489
);
485490
}
486491

487492
/**
493+
* Convert tax address array to address data object with country id and postcode
494+
*
488495
* @param array $taxAddress
489496
* @return \Magento\Customer\Api\Data\AddressInterface|null
490497
*/

0 commit comments

Comments
 (0)