Skip to content

Commit 7dfd9b3

Browse files
committed
Merge remote-tracking branch 'origin/2.3-develop' into MAGETWO-96016
2 parents 55dcd20 + 8f6eeb8 commit 7dfd9b3

File tree

58 files changed

+1340
-139
lines changed

Some content is hidden

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

58 files changed

+1340
-139
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/Model/Product/Attribute/Backend/Tierprice.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
use Magento\Catalog\Model\Attribute\ScopeOverriddenValue;
1515

16+
/**
17+
* Backend model for Tierprice attribute
18+
*/
1619
class Tierprice extends \Magento\Catalog\Model\Product\Attribute\Backend\GroupPrice\AbstractGroupPrice
1720
{
1821
/**
@@ -159,8 +162,22 @@ protected function validatePrice(array $priceRow)
159162
*/
160163
protected function modifyPriceData($object, $data)
161164
{
165+
/** @var \Magento\Catalog\Model\Product $object */
162166
$data = parent::modifyPriceData($object, $data);
163167
$price = $object->getPrice();
168+
169+
$specialPrice = $object->getSpecialPrice();
170+
$specialPriceFromDate = $object->getSpecialFromDate();
171+
$specialPriceToDate = $object->getSpecialToDate();
172+
$today = time();
173+
174+
if ($specialPrice && ($object->getPrice() > $object->getFinalPrice())) {
175+
if ($today >= strtotime($specialPriceFromDate) && $today <= strtotime($specialPriceToDate) ||
176+
$today >= strtotime($specialPriceFromDate) && $specialPriceToDate === null) {
177+
$price = $specialPrice;
178+
}
179+
}
180+
164181
foreach ($data as $key => $tierPrice) {
165182
$percentageValue = $this->getPercentage($tierPrice);
166183
if ($percentageValue) {
@@ -172,6 +189,10 @@ protected function modifyPriceData($object, $data)
172189
}
173190

174191
/**
192+
* Update Price values in DB
193+
*
194+
* Updates price values in DB from array comparing to old values. Returns bool if updated
195+
*
175196
* @param array $valuesToUpdate
176197
* @param array $oldValues
177198
* @return boolean

0 commit comments

Comments
 (0)