Skip to content

Commit 7005102

Browse files
committed
Merge remote-tracking branch 'origin/batch-35-forwardport-2.3-develop' into batch-35-forwardport-2.3-develop
2 parents 3212630 + ce7faf6 commit 7005102

File tree

54 files changed

+10349
-8972
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+10349
-8972
lines changed

app/code/Magento/Backend/etc/adminhtml/system.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@
425425
<label>Web</label>
426426
<tab>general</tab>
427427
<resource>Magento_Config::web</resource>
428-
<group id="url" translate="label" type="text" sortOrder="3" showInDefault="1" showInWebsite="0" showInStore="0">
428+
<group id="url" translate="label" type="text" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1">
429429
<label>Url Options</label>
430430
<field id="use_store" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
431431
<label>Add Store Code to Urls</label>
@@ -435,7 +435,7 @@
435435
<![CDATA[<strong style="color:red">Warning!</strong> When using Store Code in URLs, in some cases system may not work properly if URLs without Store Codes are specified in the third party services (e.g. PayPal etc.).]]>
436436
</comment>
437437
</field>
438-
<field id="redirect_to_base" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
438+
<field id="redirect_to_base" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
439439
<label>Auto-redirect to Base URL</label>
440440
<source_model>Magento\Config\Model\Config\Source\Web\Redirect</source_model>
441441
<comment>I.e. redirect from http://example.com/store/ to http://www.example.com/store/</comment>

app/code/Magento/Bundle/Model/ResourceModel/Option.php

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -81,31 +81,39 @@ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
8181
{
8282
parent::_afterSave($object);
8383

84-
$condition = [
84+
$conditions = [
8585
'option_id = ?' => $object->getId(),
8686
'store_id = ? OR store_id = 0' => $object->getStoreId(),
8787
'parent_product_id = ?' => $object->getParentId()
8888
];
8989

9090
$connection = $this->getConnection();
91-
$connection->delete($this->getTable('catalog_product_bundle_option_value'), $condition);
9291

93-
$data = new \Magento\Framework\DataObject();
94-
$data->setOptionId($object->getId())
95-
->setStoreId($object->getStoreId())
96-
->setParentProductId($object->getParentId())
97-
->setTitle($object->getTitle());
98-
99-
$connection->insert($this->getTable('catalog_product_bundle_option_value'), $data->getData());
100-
101-
/**
102-
* also saving default value if this store view scope
103-
*/
92+
if ($this->isOptionPresent($conditions)) {
93+
$connection->update(
94+
$this->getTable('catalog_product_bundle_option_value'),
95+
[
96+
'title' => $object->getTitle()
97+
],
98+
$conditions
99+
);
100+
} else {
101+
$data = new \Magento\Framework\DataObject();
102+
$data->setOptionId($object->getId())
103+
->setStoreId($object->getStoreId())
104+
->setParentProductId($object->getParentId())
105+
->setTitle($object->getTitle());
104106

105-
if ($object->getStoreId()) {
106-
$data->setStoreId(0);
107-
$data->setTitle($object->getDefaultTitle());
108107
$connection->insert($this->getTable('catalog_product_bundle_option_value'), $data->getData());
108+
109+
/**
110+
* also saving default value if this store view scope
111+
*/
112+
if ($object->getStoreId()) {
113+
$data->setStoreId(0);
114+
$data->setTitle($object->getDefaultTitle());
115+
$connection->insert($this->getTable('catalog_product_bundle_option_value'), $data->getData());
116+
}
109117
}
110118

111119
return $this;
@@ -210,4 +218,26 @@ public function save(\Magento\Framework\Model\AbstractModel $object)
210218

211219
return $this;
212220
}
221+
222+
/**
223+
* Is Bundle option present in the database
224+
*
225+
* @param array $conditions
226+
*
227+
* @return bool
228+
*/
229+
private function isOptionPresent($conditions)
230+
{
231+
$connection = $this->getConnection();
232+
233+
$select = $connection->select()->from($this->getTable('catalog_product_bundle_option_value'));
234+
foreach ($conditions as $condition => $conditionValue) {
235+
$select->where($condition, $conditionValue);
236+
}
237+
$select->limit(1);
238+
239+
$rowSelect = $connection->fetchRow($select);
240+
241+
return (is_array($rowSelect) && !empty($rowSelect));
242+
}
213243
}

app/code/Magento/Catalog/Block/Product/View.php

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -120,51 +120,6 @@ public function getWishlistOptions()
120120
return ['productType' => $this->getProduct()->getTypeId()];
121121
}
122122

123-
/**
124-
* Add meta information from product to head block
125-
*
126-
* @return \Magento\Catalog\Block\Product\View
127-
*/
128-
protected function _prepareLayout()
129-
{
130-
$this->getLayout()->createBlock(\Magento\Catalog\Block\Breadcrumbs::class);
131-
$product = $this->getProduct();
132-
if (!$product) {
133-
return parent::_prepareLayout();
134-
}
135-
136-
$title = $product->getMetaTitle();
137-
if ($title) {
138-
$this->pageConfig->getTitle()->set($title);
139-
}
140-
$keyword = $product->getMetaKeyword();
141-
$currentCategory = $this->_coreRegistry->registry('current_category');
142-
if ($keyword) {
143-
$this->pageConfig->setKeywords($keyword);
144-
} elseif ($currentCategory) {
145-
$this->pageConfig->setKeywords($product->getName());
146-
}
147-
$description = $product->getMetaDescription();
148-
if ($description) {
149-
$this->pageConfig->setDescription($description);
150-
} else {
151-
$this->pageConfig->setDescription($this->string->substr($product->getDescription(), 0, 255));
152-
}
153-
if ($this->_productHelper->canUseCanonicalTag()) {
154-
$this->pageConfig->addRemotePageAsset(
155-
$product->getUrlModel()->getUrl($product, ['_ignore_category' => true]),
156-
'canonical',
157-
['attributes' => ['rel' => 'canonical']]
158-
);
159-
}
160-
161-
$pageMainTitle = $this->getLayout()->getBlock('page.main.title');
162-
if ($pageMainTitle) {
163-
$pageMainTitle->setPageTitle($product->getName());
164-
}
165-
return parent::_prepareLayout();
166-
}
167-
168123
/**
169124
* Retrieve current product model
170125
*

app/code/Magento/Catalog/Helper/Product/View.php

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ class View extends \Magento\Framework\App\Helper\AbstractHelper
5959
*/
6060
protected $categoryUrlPathGenerator;
6161

62+
/**
63+
* @var \Magento\Framework\Stdlib\StringUtils
64+
*/
65+
private $string;
66+
6267
/**
6368
* Constructor
6469
*
@@ -70,6 +75,7 @@ class View extends \Magento\Framework\App\Helper\AbstractHelper
7075
* @param \Magento\Framework\Message\ManagerInterface $messageManager
7176
* @param \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator $categoryUrlPathGenerator
7277
* @param array $messageGroups
78+
* @param \Magento\Framework\Stdlib\StringUtils|null $string
7379
*/
7480
public function __construct(
7581
\Magento\Framework\App\Helper\Context $context,
@@ -79,7 +85,8 @@ public function __construct(
7985
\Magento\Framework\Registry $coreRegistry,
8086
\Magento\Framework\Message\ManagerInterface $messageManager,
8187
\Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator $categoryUrlPathGenerator,
82-
array $messageGroups = []
88+
array $messageGroups = [],
89+
\Magento\Framework\Stdlib\StringUtils $string = null
8390
) {
8491
$this->_catalogSession = $catalogSession;
8592
$this->_catalogDesign = $catalogDesign;
@@ -88,9 +95,61 @@ public function __construct(
8895
$this->messageGroups = $messageGroups;
8996
$this->messageManager = $messageManager;
9097
$this->categoryUrlPathGenerator = $categoryUrlPathGenerator;
98+
$this->string = $string ?: \Magento\Framework\App\ObjectManager::getInstance()
99+
->get(\Magento\Framework\Stdlib\StringUtils::class);
91100
parent::__construct($context);
92101
}
93102

103+
/**
104+
* Add meta information from product to layout
105+
*
106+
* @param \Magento\Framework\View\Result\Page $resultPage
107+
* @param \Magento\Catalog\Model\Product $product
108+
* @return \Magento\Framework\View\Result\Page
109+
*/
110+
private function preparePageMetadata(ResultPage $resultPage, $product)
111+
{
112+
$pageLayout = $resultPage->getLayout();
113+
$pageLayout->createBlock(\Magento\Catalog\Block\Breadcrumbs::class);
114+
115+
$pageConfig = $resultPage->getConfig();
116+
117+
$title = $product->getMetaTitle();
118+
if ($title) {
119+
$pageConfig->getTitle()->set($title);
120+
}
121+
122+
$keyword = $product->getMetaKeyword();
123+
$currentCategory = $this->_coreRegistry->registry('current_category');
124+
if ($keyword) {
125+
$pageConfig->setKeywords($keyword);
126+
} elseif ($currentCategory) {
127+
$pageConfig->setKeywords($product->getName());
128+
}
129+
130+
$description = $product->getMetaDescription();
131+
if ($description) {
132+
$pageConfig->setDescription($description);
133+
} else {
134+
$pageConfig->setDescription($this->string->substr($product->getDescription(), 0, 255));
135+
}
136+
137+
if ($this->_catalogProduct->canUseCanonicalTag()) {
138+
$pageConfig->addRemotePageAsset(
139+
$product->getUrlModel()->getUrl($product, ['_ignore_category' => true]),
140+
'canonical',
141+
['attributes' => ['rel' => 'canonical']]
142+
);
143+
}
144+
145+
$pageMainTitle = $pageLayout->getBlock('page.main.title');
146+
if ($pageMainTitle) {
147+
$pageMainTitle->setPageTitle($product->getName());
148+
}
149+
150+
return $this;
151+
}
152+
94153
/**
95154
* Init layout for viewing product page
96155
*
@@ -225,6 +284,7 @@ public function prepareAndRender(ResultPage $resultPage, $productId, $controller
225284
}
226285

227286
$this->initProductLayout($resultPage, $product, $params);
287+
$this->preparePageMetadata($resultPage, $product);
228288
return $this;
229289
}
230290
}

app/code/Magento/Catalog/Model/Product/Gallery/CreateHandler.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,13 @@ protected function processNewAndExistingImages($product, array &$images)
245245
if (empty($image['removed'])) {
246246
$data = $this->processNewImage($product, $image);
247247

248-
$this->resourceModel->deleteGalleryValueInStore(
249-
$image['value_id'],
250-
$product->getData($this->metadata->getLinkField()),
251-
$product->getStoreId()
252-
);
253-
248+
if (!$product->isObjectNew()) {
249+
$this->resourceModel->deleteGalleryValueInStore(
250+
$image['value_id'],
251+
$product->getData($this->metadata->getLinkField()),
252+
$product->getStoreId()
253+
);
254+
}
254255
// Add per store labels, position, disabled
255256
$data['value_id'] = $image['value_id'];
256257
$data['label'] = isset($image['label']) ? $image['label'] : '';

0 commit comments

Comments
 (0)