Skip to content

Commit 46b5683

Browse files
committed
Merge branch 'MAGETWO-62721' into 2.1-prs2
2 parents 3f9b1c5 + 5f2825e commit 46b5683

File tree

13 files changed

+658
-98
lines changed

13 files changed

+658
-98
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Deploy\Console;
7+
8+
use Magento\Framework\ObjectManagerInterface;
9+
10+
/**
11+
* This class groups and instantiates a list of deploy commands in order to be used separately before install
12+
*/
13+
class CommandList implements \Magento\Framework\Console\CommandListInterface
14+
{
15+
/**
16+
* Object Manager
17+
*
18+
* @var ObjectManagerInterface
19+
*/
20+
private $objectManager;
21+
22+
/**
23+
* @param ObjectManagerInterface $objectManager
24+
*/
25+
public function __construct(ObjectManagerInterface $objectManager)
26+
{
27+
$this->objectManager = $objectManager;
28+
}
29+
30+
/**
31+
* Gets list of command classes
32+
*
33+
* @return string[]
34+
*/
35+
protected function getCommandsClasses()
36+
{
37+
return [
38+
\Magento\Deploy\Console\Command\DeployStaticContentCommand::class
39+
];
40+
}
41+
42+
/**
43+
* {@inheritdoc}
44+
*/
45+
public function getCommands()
46+
{
47+
$commands = [];
48+
foreach ($this->getCommandsClasses() as $class) {
49+
if (class_exists($class)) {
50+
$commands[] = $this->objectManager->get($class);
51+
} else {
52+
throw new \Exception('Class ' . $class . ' does not exist');
53+
}
54+
}
55+
return $commands;
56+
}
57+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
if (PHP_SAPI == 'cli') {
8+
\Magento\Framework\Console\CommandLocator::register('Magento\Deploy\Console\CommandList');
9+
}

app/code/Magento/Deploy/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
],
1717
"autoload": {
1818
"files": [
19+
"cli_commands.php",
1920
"registration.php"
2021
],
2122
"psr-4": {

app/code/Magento/GiftMessage/Helper/Message.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
namespace Magento\GiftMessage\Helper;
1010

11+
use Magento\Catalog\Model\Product\Attribute\Source\Boolean;
12+
1113
/**
1214
* Gift Message helper
1315
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -193,20 +195,20 @@ public function isMessagesAllowed($type, \Magento\Framework\DataObject $entity,
193195
/**
194196
* Check availablity of gift messages from store config if flag eq 2.
195197
*
196-
* @param bool $productGiftMessageAllow
198+
* @param bool $productConfig
197199
* @param \Magento\Store\Model\Store|int|null $store
198200
* @return bool|string|null
199201
*/
200-
protected function _getDependenceFromStoreConfig($productGiftMessageAllow, $store = null)
202+
protected function _getDependenceFromStoreConfig($productConfig, $store = null)
201203
{
202204
$result = $this->scopeConfig->getValue(
203205
self::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ITEMS,
204206
\Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store
205207
);
206-
if ($productGiftMessageAllow === '' || is_null($productGiftMessageAllow)) {
208+
if ($productConfig === null || '' === $productConfig || $productConfig == Boolean::VALUE_USE_CONFIG) {
207209
return $result;
208210
} else {
209-
return $productGiftMessageAllow;
211+
return $productConfig;
210212
}
211213
}
212214

app/code/Magento/GiftMessage/Model/GiftMessageConfigProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\UrlInterface;
1313
use Magento\Framework\Locale\FormatInterface as LocaleFormat;
1414
use Magento\Framework\Data\Form\FormKey;
15+
use Magento\Catalog\Model\Product\Attribute\Source\Boolean;
1516

1617
/**
1718
* Configuration provider for GiftMessage rendering on "Checkout cart" page.
@@ -179,7 +180,7 @@ protected function getItemLevelGiftMessages()
179180
$itemLevelConfig[$itemId] = [];
180181
$isMessageAvailable = $item->getProduct()->getGiftMessageAvailable();
181182
// use gift message product setting if it is available
182-
if ($isMessageAvailable !== null) {
183+
if ($isMessageAvailable !== null && $isMessageAvailable != Boolean::VALUE_USE_CONFIG) {
183184
$itemLevelConfig[$itemId]['is_available'] = (bool)$isMessageAvailable;
184185
}
185186
$message = $this->itemRepository->get($quote->getId(), $itemId);

app/code/Magento/GiftMessage/Test/Unit/Model/GiftMessageConfigProviderTest.php

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
use Magento\Store\Model\ScopeInterface as Scope;
1010
use Magento\Customer\Model\Context as CustomerContext;
1111
use Magento\Framework\UrlInterface;
12+
use Magento\Catalog\Model\Product\Attribute\Source\Boolean;
1213

14+
/**
15+
* GiftMessage config provider test
16+
*/
1317
class GiftMessageConfigProviderTest extends \PHPUnit_Framework_TestCase
1418
{
1519
/**
@@ -59,22 +63,22 @@ class GiftMessageConfigProviderTest extends \PHPUnit_Framework_TestCase
5963

6064
protected function setUp()
6165
{
62-
$this->checkoutSessionMock = $this->getMock('Magento\Checkout\Model\Session', [], [], '', false);
63-
$this->httpContextMock = $this->getMock('Magento\Framework\App\Http\Context', [], [], '', false);
64-
$this->storeManagerMock = $this->getMock('Magento\Store\Model\StoreManagerInterface', [], [], '', false);
65-
$this->localeFormatMock = $this->getMock('Magento\Framework\Locale\FormatInterface', [], [], '', false);
66-
$this->formKeyMock = $this->getMock('Magento\Framework\Data\Form\FormKey', [], [], '', false);
67-
$this->scopeConfigMock = $this->getMock('Magento\Framework\App\Config\ScopeConfigInterface', [], [], '', false);
68-
$contextMock = $this->getMock('Magento\Framework\App\Helper\Context', [], [], '', false);
66+
$this->checkoutSessionMock = $this->getMock(\Magento\Checkout\Model\Session::class, [], [], '', false);
67+
$this->httpContextMock = $this->getMock(\Magento\Framework\App\Http\Context::class, [], [], '', false);
68+
$this->storeManagerMock = $this->getMock(\Magento\Store\Model\StoreManagerInterface::class, [], [], '', false);
69+
$this->localeFormatMock = $this->getMock(\Magento\Framework\Locale\FormatInterface::class, [], [], '', false);
70+
$this->formKeyMock = $this->getMock(\Magento\Framework\Data\Form\FormKey::class, [], [], '', false);
71+
$this->scopeConfigMock = $this->getMock(\Magento\Framework\App\Config\ScopeConfigInterface::class, [], [], '', false);
72+
$contextMock = $this->getMock(\Magento\Framework\App\Helper\Context::class, [], [], '', false);
6973
$this->cartRepositoryMock = $this->getMock(
70-
'Magento\GiftMessage\Api\CartRepositoryInterface',
74+
\Magento\GiftMessage\Api\CartRepositoryInterface::class,
7175
[],
7276
[],
7377
'',
7478
false
7579
);
7680
$this->itemRepositoryMock = $this->getMock(
77-
'Magento\GiftMessage\Api\ItemRepositoryInterface',
81+
\Magento\GiftMessage\Api\ItemRepositoryInterface::class,
7882
[],
7983
[],
8084
'',
@@ -108,31 +112,26 @@ public function testGetConfig()
108112
$formKey = 'ABCDEFGHIJKLMNOP';
109113
$isFrontUrlSecure = true;
110114
$baseUrl = 'https://magento.com/';
111-
$quoteItemMock = $this->getMock('Magento\Quote\Model\Quote\Item', [], [], '', false);
112-
$productMock = $this->getMock('Magento\Catalog\Model\Product', [], [], '', false);
115+
$quoteItemMock = $this->getMock(\Magento\Quote\Model\Quote\Item::class, [], [], '', false);
116+
$productMock = $this->getMock(\Magento\Catalog\Model\Product::class, [], [], '', false);
113117
$storeMock = $this->getMock(
114-
'Magento\Store\Model\Store',
118+
\Magento\Store\Model\Store::class,
115119
['isFrontUrlSecure', 'getBaseUrl', 'getCode'],
116120
[],
117121
'',
118122
false
119123
);
120124
$quoteMock = $this->getMock(
121-
'Magento\Quote\Model\Quote',
125+
\Magento\Quote\Model\Quote::class,
122126
['getQuoteCurrencyCode', 'getStore', 'getIsVirtual', 'getAllVisibleItems', 'getId'],
123127
[],
124128
'',
125129
false
126130
);
127-
$messageMock = $this->getMockForAbstractClass(
128-
'Magento\GiftMessage\Api\Data\MessageInterface',
129-
[],
130-
'',
131-
false,
132-
false,
133-
false,
134-
['getData']
135-
);
131+
$messageMock = $this->getMockBuilder(\Magento\GiftMessage\Api\Data\MessageInterface::class)
132+
->disableOriginalConstructor()
133+
->setMethods(['getData'])
134+
->getMockForAbstractClass();
136135

137136
$this->scopeConfigMock->expects($this->atLeastOnce())->method('getValue')->willReturnMap(
138137
[
@@ -151,7 +150,7 @@ public function testGetConfig()
151150
$quoteMock->expects($this->once())->method('getAllVisibleItems')->willReturn([$quoteItemMock]);
152151
$quoteItemMock->expects($this->once())->method('getId')->willReturn($itemId);
153152
$quoteItemMock->expects($this->any())->method('getProduct')->willReturn($productMock);
154-
$productMock->expects($this->any())->method('getGiftMessageAvailable')->willReturn(false);
153+
$productMock->expects($this->any())->method('getGiftMessageAvailable')->willReturn(Boolean::VALUE_USE_CONFIG);
155154
$this->itemRepositoryMock->expects($this->once())->method('get')->with($quoteId, $itemId)
156155
->willReturn($messageMock);
157156
$quoteMock->expects($this->once())->method('getQuoteCurrencyCode')->willReturn($currencyCode);
@@ -174,7 +173,6 @@ public function testGetConfig()
174173
'orderLevel' => $messageDataMock,
175174
'itemLevel' => [
176175
$itemId => [
177-
'is_available' => false,
178176
'message' => $messageDataMock,
179177
],
180178
]

app/code/Magento/GiftMessage/Test/Unit/Ui/DataProvider/Product/Modifier/GiftMessageTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
use Magento\Catalog\Test\Unit\Ui\DataProvider\Product\Form\Modifier\AbstractModifierTest;
99
use Magento\Framework\App\Config\ScopeConfigInterface;
1010
use Magento\GiftMessage\Ui\DataProvider\Product\Modifier\GiftMessage;
11+
use Magento\GiftMessage\Helper\Message as GiftMessageHelper;
12+
use Magento\Store\Model\ScopeInterface;
13+
use Magento\Catalog\Model\Product\Attribute\Source\Boolean;
1114

1215
/**
1316
* Class GiftMessageTest
@@ -67,4 +70,49 @@ public function testModifyMeta()
6770
]
6871
));
6972
}
73+
74+
public function testModifyDataUsesConfigurationValuesWhenProductDoesNotContainValidValue()
75+
{
76+
$productId = 1;
77+
$this->productMock->expects($this->any())->method('getId')->willReturn($productId);
78+
79+
$configValue = 1;
80+
$this->scopeConfigMock->expects($this->any())
81+
->method('getValue')
82+
->with(GiftMessageHelper::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ITEMS, ScopeInterface::SCOPE_STORE)
83+
->willReturn($configValue);
84+
85+
$data = [$productId => [
86+
GiftMessage::DATA_SOURCE_DEFAULT => [
87+
GiftMessage::FIELD_MESSAGE_AVAILABLE => Boolean::VALUE_USE_CONFIG,
88+
],
89+
]];
90+
$expectedResult = [$productId => [
91+
GiftMessage::DATA_SOURCE_DEFAULT => [
92+
GiftMessage::FIELD_MESSAGE_AVAILABLE => $configValue,
93+
'use_config_gift_message_available' => 1
94+
],
95+
]];
96+
97+
$this->assertEquals($expectedResult, $this->getModel()->modifyData($data));
98+
}
99+
100+
public function testModifyDataUsesConfigurationValuesForNewProduct()
101+
{
102+
$productId = null;
103+
$configValue = 1;
104+
$this->scopeConfigMock->expects($this->any())
105+
->method('getValue')
106+
->with(GiftMessageHelper::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ITEMS, ScopeInterface::SCOPE_STORE)
107+
->willReturn($configValue);
108+
109+
$expectedResult = [$productId => [
110+
GiftMessage::DATA_SOURCE_DEFAULT => [
111+
GiftMessage::FIELD_MESSAGE_AVAILABLE => $configValue,
112+
'use_config_gift_message_available' => 1
113+
],
114+
]];
115+
116+
$this->assertEquals($expectedResult, $this->getModel()->modifyData([]));
117+
}
70118
}

app/code/Magento/GiftMessage/Ui/DataProvider/Product/Modifier/GiftMessage.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Store\Model\ScopeInterface;
1414
use Magento\Ui\Component\Form\Element\Checkbox;
1515
use Magento\Ui\Component\Form\Field;
16+
use Magento\Catalog\Model\Product\Attribute\Source\Boolean;
1617

1718
/**
1819
* Class GiftMessageDataProvider
@@ -57,13 +58,12 @@ public function __construct(
5758
public function modifyData(array $data)
5859
{
5960
$modelId = $this->locator->getProduct()->getId();
60-
$value = '';
61+
$useConfigValue = Boolean::VALUE_USE_CONFIG;
6162

62-
if (isset($data[$modelId][static::DATA_SOURCE_DEFAULT][static::FIELD_MESSAGE_AVAILABLE])) {
63-
$value = $data[$modelId][static::DATA_SOURCE_DEFAULT][static::FIELD_MESSAGE_AVAILABLE];
64-
}
63+
$isConfigUsed = isset($data[$modelId][static::DATA_SOURCE_DEFAULT][static::FIELD_MESSAGE_AVAILABLE])
64+
&& $data[$modelId][static::DATA_SOURCE_DEFAULT][static::FIELD_MESSAGE_AVAILABLE] == $useConfigValue;
6565

66-
if ('' === $value) {
66+
if ($isConfigUsed || empty($modelId)) {
6767
$data[$modelId][static::DATA_SOURCE_DEFAULT][static::FIELD_MESSAGE_AVAILABLE] =
6868
$this->getValueFromConfig();
6969
$data[$modelId][static::DATA_SOURCE_DEFAULT]['use_config_' . static::FIELD_MESSAGE_AVAILABLE] = '1';
@@ -129,14 +129,8 @@ protected function customizeAllowGiftMessageField(array $meta)
129129
'data' => [
130130
'config' => [
131131
'dataScope' => static::FIELD_MESSAGE_AVAILABLE,
132-
'imports' => [
133-
'disabled' =>
134-
'${$.parentName}.use_config_'
135-
. static::FIELD_MESSAGE_AVAILABLE
136-
. ':checked',
137-
],
138132
'additionalClasses' => 'admin__field-x-small',
139-
'formElement' => Checkbox::NAME,
133+
'component' => 'Magento_Ui/js/form/element/single-checkbox-use-config',
140134
'componentType' => Field::NAME,
141135
'prefer' => 'toggle',
142136
'valueMap' => [
@@ -160,6 +154,14 @@ protected function customizeAllowGiftMessageField(array $meta)
160154
'false' => '0',
161155
'true' => '1',
162156
],
157+
'exports' => [
158+
'checked' => '${$.parentName}.' . static::FIELD_MESSAGE_AVAILABLE
159+
. ':isUseConfig',
160+
],
161+
'imports' => [
162+
'disabled' => '${$.parentName}.' . static::FIELD_MESSAGE_AVAILABLE
163+
. ':isUseDefault',
164+
]
163165
],
164166
],
165167
],

0 commit comments

Comments
 (0)