Skip to content

Commit 5e4ddd4

Browse files
committed
Merge pull request #74 from magento-folks/bugfix
[Folks] Bugfix
2 parents 7edfd0c + 097a63d commit 5e4ddd4

File tree

22 files changed

+752
-92
lines changed

22 files changed

+752
-92
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ public function initializeFromData(\Magento\Catalog\Model\Product $product, arra
178178
foreach ($useDefaults as $attributeCode => $useDefaultState) {
179179
if ($useDefaultState) {
180180
$product->setData($attributeCode, null);
181+
// UI component sends value even if field is disabled, so 'Use Config Settings' must be reset to false
182+
if ($product->hasData('use_config_' . $attributeCode)) {
183+
$product->setData('use_config_' . $attributeCode, false);
184+
}
181185
}
182186
}
183187

@@ -215,7 +219,7 @@ public function initializeFromData(\Magento\Catalog\Model\Product $product, arra
215219

216220
return $product;
217221
}
218-
222+
219223
/**
220224
* Initialize product before saving
221225
*
@@ -310,7 +314,7 @@ public function mergeProductOptions($productOptions, $overwriteOptions)
310314
if (!is_array($overwriteOptions)) {
311315
return $productOptions;
312316
}
313-
317+
314318
foreach ($productOptions as $index => $option) {
315319
$optionId = $option['option_id'];
316320

app/code/Magento/Catalog/Model/Product/Attribute/Backend/Boolean.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Catalog\Model\Product\Attribute\Backend;
77

8+
use Magento\Catalog\Model\Product\Attribute\Source\Boolean as BooleanSource;
9+
810
/**
911
* Product attribute for enable/disable option
1012
*
@@ -22,7 +24,7 @@ public function beforeSave($object)
2224
{
2325
$attributeCode = $this->getAttribute()->getName();
2426
if ($object->getData('use_config_' . $attributeCode)) {
25-
$object->setData($attributeCode, '');
27+
$object->setData($attributeCode, BooleanSource::VALUE_USE_CONFIG);
2628
}
2729
return $this;
2830
}

app/code/Magento/Catalog/Model/Product/Attribute/Source/Boolean.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313

1414
class Boolean extends \Magento\Eav\Model\Entity\Attribute\Source\Boolean
1515
{
16+
/**
17+
* Value of 'Use Config' option
18+
*/
19+
const VALUE_USE_CONFIG = 2;
20+
1621
/**
1722
* Retrieve all attribute options
1823
*
@@ -22,9 +27,9 @@ public function getAllOptions()
2227
{
2328
if (!$this->_options) {
2429
$this->_options = [
25-
['label' => __('Yes'), 'value' => 1],
26-
['label' => __('No'), 'value' => 0],
27-
['label' => __('Use config'), 'value' => 2],
30+
['label' => __('Yes'), 'value' => static::VALUE_YES],
31+
['label' => __('No'), 'value' => static::VALUE_NO],
32+
['label' => __('Use config'), 'value' => static::VALUE_USE_CONFIG],
2833
];
2934
}
3035
return $this->_options;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Test\Unit\Model\Product\Attribute\Backend;
7+
8+
use Magento\Catalog\Model\Product\Attribute\Backend\Boolean as BooleanBackend;
9+
use Magento\Catalog\Model\Product\Attribute\Source\Boolean as BooleanSource;
10+
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
11+
use Magento\Framework\DataObject;
12+
13+
class BooleanTest extends \PHPUnit_Framework_TestCase
14+
{
15+
/**
16+
* @var \PHPUnit_Framework_MockObject_MockObject|AbstractAttribute
17+
*/
18+
private $attributeMock;
19+
20+
/**
21+
* @var BooleanBackend
22+
*/
23+
private $model;
24+
25+
protected function setUp()
26+
{
27+
$this->attributeMock = $this->getMockForAbstractClass(
28+
AbstractAttribute::class,
29+
[],
30+
'',
31+
false,
32+
true,
33+
true,
34+
['getName']
35+
);
36+
$this->model = new BooleanBackend();
37+
$this->model->setAttribute($this->attributeMock);
38+
}
39+
40+
public function testBeforeSave()
41+
{
42+
$this->attributeMock->expects($this->any())->method('getName')->willReturn('attribute_name');
43+
$object = new DataObject([
44+
'use_config_attribute_name' => true,
45+
]);
46+
$this->model->beforeSave($object);
47+
$this->assertEquals(BooleanSource::VALUE_USE_CONFIG, $object->getData('attribute_name'));
48+
}
49+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Test\Unit\Model\Product\Attribute\Source;
7+
8+
use Magento\Catalog\Model\Product\Attribute\Source\Boolean as BooleanSource;
9+
10+
class BooleanTest extends \PHPUnit_Framework_TestCase
11+
{
12+
/**
13+
* @var \PHPUnit_Framework_MockObject_MockObject
14+
*/
15+
private $attributeFactoryMock;
16+
17+
/**
18+
* @var BooleanSource
19+
*/
20+
private $model;
21+
22+
protected function setUp()
23+
{
24+
$this->attributeFactoryMock = $this->getMock(
25+
'Magento\Eav\Model\ResourceModel\Entity\AttributeFactory',
26+
[],
27+
[],
28+
'',
29+
false
30+
);
31+
$this->model = new BooleanSource($this->attributeFactoryMock);
32+
}
33+
34+
public function testGetAllOptions()
35+
{
36+
$expectedResult = [
37+
['label' => __('Yes'), 'value' => BooleanSource::VALUE_YES],
38+
['label' => __('No'), 'value' => BooleanSource::VALUE_NO],
39+
['label' => __('Use config'), 'value' => BooleanSource::VALUE_USE_CONFIG],
40+
];
41+
$this->assertEquals($expectedResult, $this->model->getAllOptions());
42+
}
43+
}

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/AbstractModifierTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ protected function setUp()
5555
->getMockForAbstractClass();
5656
$this->productMock = $this->getMockBuilder(ProductInterface::class)
5757
->setMethods([
58+
'getId',
5859
'getStoreId',
5960
'getResource',
6061
'getData',

app/code/Magento/Checkout/Block/Cart/Sidebar.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@
1313
class Sidebar extends AbstractCart
1414
{
1515
/**
16-
* Xml pah to checkout sidebar count value
16+
* Xml pah to checkout sidebar display value
1717
*/
1818
const XML_PATH_CHECKOUT_SIDEBAR_DISPLAY = 'checkout/sidebar/display';
1919

20+
/**
21+
* Xml pah to checkout sidebar count value
22+
*/
23+
const XML_PATH_CHECKOUT_SIDEBAR_COUNT = 'checkout/sidebar/count';
24+
2025
/**
2126
* @var \Magento\Catalog\Helper\Image
2227
*/
@@ -63,7 +68,8 @@ public function getConfig()
6368
'updateItemQtyUrl' => $this->getUpdateItemQtyUrl(),
6469
'removeItemUrl' => $this->getRemoveItemUrl(),
6570
'imageTemplate' => $this->getImageHtmlTemplate(),
66-
'baseUrl' => $this->getBaseUrl()
71+
'baseUrl' => $this->getBaseUrl(),
72+
'minicartMaxItemsVisible' => $this->getMiniCartMaxItemsCount()
6773
];
6874
}
6975

@@ -171,4 +177,14 @@ public function getBaseUrl()
171177
{
172178
return $this->_storeManager->getStore()->getBaseUrl();
173179
}
180+
181+
/**
182+
* Return max visible item count for minicart
183+
*
184+
* @return int
185+
*/
186+
private function getMiniCartMaxItemsCount()
187+
{
188+
return (int)$this->_scopeConfig->getValue('checkout/sidebar/count', ScopeInterface::SCOPE_STORE);
189+
}
174190
}

app/code/Magento/Checkout/Block/Cart/ValidationMessages.php

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Checkout\Block\Cart;
77

8+
use Magento\Framework\App\ObjectManager;
89
use Magento\Framework\View\Element\Message\InterpretationStrategyInterface;
910

1011
/**
@@ -18,6 +19,11 @@ class ValidationMessages extends \Magento\Framework\View\Element\Messages
1819
/** @var \Magento\Framework\Locale\CurrencyInterface */
1920
protected $currency;
2021

22+
/**
23+
* @var \Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage
24+
*/
25+
private $minimumAmountErrorMessage;
26+
2127
/**
2228
* @param \Magento\Framework\View\Element\Template\Context $context
2329
* @param \Magento\Framework\Message\Factory $messageFactory
@@ -72,22 +78,23 @@ protected function _prepareLayout()
7278
protected function validateMinimumAmount()
7379
{
7480
if (!$this->cartHelper->getQuote()->validateMinimumAmount()) {
75-
$warning = $this->_scopeConfig->getValue(
76-
'sales/minimum_order/description',
77-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
81+
$this->messageManager->addNotice($this->getMinimumAmountErrorMessage()->getMessage());
82+
}
83+
}
84+
85+
/**
86+
* @return \Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage
87+
* @deprecated
88+
*/
89+
private function getMinimumAmountErrorMessage()
90+
{
91+
if ($this->minimumAmountErrorMessage === null) {
92+
$objectManager = ObjectManager::getInstance();
93+
$this->minimumAmountErrorMessage = $objectManager->get(
94+
\Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage::class
7895
);
79-
if (!$warning) {
80-
$currencyCode = $this->_storeManager->getStore()->getCurrentCurrencyCode();
81-
$minimumAmount = $this->currency->getCurrency($currencyCode)->toCurrency(
82-
$this->_scopeConfig->getValue(
83-
'sales/minimum_order/amount',
84-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
85-
)
86-
);
87-
$warning = __('Minimum order amount is %1', $minimumAmount);
88-
}
89-
$this->messageManager->addNotice($warning);
9096
}
97+
return $this->minimumAmountErrorMessage;
9198
}
9299

93100
/**

app/code/Magento/Checkout/Test/Unit/Block/Cart/SidebarTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ public function testGetConfig()
138138
'updateItemQtyUrl' => $updateItemQtyUrl,
139139
'removeItemUrl' => $removeItemUrl,
140140
'imageTemplate' => $imageTemplate,
141-
'baseUrl' => $baseUrl
141+
'baseUrl' => $baseUrl,
142+
'minicartMaxItemsVisible' => 3
142143
];
143144

144145
$valueMap = [
@@ -159,6 +160,13 @@ public function testGetConfig()
159160
$storeMock->expects($this->once())->method('getBaseUrl')->willReturn($baseUrl);
160161
$this->imageHelper->expects($this->once())->method('getFrame')->willReturn(false);
161162

163+
$this->scopeConfigMock->expects($this->once())
164+
->method('getValue')
165+
->with(
166+
\Magento\Checkout\Block\Cart\Sidebar::XML_PATH_CHECKOUT_SIDEBAR_COUNT,
167+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
168+
)->willReturn(3);
169+
162170
$this->assertEquals($expectedResult, $this->model->getConfig());
163171
}
164172

app/code/Magento/Checkout/view/frontend/web/js/sidebar.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ define([
1919
$.widget('mage.sidebar', {
2020
options: {
2121
isRecursive: true,
22-
maxItemsVisible: 3
22+
minicart: {
23+
maxItemsVisible: 3
24+
}
2325
},
2426
scrollHeight: 0,
2527

@@ -240,7 +242,7 @@ define([
240242
_calcHeight: function () {
241243
var self = this,
242244
height = 0,
243-
counter = this.options.maxItemsVisible,
245+
counter = this.options.minicart.maxItemsVisible,
244246
target = $(this.options.minicart.list),
245247
outerHeight;
246248

0 commit comments

Comments
 (0)