Skip to content

Commit

Permalink
Merge pull request #1643 from magento-engcom/2.2-develop-prs
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Oleksii Korshenko authored Oct 31, 2017
2 parents ea5e982 + 9e28e9e commit 884d717
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 52 deletions.
106 changes: 60 additions & 46 deletions app/code/Magento/Catalog/Model/ResourceModel/Product/Option/Value.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,66 @@
*/
namespace Magento\Catalog\Model\ResourceModel\Product\Option;

use Magento\Catalog\Model\Product\Option\Value as OptionValue;
use Magento\Directory\Model\Currency;
use Magento\Directory\Model\CurrencyFactory;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Locale\FormatInterface;
use Magento\Framework\Model\AbstractModel;
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
use Magento\Framework\Model\ResourceModel\Db\Context;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\Store;
use Magento\Store\Model\StoreManagerInterface;

/**
* Catalog product custom option resource model
*
* @author Magento Core Team <[email protected]>
*/
class Value extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
class Value extends AbstractDb
{
/**
* Store manager
*
* @var \Magento\Store\Model\StoreManagerInterface
* @var StoreManagerInterface
*/
protected $_storeManager;

/**
* Currency factory
*
* @var \Magento\Directory\Model\CurrencyFactory
* @var CurrencyFactory
*/
protected $_currencyFactory;

/**
* Core config model
*
* @var \Magento\Framework\App\Config\ScopeConfigInterface
* @var ScopeConfigInterface
*/
protected $_config;

/**
* @var \Magento\Framework\Locale\FormatInterface
* @var FormatInterface
*/
private $localeFormat;

/**
* Class constructor
*
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context
* @param \Magento\Directory\Model\CurrencyFactory $currencyFactory
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\App\Config\ScopeConfigInterface $config
* @param Context $context
* @param CurrencyFactory $currencyFactory
* @param StoreManagerInterface $storeManager
* @param ScopeConfigInterface $config
* @param string $connectionName
*/
public function __construct(
\Magento\Framework\Model\ResourceModel\Db\Context $context,
\Magento\Directory\Model\CurrencyFactory $currencyFactory,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\App\Config\ScopeConfigInterface $config,
Context $context,
CurrencyFactory $currencyFactory,
StoreManagerInterface $storeManager,
ScopeConfigInterface $config,
$connectionName = null
) {
$this->_currencyFactory = $currencyFactory;
Expand All @@ -74,10 +87,10 @@ protected function _construct()
* Proceed operations after object is saved
* Save options store data
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return \Magento\Framework\Model\ResourceModel\Db\AbstractDb
* @param AbstractModel $object
* @return AbstractDb
*/
protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
protected function _afterSave(AbstractModel $object)
{
$this->_saveValuePrices($object);
$this->_saveValueTitles($object);
Expand All @@ -88,20 +101,21 @@ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
/**
* Save option value price data
*
* @param \Magento\Framework\Model\AbstractModel $object
* @param AbstractModel $object
* @return void
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
protected function _saveValuePrices(\Magento\Framework\Model\AbstractModel $object)
protected function _saveValuePrices(AbstractModel $object)
{
$objectPrice = $object->getPrice();
$priceTable = $this->getTable('catalog_product_option_type_price');
$formattedPrice = $this->getLocaleFormatter()->getNumber($object->getPrice());
$formattedPrice = $this->getLocaleFormatter()->getNumber($objectPrice);

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

if ($object->getPrice() && $priceType) {
if (isset($objectPrice) && $priceType) {
//save for store_id = 0
$select = $this->getConnection()->select()->from(
$priceTable,
Expand All @@ -111,7 +125,7 @@ protected function _saveValuePrices(\Magento\Framework\Model\AbstractModel $obje
(int)$object->getId()
)->where(
'store_id = ?',
\Magento\Store\Model\Store::DEFAULT_STORE_ID
Store::DEFAULT_STORE_ID
);
$optionTypeId = $this->getConnection()->fetchOne($select);

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

$this->getConnection()->update($priceTable, $bind, $where);
}
} else {
$bind = [
'option_type_id' => (int)$object->getId(),
'store_id' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
'store_id' => Store::DEFAULT_STORE_ID,
'price' => $price,
'price_type' => $priceType,
];
Expand All @@ -137,17 +151,17 @@ protected function _saveValuePrices(\Magento\Framework\Model\AbstractModel $obje
}

$scope = (int)$this->_config->getValue(
\Magento\Store\Model\Store::XML_PATH_PRICE_SCOPE,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
Store::XML_PATH_PRICE_SCOPE,
ScopeInterface::SCOPE_STORE
);

if ($scope == \Magento\Store\Model\Store::PRICE_SCOPE_WEBSITE
if ($scope == Store::PRICE_SCOPE_WEBSITE
&& $priceType
&& $object->getPrice()
&& $object->getStoreId() != \Magento\Store\Model\Store::DEFAULT_STORE_ID
&& isset($objectPrice)
&& $object->getStoreId() != Store::DEFAULT_STORE_ID
) {
$baseCurrency = $this->_config->getValue(
\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_BASE,
Currency::XML_PATH_CURRENCY_BASE,
'default'
);

Expand All @@ -156,7 +170,7 @@ protected function _saveValuePrices(\Magento\Framework\Model\AbstractModel $obje
foreach ($storeIds as $storeId) {
if ($priceType == 'fixed') {
$storeCurrency = $this->_storeManager->getStore($storeId)->getBaseCurrencyCode();
/** @var $currencyModel \Magento\Directory\Model\Currency */
/** @var $currencyModel Currency */
$currencyModel = $this->_currencyFactory->create();
$currencyModel->load($baseCurrency);
$rate = $currencyModel->getRate($storeCurrency);
Expand Down Expand Up @@ -198,8 +212,8 @@ protected function _saveValuePrices(\Magento\Framework\Model\AbstractModel $obje
}
}
} else {
if ($scope == \Magento\Store\Model\Store::PRICE_SCOPE_WEBSITE
&& !$object->getPrice()
if ($scope == Store::PRICE_SCOPE_WEBSITE
&& !isset($objectPrice)
&& !$priceType
) {
$storeIds = $this->_storeManager->getStore($object->getStoreId())->getWebsite()->getStoreIds();
Expand All @@ -217,13 +231,13 @@ protected function _saveValuePrices(\Magento\Framework\Model\AbstractModel $obje
/**
* Save option value title data
*
* @param \Magento\Framework\Model\AbstractModel $object
* @param AbstractModel $object
* @return void
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
protected function _saveValueTitles(\Magento\Framework\Model\AbstractModel $object)
protected function _saveValueTitles(AbstractModel $object)
{
foreach ([\Magento\Store\Model\Store::DEFAULT_STORE_ID, $object->getStoreId()] as $storeId) {
foreach ([Store::DEFAULT_STORE_ID, $object->getStoreId()] as $storeId) {
$titleTable = $this->getTable('catalog_product_option_type_title');
$select = $this->getConnection()->select()->from(
$titleTable,
Expand All @@ -238,7 +252,7 @@ protected function _saveValueTitles(\Magento\Framework\Model\AbstractModel $obje
$optionTypeId = $this->getConnection()->fetchOne($select);
$existInCurrentStore = $this->getOptionIdFromOptionTable($titleTable, (int)$object->getId(), (int)$storeId);

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

Expand All @@ -256,11 +270,11 @@ protected function _saveValueTitles(\Magento\Framework\Model\AbstractModel $obje
$existInDefaultStore = $this->getOptionIdFromOptionTable(
$titleTable,
(int)$object->getId(),
\Magento\Store\Model\Store::DEFAULT_STORE_ID
Store::DEFAULT_STORE_ID
);
// we should insert record into not default store only of if it does not exist in default store
if (($storeId == \Magento\Store\Model\Store::DEFAULT_STORE_ID && !$existInDefaultStore)
|| ($storeId != \Magento\Store\Model\Store::DEFAULT_STORE_ID && !$existInCurrentStore)
if (($storeId == Store::DEFAULT_STORE_ID && !$existInDefaultStore)
|| ($storeId != Store::DEFAULT_STORE_ID && !$existInCurrentStore)
) {
$bind = [
'option_type_id' => (int)$object->getId(),
Expand All @@ -273,7 +287,7 @@ protected function _saveValueTitles(\Magento\Framework\Model\AbstractModel $obje
} else {
if ($storeId
&& $optionTypeId
&& $object->getStoreId() > \Magento\Store\Model\Store::DEFAULT_STORE_ID
&& $object->getStoreId() > Store::DEFAULT_STORE_ID
) {
$where = [
'option_type_id = ?' => (int)$optionTypeId,
Expand Down Expand Up @@ -353,12 +367,12 @@ public function deleteValues($optionTypeId)
/**
* Duplicate product options value
*
* @param \Magento\Catalog\Model\Product\Option\Value $object
* @param OptionValue $object
* @param int $oldOptionId
* @param int $newOptionId
* @return \Magento\Catalog\Model\Product\Option\Value
* @return OptionValue
*/
public function duplicate(\Magento\Catalog\Model\Product\Option\Value $object, $oldOptionId, $newOptionId)
public function duplicate(OptionValue $object, $oldOptionId, $newOptionId)
{
$connection = $this->getConnection();
$select = $connection->select()->from($this->getMainTable())->where('option_id = ?', $oldOptionId);
Expand Down Expand Up @@ -425,14 +439,14 @@ public function duplicate(\Magento\Catalog\Model\Product\Option\Value $object, $
/**
* Get FormatInterface to convert price from string to number format
*
* @return \Magento\Framework\Locale\FormatInterface
* @return FormatInterface
* @deprecated 101.0.8
*/
private function getLocaleFormatter()
{
if ($this->localeFormat === null) {
$this->localeFormat = \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Framework\Locale\FormatInterface::class);
$this->localeFormat = ObjectManager::getInstance()
->get(FormatInterface::class);
}
return $this->localeFormat;
}
Expand Down
6 changes: 3 additions & 3 deletions app/code/Magento/Cms/Model/ResourceModel/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ public function getIsUniqueBlockToStores(AbstractModel $object)
$entityMetadata = $this->metadataPool->getMetadata(BlockInterface::class);
$linkField = $entityMetadata->getLinkField();

if ($this->_storeManager->hasSingleStore()) {
if ($this->_storeManager->isSingleStoreMode()) {
$stores = [Store::DEFAULT_STORE_ID];
} else {
$stores = (array)$object->getData('stores');
$stores = (array)$object->getData('store_id');
}

$select = $this->getConnection()->select()
Expand Down Expand Up @@ -230,7 +230,7 @@ public function lookupStoreIds($id)
'cbs.' . $linkField . ' = cb.' . $linkField,
[]
)
->where('cb.' . $entityMetadata->getIdentifierField() . ' = :block_id');
->where('cb.' . $entityMetadata->getIdentifierField() . ' = :block_id');

return $connection->fetchCol($select, ['block_id' => (int)$id]);
}
Expand Down
5 changes: 4 additions & 1 deletion app/code/Magento/Tax/Setup/UpgradeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
false
);
}
if (version_compare($context->getVersion(), '2.0.2', '<')) {
if (version_compare($context->getVersion(), '2.0.3', '<')) {
//Update the tax_region_id
$taxRateList = $this->taxRateRepository->getList($this->searchCriteriaFactory->create());
/** @var \Magento\Tax\Api\Data\TaxRateInterface $taxRateData */
Expand All @@ -91,6 +91,9 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
/** @var \Magento\Directory\Model\Region $region */
$region = $this->directoryRegionFactory->create();
$region->loadByCode($regionCode, $taxRateData->getTaxCountryId());
if ($taxRateData->getTaxPostcode() === null) {
$taxRateData->setTaxPostcode('*');
}
$taxRateData->setTaxRegionId($region->getRegionId());
$this->taxRateRepository->save($taxRateData);
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Tax/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_Tax" setup_version="2.0.2">
<module name="Magento_Tax" setup_version="2.0.3">
<sequence>
<module name="Magento_Catalog"/>
<module name="Magento_Checkout"/>
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/Magento/Framework/Api/FilterBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function setField($field)
/**
* Set value
*
* @param string $value
* @param string|array $value
* @return $this
*/
public function setValue($value)
Expand Down

0 comments on commit 884d717

Please sign in to comment.