Skip to content

Commit 7aea9ef

Browse files
committed
Merge remote-tracking branch 'mainline/2.2-develop' into MAGETWO-93985
2 parents ee004f4 + c34ced3 commit 7aea9ef

File tree

35 files changed

+1008
-57
lines changed

35 files changed

+1008
-57
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,8 @@ private function preprocessOptionsData(&$data)
327327
$serializedOptions = json_decode($data['serialized_options'], JSON_OBJECT_AS_ARRAY);
328328
foreach ($serializedOptions as $serializedOption) {
329329
$option = [];
330-
parse_str($serializedOption, $option);
330+
$serializedOptionWithParsedAmpersand = str_replace('&', '%26', $serializedOption);
331+
parse_str($serializedOptionWithParsedAmpersand, $option);
331332
$data = array_replace_recursive($data, $option);
332333
}
333334
}

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,7 +1562,10 @@ protected function _saveProducts()
15621562
}
15631563
$rowScope = $this->getRowScope($rowData);
15641564

1565-
$rowData[self::URL_KEY] = $this->getUrlKey($rowData);
1565+
$urlKey = $this->getUrlKey($rowData);
1566+
if (!empty($urlKey)) {
1567+
$rowData[self::URL_KEY] = $urlKey;
1568+
}
15661569

15671570
$rowSku = $rowData[self::COL_SKU];
15681571

@@ -2452,7 +2455,9 @@ public function validateRow(array $rowData, $rowNum)
24522455
*/
24532456
private function isNeedToValidateUrlKey($rowData)
24542457
{
2455-
return (!empty($rowData[self::URL_KEY]) || !empty($rowData[self::COL_NAME]))
2458+
$urlKey = $this->getUrlKey($rowData);
2459+
2460+
return (!empty($urlKey))
24562461
&& (empty($rowData[self::COL_VISIBILITY])
24572462
|| $rowData[self::COL_VISIBILITY]
24582463
!== (string)Visibility::getOptionArray()[Visibility::VISIBILITY_NOT_VISIBLE]);
@@ -2764,8 +2769,14 @@ protected function getUrlKey($rowData)
27642769
if (!empty($rowData[self::URL_KEY])) {
27652770
return $this->productUrl->formatUrlKey($rowData[self::URL_KEY]);
27662771
}
2767-
2768-
if (!empty($rowData[self::COL_NAME])) {
2772+
2773+
/**
2774+
* If the product exists, assume it already has a URL Key and even
2775+
* if a name is provided in the import data, it should not be used
2776+
* to overwrite that existing URL Key the product already has.
2777+
*/
2778+
$isSkuExist = $this->isSkuExist($rowData[self::COL_SKU]);
2779+
if (!$isSkuExist && !empty($rowData[self::COL_NAME])) {
27692780
return $this->productUrl->formatUrlKey($rowData[self::COL_NAME]);
27702781
}
27712782

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\CatalogUrlRewrite\Model;
10+
11+
use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
12+
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
13+
14+
/**
15+
* Class for creating product url through web-api.
16+
*/
17+
class WebapiProductUrlPathGenerator extends ProductUrlPathGenerator
18+
{
19+
/**
20+
* @var CollectionFactory
21+
*/
22+
private $collectionFactory;
23+
24+
/**
25+
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
26+
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
27+
* @param \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator $categoryUrlPathGenerator
28+
* @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
29+
* @param CollectionFactory $collectionFactory
30+
*/
31+
public function __construct(
32+
\Magento\Store\Model\StoreManagerInterface $storeManager,
33+
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
34+
\Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator $categoryUrlPathGenerator,
35+
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
36+
CollectionFactory $collectionFactory
37+
) {
38+
parent::__construct($storeManager, $scopeConfig, $categoryUrlPathGenerator, $productRepository);
39+
$this->collectionFactory = $collectionFactory;
40+
}
41+
42+
/**
43+
* @inheritdoc
44+
*/
45+
protected function prepareProductUrlKey(\Magento\Catalog\Model\Product $product)
46+
{
47+
$urlKey = $product->getUrlKey();
48+
if ($urlKey === '' || $urlKey === null) {
49+
$urlKey = $this->prepareUrlKey($product->formatUrlKey($product->getName()));
50+
}
51+
52+
return $product->formatUrlKey($urlKey);
53+
}
54+
55+
/**
56+
* Crete url key if it does not exist yet.
57+
*
58+
* @param string $urlKey
59+
* @return string
60+
*/
61+
private function prepareUrlKey(string $urlKey) : string
62+
{
63+
/** @var ProductCollection $collection */
64+
$collection = $this->collectionFactory->create();
65+
$collection->addFieldToFilter('url_key', ['like' => $urlKey]);
66+
if ($collection->getSize() !== 0) {
67+
$urlKey = $urlKey . '-1';
68+
$urlKey = $this->prepareUrlKey($urlKey);
69+
}
70+
71+
return $urlKey;
72+
}
73+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9+
<preference for="Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator" type="Magento\CatalogUrlRewrite\Model\WebapiProductUrlPathGenerator"/>
10+
</config>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9+
<preference for="Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator" type="Magento\CatalogUrlRewrite\Model\WebapiProductUrlPathGenerator"/>
10+
</config>

app/code/Magento/Checkout/Controller/Cart/Delete.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ public function execute()
2222
$id = (int)$this->getRequest()->getParam('id');
2323
if ($id) {
2424
try {
25-
$this->cart->removeItem($id)->save();
25+
$this->cart->removeItem($id);
26+
// We should set Totals to be recollected once more because of Cart model as usually is loading
27+
// before action executing and in case when triggerRecollect setted as true recollecting will
28+
// executed and the flag will be true already.
29+
$this->cart->getQuote()->setTotalsCollectedFlag(false);
30+
$this->cart->save();
2631
} catch (\Exception $e) {
2732
$this->messageManager->addError(__('We can\'t remove the item.'));
2833
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);

app/code/Magento/Checkout/Test/Mftf/ActionGroup/CheckoutActionGroup.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
<!-- Checkout select Check/Money Order payment -->
1212
<actionGroup name="CheckoutSelectCheckMoneyOrderPaymentActionGroup">
1313
<waitForElement selector="{{CheckoutPaymentSection.paymentSectionTitle}}" time="30" stepKey="waitForPaymentSectionLoaded"/>
14-
<waitForElementVisible selector="{{CheckoutPaymentSection.billingAddress}}" time="30" stepKey="waitForBillingAddressDetailsAppears"/>
1514
<conditionalClick selector="{{CheckoutPaymentSection.checkMoneyOrderPayment}}" dependentSelector="{{CheckoutPaymentSection.checkMoneyOrderPayment}}" visible="true" stepKey="clickCheckMoneyOrderPayment"/>
1615
</actionGroup>
1716

app/code/Magento/Checkout/view/frontend/web/js/model/error-processor.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
*/
99
define([
1010
'mage/url',
11-
'Magento_Ui/js/model/messageList'
12-
], function (url, globalMessageList) {
11+
'Magento_Ui/js/model/messageList',
12+
'consoleLogger'
13+
], function (url, globalMessageList, consoleLogger) {
1314
'use strict';
1415

1516
return {
@@ -25,8 +26,12 @@ define([
2526
if (response.status == 401) { //eslint-disable-line eqeqeq
2627
window.location.replace(url.build('customer/account/login/'));
2728
} else {
28-
error = JSON.parse(response.responseText);
29-
messageContainer.addErrorMessage(error);
29+
try {
30+
error = JSON.parse(response.responseText);
31+
messageContainer.addErrorMessage(error);
32+
} catch (e) {
33+
consoleLogger.error(e);
34+
}
3035
}
3136
}
3237
};

app/code/Magento/ConfigurableProduct/view/frontend/web/js/configurable.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,11 @@ define([
360360
index = 1,
361361
allowedProducts,
362362
i,
363-
j;
363+
j,
364+
basePrice = parseFloat(this.options.spConfig.prices.basePrice.amount),
365+
optionFinalPrice,
366+
optionPriceDiff,
367+
optionPrices = this.options.spConfig.optionPrices;
364368

365369
this._clearSelect(element);
366370
element.options[0] = new Option('', '');
@@ -374,6 +378,7 @@ define([
374378
if (options) {
375379
for (i = 0; i < options.length; i++) {
376380
allowedProducts = [];
381+
optionPriceDiff = 0;
377382

378383
/* eslint-disable max-depth */
379384
if (prevConfig) {
@@ -387,14 +392,28 @@ define([
387392
}
388393
} else {
389394
allowedProducts = options[i].products.slice(0);
395+
396+
if (typeof allowedProducts[0] !== 'undefined' &&
397+
typeof optionPrices[allowedProducts[0]] !== 'undefined') {
398+
399+
optionFinalPrice = parseFloat(optionPrices[allowedProducts[0]].finalPrice.amount);
400+
optionPriceDiff = optionFinalPrice - basePrice;
401+
402+
if (optionPriceDiff !== 0) {
403+
options[i].label = options[i].label + ' ' + priceUtils.formatPrice(
404+
optionPriceDiff,
405+
this.options.priceFormat,
406+
true);
407+
}
408+
}
390409
}
391410

392411
if (allowedProducts.length > 0) {
393412
options[i].allowedProducts = allowedProducts;
394413
element.options[index] = new Option(this._getOptionLabel(options[i]), options[i].id);
395414

396415
if (typeof options[i].price !== 'undefined') {
397-
element.options[index].setAttribute('price', options[i].prices);
416+
element.options[index].setAttribute('price', options[i].price);
398417
}
399418

400419
element.options[index].config = options[i];

app/code/Magento/Customer/Test/Mftf/Data/RegionData.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<entity name="RegionTX" type="region">
1616
<data key="region">Texas</data>
1717
<data key="region_code">TX</data>
18-
<data key="region_id">1</data>
18+
<data key="region_id">57</data>
1919
</entity>
2020
<entity name="RegionCA" type="region">
2121
<data key="region">California</data>

0 commit comments

Comments
 (0)