Skip to content

Commit eab1b2d

Browse files
author
Alexander Akimov
authored
Merge pull request #2363 from magento-tsg/2.3-develop-pr9
[TSG] Upporting for 2.3 (pr9) (2.3.0)
2 parents b18ce4a + c55ddf1 commit eab1b2d

File tree

37 files changed

+1545
-290
lines changed

37 files changed

+1545
-290
lines changed

app/code/Magento/Amqp/Setup/ConfigOptionsList.php

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class ConfigOptionsList implements ConfigOptionsListInterface
2525
const INPUT_KEY_QUEUE_AMQP_PASSWORD = 'amqp-password';
2626
const INPUT_KEY_QUEUE_AMQP_VIRTUAL_HOST = 'amqp-virtualhost';
2727
const INPUT_KEY_QUEUE_AMQP_SSL = 'amqp-ssl';
28+
const INPUT_KEY_QUEUE_AMQP_SSL_OPTIONS = 'amqp-ssl-options';
2829

2930
/**
3031
* Path to the values in the deployment config
@@ -35,6 +36,7 @@ class ConfigOptionsList implements ConfigOptionsListInterface
3536
const CONFIG_PATH_QUEUE_AMQP_PASSWORD = 'queue/amqp/password';
3637
const CONFIG_PATH_QUEUE_AMQP_VIRTUAL_HOST = 'queue/amqp/virtualhost';
3738
const CONFIG_PATH_QUEUE_AMQP_SSL = 'queue/amqp/ssl';
39+
const CONFIG_PATH_QUEUE_AMQP_SSL_OPTIONS = 'queue/amqp/ssl_options';
3840

3941
/**
4042
* Default values
@@ -109,6 +111,13 @@ public function getOptions()
109111
'Amqp SSL',
110112
self::DEFAULT_AMQP_SSL
111113
),
114+
new TextConfigOption(
115+
self::INPUT_KEY_QUEUE_AMQP_SSL_OPTIONS,
116+
TextConfigOption::FRONTEND_WIZARD_TEXTAREA,
117+
self::CONFIG_PATH_QUEUE_AMQP_SSL_OPTIONS,
118+
'Amqp SSL Options (JSON)',
119+
self::DEFAULT_AMQP_SSL
120+
),
112121
];
113122
}
114123

@@ -140,6 +149,21 @@ public function createConfig(array $data, DeploymentConfig $deploymentConfig)
140149
if (!$this->isDataEmpty($data, self::INPUT_KEY_QUEUE_AMQP_SSL)) {
141150
$configData->set(self::CONFIG_PATH_QUEUE_AMQP_SSL, $data[self::INPUT_KEY_QUEUE_AMQP_SSL]);
142151
}
152+
if (!$this->isDataEmpty(
153+
$data,
154+
self::INPUT_KEY_QUEUE_AMQP_SSL_OPTIONS
155+
)) {
156+
$options = json_decode(
157+
$data[self::INPUT_KEY_QUEUE_AMQP_SSL_OPTIONS],
158+
true
159+
);
160+
if ($options !== null) {
161+
$configData->set(
162+
self::CONFIG_PATH_QUEUE_AMQP_SSL_OPTIONS,
163+
$options
164+
);
165+
}
166+
}
143167
}
144168

145169
return [$configData];
@@ -154,12 +178,28 @@ public function validate(array $options, DeploymentConfig $deploymentConfig)
154178

155179
if (isset($options[self::INPUT_KEY_QUEUE_AMQP_HOST])
156180
&& $options[self::INPUT_KEY_QUEUE_AMQP_HOST] !== '') {
181+
if (!$this->isDataEmpty(
182+
$options,
183+
self::INPUT_KEY_QUEUE_AMQP_SSL_OPTIONS
184+
)) {
185+
$sslOptions = json_decode(
186+
$options[self::INPUT_KEY_QUEUE_AMQP_SSL_OPTIONS],
187+
true
188+
);
189+
} else {
190+
$sslOptions = null;
191+
}
192+
$isSslEnabled = !empty($options[self::INPUT_KEY_QUEUE_AMQP_SSL])
193+
&& $options[self::INPUT_KEY_QUEUE_AMQP_SSL] !== 'false';
194+
157195
$result = $this->connectionValidator->isConnectionValid(
158196
$options[self::INPUT_KEY_QUEUE_AMQP_HOST],
159197
$options[self::INPUT_KEY_QUEUE_AMQP_PORT],
160198
$options[self::INPUT_KEY_QUEUE_AMQP_USER],
161199
$options[self::INPUT_KEY_QUEUE_AMQP_PASSWORD],
162-
$options[self::INPUT_KEY_QUEUE_AMQP_VIRTUAL_HOST]
200+
$options[self::INPUT_KEY_QUEUE_AMQP_VIRTUAL_HOST],
201+
$isSslEnabled,
202+
$sslOptions
163203
);
164204

165205
if (!$result) {

app/code/Magento/Amqp/Setup/ConnectionValidator.php

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,27 @@
55
*/
66
namespace Magento\Amqp\Setup;
77

8-
use PhpAmqpLib\Connection\AMQPStreamConnection;
8+
use Magento\Framework\Amqp\Connection\Factory as ConnectionFactory;
9+
use Magento\Framework\Amqp\Connection\FactoryOptions;
910

1011
/**
1112
* Class ConnectionValidator - validates Amqp related settings
1213
*/
1314
class ConnectionValidator
1415
{
16+
/**
17+
* @var ConnectionFactory
18+
*/
19+
private $connectionFactory;
20+
21+
/**
22+
* @param ConnectionFactory $connectionFactory
23+
*/
24+
public function __construct(ConnectionFactory $connectionFactory)
25+
{
26+
$this->connectionFactory = $connectionFactory;
27+
}
28+
1529
/**
1630
* Checks Amqp Connection
1731
*
@@ -20,18 +34,33 @@ class ConnectionValidator
2034
* @param string $user
2135
* @param string $password
2236
* @param string $virtualHost
37+
* @param bool $ssl
38+
* @param string[]|null $sslOptions
2339
* @return bool true if the connection succeeded, false otherwise
2440
*/
25-
public function isConnectionValid($host, $port, $user, $password = '', $virtualHost = '')
26-
{
41+
public function isConnectionValid(
42+
$host,
43+
$port,
44+
$user,
45+
$password = '',
46+
$virtualHost = '',
47+
bool $ssl = false,
48+
array $sslOptions = null
49+
) {
2750
try {
28-
$connection = new AMQPStreamConnection(
29-
$host,
30-
$port,
31-
$user,
32-
$password,
33-
$virtualHost
34-
);
51+
$options = new FactoryOptions();
52+
$options->setHost($host);
53+
$options->setPort($port);
54+
$options->setUsername($user);
55+
$options->setPassword($password);
56+
$options->setVirtualHost($virtualHost);
57+
$options->setSslEnabled($ssl);
58+
59+
if ($sslOptions) {
60+
$options->setSslOptions($sslOptions);
61+
}
62+
63+
$connection = $this->connectionFactory->create($options);
3564

3665
$connection->close();
3766
} catch (\Exception $e) {

app/code/Magento/Amqp/Test/Unit/Setup/ConfigOptionsListTest.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ protected function setUp()
4747
ConfigOptionsList::INPUT_KEY_QUEUE_AMQP_PASSWORD => 'password',
4848
ConfigOptionsList::INPUT_KEY_QUEUE_AMQP_VIRTUAL_HOST => 'virtual host',
4949
ConfigOptionsList::INPUT_KEY_QUEUE_AMQP_SSL => 'ssl',
50-
50+
ConfigOptionsList::INPUT_KEY_QUEUE_AMQP_SSL_OPTIONS => '{"ssl_option":"test"}',
5151
];
5252

5353
$this->objectManager = new ObjectManager($this);
@@ -113,7 +113,14 @@ public function testGetOptions()
113113
ConfigOptionsList::CONFIG_PATH_QUEUE_AMQP_SSL,
114114
'Amqp SSL',
115115
ConfigOptionsList::DEFAULT_AMQP_SSL
116-
)
116+
),
117+
new TextConfigOption(
118+
ConfigOptionsList::INPUT_KEY_QUEUE_AMQP_SSL_OPTIONS,
119+
TextConfigOption::FRONTEND_WIZARD_TEXTAREA,
120+
ConfigOptionsList::CONFIG_PATH_QUEUE_AMQP_SSL_OPTIONS,
121+
'Amqp SSL Options (JSON)',
122+
ConfigOptionsList::DEFAULT_AMQP_SSL
123+
),
117124
];
118125
$this->assertEquals($expectedOptions, $this->model->getOptions());
119126
}
@@ -167,6 +174,7 @@ public function getCreateConfigDataProvider()
167174
ConfigOptionsList::INPUT_KEY_QUEUE_AMQP_PASSWORD => 'password',
168175
ConfigOptionsList::INPUT_KEY_QUEUE_AMQP_VIRTUAL_HOST => 'virtual host',
169176
ConfigOptionsList::INPUT_KEY_QUEUE_AMQP_SSL => 'ssl',
177+
ConfigOptionsList::INPUT_KEY_QUEUE_AMQP_SSL_OPTIONS => '{"ssl_option":"test"}',
170178
],
171179
['queue' =>
172180
['amqp' =>
@@ -177,6 +185,7 @@ public function getCreateConfigDataProvider()
177185
'password' => 'password',
178186
'virtualhost' => 'virtual host',
179187
'ssl' => 'ssl',
188+
'ssl_options' => ['ssl_option' => 'test'],
180189
]
181190
]
182191
],
@@ -189,6 +198,7 @@ public function getCreateConfigDataProvider()
189198
ConfigOptionsList::INPUT_KEY_QUEUE_AMQP_PASSWORD => 'password',
190199
ConfigOptionsList::INPUT_KEY_QUEUE_AMQP_VIRTUAL_HOST => 'virtual host',
191200
ConfigOptionsList::INPUT_KEY_QUEUE_AMQP_SSL => 'ssl',
201+
ConfigOptionsList::INPUT_KEY_QUEUE_AMQP_SSL_OPTIONS => '{"ssl_option":"test"}',
192202
],
193203
['queue' =>
194204
['amqp' =>
@@ -199,6 +209,7 @@ public function getCreateConfigDataProvider()
199209
'password' => 'password',
200210
'virtualhost' => 'virtual host',
201211
'ssl' => 'ssl',
212+
'ssl_options' => ['ssl_option' => 'test'],
202213
]
203214
]
204215
],

app/code/Magento/Bundle/Pricing/Price/BundleRegularPrice.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function getAmount()
5252
if ($this->product->getPriceType() == Price::PRICE_TYPE_FIXED) {
5353
/** @var \Magento\Catalog\Pricing\Price\CustomOptionPrice $customOptionPrice */
5454
$customOptionPrice = $this->priceInfo->getPrice(CustomOptionPrice::PRICE_CODE);
55-
$price += $customOptionPrice->getCustomOptionRange(true);
55+
$price += $customOptionPrice->getCustomOptionRange(true, $this->getPriceCode());
5656
}
5757
$this->amount[$this->getValue()] = $this->calculator->getMinRegularAmount($price, $this->product);
5858
}
@@ -71,7 +71,7 @@ public function getMaximalPrice()
7171
if ($this->product->getPriceType() == Price::PRICE_TYPE_FIXED) {
7272
/** @var \Magento\Catalog\Pricing\Price\CustomOptionPrice $customOptionPrice */
7373
$customOptionPrice = $this->priceInfo->getPrice(CustomOptionPrice::PRICE_CODE);
74-
$price += $customOptionPrice->getCustomOptionRange(false);
74+
$price += $customOptionPrice->getCustomOptionRange(false, $this->getPriceCode());
7575
}
7676
$this->maximalPrice = $this->calculator->getMaxRegularAmount($price, $this->product);
7777
}

app/code/Magento/Bundle/Pricing/Price/BundleSelectionPrice.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ public function getValue()
128128
'catalog_product_get_final_price',
129129
['product' => $product, 'qty' => $this->bundleProduct->getQty()]
130130
);
131-
$value = $product->getData('final_price') * ($selectionPriceValue / 100);
131+
$price = $this->useRegularPrice ? $product->getData('price') : $product->getData('final_price');
132+
$value = $price * ($selectionPriceValue / 100);
132133
} else {
133134
// calculate price for selection type fixed
134135
$value = $this->priceCurrency->convert($selectionPriceValue);

app/code/Magento/Bundle/Test/Unit/Pricing/Price/BundleSelectionPriceTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ public function testGetValueTypeFixedWithSelectionPriceType($useRegularPrice)
201201
[
202202
['qty', null, 1],
203203
['final_price', null, 100],
204+
['price', null, 100],
204205
]
205206
)
206207
);

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,7 @@ public function getUpdatedAt()
625625
*
626626
* @param bool $calculate
627627
* @return void
628+
* @deprecated
628629
*/
629630
public function setPriceCalculation($calculate = true)
630631
{
@@ -1174,10 +1175,11 @@ public function setFinalPrice($price)
11741175
*/
11751176
public function getFinalPrice($qty = null)
11761177
{
1177-
if ($this->_getData('final_price') === null) {
1178-
$this->setFinalPrice($this->getPriceModel()->getFinalPrice($qty, $this));
1178+
if ($this->_calculatePrice || $this->_getData('final_price') === null) {
1179+
return $this->getPriceModel()->getFinalPrice($qty, $this);
1180+
} else {
1181+
return $this->_getData('final_price');
11791182
}
1180-
return $this->_getData('final_price');
11811183
}
11821184

11831185
/**

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

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88

99
use Magento\Catalog\Model\Product;
1010
use Magento\Catalog\Model\Product\Option;
11-
use Magento\Catalog\Pricing\Price\BasePrice;
1211
use Magento\Framework\Model\AbstractModel;
12+
use Magento\Catalog\Pricing\Price\BasePrice;
13+
use Magento\Catalog\Pricing\Price\CustomOptionPriceCalculator;
14+
use Magento\Catalog\Pricing\Price\RegularPrice;
1315

1416
/**
1517
* Catalog product option select type model
@@ -19,6 +21,9 @@
1921
* @method \Magento\Catalog\Model\Product\Option\Value setOptionId(int $value)
2022
*
2123
* @SuppressWarnings(PHPMD.LongVariable)
24+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) - added use of constants instead of string literals:
25+
* BasePrice::PRICE_CODE - instead of 'base_price'
26+
* RegularPrice::PRICE_CODE - instead of 'regular_price'
2227
* @since 100.0.2
2328
*/
2429
class Value extends AbstractModel implements \Magento\Catalog\Api\Data\ProductCustomOptionValuesInterface
@@ -59,6 +64,11 @@ class Value extends AbstractModel implements \Magento\Catalog\Api\Data\ProductCu
5964
*/
6065
protected $_valueCollectionFactory;
6166

67+
/**
68+
* @var CustomOptionPriceCalculator
69+
*/
70+
private $customOptionPriceCalculator;
71+
6272
/**
6373
* @param \Magento\Framework\Model\Context $context
6474
* @param \Magento\Framework\Registry $registry
@@ -73,9 +83,12 @@ public function __construct(
7383
\Magento\Catalog\Model\ResourceModel\Product\Option\Value\CollectionFactory $valueCollectionFactory,
7484
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
7585
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
76-
array $data = []
86+
array $data = [],
87+
CustomOptionPriceCalculator $customOptionPriceCalculator = null
7788
) {
7889
$this->_valueCollectionFactory = $valueCollectionFactory;
90+
$this->customOptionPriceCalculator = $customOptionPriceCalculator
91+
?? \Magento\Framework\App\ObjectManager::getInstance()->get(CustomOptionPriceCalculator::class);
7992
parent::__construct(
8093
$context,
8194
$registry,
@@ -222,10 +235,8 @@ public function saveValues()
222235
*/
223236
public function getPrice($flag = false)
224237
{
225-
if ($flag && $this->getPriceType() == self::TYPE_PERCENT) {
226-
$basePrice = $this->getOption()->getProduct()->getPriceInfo()->getPrice(BasePrice::PRICE_CODE)->getValue();
227-
$price = $basePrice * ($this->_getData(self::KEY_PRICE) / 100);
228-
return $price;
238+
if ($flag) {
239+
return $this->customOptionPriceCalculator->getOptionPriceByPriceCode($this, BasePrice::PRICE_CODE);
229240
}
230241
return $this->_getData(self::KEY_PRICE);
231242
}
@@ -237,13 +248,7 @@ public function getPrice($flag = false)
237248
*/
238249
public function getRegularPrice()
239250
{
240-
if ($this->getPriceType() == self::TYPE_PERCENT) {
241-
$basePrice = $this->getOption()->getProduct()->getPriceInfo()
242-
->getPrice('regular_price')->getAmount()->getValue();
243-
$price = $basePrice * ($this->_getData(self::KEY_PRICE) / 100);
244-
return $price;
245-
}
246-
return $this->_getData(self::KEY_PRICE);
251+
return $this->customOptionPriceCalculator->getOptionPriceByPriceCode($this, RegularPrice::PRICE_CODE);
247252
}
248253

249254
/**

0 commit comments

Comments
 (0)