Skip to content

Commit 8ebf3e0

Browse files
author
Joan He
committed
Merge remote-tracking branch 'arcticfoxes/pr' into 2.3.1-qwerty-pr
2 parents 863e2bd + 12c6c9b commit 8ebf3e0

File tree

27 files changed

+451
-55
lines changed

27 files changed

+451
-55
lines changed

app/code/Magento/Catalog/Test/Mftf/Section/AdminProductFormSection.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,30 @@
1313
<element name="attributeSetFilterResult" type="input" selector="div[data-index='attribute_set_id'] .action-menu-item._last" timeout="30"/>
1414
<element name="attributeSetFilterResultByName" type="text" selector="//label/span[text() = '{{var}}']" timeout="30" parameterized="true"/>
1515
<element name="productName" type="input" selector=".admin__field[data-index=name] input"/>
16+
<element name="productNameDisabled" type="input" selector=".admin__field[data-index=name] input[disabled=true]"/>
1617
<element name="RequiredNameIndicator" type="text" selector=" return window.getComputedStyle(document.querySelector('._required[data-index=name]&gt;.admin__field-label span'), ':after').getPropertyValue('content');"/>
1718
<element name="RequiredSkuIndicator" type="text" selector=" return window.getComputedStyle(document.querySelector('._required[data-index=sku]&gt;.admin__field-label span'), ':after').getPropertyValue('content');"/>
1819
<element name="productSku" type="input" selector=".admin__field[data-index=sku] input"/>
20+
<element name="productSkuDisabled" type="input" selector=".admin__field[data-index=sku] input[disabled=true]"/>
1921
<element name="enableProductAttributeLabel" type="text" selector="//span[text()='Enable Product']/parent::label"/>
2022
<element name="enableProductAttributeLabelWrapper" type="text" selector="//span[text()='Enable Product']/parent::label/parent::div"/>
2123
<element name="productStatus" type="checkbox" selector="input[name='product[status]']"/>
24+
<element name="productStatusDisabled" type="checkbox" selector="input[name='product[status]'][disabled]"/>
2225
<element name="enableProductLabel" type="checkbox" selector="input[name='product[status]']+label"/>
2326
<element name="productStatusUseDefault" type="checkbox" selector="input[name='use_default[status]']"/>
2427
<element name="productNameUseDefault" type="checkbox" selector="input[name='use_default[name]']"/>
2528
<element name="productPrice" type="input" selector=".admin__field[data-index=price] input"/>
29+
<element name="productPriceDisabled" type="input" selector=".admin__field[data-index=price] input[disabled=true]"/>
30+
<element name="productPriceUseDefault" type="checkbox" selector=".admin__field[data-index=price] [name='use_default[price]']"/>
2631
<element name="productTaxClass" type="select" selector="//*[@name='product[tax_class_id]']"/>
32+
<element name="productTaxClassDisabled" type="select" selector="select[name='product[tax_class_id]'][disabled=true]"/>
2733
<element name="productTaxClassUseDefault" type="checkbox" selector="input[name='use_default[tax_class_id]']"/>
2834
<element name="advancedPricingLink" type="button" selector="button[data-index='advanced_pricing_button']" timeout="30"/>
2935
<element name="categoriesDropdown" type="multiselect" selector="div[data-index='category_ids']"/>
3036
<element name="productQuantity" type="input" selector=".admin__field[data-index=qty] input"/>
3137
<element name="advancedInventoryLink" type="button" selector="//button[contains(@data-index, 'advanced_inventory_button')]" timeout="30"/>
3238
<element name="productStockStatus" type="select" selector="select[name='product[quantity_and_stock_status][is_in_stock]']"/>
39+
<element name="productStockStatusDisabled" type="select" selector="select[name='product[quantity_and_stock_status][is_in_stock]'][disabled=true]"/>
3340
<element name="stockStatus" type="select" selector="[data-index='product-details'] select[name='product[quantity_and_stock_status][is_in_stock]']"/>
3441
<element name="productWeight" type="input" selector=".admin__field[data-index=weight] input"/>
3542
<element name="productWeightSelect" type="select" selector="select[name='product[product_has_weight]']"/>
@@ -47,6 +54,7 @@
4754
<element name="productFormTab" type="button" selector="//strong[@class='admin__collapsible-title']/span[contains(text(), '{{tabName}}')]" parameterized="true"/>
4855
<element name="productFormTabState" type="text" selector="//strong[@class='admin__collapsible-title']/span[contains(text(), '{{tabName}}')]/parent::*/parent::*[@data-state-collapsible='{{state}}']" parameterized="true"/>
4956
<element name="visibility" type="select" selector="//select[@name='product[visibility]']"/>
57+
<element name="visibilityDisabled" type="select" selector="select[name='product[visibility]'][disabled=true]"/>
5058
<element name="visibilityUseDefault" type="checkbox" selector="//input[@name='use_default[visibility]']"/>
5159
<element name="divByDataIndex" type="input" selector="div[data-index='{{var}}']" parameterized="true"/>
5260
<element name="setProductAsNewFrom" type="input" selector="input[name='product[news_from_date]']"/>

app/code/Magento/ConfigurableImportExport/etc/module.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9-
<module name="Magento_ConfigurableImportExport" >
9+
<module name="Magento_ConfigurableImportExport">
10+
<sequence>
11+
<module name="Magento_ConfigurableProduct"/>
12+
</sequence>
1013
</module>
1114
</config>

app/code/Magento/ConfigurableProduct/view/adminhtml/web/js/components/price-configurable.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ define([
1111

1212
return Abstract.extend({
1313
defaults: {
14-
listens: {
15-
isConfigurable: 'handlePriceValue'
16-
},
1714
imports: {
1815
isConfigurable: '!ns = ${ $.ns }, index = configurable-matrix:isEmpty'
1916
},
@@ -22,12 +19,15 @@ define([
2219
}
2320
},
2421

25-
/**
26-
* Invokes initialize method of parent class,
27-
* contains initialization logic
28-
*/
22+
/** @inheritdoc */
2923
initialize: function () {
3024
this._super();
25+
// resolve initial disable state
26+
this.handlePriceValue(this.isConfigurable);
27+
// add listener to track "configurable" type
28+
this.setListeners({
29+
isConfigurable: 'handlePriceValue'
30+
});
3131

3232
return this;
3333
},
@@ -50,11 +50,10 @@ define([
5050
* @param {String} isConfigurable
5151
*/
5252
handlePriceValue: function (isConfigurable) {
53+
this.disabled(!!this.isUseDefault() || isConfigurable);
54+
5355
if (isConfigurable) {
54-
this.disable();
5556
this.clear();
56-
} else {
57-
this.enable();
5857
}
5958
}
6059
});

app/code/Magento/Msrp/Helper/Data.php

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@
77

88
use Magento\Framework\App\Helper\AbstractHelper;
99
use Magento\Framework\App\Helper\Context;
10+
use Magento\Framework\App\ObjectManager;
1011
use Magento\Msrp\Model\Product\Attribute\Source\Type;
12+
use Magento\Msrp\Pricing\MsrpPriceCalculatorInterface;
1113
use Magento\Store\Model\StoreManagerInterface;
1214
use Magento\Catalog\Model\Product;
1315
use Magento\Catalog\Api\ProductRepositoryInterface;
14-
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
1516

1617
/**
1718
* Msrp data helper
19+
*
20+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1821
*/
1922
class Data extends AbstractHelper
2023
{
@@ -43,6 +46,11 @@ class Data extends AbstractHelper
4346
*/
4447
protected $productRepository;
4548

49+
/**
50+
* @var MsrpPriceCalculatorInterface
51+
*/
52+
private $msrpPriceCalculator;
53+
4654
/**
4755
* @param Context $context
4856
* @param StoreManagerInterface $storeManager
@@ -51,6 +59,7 @@ class Data extends AbstractHelper
5159
* @param \Magento\Msrp\Model\Config $config
5260
* @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
5361
* @param ProductRepositoryInterface $productRepository
62+
* @param MsrpPriceCalculatorInterface|null $msrpPriceCalculator
5463
*/
5564
public function __construct(
5665
Context $context,
@@ -59,7 +68,8 @@ public function __construct(
5968
\Magento\Msrp\Model\Msrp $msrp,
6069
\Magento\Msrp\Model\Config $config,
6170
\Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency,
62-
ProductRepositoryInterface $productRepository
71+
ProductRepositoryInterface $productRepository,
72+
MsrpPriceCalculatorInterface $msrpPriceCalculator = null
6373
) {
6474
parent::__construct($context);
6575
$this->storeManager = $storeManager;
@@ -68,6 +78,8 @@ public function __construct(
6878
$this->config = $config;
6979
$this->priceCurrency = $priceCurrency;
7080
$this->productRepository = $productRepository;
81+
$this->msrpPriceCalculator = $msrpPriceCalculator
82+
?: ObjectManager::getInstance()->get(MsrpPriceCalculatorInterface::class);
7183
}
7284

7385
/**
@@ -78,6 +90,7 @@ public function __construct(
7890
* @return bool
7991
*
8092
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
93+
* @throws \Magento\Framework\Exception\NoSuchEntityException
8194
*/
8295
public function canApplyMsrp($product, $visibility = null)
8396
{
@@ -111,6 +124,7 @@ public function canApplyMsrp($product, $visibility = null)
111124
*
112125
* @param Product $product
113126
* @return string
127+
* @throws \Magento\Framework\Exception\NoSuchEntityException
114128
*/
115129
public function getMsrpPriceMessage($product)
116130
{
@@ -128,6 +142,7 @@ public function getMsrpPriceMessage($product)
128142
*
129143
* @param int|Product $product
130144
* @return bool
145+
* @throws \Magento\Framework\Exception\NoSuchEntityException
131146
*/
132147
public function isShowPriceOnGesture($product)
133148
{
@@ -139,6 +154,7 @@ public function isShowPriceOnGesture($product)
139154
*
140155
* @param int|Product $product
141156
* @return bool
157+
* @throws \Magento\Framework\Exception\NoSuchEntityException
142158
*/
143159
public function isShowBeforeOrderConfirm($product)
144160
{
@@ -149,31 +165,16 @@ public function isShowBeforeOrderConfirm($product)
149165
* Check if any MAP price is larger than as low as value.
150166
*
151167
* @param int|Product $product
152-
* @return bool|float
168+
* @return bool
169+
* @throws \Magento\Framework\Exception\NoSuchEntityException
153170
*/
154171
public function isMinimalPriceLessMsrp($product)
155172
{
156173
if (is_numeric($product)) {
157174
$product = $this->productRepository->getById($product, false, $this->storeManager->getStore()->getId());
158175
}
159-
$msrp = $product->getMsrp();
176+
$msrp = $this->msrpPriceCalculator->getMsrpPriceValue($product);
160177
$price = $product->getPriceInfo()->getPrice(\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE);
161-
if ($msrp === null) {
162-
if ($product->getTypeId() === \Magento\GroupedProduct\Model\Product\Type\Grouped::TYPE_CODE) {
163-
$msrp = $product->getTypeInstance()->getChildrenMsrp($product);
164-
} elseif ($product->getTypeId() === Configurable::TYPE_CODE) {
165-
$prices = [];
166-
foreach ($product->getTypeInstance()->getUsedProducts($product) as $item) {
167-
if ($item->getMsrp() !== null) {
168-
$prices[] = $item->getMsrp();
169-
}
170-
}
171-
172-
$msrp = $prices ? max($prices) : 0;
173-
} else {
174-
return false;
175-
}
176-
}
177178
if ($msrp) {
178179
$msrp = $this->priceCurrency->convertAndRound($msrp);
179180
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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\Msrp\Pricing;
10+
11+
use Magento\Catalog\Api\Data\ProductInterface;
12+
13+
/**
14+
* @inheritdoc
15+
*/
16+
class MsrpPriceCalculator implements MsrpPriceCalculatorInterface
17+
{
18+
/**
19+
* @var MsrpPriceCalculatorInterface[]
20+
*/
21+
private $msrpPriceCalculators;
22+
23+
/**
24+
* @param array $msrpPriceCalculators
25+
*/
26+
public function __construct(array $msrpPriceCalculators)
27+
{
28+
$this->msrpPriceCalculators = $this->getMsrpPriceCalculators($msrpPriceCalculators);
29+
}
30+
31+
/**
32+
* @inheritdoc
33+
*/
34+
public function getMsrpPriceValue(ProductInterface $product): float
35+
{
36+
$productType = $product->getTypeId();
37+
if (isset($this->msrpPriceCalculators[$productType])) {
38+
$priceCalculator = $this->msrpPriceCalculators[$productType];
39+
$msrp = $priceCalculator->getMsrpPriceValue($product);
40+
} else {
41+
$msrp = (float)$product->getMsrp();
42+
}
43+
44+
return $msrp;
45+
}
46+
47+
/**
48+
* Convert the configuration of MSRP price calculators.
49+
*
50+
* @param array $msrpPriceCalculatorsConfig
51+
* @return array
52+
*/
53+
private function getMsrpPriceCalculators(array $msrpPriceCalculatorsConfig): array
54+
{
55+
$msrpPriceCalculators = [];
56+
foreach ($msrpPriceCalculatorsConfig as $msrpPriceCalculator) {
57+
if (isset($msrpPriceCalculator['productType'], $msrpPriceCalculator['priceCalculator'])) {
58+
$msrpPriceCalculators[$msrpPriceCalculator['productType']] =
59+
$msrpPriceCalculator['priceCalculator'];
60+
}
61+
}
62+
return $msrpPriceCalculators;
63+
}
64+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Msrp\Pricing;
8+
9+
use Magento\Catalog\Api\Data\ProductInterface;
10+
11+
/**
12+
* Provide information about MSRP price of a product.
13+
*/
14+
interface MsrpPriceCalculatorInterface
15+
{
16+
/**
17+
* Return the value of MSRP product price.
18+
*
19+
* @param ProductInterface $product
20+
* @return float
21+
*/
22+
public function getMsrpPriceValue(ProductInterface $product): float;
23+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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\Msrp\Pricing\Render;
10+
11+
use Magento\Catalog\Model\Product;
12+
use Magento\Framework\Json\Helper\Data;
13+
use Magento\Framework\Math\Random;
14+
use Magento\Framework\Pricing\Price\PriceInterface;
15+
use Magento\Framework\Pricing\Render\RendererPool;
16+
use Magento\Framework\View\Element\Template\Context;
17+
use Magento\Msrp\Pricing\MsrpPriceCalculatorInterface;
18+
19+
/**
20+
* MSRP price box render.
21+
*/
22+
class PriceBox extends \Magento\Catalog\Pricing\Render\PriceBox
23+
{
24+
/**
25+
* @var MsrpPriceCalculatorInterface
26+
*/
27+
private $msrpPriceCalculator;
28+
29+
/**
30+
* Constructor
31+
*
32+
* @param Context $context
33+
* @param Product $saleableItem
34+
* @param PriceInterface $price
35+
* @param RendererPool $rendererPool
36+
* @param Data $jsonHelper
37+
* @param Random $mathRandom
38+
* @param MsrpPriceCalculatorInterface $msrpPriceCalculator
39+
*/
40+
public function __construct(
41+
Context $context,
42+
Product $saleableItem,
43+
PriceInterface $price,
44+
RendererPool $rendererPool,
45+
Data $jsonHelper,
46+
Random $mathRandom,
47+
MsrpPriceCalculatorInterface $msrpPriceCalculator
48+
) {
49+
$this->msrpPriceCalculator = $msrpPriceCalculator;
50+
parent::__construct($context, $saleableItem, $price, $rendererPool, $jsonHelper, $mathRandom);
51+
}
52+
53+
/**
54+
* Return MSRP price calculator.
55+
*
56+
* @return MsrpPriceCalculatorInterface
57+
*/
58+
public function getMsrpPriceCalculator(): MsrpPriceCalculatorInterface
59+
{
60+
return $this->msrpPriceCalculator;
61+
}
62+
}

0 commit comments

Comments
 (0)