Skip to content

Commit 81a5c5a

Browse files
committed
MAGETWO-54200: Wrong "gift_message_available" parameter exported
1 parent 1ea57c2 commit 81a5c5a

File tree

5 files changed

+38
-24
lines changed

5 files changed

+38
-24
lines changed

app/code/Magento/CatalogImportExport/Model/Export/Product.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
8484
* @var string[]
8585
*/
8686
protected $_indexValueAttributes = [
87-
'status',
88-
'gift_message_available',
87+
'status'
8988
];
9089

9190
/**

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
196196
protected $_indexValueAttributes = [
197197
'status',
198198
'tax_class_id',
199-
'gift_message_available',
200199
];
201200

202201
/**

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
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;
16+
use Magento\Store\Model\ScopeInterface;
1517

1618
/**
1719
* Configuration provider for GiftMessage rendering on "Checkout cart" page.
@@ -94,11 +96,11 @@ public function getConfig()
9496
$configuration['giftMessage'] = [];
9597
$orderLevelGiftMessageConfiguration = (bool)$this->scopeConfiguration->getValue(
9698
GiftMessageHelper::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ORDER,
97-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
99+
ScopeInterface::SCOPE_STORE
98100
);
99101
$itemLevelGiftMessageConfiguration = (bool)$this->scopeConfiguration->getValue(
100102
GiftMessageHelper::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ITEMS,
101-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
103+
ScopeInterface::SCOPE_STORE
102104
);
103105
if ($orderLevelGiftMessageConfiguration) {
104106
$orderMessages = $this->getOrderLevelGiftMessages();
@@ -178,9 +180,12 @@ protected function getItemLevelGiftMessages()
178180
$itemId = $item->getId();
179181
$itemLevelConfig[$itemId] = [];
180182
$isMessageAvailable = $item->getProduct()->getGiftMessageAvailable();
181-
// use gift message product setting if it is available
182-
if ($isMessageAvailable !== null) {
183-
$itemLevelConfig[$itemId]['is_available'] = (bool)$isMessageAvailable;
183+
184+
if ($isMessageAvailable == Boolean::VALUE_USE_CONFIG || in_array($isMessageAvailable, [null, ''], true)) {
185+
$itemLevelConfig[$itemId]['is_available'] = (bool)$this->scopeConfiguration->getValue(
186+
GiftMessageHelper::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ITEMS,
187+
ScopeInterface::SCOPE_STORE
188+
);
184189
}
185190
$message = $this->itemRepository->get($quote->getId(), $itemId);
186191
if ($message) {

app/code/Magento/GiftMessage/Setup/UpgradeData.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,20 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
3535
{
3636
$setup->startSetup();
3737

38+
/** @var \Magento\Catalog\Setup\CategorySetup $categorySetup */
39+
$categorySetup = $this->categorySetupFactory->create(['setup' => $setup]);
40+
$entityTypeId = $categorySetup->getEntityTypeId(Product::ENTITY);
41+
$attributeSetId = $categorySetup->getAttributeSetId($entityTypeId, 'Default');
42+
$attribute = $categorySetup->getAttribute($entityTypeId, 'gift_message_available');
43+
3844
if (version_compare($context->getVersion(), '2.0.1', '<')) {
39-
/** @var \Magento\Catalog\Setup\CategorySetup $categorySetup */
40-
$categorySetup = $this->categorySetupFactory->create(['setup' => $setup]);
45+
4146
$groupName = 'Gift Options';
4247

4348
if (!$categorySetup->getAttributeGroup(Product::ENTITY, 'Default', $groupName)) {
4449
$categorySetup->addAttributeGroup(Product::ENTITY, 'Default', $groupName, 60);
4550
}
4651

47-
$entityTypeId = $categorySetup->getEntityTypeId(Product::ENTITY);
48-
$attributeSetId = $categorySetup->getAttributeSetId($entityTypeId, 'Default');
49-
$attribute = $categorySetup->getAttribute($entityTypeId, 'gift_message_available');
50-
5152
$categorySetup->addAttributeToGroup(
5253
$entityTypeId,
5354
$attributeSetId,
@@ -57,6 +58,16 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
5758
);
5859
}
5960

61+
if (version_compare($context->getVersion(), '2.1.0', '<')) {
62+
63+
$categorySetup->updateAttribute(
64+
$entityTypeId,
65+
$attribute['attribute_id'],
66+
'source_model',
67+
'Magento\Catalog\Model\Product\Attribute\Source\Boolean'
68+
);
69+
}
70+
6071
$setup->endSetup();
6172
}
6273
}

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

Lines changed: 10 additions & 10 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
@@ -63,9 +64,8 @@ public function modifyData(array $data)
6364
$value = $data[$modelId][static::DATA_SOURCE_DEFAULT][static::FIELD_MESSAGE_AVAILABLE];
6465
}
6566

66-
if ('' === $value) {
67-
$data[$modelId][static::DATA_SOURCE_DEFAULT][static::FIELD_MESSAGE_AVAILABLE] =
68-
$this->getValueFromConfig();
67+
if ($value == Boolean::VALUE_USE_CONFIG || $value === '' || $value === null) {
68+
$data[$modelId][static::DATA_SOURCE_DEFAULT][static::FIELD_MESSAGE_AVAILABLE] = $this->getValueFromConfig();
6969
$data[$modelId][static::DATA_SOURCE_DEFAULT]['use_config_' . static::FIELD_MESSAGE_AVAILABLE] = '1';
7070
}
7171

@@ -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-
],
132+
'component' => 'Magento_Ui/js/form/element/single-checkbox-use-config',
138133
'additionalClasses' => 'admin__field-x-small',
139-
'formElement' => Checkbox::NAME,
140134
'componentType' => Field::NAME,
141135
'prefer' => 'toggle',
142136
'valueMap' => [
@@ -160,6 +154,12 @@ protected function customizeAllowGiftMessageField(array $meta)
160154
'false' => '0',
161155
'true' => '1',
162156
],
157+
'exports' => [
158+
'checked' => '${$.parentName}.' . static::FIELD_MESSAGE_AVAILABLE . ':isUseConfig',
159+
],
160+
'imports' => [
161+
'disabled' => '${$.parentName}.' . static::FIELD_MESSAGE_AVAILABLE . ':isUseDefault',
162+
],
163163
],
164164
],
165165
],

0 commit comments

Comments
 (0)