Skip to content

Commit 6ff2486

Browse files
committed
Merge remote-tracking branch 'mainline/2.2-develop' into MAGETWO-64085
2 parents 4dbeed5 + 59a6784 commit 6ff2486

File tree

15 files changed

+506
-60
lines changed

15 files changed

+506
-60
lines changed

app/code/Magento/Bundle/Block/Catalog/Product/View/Type/Bundle/Option.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function getDefaultValues()
142142
*/
143143
protected function _getSelectedOptions()
144144
{
145-
if (is_null($this->_selectedOptions)) {
145+
if ($this->_selectedOptions === null) {
146146
$this->_selectedOptions = [];
147147

148148
/** @var \Magento\Bundle\Model\Option $option */
@@ -152,17 +152,29 @@ protected function _getSelectedOptions()
152152
$selectionId = $this->getProduct()->getPreconfiguredValues()->getData(
153153
'bundle_option/' . $option->getId()
154154
);
155-
if ($selectionId && $option->getSelectionById($selectionId)) {
156-
$this->_selectedOptions = $selectionId;
157-
} elseif (!$option->getRequired()) {
158-
$this->_selectedOptions = 'None';
159-
}
155+
$this->assignSelection($option, $selectionId);
160156
}
161157
}
162158

163159
return $this->_selectedOptions;
164160
}
165161

162+
/**
163+
* Set selected options.
164+
*
165+
* @param \Magento\Bundle\Model\Option $option
166+
* @param mixed $selectionId
167+
* @return void
168+
*/
169+
protected function assignSelection(\Magento\Bundle\Model\Option $option, $selectionId)
170+
{
171+
if ($selectionId && $option->getSelectionById($selectionId)) {
172+
$this->_selectedOptions = $selectionId;
173+
} elseif (!$option->getRequired()) {
174+
$this->_selectedOptions = 'None';
175+
}
176+
}
177+
166178
/**
167179
* Define if selection is selected
168180
*

app/code/Magento/Bundle/Block/Catalog/Product/View/Type/Bundle/Option/Multi.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,20 @@ class Multi extends \Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Optio
1717
* @var string
1818
*/
1919
protected $_template = 'catalog/product/view/type/bundle/option/multi.phtml';
20+
21+
/**
22+
* @inheritdoc
23+
*/
24+
protected function assignSelection(\Magento\Bundle\Model\Option $option, $selectionId)
25+
{
26+
if (is_array($selectionId)) {
27+
foreach ($selectionId as $id) {
28+
if ($id && $option->getSelectionById($id)) {
29+
$this->_selectedOptions[] = $id;
30+
}
31+
}
32+
} else {
33+
parent::assignSelection($option, $selectionId);
34+
}
35+
}
2036
}

app/code/Magento/Bundle/view/frontend/templates/catalog/product/view/type/bundle/options.phtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
<?php
1212
$product = $block->getProduct();
1313
$helper = $this->helper('Magento\Catalog\Helper\Output');
14+
$stripSelection = $product->getConfigureMode() ? true : false;
15+
$options = $block->decorateArray($block->getOptions($stripSelection));
1416
?>
15-
<?php $options = $block->decorateArray($block->getOptions()); ?>
1617
<?php if ($product->isSaleable()):?>
1718
<?php if (count($options)): ?>
1819
<script type="text/x-magento-init">

app/code/Magento/Directory/Setup/InstallData.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -809,27 +809,6 @@ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface
809809
['BR', 'SE', 'Sergipe'],
810810
['BR', 'TO', 'Tocantins'],
811811
['BR', 'DF', 'Distrito Federal'],
812-
['HR', 'HR-01', 'Zagrebačka županija'],
813-
['HR', 'HR-02', 'Krapinsko-zagorska županija'],
814-
['HR', 'HR-03', 'Sisačko-moslavačka županija'],
815-
['HR', 'HR-04', 'Karlovačka županija'],
816-
['HR', 'HR-05', 'Varaždinska županija'],
817-
['HR', 'HR-06', 'Koprivničko-križevačka županija'],
818-
['HR', 'HR-07', 'Bjelovarsko-bilogorska županija'],
819-
['HR', 'HR-08', 'Primorsko-goranska županija'],
820-
['HR', 'HR-09', 'Ličko-senjska županija'],
821-
['HR', 'HR-10', 'Virovitičko-podravska županija'],
822-
['HR', 'HR-11', 'Požeško-slavonska županija'],
823-
['HR', 'HR-12', 'Brodsko-posavska županija'],
824-
['HR', 'HR-13', 'Zadarska županija'],
825-
['HR', 'HR-14', 'Osječko-baranjska županija'],
826-
['HR', 'HR-15', 'Šibensko-kninska županija'],
827-
['HR', 'HR-16', 'Vukovarsko-srijemska županija'],
828-
['HR', 'HR-17', 'Splitsko-dalmatinska županija'],
829-
['HR', 'HR-18', 'Istarska županija'],
830-
['HR', 'HR-19', 'Dubrovačko-neretvanska županija'],
831-
['HR', 'HR-20', 'Međimurska županija'],
832-
['HR', 'HR-21', 'Grad Zagreb']
833812
];
834813

835814
foreach ($data as $row) {
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Directory\Setup;
8+
9+
use Magento\Framework\Setup\ModuleContextInterface;
10+
use Magento\Framework\Setup\ModuleDataSetupInterface;
11+
use Magento\Framework\Setup\UpgradeDataInterface;
12+
use Magento\Directory\Helper\Data;
13+
14+
/**
15+
* Upgrade Data script for Directory module.
16+
*/
17+
class UpgradeData implements UpgradeDataInterface
18+
{
19+
/**
20+
* Directory data.
21+
*
22+
* @var Data
23+
*/
24+
private $directoryData;
25+
26+
/**
27+
* @param Data $directoryData
28+
*/
29+
public function __construct(Data $directoryData)
30+
{
31+
$this->directoryData = $directoryData;
32+
}
33+
34+
/**
35+
* Upgrades data for Directry module.
36+
*
37+
* @param ModuleDataSetupInterface $setup
38+
* @param ModuleContextInterface $context
39+
* @return void
40+
*/
41+
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
42+
{
43+
if (version_compare($context->getVersion(), '2.0.1', '<')) {
44+
$this->addCroatia($setup);
45+
}
46+
}
47+
48+
/**
49+
* Add Croatia and it's states to appropriate tables.
50+
*
51+
* @param ModuleDataSetupInterface $setup
52+
* @return void
53+
*/
54+
private function addCroatia($setup)
55+
{
56+
/**
57+
* Fill table directory/country_region
58+
* Fill table directory/country_region_name for en_US locale
59+
*/
60+
$data = [
61+
['HR', 'HR-01', 'Zagrebačka županija'],
62+
['HR', 'HR-02', 'Krapinsko-zagorska županija'],
63+
['HR', 'HR-03', 'Sisačko-moslavačka županija'],
64+
['HR', 'HR-04', 'Karlovačka županija'],
65+
['HR', 'HR-05', 'Varaždinska županija'],
66+
['HR', 'HR-06', 'Koprivničko-križevačka županija'],
67+
['HR', 'HR-07', 'Bjelovarsko-bilogorska županija'],
68+
['HR', 'HR-08', 'Primorsko-goranska županija'],
69+
['HR', 'HR-09', 'Ličko-senjska županija'],
70+
['HR', 'HR-10', 'Virovitičko-podravska županija'],
71+
['HR', 'HR-11', 'Požeško-slavonska županija'],
72+
['HR', 'HR-12', 'Brodsko-posavska županija'],
73+
['HR', 'HR-13', 'Zadarska županija'],
74+
['HR', 'HR-14', 'Osječko-baranjska županija'],
75+
['HR', 'HR-15', 'Šibensko-kninska županija'],
76+
['HR', 'HR-16', 'Vukovarsko-srijemska županija'],
77+
['HR', 'HR-17', 'Splitsko-dalmatinska županija'],
78+
['HR', 'HR-18', 'Istarska županija'],
79+
['HR', 'HR-19', 'Dubrovačko-neretvanska županija'],
80+
['HR', 'HR-20', 'Međimurska županija'],
81+
['HR', 'HR-21', 'Grad Zagreb']
82+
];
83+
foreach ($data as $row) {
84+
$bind = ['country_id' => $row[0], 'code' => $row[1], 'default_name' => $row[2]];
85+
$setup->getConnection()->insert($setup->getTable('directory_country_region'), $bind);
86+
$regionId = $setup->getConnection()->lastInsertId($setup->getTable('directory_country_region'));
87+
$bind = ['locale' => 'en_US', 'region_id' => $regionId, 'name' => $row[2]];
88+
$setup->getConnection()->insert($setup->getTable('directory_country_region_name'), $bind);
89+
}
90+
/**
91+
* Upgrade core_config_data general/region/state_required field.
92+
*/
93+
$countries = $this->directoryData->getCountryCollection()->getCountriesWithRequiredStates();
94+
$setup->getConnection()->update(
95+
$setup->getTable('core_config_data'),
96+
[
97+
'value' => implode(',', array_keys($countries))
98+
],
99+
[
100+
'scope="default"',
101+
'scope_id=0',
102+
'path=?' => Data::XML_PATH_STATES_REQUIRED
103+
]
104+
);
105+
}
106+
}

app/code/Magento/Directory/etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9-
<module name="Magento_Directory" setup_version="2.0.0">
9+
<module name="Magento_Directory" setup_version="2.0.1">
1010
<sequence>
1111
<module name="Magento_Store"/>
1212
</sequence>

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

Lines changed: 93 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,77 +3,117 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
namespace Magento\SalesRule\Setup;
76

8-
use Magento\Framework\DB\AggregatedFieldDataConverter;
9-
use Magento\Framework\DB\DataConverter\SerializedToJson;
10-
use Magento\Framework\DB\FieldToConvert;
11-
use Magento\Framework\Setup\ModuleContextInterface;
12-
use Magento\Framework\Setup\ModuleDataSetupInterface;
13-
use Magento\Framework\Setup\UpgradeDataInterface;
14-
use Magento\Framework\EntityManager\MetadataPool;
15-
use Magento\SalesRule\Api\Data\RuleInterface;
7+
namespace Magento\SalesRule\Setup;
168

17-
class UpgradeData implements UpgradeDataInterface
9+
/**
10+
* Class \Magento\SalesRule\Setup\UpgradeData
11+
*/
12+
class UpgradeData implements \Magento\Framework\Setup\UpgradeDataInterface
1813
{
1914
/**
20-
* @var MetadataPool
15+
* @var \Magento\Framework\EntityManager\MetadataPool
2116
*/
2217
private $metadataPool;
2318

2419
/**
25-
* @var AggregatedFieldDataConverter
20+
* @var \Magento\Framework\DB\AggregatedFieldDataConverter
2621
*/
2722
private $aggregatedFieldConverter;
2823

2924
/**
30-
* UpgradeData constructor.
25+
* Resource Model of sales rule.
3126
*
32-
* @param AggregatedFieldDataConverter $aggregatedFieldConverter
33-
* @param MetadataPool $metadataPool
27+
* @var \Magento\SalesRule\Model\ResourceModel\Rule;
28+
*/
29+
private $resourceModelRule;
30+
31+
/**
32+
* App state.
33+
*
34+
* @var \Magento\Framework\App\State
35+
*/
36+
private $state;
37+
38+
/**
39+
* Serializer.
40+
*
41+
* @var \Magento\Framework\Serialize\SerializerInterface
42+
*/
43+
private $serializer;
44+
45+
/**
46+
* Rule Collection Factory.
47+
*
48+
* @var \Magento\SalesRule\Model\ResourceModel\Rule\CollectionFactory
49+
*/
50+
private $ruleColletionFactory;
51+
52+
/**
53+
* @param \Magento\Framework\DB\AggregatedFieldDataConverter $aggregatedFieldConverter
54+
* @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
55+
* @param \Magento\SalesRule\Model\ResourceModel\Rule $resourceModelRule
56+
* @param \Magento\Framework\Serialize\SerializerInterface $serializer
57+
* @param \Magento\Framework\App\State $state
58+
* @param \Magento\SalesRule\Model\ResourceModel\Rule\CollectionFactory $ruleColletionFactory
3459
*/
3560
public function __construct(
36-
AggregatedFieldDataConverter $aggregatedFieldConverter,
37-
MetadataPool $metadataPool
61+
\Magento\Framework\DB\AggregatedFieldDataConverter $aggregatedFieldConverter,
62+
\Magento\Framework\EntityManager\MetadataPool $metadataPool,
63+
\Magento\SalesRule\Model\ResourceModel\Rule $resourceModelRule,
64+
\Magento\Framework\Serialize\SerializerInterface $serializer,
65+
\Magento\Framework\App\State $state,
66+
\Magento\SalesRule\Model\ResourceModel\Rule\CollectionFactory $ruleColletionFactory
3867
) {
3968
$this->aggregatedFieldConverter = $aggregatedFieldConverter;
4069
$this->metadataPool = $metadataPool;
70+
$this->resourceModelRule = $resourceModelRule;
71+
$this->serializer = $serializer;
72+
$this->state = $state;
73+
$this->ruleColletionFactory = $ruleColletionFactory;
4174
}
4275

4376
/**
4477
* @inheritdoc
4578
*/
46-
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
47-
{
79+
public function upgrade(
80+
\Magento\Framework\Setup\ModuleDataSetupInterface $setup,
81+
\Magento\Framework\Setup\ModuleContextInterface $context
82+
) {
4883
$setup->startSetup();
49-
5084
if (version_compare($context->getVersion(), '2.0.2', '<')) {
5185
$this->convertSerializedDataToJson($setup);
5286
}
53-
87+
if (version_compare($context->getVersion(), '2.0.3', '<')) {
88+
$this->state->emulateAreaCode(
89+
\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE,
90+
[$this, 'fillSalesRuleProductAttributeTable'],
91+
[$setup]
92+
);
93+
$this->fillSalesRuleProductAttributeTable();
94+
}
5495
$setup->endSetup();
5596
}
5697

5798
/**
5899
* Convert metadata from serialized to JSON format:
59100
*
60-
* @param ModuleDataSetupInterface $setup
61-
*
101+
* @param \Magento\Framework\Setup\ModuleDataSetupInterface $setup *
62102
* @return void
63103
*/
64104
public function convertSerializedDataToJson($setup)
65105
{
66-
$metadata = $this->metadataPool->getMetadata(RuleInterface::class);
106+
$metadata = $this->metadataPool->getMetadata(\Magento\SalesRule\Api\Data\RuleInterface::class);
67107
$this->aggregatedFieldConverter->convert(
68108
[
69-
new FieldToConvert(
70-
SerializedToJson::class,
109+
new \Magento\Framework\DB\FieldToConvert(
110+
\Magento\Framework\DB\DataConverter\SerializedToJson::class,
71111
$setup->getTable('salesrule'),
72112
$metadata->getLinkField(),
73113
'conditions_serialized'
74114
),
75-
new FieldToConvert(
76-
SerializedToJson::class,
115+
new \Magento\Framework\DB\FieldToConvert(
116+
\Magento\Framework\DB\DataConverter\SerializedToJson::class,
77117
$setup->getTable('salesrule'),
78118
$metadata->getLinkField(),
79119
'actions_serialized'
@@ -82,4 +122,29 @@ public function convertSerializedDataToJson($setup)
82122
$setup->getConnection()
83123
);
84124
}
125+
126+
/**
127+
* Fills blank table salesrule_product_attribute with data.
128+
*
129+
* @return void
130+
*/
131+
public function fillSalesRuleProductAttributeTable()
132+
{
133+
/** @var \Magento\SalesRule\Model\ResourceModel\Rule\Collection $ruleCollection */
134+
$ruleCollection = $this->ruleColletionFactory->create();
135+
/** @var \Magento\SalesRule\Model\Rule $rule */
136+
foreach ($ruleCollection as $rule) {
137+
// Save product attributes used in rule
138+
$conditions = $rule->getConditions()->asArray();
139+
$actions = $rule->getActions()->asArray();
140+
$serializedConditions = $this->serializer->serialize($conditions);
141+
$serializedActions = $this->serializer->serialize($actions);
142+
$conditionAttributes = $this->resourceModelRule->getProductAttributes($serializedConditions);
143+
$actionAttributes = $this->resourceModelRule->getProductAttributes($serializedActions);
144+
$ruleProductAttributes = array_merge($conditionAttributes, $actionAttributes);
145+
if ($ruleProductAttributes) {
146+
$this->resourceModelRule->setActualProductAttributes($rule, $ruleProductAttributes);
147+
}
148+
}
149+
}
85150
}

0 commit comments

Comments
 (0)