Skip to content

Commit 498d679

Browse files
author
Lysenko Olexandr
authored
Merge pull request #3032 from magento-tsg-csl3/2.3-develop-pr1
[TSG-CSL3] Upporting 2.3 (pr1)
2 parents 9b01481 + 96e0f8d commit 498d679

File tree

21 files changed

+419
-150
lines changed

21 files changed

+419
-150
lines changed

app/code/Magento/Catalog/Model/Product/Option/Validator/DefaultValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ protected function validateOptionType(Option $option)
132132
*/
133133
protected function validateOptionValue(Option $option)
134134
{
135-
return $this->isInRange($option->getPriceType(), $this->priceTypes) && !$this->isNegative($option->getPrice());
135+
return $this->isInRange($option->getPriceType(), $this->priceTypes);
136136
}
137137

138138
/**

app/code/Magento/Catalog/Model/Product/Option/Validator/Select.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ protected function isValidOptionPrice($priceType, $price, $storeId)
8383
if (!$priceType && !$price) {
8484
return true;
8585
}
86-
if (!$this->isInRange($priceType, $this->priceTypes) || $this->isNegative($price)) {
86+
if (!$this->isInRange($priceType, $this->priceTypes)) {
8787
return false;
8888
}
8989

app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/DefaultValidatorTest.php

Lines changed: 17 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ class DefaultValidatorTest extends \PHPUnit\Framework\TestCase
1818
*/
1919
protected $valueMock;
2020

21+
/**
22+
* @inheritdoc
23+
*/
2124
protected function setUp()
2225
{
2326
$configMock = $this->createMock(\Magento\Catalog\Model\ProductOptions\ConfigInterface::class);
@@ -60,31 +63,30 @@ public function isValidTitleDataProvider()
6063
{
6164
$mess = ['option required fields' => 'Missed values for option required fields'];
6265
return [
63-
['option_title', 'name 1.1', 'fixed', 10, new \Magento\Framework\DataObject(['store_id' => 1]), [], true],
64-
['option_title', 'name 1.1', 'fixed', 10, new \Magento\Framework\DataObject(['store_id' => 0]), [], true],
65-
[null, 'name 1.1', 'fixed', 10, new \Magento\Framework\DataObject(['store_id' => 1]), [], true],
66-
[null, 'name 1.1', 'fixed', 10, new \Magento\Framework\DataObject(['store_id' => 0]), $mess, false],
66+
['option_title', 'name 1.1', 'fixed', new \Magento\Framework\DataObject(['store_id' => 1]), [], true],
67+
['option_title', 'name 1.1', 'fixed', new \Magento\Framework\DataObject(['store_id' => 0]), [], true],
68+
[null, 'name 1.1', 'fixed', new \Magento\Framework\DataObject(['store_id' => 1]), [], true],
69+
[null, 'name 1.1', 'fixed', new \Magento\Framework\DataObject(['store_id' => 0]), $mess, false],
6770
];
6871
}
6972

7073
/**
71-
* @param $title
72-
* @param $type
73-
* @param $priceType
74-
* @param $price
75-
* @param $product
76-
* @param $messages
77-
* @param $result
74+
* @param string $title
75+
* @param string $type
76+
* @param string $priceType
77+
* @param \Magento\Framework\DataObject $product
78+
* @param array $messages
79+
* @param bool $result
7880
* @dataProvider isValidTitleDataProvider
7981
*/
80-
public function testIsValidTitle($title, $type, $priceType, $price, $product, $messages, $result)
82+
public function testIsValidTitle($title, $type, $priceType, $product, $messages, $result)
8183
{
82-
$methods = ['getTitle', 'getType', 'getPriceType', 'getPrice', '__wakeup', 'getProduct'];
84+
$methods = ['getTitle', 'getType', 'getPriceType', '__wakeup', 'getProduct'];
8385
$valueMock = $this->createPartialMock(\Magento\Catalog\Model\Product\Option::class, $methods);
8486
$valueMock->expects($this->once())->method('getTitle')->will($this->returnValue($title));
8587
$valueMock->expects($this->any())->method('getType')->will($this->returnValue($type));
8688
$valueMock->expects($this->once())->method('getPriceType')->will($this->returnValue($priceType));
87-
$valueMock->expects($this->once())->method('getPrice')->will($this->returnValue($price));
89+
// $valueMock->expects($this->once())->method('getPrice')->will($this->returnValue($price));
8890
$valueMock->expects($this->once())->method('getProduct')->will($this->returnValue($product));
8991
$this->assertEquals($result, $this->validator->isValid($valueMock));
9092
$this->assertEquals($messages, $this->validator->getMessages());
@@ -104,7 +106,7 @@ public function isValidFailDataProvider()
104106
}
105107

106108
/**
107-
* @param $product
109+
* @param \Magento\Framework\DataObject $product
108110
* @dataProvider isValidFailDataProvider
109111
*/
110112
public function testIsValidFail($product)
@@ -124,41 +126,4 @@ public function testIsValidFail($product)
124126
$this->assertFalse($this->validator->isValid($valueMock));
125127
$this->assertEquals($messages, $this->validator->getMessages());
126128
}
127-
128-
/**
129-
* Data provider for testValidationNegativePrice
130-
* @return array
131-
*/
132-
public function validationNegativePriceDataProvider()
133-
{
134-
return [
135-
['option_title', 'name 1.1', 'fixed', -12, new \Magento\Framework\DataObject(['store_id' => 1])],
136-
['option_title', 'name 1.1', 'fixed', -12, new \Magento\Framework\DataObject(['store_id' => 0])],
137-
];
138-
}
139-
140-
/**
141-
* @param $title
142-
* @param $type
143-
* @param $priceType
144-
* @param $price
145-
* @param $product
146-
* @dataProvider validationNegativePriceDataProvider
147-
*/
148-
public function testValidationNegativePrice($title, $type, $priceType, $price, $product)
149-
{
150-
$methods = ['getTitle', 'getType', 'getPriceType', 'getPrice', '__wakeup', 'getProduct'];
151-
$valueMock = $this->createPartialMock(\Magento\Catalog\Model\Product\Option::class, $methods);
152-
$valueMock->expects($this->once())->method('getTitle')->will($this->returnValue($title));
153-
$valueMock->expects($this->exactly(2))->method('getType')->will($this->returnValue($type));
154-
$valueMock->expects($this->once())->method('getPriceType')->will($this->returnValue($priceType));
155-
$valueMock->expects($this->once())->method('getPrice')->will($this->returnValue($price));
156-
$valueMock->expects($this->once())->method('getProduct')->will($this->returnValue($product));
157-
158-
$messages = [
159-
'option values' => 'Invalid option value',
160-
];
161-
$this->assertFalse($this->validator->isValid($valueMock));
162-
$this->assertEquals($messages, $this->validator->getMessages());
163-
}
164129
}

app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/FileTest.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ class FileTest extends \PHPUnit\Framework\TestCase
1818
*/
1919
protected $valueMock;
2020

21+
/**
22+
* @inheritdoc
23+
*/
2124
protected function setUp()
2225
{
2326
$configMock = $this->createMock(\Magento\Catalog\Model\ProductOptions\ConfigInterface::class);
@@ -54,24 +57,34 @@ protected function setUp()
5457
);
5558
}
5659

60+
/**
61+
* @return void
62+
*/
5763
public function testIsValidSuccess()
5864
{
5965
$this->valueMock->expects($this->once())->method('getTitle')->will($this->returnValue('option_title'));
6066
$this->valueMock->expects($this->exactly(2))->method('getType')->will($this->returnValue('name 1.1'));
61-
$this->valueMock->expects($this->once())->method('getPriceType')->will($this->returnValue('fixed'));
62-
$this->valueMock->expects($this->once())->method('getPrice')->will($this->returnValue(10));
67+
$this->valueMock->method('getPriceType')
68+
->willReturn('fixed');
69+
$this->valueMock->method('getPrice')
70+
->willReturn(10);
6371
$this->valueMock->expects($this->once())->method('getImageSizeX')->will($this->returnValue(10));
6472
$this->valueMock->expects($this->once())->method('getImageSizeY')->will($this->returnValue(15));
6573
$this->assertEmpty($this->validator->getMessages());
6674
$this->assertTrue($this->validator->isValid($this->valueMock));
6775
}
6876

77+
/**
78+
* @return void
79+
*/
6980
public function testIsValidWithNegativeImageSize()
7081
{
7182
$this->valueMock->expects($this->once())->method('getTitle')->will($this->returnValue('option_title'));
7283
$this->valueMock->expects($this->exactly(2))->method('getType')->will($this->returnValue('name 1.1'));
73-
$this->valueMock->expects($this->once())->method('getPriceType')->will($this->returnValue('fixed'));
74-
$this->valueMock->expects($this->once())->method('getPrice')->will($this->returnValue(10));
84+
$this->valueMock->method('getPriceType')
85+
->willReturn('fixed');
86+
$this->valueMock->method('getPrice')
87+
->willReturn(10);
7588
$this->valueMock->expects($this->once())->method('getImageSizeX')->will($this->returnValue(-10));
7689
$this->valueMock->expects($this->never())->method('getImageSizeY');
7790
$messages = [
@@ -81,12 +94,17 @@ public function testIsValidWithNegativeImageSize()
8194
$this->assertEquals($messages, $this->validator->getMessages());
8295
}
8396

97+
/**
98+
* @return void
99+
*/
84100
public function testIsValidWithNegativeImageSizeY()
85101
{
86102
$this->valueMock->expects($this->once())->method('getTitle')->will($this->returnValue('option_title'));
87103
$this->valueMock->expects($this->exactly(2))->method('getType')->will($this->returnValue('name 1.1'));
88-
$this->valueMock->expects($this->once())->method('getPriceType')->will($this->returnValue('fixed'));
89-
$this->valueMock->expects($this->once())->method('getPrice')->will($this->returnValue(10));
104+
$this->valueMock->method('getPriceType')
105+
->willReturn('fixed');
106+
$this->valueMock->method('getPrice')
107+
->willReturn(10);
90108
$this->valueMock->expects($this->once())->method('getImageSizeX')->will($this->returnValue(10));
91109
$this->valueMock->expects($this->once())->method('getImageSizeY')->will($this->returnValue(-10));
92110
$messages = [

app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/SelectTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ class SelectTest extends \PHPUnit\Framework\TestCase
1818
*/
1919
protected $valueMock;
2020

21+
/**
22+
* @inheritdoc
23+
*/
2124
protected function setUp()
2225
{
2326
$configMock = $this->createMock(\Magento\Catalog\Model\ProductOptions\ConfigInterface::class);
@@ -90,7 +93,7 @@ public function isValidSuccessDataProvider()
9093
]
9194
],
9295
[
93-
false,
96+
true,
9497
[
9598
'title' => 'Some Title',
9699
'price_type' => 'fixed',
@@ -100,6 +103,9 @@ public function isValidSuccessDataProvider()
100103
];
101104
}
102105

106+
/**
107+
* @return void
108+
*/
103109
public function testIsValidateWithInvalidOptionValues()
104110
{
105111
$this->valueMock->expects($this->once())->method('getTitle')->will($this->returnValue('option_title'));
@@ -118,6 +124,9 @@ public function testIsValidateWithInvalidOptionValues()
118124
$this->assertEquals($messages, $this->validator->getMessages());
119125
}
120126

127+
/**
128+
* @return void
129+
*/
121130
public function testIsValidateWithEmptyValues()
122131
{
123132
$this->valueMock->expects($this->once())->method('getTitle')->will($this->returnValue('option_title'));
@@ -163,7 +172,6 @@ public function testIsValidateWithInvalidData($priceType, $price, $title)
163172
public function isValidateWithInvalidDataDataProvider()
164173
{
165174
return [
166-
'invalid_price' => ['fixed', -10, 'Title'],
167175
'invalid_price_type' => ['some_value', '10', 'Title'],
168176
'empty_title' => ['fixed', 10, null]
169177
];

app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Validator/TextTest.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ class TextTest extends \PHPUnit\Framework\TestCase
1818
*/
1919
protected $valueMock;
2020

21+
/**
22+
* @inheritdoc
23+
*/
2124
protected function setUp()
2225
{
2326
$configMock = $this->createMock(\Magento\Catalog\Model\ProductOptions\ConfigInterface::class);
@@ -54,23 +57,33 @@ protected function setUp()
5457
);
5558
}
5659

60+
/**
61+
* @return void
62+
*/
5763
public function testIsValidSuccess()
5864
{
5965
$this->valueMock->expects($this->once())->method('getTitle')->will($this->returnValue('option_title'));
6066
$this->valueMock->expects($this->exactly(2))->method('getType')->will($this->returnValue('name 1.1'));
61-
$this->valueMock->expects($this->once())->method('getPriceType')->will($this->returnValue('fixed'));
62-
$this->valueMock->expects($this->once())->method('getPrice')->will($this->returnValue(10));
67+
$this->valueMock->method('getPriceType')
68+
->willReturn('fixed');
69+
$this->valueMock->method('getPrice')
70+
->willReturn(10);
6371
$this->valueMock->expects($this->once())->method('getMaxCharacters')->will($this->returnValue(10));
6472
$this->assertTrue($this->validator->isValid($this->valueMock));
6573
$this->assertEmpty($this->validator->getMessages());
6674
}
6775

76+
/**
77+
* @return void
78+
*/
6879
public function testIsValidWithNegativeMaxCharacters()
6980
{
7081
$this->valueMock->expects($this->once())->method('getTitle')->will($this->returnValue('option_title'));
7182
$this->valueMock->expects($this->exactly(2))->method('getType')->will($this->returnValue('name 1.1'));
72-
$this->valueMock->expects($this->once())->method('getPriceType')->will($this->returnValue('fixed'));
73-
$this->valueMock->expects($this->once())->method('getPrice')->will($this->returnValue(10));
83+
$this->valueMock->method('getPriceType')
84+
->willReturn('fixed');
85+
$this->valueMock->method('getPrice')
86+
->willReturn(10);
7487
$this->valueMock->expects($this->once())->method('getMaxCharacters')->will($this->returnValue(-10));
7588
$messages = [
7689
'option values' => 'Invalid option value',

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/CustomOptions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public function __construct(
166166
}
167167

168168
/**
169-
* {@inheritdoc}
169+
* @inheritdoc
170170
* @since 101.0.0
171171
*/
172172
public function modifyData(array $data)
@@ -226,7 +226,7 @@ protected function formatPriceByPath($path, array $data)
226226
}
227227

228228
/**
229-
* {@inheritdoc}
229+
* @inheritdoc
230230
* @since 101.0.0
231231
*/
232232
public function modifyMeta(array $meta)
@@ -923,7 +923,7 @@ protected function getPriceFieldConfig($sortOrder)
923923
'addbeforePool' => $this->productOptionsPrice->prefixesToOptionArray(),
924924
'sortOrder' => $sortOrder,
925925
'validation' => [
926-
'validate-zero-or-greater' => true
926+
'validate-number' => true
927927
],
928928
],
929929
],

app/code/Magento/Checkout/view/frontend/web/js/sidebar.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,23 @@ define([
6161
};
6262
events['click ' + this.options.button.checkout] = $.proxy(function () {
6363
var cart = customerData.get('cart'),
64-
customer = customerData.get('customer');
64+
customer = customerData.get('customer'),
65+
element = $(this.options.button.checkout);
6566

6667
if (!customer().firstname && cart().isGuestCheckoutAllowed === false) {
6768
// set URL for redirect on successful login/registration. It's postprocessed on backend.
6869
$.cookie('login_redirect', this.options.url.checkout);
6970

7071
if (this.options.url.isRedirectRequired) {
72+
element.prop('disabled', true);
7173
location.href = this.options.url.loginUrl;
7274
} else {
7375
authenticationPopup.showModal();
7476
}
7577

7678
return false;
7779
}
80+
element.prop('disabled', true);
7881
location.href = this.options.url.checkout;
7982
}, this);
8083

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\GiftMessage\Observer;
9+
10+
use Magento\Framework\Event\ObserverInterface;
11+
use Magento\Quote\Model\Quote;
12+
13+
/**
14+
* Gift Message Observer Model
15+
*/
16+
class SalesEventQuoteMerge implements ObserverInterface
17+
{
18+
/**
19+
* Sets gift message to customer quote from guest quote.
20+
*
21+
* @param \Magento\Framework\Event\Observer $observer
22+
* @return $this
23+
*/
24+
public function execute(\Magento\Framework\Event\Observer $observer)
25+
{
26+
/** @var Quote $targetQuote */
27+
$targetQuote = $observer->getData('quote');
28+
/** @var Quote $sourceQuote */
29+
$sourceQuote = $observer->getData('source');
30+
31+
$targetQuote->setGiftMessageId($sourceQuote->getGiftMessageId());
32+
33+
return $this;
34+
}
35+
}

app/code/Magento/GiftMessage/etc/frontend/events.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
<event name="sales_convert_order_to_quote">
1313
<observer name="giftmessage" instance="Magento\GiftMessage\Observer\SalesEventOrderToQuoteObserver" shared="false" />
1414
</event>
15+
<event name="sales_quote_merge_after">
16+
<observer name="giftmessage" instance="Magento\GiftMessage\Observer\SalesEventQuoteMerge" shared="false" />
17+
</event>
1518
<event name="checkout_type_multishipping_create_orders_single">
1619
<observer name="giftmessage" instance="Magento\GiftMessage\Observer\MultishippingEventCreateOrdersObserver" shared="false" />
1720
</event>

0 commit comments

Comments
 (0)