Skip to content

Commit

Permalink
Merge pull request magento#3856 from magento-arcticfoxes/2.3.1-qwerty-pr
Browse files Browse the repository at this point in the history
[2.3.1-qwerty] Sync with 2.3.1-release
  • Loading branch information
joanhe authored Mar 6, 2019
2 parents 863e2bd + 8ebf3e0 commit 0048c0e
Show file tree
Hide file tree
Showing 27 changed files with 451 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,30 @@
<element name="attributeSetFilterResult" type="input" selector="div[data-index='attribute_set_id'] .action-menu-item._last" timeout="30"/>
<element name="attributeSetFilterResultByName" type="text" selector="//label/span[text() = '{{var}}']" timeout="30" parameterized="true"/>
<element name="productName" type="input" selector=".admin__field[data-index=name] input"/>
<element name="productNameDisabled" type="input" selector=".admin__field[data-index=name] input[disabled=true]"/>
<element name="RequiredNameIndicator" type="text" selector=" return window.getComputedStyle(document.querySelector('._required[data-index=name]&gt;.admin__field-label span'), ':after').getPropertyValue('content');"/>
<element name="RequiredSkuIndicator" type="text" selector=" return window.getComputedStyle(document.querySelector('._required[data-index=sku]&gt;.admin__field-label span'), ':after').getPropertyValue('content');"/>
<element name="productSku" type="input" selector=".admin__field[data-index=sku] input"/>
<element name="productSkuDisabled" type="input" selector=".admin__field[data-index=sku] input[disabled=true]"/>
<element name="enableProductAttributeLabel" type="text" selector="//span[text()='Enable Product']/parent::label"/>
<element name="enableProductAttributeLabelWrapper" type="text" selector="//span[text()='Enable Product']/parent::label/parent::div"/>
<element name="productStatus" type="checkbox" selector="input[name='product[status]']"/>
<element name="productStatusDisabled" type="checkbox" selector="input[name='product[status]'][disabled]"/>
<element name="enableProductLabel" type="checkbox" selector="input[name='product[status]']+label"/>
<element name="productStatusUseDefault" type="checkbox" selector="input[name='use_default[status]']"/>
<element name="productNameUseDefault" type="checkbox" selector="input[name='use_default[name]']"/>
<element name="productPrice" type="input" selector=".admin__field[data-index=price] input"/>
<element name="productPriceDisabled" type="input" selector=".admin__field[data-index=price] input[disabled=true]"/>
<element name="productPriceUseDefault" type="checkbox" selector=".admin__field[data-index=price] [name='use_default[price]']"/>
<element name="productTaxClass" type="select" selector="//*[@name='product[tax_class_id]']"/>
<element name="productTaxClassDisabled" type="select" selector="select[name='product[tax_class_id]'][disabled=true]"/>
<element name="productTaxClassUseDefault" type="checkbox" selector="input[name='use_default[tax_class_id]']"/>
<element name="advancedPricingLink" type="button" selector="button[data-index='advanced_pricing_button']" timeout="30"/>
<element name="categoriesDropdown" type="multiselect" selector="div[data-index='category_ids']"/>
<element name="productQuantity" type="input" selector=".admin__field[data-index=qty] input"/>
<element name="advancedInventoryLink" type="button" selector="//button[contains(@data-index, 'advanced_inventory_button')]" timeout="30"/>
<element name="productStockStatus" type="select" selector="select[name='product[quantity_and_stock_status][is_in_stock]']"/>
<element name="productStockStatusDisabled" type="select" selector="select[name='product[quantity_and_stock_status][is_in_stock]'][disabled=true]"/>
<element name="stockStatus" type="select" selector="[data-index='product-details'] select[name='product[quantity_and_stock_status][is_in_stock]']"/>
<element name="productWeight" type="input" selector=".admin__field[data-index=weight] input"/>
<element name="productWeightSelect" type="select" selector="select[name='product[product_has_weight]']"/>
Expand All @@ -47,6 +54,7 @@
<element name="productFormTab" type="button" selector="//strong[@class='admin__collapsible-title']/span[contains(text(), '{{tabName}}')]" parameterized="true"/>
<element name="productFormTabState" type="text" selector="//strong[@class='admin__collapsible-title']/span[contains(text(), '{{tabName}}')]/parent::*/parent::*[@data-state-collapsible='{{state}}']" parameterized="true"/>
<element name="visibility" type="select" selector="//select[@name='product[visibility]']"/>
<element name="visibilityDisabled" type="select" selector="select[name='product[visibility]'][disabled=true]"/>
<element name="visibilityUseDefault" type="checkbox" selector="//input[@name='use_default[visibility]']"/>
<element name="divByDataIndex" type="input" selector="div[data-index='{{var}}']" parameterized="true"/>
<element name="setProductAsNewFrom" type="input" selector="input[name='product[news_from_date]']"/>
Expand Down
5 changes: 4 additions & 1 deletion app/code/Magento/ConfigurableImportExport/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_ConfigurableImportExport" >
<module name="Magento_ConfigurableImportExport">
<sequence>
<module name="Magento_ConfigurableProduct"/>
</sequence>
</module>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ define([

return Abstract.extend({
defaults: {
listens: {
isConfigurable: 'handlePriceValue'
},
imports: {
isConfigurable: '!ns = ${ $.ns }, index = configurable-matrix:isEmpty'
},
Expand All @@ -22,12 +19,15 @@ define([
}
},

/**
* Invokes initialize method of parent class,
* contains initialization logic
*/
/** @inheritdoc */
initialize: function () {
this._super();
// resolve initial disable state
this.handlePriceValue(this.isConfigurable);
// add listener to track "configurable" type
this.setListeners({
isConfigurable: 'handlePriceValue'
});

return this;
},
Expand All @@ -50,11 +50,10 @@ define([
* @param {String} isConfigurable
*/
handlePriceValue: function (isConfigurable) {
this.disabled(!!this.isUseDefault() || isConfigurable);

if (isConfigurable) {
this.disable();
this.clear();
} else {
this.enable();
}
}
});
Expand Down
41 changes: 21 additions & 20 deletions app/code/Magento/Msrp/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@

use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
use Magento\Framework\App\ObjectManager;
use Magento\Msrp\Model\Product\Attribute\Source\Type;
use Magento\Msrp\Pricing\MsrpPriceCalculatorInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;

/**
* Msrp data helper
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Data extends AbstractHelper
{
Expand Down Expand Up @@ -43,6 +46,11 @@ class Data extends AbstractHelper
*/
protected $productRepository;

/**
* @var MsrpPriceCalculatorInterface
*/
private $msrpPriceCalculator;

/**
* @param Context $context
* @param StoreManagerInterface $storeManager
Expand All @@ -51,6 +59,7 @@ class Data extends AbstractHelper
* @param \Magento\Msrp\Model\Config $config
* @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
* @param ProductRepositoryInterface $productRepository
* @param MsrpPriceCalculatorInterface|null $msrpPriceCalculator
*/
public function __construct(
Context $context,
Expand All @@ -59,7 +68,8 @@ public function __construct(
\Magento\Msrp\Model\Msrp $msrp,
\Magento\Msrp\Model\Config $config,
\Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency,
ProductRepositoryInterface $productRepository
ProductRepositoryInterface $productRepository,
MsrpPriceCalculatorInterface $msrpPriceCalculator = null
) {
parent::__construct($context);
$this->storeManager = $storeManager;
Expand All @@ -68,6 +78,8 @@ public function __construct(
$this->config = $config;
$this->priceCurrency = $priceCurrency;
$this->productRepository = $productRepository;
$this->msrpPriceCalculator = $msrpPriceCalculator
?: ObjectManager::getInstance()->get(MsrpPriceCalculatorInterface::class);
}

/**
Expand All @@ -78,6 +90,7 @@ public function __construct(
* @return bool
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function canApplyMsrp($product, $visibility = null)
{
Expand Down Expand Up @@ -111,6 +124,7 @@ public function canApplyMsrp($product, $visibility = null)
*
* @param Product $product
* @return string
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getMsrpPriceMessage($product)
{
Expand All @@ -128,6 +142,7 @@ public function getMsrpPriceMessage($product)
*
* @param int|Product $product
* @return bool
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function isShowPriceOnGesture($product)
{
Expand All @@ -139,6 +154,7 @@ public function isShowPriceOnGesture($product)
*
* @param int|Product $product
* @return bool
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function isShowBeforeOrderConfirm($product)
{
Expand All @@ -149,31 +165,16 @@ public function isShowBeforeOrderConfirm($product)
* Check if any MAP price is larger than as low as value.
*
* @param int|Product $product
* @return bool|float
* @return bool
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function isMinimalPriceLessMsrp($product)
{
if (is_numeric($product)) {
$product = $this->productRepository->getById($product, false, $this->storeManager->getStore()->getId());
}
$msrp = $product->getMsrp();
$msrp = $this->msrpPriceCalculator->getMsrpPriceValue($product);
$price = $product->getPriceInfo()->getPrice(\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE);
if ($msrp === null) {
if ($product->getTypeId() === \Magento\GroupedProduct\Model\Product\Type\Grouped::TYPE_CODE) {
$msrp = $product->getTypeInstance()->getChildrenMsrp($product);
} elseif ($product->getTypeId() === Configurable::TYPE_CODE) {
$prices = [];
foreach ($product->getTypeInstance()->getUsedProducts($product) as $item) {
if ($item->getMsrp() !== null) {
$prices[] = $item->getMsrp();
}
}

$msrp = $prices ? max($prices) : 0;
} else {
return false;
}
}
if ($msrp) {
$msrp = $this->priceCurrency->convertAndRound($msrp);
}
Expand Down
64 changes: 64 additions & 0 deletions app/code/Magento/Msrp/Pricing/MsrpPriceCalculator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\Msrp\Pricing;

use Magento\Catalog\Api\Data\ProductInterface;

/**
* @inheritdoc
*/
class MsrpPriceCalculator implements MsrpPriceCalculatorInterface
{
/**
* @var MsrpPriceCalculatorInterface[]
*/
private $msrpPriceCalculators;

/**
* @param array $msrpPriceCalculators
*/
public function __construct(array $msrpPriceCalculators)
{
$this->msrpPriceCalculators = $this->getMsrpPriceCalculators($msrpPriceCalculators);
}

/**
* @inheritdoc
*/
public function getMsrpPriceValue(ProductInterface $product): float
{
$productType = $product->getTypeId();
if (isset($this->msrpPriceCalculators[$productType])) {
$priceCalculator = $this->msrpPriceCalculators[$productType];
$msrp = $priceCalculator->getMsrpPriceValue($product);
} else {
$msrp = (float)$product->getMsrp();
}

return $msrp;
}

/**
* Convert the configuration of MSRP price calculators.
*
* @param array $msrpPriceCalculatorsConfig
* @return array
*/
private function getMsrpPriceCalculators(array $msrpPriceCalculatorsConfig): array
{
$msrpPriceCalculators = [];
foreach ($msrpPriceCalculatorsConfig as $msrpPriceCalculator) {
if (isset($msrpPriceCalculator['productType'], $msrpPriceCalculator['priceCalculator'])) {
$msrpPriceCalculators[$msrpPriceCalculator['productType']] =
$msrpPriceCalculator['priceCalculator'];
}
}
return $msrpPriceCalculators;
}
}
23 changes: 23 additions & 0 deletions app/code/Magento/Msrp/Pricing/MsrpPriceCalculatorInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Msrp\Pricing;

use Magento\Catalog\Api\Data\ProductInterface;

/**
* Provide information about MSRP price of a product.
*/
interface MsrpPriceCalculatorInterface
{
/**
* Return the value of MSRP product price.
*
* @param ProductInterface $product
* @return float
*/
public function getMsrpPriceValue(ProductInterface $product): float;
}
62 changes: 62 additions & 0 deletions app/code/Magento/Msrp/Pricing/Render/PriceBox.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\Msrp\Pricing\Render;

use Magento\Catalog\Model\Product;
use Magento\Framework\Json\Helper\Data;
use Magento\Framework\Math\Random;
use Magento\Framework\Pricing\Price\PriceInterface;
use Magento\Framework\Pricing\Render\RendererPool;
use Magento\Framework\View\Element\Template\Context;
use Magento\Msrp\Pricing\MsrpPriceCalculatorInterface;

/**
* MSRP price box render.
*/
class PriceBox extends \Magento\Catalog\Pricing\Render\PriceBox
{
/**
* @var MsrpPriceCalculatorInterface
*/
private $msrpPriceCalculator;

/**
* Constructor
*
* @param Context $context
* @param Product $saleableItem
* @param PriceInterface $price
* @param RendererPool $rendererPool
* @param Data $jsonHelper
* @param Random $mathRandom
* @param MsrpPriceCalculatorInterface $msrpPriceCalculator
*/
public function __construct(
Context $context,
Product $saleableItem,
PriceInterface $price,
RendererPool $rendererPool,
Data $jsonHelper,
Random $mathRandom,
MsrpPriceCalculatorInterface $msrpPriceCalculator
) {
$this->msrpPriceCalculator = $msrpPriceCalculator;
parent::__construct($context, $saleableItem, $price, $rendererPool, $jsonHelper, $mathRandom);
}

/**
* Return MSRP price calculator.
*
* @return MsrpPriceCalculatorInterface
*/
public function getMsrpPriceCalculator(): MsrpPriceCalculatorInterface
{
return $this->msrpPriceCalculator;
}
}
Loading

0 comments on commit 0048c0e

Please sign in to comment.