Skip to content

Commit 884d717

Browse files
author
Oleksii Korshenko
authored
Merge pull request #1643 from magento-engcom/2.2-develop-prs
Public Pull Requests #11843 Save the price 0 as price in custom options [backport 2.2] by @raumatbel #11854 FilterBuilder Doc Block Update by @ByteCreation #11802 #8236 FIX CMS blocks by @thiagolima-bm #11651 [BUGFIX] Solved error while upgrading from 2.1 to 2.2 by @lewisvoncken Fixed Public Issues #4808 The price of product custom option can't be set to 0. #11095 Magento_Tax "postcode is a required field" when upgrading from 2.1.9 to 2.2
2 parents ea5e982 + 9e28e9e commit 884d717

File tree

5 files changed

+69
-52
lines changed

5 files changed

+69
-52
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Product/Option/Value.php

Lines changed: 60 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,53 +5,66 @@
55
*/
66
namespace Magento\Catalog\Model\ResourceModel\Product\Option;
77

8+
use Magento\Catalog\Model\Product\Option\Value as OptionValue;
9+
use Magento\Directory\Model\Currency;
10+
use Magento\Directory\Model\CurrencyFactory;
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
12+
use Magento\Framework\App\ObjectManager;
13+
use Magento\Framework\Locale\FormatInterface;
14+
use Magento\Framework\Model\AbstractModel;
15+
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
16+
use Magento\Framework\Model\ResourceModel\Db\Context;
17+
use Magento\Store\Model\ScopeInterface;
18+
use Magento\Store\Model\Store;
19+
use Magento\Store\Model\StoreManagerInterface;
20+
821
/**
922
* Catalog product custom option resource model
1023
*
1124
* @author Magento Core Team <[email protected]>
1225
*/
13-
class Value extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
26+
class Value extends AbstractDb
1427
{
1528
/**
1629
* Store manager
1730
*
18-
* @var \Magento\Store\Model\StoreManagerInterface
31+
* @var StoreManagerInterface
1932
*/
2033
protected $_storeManager;
2134

2235
/**
2336
* Currency factory
2437
*
25-
* @var \Magento\Directory\Model\CurrencyFactory
38+
* @var CurrencyFactory
2639
*/
2740
protected $_currencyFactory;
2841

2942
/**
3043
* Core config model
3144
*
32-
* @var \Magento\Framework\App\Config\ScopeConfigInterface
45+
* @var ScopeConfigInterface
3346
*/
3447
protected $_config;
3548

3649
/**
37-
* @var \Magento\Framework\Locale\FormatInterface
50+
* @var FormatInterface
3851
*/
3952
private $localeFormat;
4053

4154
/**
4255
* Class constructor
4356
*
44-
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context
45-
* @param \Magento\Directory\Model\CurrencyFactory $currencyFactory
46-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
47-
* @param \Magento\Framework\App\Config\ScopeConfigInterface $config
57+
* @param Context $context
58+
* @param CurrencyFactory $currencyFactory
59+
* @param StoreManagerInterface $storeManager
60+
* @param ScopeConfigInterface $config
4861
* @param string $connectionName
4962
*/
5063
public function __construct(
51-
\Magento\Framework\Model\ResourceModel\Db\Context $context,
52-
\Magento\Directory\Model\CurrencyFactory $currencyFactory,
53-
\Magento\Store\Model\StoreManagerInterface $storeManager,
54-
\Magento\Framework\App\Config\ScopeConfigInterface $config,
64+
Context $context,
65+
CurrencyFactory $currencyFactory,
66+
StoreManagerInterface $storeManager,
67+
ScopeConfigInterface $config,
5568
$connectionName = null
5669
) {
5770
$this->_currencyFactory = $currencyFactory;
@@ -74,10 +87,10 @@ protected function _construct()
7487
* Proceed operations after object is saved
7588
* Save options store data
7689
*
77-
* @param \Magento\Framework\Model\AbstractModel $object
78-
* @return \Magento\Framework\Model\ResourceModel\Db\AbstractDb
90+
* @param AbstractModel $object
91+
* @return AbstractDb
7992
*/
80-
protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
93+
protected function _afterSave(AbstractModel $object)
8194
{
8295
$this->_saveValuePrices($object);
8396
$this->_saveValueTitles($object);
@@ -88,20 +101,21 @@ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
88101
/**
89102
* Save option value price data
90103
*
91-
* @param \Magento\Framework\Model\AbstractModel $object
104+
* @param AbstractModel $object
92105
* @return void
93106
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
94107
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
95108
*/
96-
protected function _saveValuePrices(\Magento\Framework\Model\AbstractModel $object)
109+
protected function _saveValuePrices(AbstractModel $object)
97110
{
111+
$objectPrice = $object->getPrice();
98112
$priceTable = $this->getTable('catalog_product_option_type_price');
99-
$formattedPrice = $this->getLocaleFormatter()->getNumber($object->getPrice());
113+
$formattedPrice = $this->getLocaleFormatter()->getNumber($objectPrice);
100114

101115
$price = (double)sprintf('%F', $formattedPrice);
102116
$priceType = $object->getPriceType();
103117

104-
if ($object->getPrice() && $priceType) {
118+
if (isset($objectPrice) && $priceType) {
105119
//save for store_id = 0
106120
$select = $this->getConnection()->select()->from(
107121
$priceTable,
@@ -111,7 +125,7 @@ protected function _saveValuePrices(\Magento\Framework\Model\AbstractModel $obje
111125
(int)$object->getId()
112126
)->where(
113127
'store_id = ?',
114-
\Magento\Store\Model\Store::DEFAULT_STORE_ID
128+
Store::DEFAULT_STORE_ID
115129
);
116130
$optionTypeId = $this->getConnection()->fetchOne($select);
117131

@@ -120,15 +134,15 @@ protected function _saveValuePrices(\Magento\Framework\Model\AbstractModel $obje
120134
$bind = ['price' => $price, 'price_type' => $priceType];
121135
$where = [
122136
'option_type_id = ?' => $optionTypeId,
123-
'store_id = ?' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
137+
'store_id = ?' => Store::DEFAULT_STORE_ID,
124138
];
125139

126140
$this->getConnection()->update($priceTable, $bind, $where);
127141
}
128142
} else {
129143
$bind = [
130144
'option_type_id' => (int)$object->getId(),
131-
'store_id' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
145+
'store_id' => Store::DEFAULT_STORE_ID,
132146
'price' => $price,
133147
'price_type' => $priceType,
134148
];
@@ -137,17 +151,17 @@ protected function _saveValuePrices(\Magento\Framework\Model\AbstractModel $obje
137151
}
138152

139153
$scope = (int)$this->_config->getValue(
140-
\Magento\Store\Model\Store::XML_PATH_PRICE_SCOPE,
141-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
154+
Store::XML_PATH_PRICE_SCOPE,
155+
ScopeInterface::SCOPE_STORE
142156
);
143157

144-
if ($scope == \Magento\Store\Model\Store::PRICE_SCOPE_WEBSITE
158+
if ($scope == Store::PRICE_SCOPE_WEBSITE
145159
&& $priceType
146-
&& $object->getPrice()
147-
&& $object->getStoreId() != \Magento\Store\Model\Store::DEFAULT_STORE_ID
160+
&& isset($objectPrice)
161+
&& $object->getStoreId() != Store::DEFAULT_STORE_ID
148162
) {
149163
$baseCurrency = $this->_config->getValue(
150-
\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_BASE,
164+
Currency::XML_PATH_CURRENCY_BASE,
151165
'default'
152166
);
153167

@@ -156,7 +170,7 @@ protected function _saveValuePrices(\Magento\Framework\Model\AbstractModel $obje
156170
foreach ($storeIds as $storeId) {
157171
if ($priceType == 'fixed') {
158172
$storeCurrency = $this->_storeManager->getStore($storeId)->getBaseCurrencyCode();
159-
/** @var $currencyModel \Magento\Directory\Model\Currency */
173+
/** @var $currencyModel Currency */
160174
$currencyModel = $this->_currencyFactory->create();
161175
$currencyModel->load($baseCurrency);
162176
$rate = $currencyModel->getRate($storeCurrency);
@@ -198,8 +212,8 @@ protected function _saveValuePrices(\Magento\Framework\Model\AbstractModel $obje
198212
}
199213
}
200214
} else {
201-
if ($scope == \Magento\Store\Model\Store::PRICE_SCOPE_WEBSITE
202-
&& !$object->getPrice()
215+
if ($scope == Store::PRICE_SCOPE_WEBSITE
216+
&& !isset($objectPrice)
203217
&& !$priceType
204218
) {
205219
$storeIds = $this->_storeManager->getStore($object->getStoreId())->getWebsite()->getStoreIds();
@@ -217,13 +231,13 @@ protected function _saveValuePrices(\Magento\Framework\Model\AbstractModel $obje
217231
/**
218232
* Save option value title data
219233
*
220-
* @param \Magento\Framework\Model\AbstractModel $object
234+
* @param AbstractModel $object
221235
* @return void
222236
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
223237
*/
224-
protected function _saveValueTitles(\Magento\Framework\Model\AbstractModel $object)
238+
protected function _saveValueTitles(AbstractModel $object)
225239
{
226-
foreach ([\Magento\Store\Model\Store::DEFAULT_STORE_ID, $object->getStoreId()] as $storeId) {
240+
foreach ([Store::DEFAULT_STORE_ID, $object->getStoreId()] as $storeId) {
227241
$titleTable = $this->getTable('catalog_product_option_type_title');
228242
$select = $this->getConnection()->select()->from(
229243
$titleTable,
@@ -238,7 +252,7 @@ protected function _saveValueTitles(\Magento\Framework\Model\AbstractModel $obje
238252
$optionTypeId = $this->getConnection()->fetchOne($select);
239253
$existInCurrentStore = $this->getOptionIdFromOptionTable($titleTable, (int)$object->getId(), (int)$storeId);
240254

241-
if ($storeId != \Magento\Store\Model\Store::DEFAULT_STORE_ID && $object->getData('is_delete_store_title')) {
255+
if ($storeId != Store::DEFAULT_STORE_ID && $object->getData('is_delete_store_title')) {
242256
$object->unsetData('title');
243257
}
244258

@@ -256,11 +270,11 @@ protected function _saveValueTitles(\Magento\Framework\Model\AbstractModel $obje
256270
$existInDefaultStore = $this->getOptionIdFromOptionTable(
257271
$titleTable,
258272
(int)$object->getId(),
259-
\Magento\Store\Model\Store::DEFAULT_STORE_ID
273+
Store::DEFAULT_STORE_ID
260274
);
261275
// we should insert record into not default store only of if it does not exist in default store
262-
if (($storeId == \Magento\Store\Model\Store::DEFAULT_STORE_ID && !$existInDefaultStore)
263-
|| ($storeId != \Magento\Store\Model\Store::DEFAULT_STORE_ID && !$existInCurrentStore)
276+
if (($storeId == Store::DEFAULT_STORE_ID && !$existInDefaultStore)
277+
|| ($storeId != Store::DEFAULT_STORE_ID && !$existInCurrentStore)
264278
) {
265279
$bind = [
266280
'option_type_id' => (int)$object->getId(),
@@ -273,7 +287,7 @@ protected function _saveValueTitles(\Magento\Framework\Model\AbstractModel $obje
273287
} else {
274288
if ($storeId
275289
&& $optionTypeId
276-
&& $object->getStoreId() > \Magento\Store\Model\Store::DEFAULT_STORE_ID
290+
&& $object->getStoreId() > Store::DEFAULT_STORE_ID
277291
) {
278292
$where = [
279293
'option_type_id = ?' => (int)$optionTypeId,
@@ -353,12 +367,12 @@ public function deleteValues($optionTypeId)
353367
/**
354368
* Duplicate product options value
355369
*
356-
* @param \Magento\Catalog\Model\Product\Option\Value $object
370+
* @param OptionValue $object
357371
* @param int $oldOptionId
358372
* @param int $newOptionId
359-
* @return \Magento\Catalog\Model\Product\Option\Value
373+
* @return OptionValue
360374
*/
361-
public function duplicate(\Magento\Catalog\Model\Product\Option\Value $object, $oldOptionId, $newOptionId)
375+
public function duplicate(OptionValue $object, $oldOptionId, $newOptionId)
362376
{
363377
$connection = $this->getConnection();
364378
$select = $connection->select()->from($this->getMainTable())->where('option_id = ?', $oldOptionId);
@@ -425,14 +439,14 @@ public function duplicate(\Magento\Catalog\Model\Product\Option\Value $object, $
425439
/**
426440
* Get FormatInterface to convert price from string to number format
427441
*
428-
* @return \Magento\Framework\Locale\FormatInterface
442+
* @return FormatInterface
429443
* @deprecated 101.0.8
430444
*/
431445
private function getLocaleFormatter()
432446
{
433447
if ($this->localeFormat === null) {
434-
$this->localeFormat = \Magento\Framework\App\ObjectManager::getInstance()
435-
->get(\Magento\Framework\Locale\FormatInterface::class);
448+
$this->localeFormat = ObjectManager::getInstance()
449+
->get(FormatInterface::class);
436450
}
437451
return $this->localeFormat;
438452
}

app/code/Magento/Cms/Model/ResourceModel/Block.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,10 @@ public function getIsUniqueBlockToStores(AbstractModel $object)
183183
$entityMetadata = $this->metadataPool->getMetadata(BlockInterface::class);
184184
$linkField = $entityMetadata->getLinkField();
185185

186-
if ($this->_storeManager->hasSingleStore()) {
186+
if ($this->_storeManager->isSingleStoreMode()) {
187187
$stores = [Store::DEFAULT_STORE_ID];
188188
} else {
189-
$stores = (array)$object->getData('stores');
189+
$stores = (array)$object->getData('store_id');
190190
}
191191

192192
$select = $this->getConnection()->select()
@@ -230,7 +230,7 @@ public function lookupStoreIds($id)
230230
'cbs.' . $linkField . ' = cb.' . $linkField,
231231
[]
232232
)
233-
->where('cb.' . $entityMetadata->getIdentifierField() . ' = :block_id');
233+
->where('cb.' . $entityMetadata->getIdentifierField() . ' = :block_id');
234234

235235
return $connection->fetchCol($select, ['block_id' => (int)$id]);
236236
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
8181
false
8282
);
8383
}
84-
if (version_compare($context->getVersion(), '2.0.2', '<')) {
84+
if (version_compare($context->getVersion(), '2.0.3', '<')) {
8585
//Update the tax_region_id
8686
$taxRateList = $this->taxRateRepository->getList($this->searchCriteriaFactory->create());
8787
/** @var \Magento\Tax\Api\Data\TaxRateInterface $taxRateData */
@@ -91,6 +91,9 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
9191
/** @var \Magento\Directory\Model\Region $region */
9292
$region = $this->directoryRegionFactory->create();
9393
$region->loadByCode($regionCode, $taxRateData->getTaxCountryId());
94+
if ($taxRateData->getTaxPostcode() === null) {
95+
$taxRateData->setTaxPostcode('*');
96+
}
9497
$taxRateData->setTaxRegionId($region->getRegionId());
9598
$this->taxRateRepository->save($taxRateData);
9699
}

app/code/Magento/Tax/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_Tax" setup_version="2.0.2">
9+
<module name="Magento_Tax" setup_version="2.0.3">
1010
<sequence>
1111
<module name="Magento_Catalog"/>
1212
<module name="Magento_Checkout"/>

lib/internal/Magento/Framework/Api/FilterBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function setField($field)
2929
/**
3030
* Set value
3131
*
32-
* @param string $value
32+
* @param string|array $value
3333
* @return $this
3434
*/
3535
public function setValue($value)

0 commit comments

Comments
 (0)