Skip to content

Commit 755e29b

Browse files
author
Viktor Tymchynskyi
committed
Merge remote-tracking branch 'magento2/develop' into MPI-BUGFIXES
2 parents d8de0b4 + f93b8da commit 755e29b

File tree

33 files changed

+891
-111
lines changed

33 files changed

+891
-111
lines changed

app/code/Magento/Bundle/Test/Unit/Pricing/Price/TierPriceTest.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,8 @@ public function providerForGetterTierPriceList()
162162
'basePrice' => 20.,
163163
'expectedResult' => [
164164
[
165-
'price' => '50.',
166-
'website_price' => '50.',
167-
'price_qty' => '2.',
168-
'cust_group' => Group::CUST_GROUP_ALL,
169-
],
170-
[
171-
'price' => '30.',
172-
'website_price' => '30.',
165+
'price' => '15.',
166+
'website_price' => '15.',
173167
'price_qty' => '5.',
174168
'cust_group' => Group::CUST_GROUP_ALL
175169
],

app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Edit.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ public function __construct(
5353
*/
5454
public function execute()
5555
{
56-
$collection = $this->filter->getCollection($this->collectionFactory->create());
57-
$this->attributeHelper->setProductIds($collection->getAllIds());
56+
if ($this->getRequest()->getParam('filters')) {
57+
$collection = $this->filter->getCollection($this->collectionFactory->create());
58+
$this->attributeHelper->setProductIds($collection->getAllIds());
59+
}
5860

5961
if (!$this->_validateProducts()) {
6062
return $this->resultRedirectFactory->create()->setPath('catalog/product/', ['_current' => true]);

app/code/Magento/Catalog/Pricing/Price/TierPrice.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ protected function filterTierPrices(array $priceList)
162162
$qtyCache = [];
163163
$allCustomersGroupId = $this->groupManagement->getAllCustomersGroup()->getId();
164164
foreach ($priceList as $priceKey => &$price) {
165+
if ($price['price'] >= $this->priceInfo->getPrice(FinalPrice::PRICE_CODE)->getValue()) {
166+
unset($priceList[$priceKey]);
167+
continue;
168+
}
169+
165170
if (isset($price['price_qty']) && $price['price_qty'] == 1) {
166171
unset($priceList[$priceKey]);
167172
continue;
@@ -204,7 +209,7 @@ protected function getBasePrice()
204209
public function getSavePercent(AmountInterface $amount)
205210
{
206211
return ceil(
207-
100 - ((100 / $this->priceInfo->getPrice(RegularPrice::PRICE_CODE)->getAmount()->getBaseAmount())
212+
100 - ((100 / $this->priceInfo->getPrice(FinalPrice::PRICE_CODE)->getValue())
208213
* $amount->getBaseAmount())
209214
);
210215
}
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
<?php
2+
/**
3+
*
4+
* Copyright © 2016 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
namespace Magento\Catalog\Test\Unit\Controller\Adminhtml\Product\Action\Attribute;
8+
9+
class EditTest extends \PHPUnit_Framework_TestCase
10+
{
11+
/** @var \Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute\Save */
12+
private $object;
13+
14+
/** @var \Magento\Catalog\Helper\Product\Edit\Action\Attribute|\PHPUnit_Framework_MockObject_MockObject */
15+
private $attributeHelper;
16+
17+
/** @var \Magento\Backend\Model\View\Result\RedirectFactory|\PHPUnit_Framework_MockObject_MockObject */
18+
private $resultRedirectFactory;
19+
20+
/** @var \Magento\Ui\Component\MassAction\Filter|\PHPUnit_Framework_MockObject_MockObject */
21+
private $filter;
22+
23+
/** @var \Magento\Backend\App\Action\Context|\PHPUnit_Framework_MockObject_MockObject */
24+
private $context;
25+
26+
/** @var \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject */
27+
private $collectionFactory;
28+
29+
/** @var \Magento\Framework\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject */
30+
private $resultPage;
31+
32+
/** @var \Magento\Framework\App\Request\Http|\PHPUnit_Framework_MockObject_MockObject */
33+
private $request;
34+
35+
protected function setUp()
36+
{
37+
$this->attributeHelper = $this->getMockBuilder('Magento\Catalog\Helper\Product\Edit\Action\Attribute')
38+
->setMethods(['getProductIds', 'setProductIds'])
39+
->disableOriginalConstructor()->getMock();
40+
41+
$this->resultRedirectFactory = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory')
42+
->disableOriginalConstructor()
43+
->setMethods(['create'])
44+
->getMock();
45+
46+
$this->filter = $this->getMockBuilder('Magento\Ui\Component\MassAction\Filter')
47+
->setMethods(['getCollection'])->disableOriginalConstructor()->getMock();
48+
49+
$this->collectionFactory = $this->getMockBuilder(
50+
'Magento\Catalog\Model\ResourceModel\Product\CollectionFactory'
51+
)->setMethods(['create'])->disableOriginalConstructor()->getMock();
52+
53+
$this->resultPage = $this->getMockBuilder('Magento\Framework\View\Result\Page')
54+
->setMethods(['getConfig'])->disableOriginalConstructor()->getMock();
55+
56+
$resultPageFactory = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory')
57+
->setMethods(['create'])->disableOriginalConstructor()->getMock();
58+
$resultPageFactory->expects($this->any())->method('create')->willReturn($this->resultPage);
59+
60+
$this->prepareContext();
61+
62+
$this->object = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject(
63+
'Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute\Edit',
64+
[
65+
'context' => $this->context,
66+
'attributeHelper' => $this->attributeHelper,
67+
'filter' => $this->filter,
68+
'resultPageFactory' => $resultPageFactory,
69+
'collectionFactory' => $this->collectionFactory
70+
]
71+
);
72+
}
73+
74+
private function prepareContext()
75+
{
76+
$this->request = $this->getMockBuilder('Magento\Framework\App\Request\Http')
77+
->setMethods(['getParam', 'getParams', 'setParams'])
78+
->disableOriginalConstructor()->getMock();
79+
80+
$objectManager = $this->getMock('Magento\Framework\ObjectManagerInterface');
81+
$product = $this->getMockBuilder('Magento\Catalog\Model\Product')
82+
->setMethods(['isProductsHasSku'])
83+
->disableOriginalConstructor()->getMock();
84+
$product->expects($this->any())->method('isProductsHasSku')
85+
->with([1, 2, 3])
86+
->willReturn(true);
87+
$objectManager->expects($this->any())->method('create')
88+
->with('Magento\Catalog\Model\Product')
89+
->willReturn($product);
90+
$messageManager = $this->getMockBuilder('\Magento\Framework\Message\ManagerInterface')
91+
->setMethods([])
92+
->disableOriginalConstructor()->getMock();
93+
$messageManager->expects($this->any())->method('addError')->willReturn(true);
94+
$this->context = $this->getMockBuilder('Magento\Backend\App\Action\Context')
95+
->setMethods(['getRequest', 'getObjectManager', 'getMessageManager', 'getResultRedirectFactory'])
96+
->disableOriginalConstructor()->getMock();
97+
$this->context->expects($this->any())->method('getRequest')->willReturn($this->request);
98+
$this->context->expects($this->any())->method('getObjectManager')->willReturn($objectManager);
99+
$this->context->expects($this->any())->method('getMessageManager')->willReturn($messageManager);
100+
$this->context->expects($this->any())->method('getResultRedirectFactory')
101+
->willReturn($this->resultRedirectFactory);
102+
}
103+
104+
public function testExecutePageRequested()
105+
{
106+
$this->request->expects($this->any())->method('getParam')->with('filters')->willReturn(['placeholder' => true]);
107+
$this->request->expects($this->any())->method('getParams')->willReturn(
108+
[
109+
'namespace' => 'product_listing',
110+
'exclude' => true,
111+
'filters' => ['placeholder' => true]
112+
]
113+
);
114+
115+
$this->attributeHelper->expects($this->any())->method('getProductIds')->willReturn([1, 2, 3]);
116+
$this->attributeHelper->expects($this->any())->method('setProductIds')->with([1, 2, 3]);
117+
118+
$collection = $this->getMockBuilder('Magento\Catalog\Model\ResourceModel\Product\Collection')
119+
->setMethods(['getAllIds'])
120+
->disableOriginalConstructor()->getMock();
121+
$collection->expects($this->any())->method('getAllIds')->willReturn([1, 2, 3]);
122+
$this->filter->expects($this->any())->method('getCollection')->with($collection)->willReturn($collection);
123+
$this->collectionFactory->expects($this->any())->method('create')->willReturn($collection);
124+
125+
$title = $this->getMockBuilder('Magento\Framework\View\Page\Title')
126+
->setMethods(['prepend'])
127+
->disableOriginalConstructor()->getMock();
128+
$config = $this->getMockBuilder('Magento\Framework\View\Page\Config')
129+
->setMethods(['getTitle'])
130+
->disableOriginalConstructor()->getMock();
131+
$config->expects($this->any())->method('getTitle')->willReturn($title);
132+
$this->resultPage->expects($this->any())->method('getConfig')->willReturn($config);
133+
134+
$this->assertSame($this->resultPage, $this->object->execute());
135+
}
136+
137+
public function testExecutePageReload()
138+
{
139+
$this->request->expects($this->any())->method('getParam')->with('filters')->willReturn(null);
140+
$this->request->expects($this->any())->method('getParams')->willReturn([]);
141+
142+
$this->attributeHelper->expects($this->any())->method('getProductIds')->willReturn([1, 2, 3]);
143+
$this->attributeHelper->expects($this->any())->method('setProductIds')->with([1, 2, 3]);
144+
145+
$title = $this->getMockBuilder('Magento\Framework\View\Page\Title')
146+
->setMethods(['prepend'])
147+
->disableOriginalConstructor()->getMock();
148+
$config = $this->getMockBuilder('Magento\Framework\View\Page\Config')
149+
->setMethods(['getTitle'])
150+
->disableOriginalConstructor()->getMock();
151+
$config->expects($this->any())->method('getTitle')->willReturn($title);
152+
$this->resultPage->expects($this->any())->method('getConfig')->willReturn($config);
153+
154+
$this->assertSame($this->resultPage, $this->object->execute());
155+
}
156+
157+
public function testExecutePageDirectAccess()
158+
{
159+
$this->request->expects($this->any())->method('getParam')->with('filters')->willReturn(null);
160+
$this->request->expects($this->any())->method('getParams')->willReturn([]);
161+
$this->attributeHelper->expects($this->any())->method('getProductIds')->willReturn(null);
162+
163+
$resultRedirect = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect')
164+
->setMethods(['setPath'])
165+
->disableOriginalConstructor()
166+
->getMock();
167+
$resultRedirect->expects($this->any())->method('setPath')
168+
->with('catalog/product/', ['_current' => true])
169+
->willReturnSelf();
170+
$this->resultRedirectFactory->expects($this->any())
171+
->method('create')
172+
->willReturn($resultRedirect);
173+
174+
$this->assertSame($resultRedirect, $this->object->execute());
175+
}
176+
}

app/code/Magento/Catalog/Test/Unit/Pricing/Price/TierPriceTest.php

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88

99
namespace Magento\Catalog\Test\Unit\Pricing\Price;
1010

11-
use \Magento\Catalog\Pricing\Price\TierPrice;
12-
use \Magento\Catalog\Pricing\Price\RegularPrice;
13-
11+
use Magento\Catalog\Pricing\Price\TierPrice;
12+
use Magento\Catalog\Pricing\Price\FinalPrice;
1413
use Magento\Customer\Model\Group;
1514
use Magento\Customer\Model\GroupManagement;
1615

@@ -271,6 +270,10 @@ public function testGetterTierPriceList($tierPrices, $basePrice, $expectedResult
271270
$this->calculator->expects($this->atLeastOnce())->method('getAmount')
272271
->will($this->returnArgument(0));
273272

273+
$this->priceInfo->expects(static::atLeastOnce())
274+
->method('getPrice')
275+
->with(FinalPrice::PRICE_CODE)
276+
->willReturn($price);
274277
$this->priceCurrencyMock->expects($this->any())
275278
->method('convertAndRound')
276279
->will($this->returnCallback(
@@ -365,20 +368,15 @@ public function providerForGetterTierPriceList()
365368
*/
366369
public function testGetSavePercent($basePrice, $tierPrice, $savedPercent)
367370
{
368-
$priceAmount = $this->getMockForAbstractClass('Magento\Framework\Pricing\Amount\AmountInterface');
369-
$priceAmount->expects($this->once())
370-
->method('getBaseAmount')
371-
->will($this->returnValue($basePrice));
372-
373371
$price = $this->getMock('Magento\Framework\Pricing\Price\PriceInterface');
374-
$price->expects($this->any())
375-
->method('getAmount')
376-
->will($this->returnValue($priceAmount));
377372

378-
$this->priceInfo->expects($this->atLeastOnce())
373+
$this->priceInfo->expects(static::atLeastOnce())
379374
->method('getPrice')
380-
->will($this->returnValue($price))
381-
->with(RegularPrice::PRICE_CODE);
375+
->with(FinalPrice::PRICE_CODE)
376+
->willReturn($price);
377+
$price->expects(static::atLeastOnce())
378+
->method('getValue')
379+
->willReturn($basePrice);
382380

383381
$amount = $this->getMockForAbstractClass('Magento\Framework\Pricing\Amount\AmountInterface');
384382
$amount->expects($this->atLeastOnce())

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/General.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ protected function customizeNameListeners(array $meta)
342342
'handleShortDescriptionChanges' => '${$.provider}:data.product.short_description',
343343
'handleSizeChanges' => '${$.provider}:data.product.size'
344344
],
345+
'allowImport' => !$this->locator->getProduct()->getId(),
345346
];
346347

347348
if (!in_array($listener, $textListeners)) {
@@ -356,8 +357,7 @@ protected function customizeNameListeners(array $meta)
356357
$skuPath . static::META_CONFIG_PATH,
357358
$meta,
358359
[
359-
'autoImportIfEmpty' => true,
360-
'allowImport' => $this->locator->getProduct()->getId() ? false : true,
360+
'autoImportIfEmpty' => true
361361
]
362362
);
363363

app/code/Magento/Catalog/view/adminhtml/templates/catalog/form/renderer/fieldset/element.phtml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
<?php
1616
/* @var $block \Magento\Backend\Block\Widget\Form\Renderer\Fieldset\Element */
1717
$element = $block->getElement();
18-
$note = $element->getNote() ? '<div class="note">' . $element->getNote() . '</div>' : '';
18+
$note = $element->getNote() ? '<div class="note admin__field-note">' . $element->getNote() . '</div>' : '';
1919
$elementBeforeLabel = $element->getExtType() == 'checkbox' || $element->getExtType() == 'radio';
2020
$addOn = $element->getBeforeElementHtml() || $element->getAfterElementHtml();
2121
$fieldId = ($element->getHtmlId()) ? ' id="attribute-' . $element->getHtmlId() . '-container"' : '';
2222
$entity = $element->getEntityAttribute();
23-
$fieldClass = "field field-{$element->getId()} {$element->getCssClass()}";
23+
$fieldClass = "admin__field field field-{$element->getId()} {$element->getCssClass()}";
2424
$fieldClass .= ($elementBeforeLabel) ? ' choice' : '';
2525
$fieldClass .= ($addOn) ? ' with-addon' : '';
2626
$fieldClass .= ($element->getRequired()) ? ' required' : '';
@@ -51,7 +51,7 @@ $fieldAttributes = $fieldId . ' class="' . $fieldClass . '" '
5151
<?php /* @escapeNotVerified */ echo $note ?>
5252
<?php else: ?>
5353
<?php echo $element->getLabelHtml('', $block->getScopeLabel()) ?>
54-
<div class="control">
54+
<div class="admin__field-control control">
5555
<?php /* @escapeNotVerified */ echo($addOn) ? '<div class="addon">' . $block->getElementHtml() . '</div>' : $block->getElementHtml(); ?>
5656
<?php /* @escapeNotVerified */ echo $note ?>
5757
</div>

0 commit comments

Comments
 (0)