Skip to content

Commit 3e8c89e

Browse files
author
Yaroslav Onischenko
authored
Merge pull request #732 from magento-mpi/pr-mpi-bugfix-ce
[MPI] bugfixes
2 parents cac91b5 + dcafe4a commit 3e8c89e

File tree

18 files changed

+654
-89
lines changed

18 files changed

+654
-89
lines changed

app/code/Magento/CatalogInventory/Block/Plugin/ProductView.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function afterGetQuantityValidators(
3838
);
3939

4040
$params = [];
41-
$params['minAllowed'] = max((float)$stockItem->getQtyMinAllowed(), 1);
41+
$params['minAllowed'] = (float)$stockItem->getMinSaleQty();
4242
if ($stockItem->getQtyMaxAllowed()) {
4343
$params['maxAllowed'] = $stockItem->getQtyMaxAllowed();
4444
}

app/code/Magento/CatalogInventory/Test/Unit/Block/Plugin/ProductViewTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected function setUp()
2828

2929
$this->stockItem = $this->getMockBuilder(\Magento\CatalogInventory\Model\Stock\Item::class)
3030
->disableOriginalConstructor()
31-
->setMethods(['getQtyMinAllowed', 'getQtyMaxAllowed', 'getQtyIncrements'])
31+
->setMethods(['getMinSaleQty', 'getQtyMaxAllowed', 'getQtyIncrements'])
3232
->getMock();
3333

3434
$this->stockRegistry = $this->getMockBuilder(\Magento\CatalogInventory\Api\StockRegistryInterface::class)
@@ -47,7 +47,7 @@ public function testAfterGetQuantityValidators()
4747
$result = [
4848
'validate-item-quantity' =>
4949
[
50-
'minAllowed' => 2,
50+
'minAllowed' => 0.5,
5151
'maxAllowed' => 5,
5252
'qtyIncrements' => 3
5353
]
@@ -73,7 +73,7 @@ public function testAfterGetQuantityValidators()
7373
->method('getStockItem')
7474
->with('productId', 'websiteId')
7575
->willReturn($this->stockItem);
76-
$this->stockItem->expects($this->once())->method('getQtyMinAllowed')->willReturn(2);
76+
$this->stockItem->expects($this->once())->method('getMinSaleQty')->willReturn(0.5);
7777
$this->stockItem->expects($this->any())->method('getQtyMaxAllowed')->willReturn(5);
7878
$this->stockItem->expects($this->any())->method('getQtyIncrements')->willReturn(3);
7979

app/code/Magento/CatalogInventory/view/adminhtml/ui_component/product_form.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@
179179
<item name="dataScope" xsi:type="string">min_sale_qty</item>
180180
<item name="validation" xsi:type="array">
181181
<item name="validate-number" xsi:type="boolean">true</item>
182-
<item name="validate-digits" xsi:type="boolean">true</item>
183182
</item>
184183
<item name="sortOrder" xsi:type="string">0</item>
185184
<item name="value" xsi:type="object">Magento\CatalogInventory\Model\Source\StockConfiguration</item>

app/code/Magento/Checkout/Model/Cart.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,11 +358,10 @@ public function addProduct($productInfo, $requestInfo = null)
358358
if ($productId) {
359359
$stockItem = $this->stockRegistry->getStockItem($productId, $product->getStore()->getWebsiteId());
360360
$minimumQty = $stockItem->getMinSaleQty();
361-
//If product was not found in cart and there is set minimal qty for it
361+
//If product quantity is not specified in request and there is set minimal qty for it
362362
if ($minimumQty
363363
&& $minimumQty > 0
364364
&& !$request->getQty()
365-
&& !$this->getQuote()->hasProductId($productId)
366365
) {
367366
$request->setQty($minimumQty);
368367
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Paypal\Model\Config\Structure;
7+
8+
/**
9+
* PayPal change structure of payment methods configuration in admin panel.
10+
*/
11+
class PaymentSectionModifier
12+
{
13+
/**
14+
* Identifiers of special payment method configuration groups
15+
*
16+
* @var array
17+
*/
18+
private static $specialGroups = [
19+
'account',
20+
'recommended_solutions',
21+
'other_paypal_payment_solutions',
22+
'other_payment_methods',
23+
];
24+
25+
/**
26+
* Returns changed section structure.
27+
*
28+
* Payment configuration has predefined special blocks:
29+
* - Account information (id = account),
30+
* - Recommended Solutions (id = recommended_solutions),
31+
* - Other PayPal paymnt solution (id = other_paypal_payment_solutions),
32+
* - Other payment methods (id = other_payment_methods).
33+
* All payment methods configuration should be moved to one of this group.
34+
* To move payment method to specific configuration group specify "displayIn"
35+
* attribute in system.xml file equals to any id of predefined special group.
36+
* If "displayIn" attribute is not specified then payment method moved to "Other payment methods" group
37+
*
38+
* @param array $initialStructure
39+
* @return array
40+
*/
41+
public function modify(array $initialStructure)
42+
{
43+
$changedStructure = array_fill_keys(self::$specialGroups, []);
44+
45+
foreach ($initialStructure as $childSection => $childData) {
46+
if (in_array($childSection, self::$specialGroups)) {
47+
if (isset($changedStructure[$childSection]['children'])) {
48+
$children = $changedStructure[$childSection]['children'];
49+
if (isset($childData['children'])) {
50+
$children += $childData['children'];
51+
}
52+
$childData['children'] = $children;
53+
unset($children);
54+
}
55+
$changedStructure[$childSection] = $childData;
56+
} else {
57+
$moveInstructions = $this->getMoveInstructions($childSection, $childData);
58+
if (!empty($moveInstructions)) {
59+
foreach ($moveInstructions as $moveInstruction) {
60+
unset($childData['children'][$moveInstruction['section']]);
61+
unset($moveInstruction['data']['displayIn']);
62+
$changedStructure
63+
[$moveInstruction['parent']]
64+
['children']
65+
[$moveInstruction['section']] = $moveInstruction['data'];
66+
}
67+
}
68+
if (!isset($moveInstructions[$childSection])) {
69+
$changedStructure['other_payment_methods']['children'][$childSection] = $childData;
70+
}
71+
}
72+
}
73+
74+
return $changedStructure;
75+
}
76+
77+
/**
78+
* Recursively collect groups that should be moved to special section
79+
*
80+
* @param string $section
81+
* @param array $data
82+
* @return array
83+
*/
84+
private function getMoveInstructions($section, $data)
85+
{
86+
$moved = [];
87+
88+
if (array_key_exists('children', $data)) {
89+
foreach ($data['children'] as $childSection => $childData) {
90+
$movedChildren = $this->getMoveInstructions($childSection, $childData);
91+
if (isset($movedChildren[$childSection])) {
92+
unset($data['children'][$childSection]);
93+
}
94+
$moved = array_merge($moved, $movedChildren);
95+
}
96+
}
97+
98+
if (isset($data['displayIn']) && in_array($data['displayIn'], self::$specialGroups)) {
99+
$moved = array_merge(
100+
[
101+
$section => [
102+
'parent' => $data['displayIn'],
103+
'section' => $section,
104+
'data' => $data
105+
]
106+
],
107+
$moved
108+
);
109+
}
110+
111+
return $moved;
112+
}
113+
}

app/code/Magento/Paypal/Model/Config/StructurePlugin.php

Lines changed: 23 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Magento\Config\Model\Config\Structure\Element\Section;
1111
use Magento\Config\Model\Config\Structure\ElementInterface;
1212
use Magento\Paypal\Helper\Backend as BackendHelper;
13+
use Magento\Framework\App\ObjectManager;
14+
use Magento\Paypal\Model\Config\Structure\PaymentSectionModifier;
1315

1416
/**
1517
* Plugin for \Magento\Config\Model\Config\Structure
@@ -31,6 +33,11 @@ class StructurePlugin
3133
*/
3234
private $scopeDefiner;
3335

36+
/**
37+
* @var PaymentSectionModifier
38+
*/
39+
private $paymentSectionModifier;
40+
3441
/**
3542
* @var string[]
3643
*/
@@ -50,12 +57,18 @@ class StructurePlugin
5057

5158
/**
5259
* @param ScopeDefiner $scopeDefiner
53-
* @param BackendHelper $helper
60+
* @param BackendHelper $backendHelper
61+
* @param PaymentSectionModifier|null $paymentSectionModifier
5462
*/
55-
public function __construct(ScopeDefiner $scopeDefiner, BackendHelper $helper)
56-
{
63+
public function __construct(
64+
ScopeDefiner $scopeDefiner,
65+
BackendHelper $backendHelper,
66+
PaymentSectionModifier $paymentSectionModifier = null
67+
) {
5768
$this->scopeDefiner = $scopeDefiner;
58-
$this->backendHelper = $helper;
69+
$this->backendHelper = $backendHelper;
70+
$this->paymentSectionModifier = $paymentSectionModifier
71+
?: ObjectManager::getInstance()->get(PaymentSectionModifier::class);
5972
}
6073

6174
/**
@@ -118,62 +131,17 @@ public function aroundGetElementByPathParts(Structure $subject, \Closure $procee
118131
}
119132

120133
/**
121-
* Change payment config structure
122-
*
123-
* Groups which have `displayIn` element, transfer to appropriate group.
124-
* Groups without `displayIn` transfer to other payment methods group.
134+
* Changes payment config structure.
125135
*
126136
* @param Section $result
127137
* @return void
128138
*/
129139
private function restructurePayments(Section $result)
130140
{
131-
$sectionMap = [
132-
'account' => [],
133-
'recommended_solutions' => [],
134-
'other_paypal_payment_solutions' => [],
135-
'other_payment_methods' => []
136-
];
137-
138-
$configuration = $result->getData();
139-
140-
foreach ($configuration['children'] as $section => $data) {
141-
if (array_key_exists($section, $sectionMap)) {
142-
$sectionMap[$section] = $data;
143-
} elseif ($displayIn = $this->getDisplayInSection($section, $data)) {
144-
$sectionMap[$displayIn['parent']]['children'][$displayIn['section']] = $displayIn['data'];
145-
} else {
146-
$sectionMap['other_payment_methods']['children'][$section] = $data;
147-
}
148-
}
149-
150-
$configuration['children'] = $sectionMap;
151-
$result->setData($configuration, $this->scopeDefiner->getScope());
152-
}
153-
154-
/**
155-
* Recursive search of `displayIn` element in node children
156-
*
157-
* @param string $section
158-
* @param array $data
159-
* @return array|null
160-
*/
161-
private function getDisplayInSection($section, $data)
162-
{
163-
if (is_array($data) && array_key_exists('displayIn', $data)) {
164-
return [
165-
'parent' => $data['displayIn'],
166-
'section' => $section,
167-
'data' => $data
168-
];
169-
}
170-
171-
if (array_key_exists('children', $data)) {
172-
foreach ($data['children'] as $childSection => $childData) {
173-
return $this->getDisplayInSection($childSection, $childData);
174-
}
175-
}
176-
177-
return null;
141+
$sectionData = $result->getData();
142+
$sectionInitialStructure = isset($sectionData['children']) ? $sectionData['children'] : [];
143+
$sectionChangedStructure = $this->paymentSectionModifier->modify($sectionInitialStructure);
144+
$sectionData['children'] = $sectionChangedStructure;
145+
$result->setData($sectionData, $this->scopeDefiner->getScope());
178146
}
179147
}

0 commit comments

Comments
 (0)