Skip to content

Commit

Permalink
ENGCOM-8315: Added correct block class for frontend viewModel referen…
Browse files Browse the repository at this point in the history
…ce example. #30358
  • Loading branch information
sidolov committed Oct 12, 2020
2 parents 5c30cdb + 5f7969d commit 9f4fd32
Show file tree
Hide file tree
Showing 94 changed files with 3,114 additions and 404 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@
<element name="success" type="text" selector="#system_messages div.message-success"/>
<element name="warning" type="text" selector="#system_messages div.message-warning"/>
<element name="notice" type="text" selector="#system_messages div.message-notice"/>
<element name="info" type="text" selector="#system_messages div.message-info"/>
<element name="viewDetailsLink" type="button" selector="//div[contains(@class, 'message-system-short')]/a[contains(text(), 'View Details')]" timeout="30"/>
</section>
</sections>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
<section name="AdminBulkDetailsModalSection">
<element name="descriptionValue" type="text" selector="//aside//div[@data-index='description']//span[@name='description']"/>
<element name="summaryValue" type="text" selector="//aside//div[@data-index='summary']//span[@name='summary']" />
<element name="startTimeValue" type="text" selector="//aside//div[@data-index='start_time']//span[@name='start_time']" />
</section>
</sections>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@

namespace Magento\Catalog\Block\Product\View\Options;

use Magento\Catalog\Pricing\Price\BasePrice;
use Magento\Catalog\Pricing\Price\CalculateCustomOptionCatalogRule;
use Magento\Catalog\Pricing\Price\CustomOptionPriceInterface;
use Magento\Framework\App\ObjectManager;

/**
* Product options section abstract block.
Expand Down Expand Up @@ -47,20 +50,29 @@ abstract class AbstractOptions extends \Magento\Framework\View\Element\Template
*/
protected $_catalogHelper;

/**
* @var CalculateCustomOptionCatalogRule
*/
private $calculateCustomOptionCatalogRule;

/**
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Framework\Pricing\Helper\Data $pricingHelper
* @param \Magento\Catalog\Helper\Data $catalogData
* @param array $data
* @param CalculateCustomOptionCatalogRule|null $calculateCustomOptionCatalogRule
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Framework\Pricing\Helper\Data $pricingHelper,
\Magento\Catalog\Helper\Data $catalogData,
array $data = []
array $data = [],
CalculateCustomOptionCatalogRule $calculateCustomOptionCatalogRule = null
) {
$this->pricingHelper = $pricingHelper;
$this->_catalogHelper = $catalogData;
$this->calculateCustomOptionCatalogRule = $calculateCustomOptionCatalogRule
?? ObjectManager::getInstance()->get(CalculateCustomOptionCatalogRule::class);
parent::__construct($context, $data);
}

Expand Down Expand Up @@ -162,6 +174,19 @@ protected function _formatPrice($value, $flag = true)
$priceStr = $sign;

$customOptionPrice = $this->getProduct()->getPriceInfo()->getPrice('custom_option_price');
$isPercent = (bool) $value['is_percent'];

if (!$isPercent) {
$catalogPriceValue = $this->calculateCustomOptionCatalogRule->execute(
$this->getProduct(),
(float)$value['pricing_value'],
$isPercent
);
if ($catalogPriceValue !== null) {
$value['pricing_value'] = $catalogPriceValue;
}
}

$context = [CustomOptionPriceInterface::CONFIGURATION_OPTION_FLAG => true];
$optionAmount = $customOptionPrice->getCustomAmount($value['pricing_value'], null, $context);
$priceStr .= $this->getLayout()->getBlock('product.price.render.default')->renderAmount(
Expand Down
32 changes: 27 additions & 5 deletions app/code/Magento/Catalog/Model/Product/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
use Magento\Catalog\Model\Product\Option\Type\File;
use Magento\Catalog\Model\Product\Option\Type\Select;
use Magento\Catalog\Model\Product\Option\Type\Text;
use Magento\Catalog\Model\Product\Option\Value;
use Magento\Catalog\Model\ResourceModel\Product\Option\Value\Collection;
use Magento\Catalog\Pricing\Price\BasePrice;
use Magento\Catalog\Pricing\Price\CalculateCustomOptionCatalogRule;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Model\AbstractExtensibleModel;
Expand Down Expand Up @@ -123,6 +126,11 @@ class Option extends AbstractExtensibleModel implements ProductCustomOptionInter
*/
private $customOptionValuesFactory;

/**
* @var CalculateCustomOptionCatalogRule
*/
private $calculateCustomOptionCatalogRule;

/**
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
Expand All @@ -138,6 +146,7 @@ class Option extends AbstractExtensibleModel implements ProductCustomOptionInter
* @param ProductCustomOptionValuesInterfaceFactory|null $customOptionValuesFactory
* @param array $optionGroups
* @param array $optionTypesToGroups
* @param CalculateCustomOptionCatalogRule|null $calculateCustomOptionCatalogRule
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand All @@ -154,14 +163,17 @@ public function __construct(
array $data = [],
ProductCustomOptionValuesInterfaceFactory $customOptionValuesFactory = null,
array $optionGroups = [],
array $optionTypesToGroups = []
array $optionTypesToGroups = [],
CalculateCustomOptionCatalogRule $calculateCustomOptionCatalogRule = null
) {
$this->productOptionValue = $productOptionValue;
$this->optionTypeFactory = $optionFactory;
$this->string = $string;
$this->validatorPool = $validatorPool;
$this->customOptionValuesFactory = $customOptionValuesFactory ?:
\Magento\Framework\App\ObjectManager::getInstance()->get(ProductCustomOptionValuesInterfaceFactory::class);
ObjectManager::getInstance()->get(ProductCustomOptionValuesInterfaceFactory::class);
$this->calculateCustomOptionCatalogRule = $calculateCustomOptionCatalogRule ??
ObjectManager::getInstance()->get(CalculateCustomOptionCatalogRule::class);
$this->optionGroups = $optionGroups ?: [
self::OPTION_GROUP_DATE => Date::class,
self::OPTION_GROUP_FILE => File::class,
Expand Down Expand Up @@ -462,11 +474,21 @@ public function afterSave()
*/
public function getPrice($flag = false)
{
if ($flag && $this->getPriceType() == self::$typePercent) {
$basePrice = $this->getProduct()->getPriceInfo()->getPrice(BasePrice::PRICE_CODE)->getValue();
$price = $basePrice * ($this->_getData(self::KEY_PRICE) / 100);
if ($flag && $this->getPriceType() === self::$typePercent) {
$price = $this->calculateCustomOptionCatalogRule->execute(
$this->getProduct(),
(float)$this->getData(self::KEY_PRICE),
$this->getPriceType() === Value::TYPE_PERCENT
);

if ($price === null) {
$basePrice = $this->getProduct()->getPriceInfo()->getPrice(BasePrice::PRICE_CODE)->getValue();
$price = $basePrice * ($this->_getData(self::KEY_PRICE) / 100);
}

return $price;
}

return $this->_getData(self::KEY_PRICE);
}

Expand Down
28 changes: 26 additions & 2 deletions app/code/Magento/Catalog/Model/Product/Option/Type/DefaultType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface;
use Magento\Catalog\Model\Product\Configuration\Item\ItemInterface;
use Magento\Catalog\Model\Product\Option\Value;
use Magento\Catalog\Pricing\Price\CalculateCustomOptionCatalogRule;
use Magento\Framework\App\ObjectManager;

/**
* Catalog product option default type
Expand Down Expand Up @@ -60,21 +62,30 @@ class DefaultType extends \Magento\Framework\DataObject
*/
protected $_checkoutSession;

/**
* @var CalculateCustomOptionCatalogRule
*/
private $calculateCustomOptionCatalogRule;

/**
* Construct
*
* @param \Magento\Checkout\Model\Session $checkoutSession
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param array $data
* @param CalculateCustomOptionCatalogRule|null $calculateCustomOptionCatalogRule
*/
public function __construct(
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
array $data = []
array $data = [],
CalculateCustomOptionCatalogRule $calculateCustomOptionCatalogRule = null
) {
$this->_checkoutSession = $checkoutSession;
parent::__construct($data);
$this->_scopeConfig = $scopeConfig;
$this->calculateCustomOptionCatalogRule = $calculateCustomOptionCatalogRule ?? ObjectManager::getInstance()
->get(CalculateCustomOptionCatalogRule::class);
}

/**
Expand Down Expand Up @@ -341,7 +352,20 @@ public function getOptionPrice($optionValue, $basePrice)
{
$option = $this->getOption();

return $this->_getChargeableOptionPrice($option->getPrice(), $option->getPriceType() == 'percent', $basePrice);
$catalogPriceValue = $this->calculateCustomOptionCatalogRule->execute(
$option->getProduct(),
(float)$option->getPrice(),
$option->getPriceType() === Value::TYPE_PERCENT
);
if ($catalogPriceValue !== null) {
return $catalogPriceValue;
} else {
return $this->_getChargeableOptionPrice(
$option->getPrice(),
$option->getPriceType() === Value::TYPE_PERCENT,
$basePrice
);
}
}

/**
Expand Down
65 changes: 55 additions & 10 deletions app/code/Magento/Catalog/Model/Product/Option/Type/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

namespace Magento\Catalog\Model\Product\Option\Type;

use Magento\Catalog\Model\Product\Option\Value;
use Magento\Catalog\Pricing\Price\CalculateCustomOptionCatalogRule;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Exception\LocalizedException;
use Magento\Catalog\Model\Product\Option;

/**
* Catalog product option select type
Expand Down Expand Up @@ -37,21 +41,28 @@ class Select extends \Magento\Catalog\Model\Product\Option\Type\DefaultType
*/
private $singleSelectionTypes;

/**
* @var CalculateCustomOptionCatalogRule
*/
private $calculateCustomOptionCatalogRule;

/**
* @param \Magento\Checkout\Model\Session $checkoutSession
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param \Magento\Framework\Stdlib\StringUtils $string
* @param \Magento\Framework\Escaper $escaper
* @param array $data
* @param array $singleSelectionTypes
* @param CalculateCustomOptionCatalogRule|null $calculateCustomOptionCatalogRule
*/
public function __construct(
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Framework\Stdlib\StringUtils $string,
\Magento\Framework\Escaper $escaper,
array $data = [],
array $singleSelectionTypes = []
array $singleSelectionTypes = [],
CalculateCustomOptionCatalogRule $calculateCustomOptionCatalogRule = null
) {
$this->string = $string;
$this->_escaper = $escaper;
Expand All @@ -61,6 +72,8 @@ public function __construct(
'drop_down' => \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_DROP_DOWN,
'radio' => \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_RADIO,
];
$this->calculateCustomOptionCatalogRule = $calculateCustomOptionCatalogRule ?? ObjectManager::getInstance()
->get(CalculateCustomOptionCatalogRule::class);
}

/**
Expand Down Expand Up @@ -248,11 +261,7 @@ public function getOptionPrice($optionValue, $basePrice)
foreach (explode(',', $optionValue) as $value) {
$_result = $option->getValueById($value);
if ($_result) {
$result += $this->_getChargeableOptionPrice(
$_result->getPrice(),
$_result->getPriceType() == 'percent',
$basePrice
);
$result += $this->getCalculatedOptionValue($option, $_result, $basePrice);
} else {
if ($this->getListener()) {
$this->getListener()->setHasError(true)->setMessage($this->_getWrongConfigurationMessage());
Expand All @@ -263,11 +272,20 @@ public function getOptionPrice($optionValue, $basePrice)
} elseif ($this->_isSingleSelection()) {
$_result = $option->getValueById($optionValue);
if ($_result) {
$result = $this->_getChargeableOptionPrice(
$_result->getPrice(),
$_result->getPriceType() == 'percent',
$basePrice
$catalogPriceValue = $this->calculateCustomOptionCatalogRule->execute(
$option->getProduct(),
(float)$_result->getPrice(),
$_result->getPriceType() === Value::TYPE_PERCENT
);
if ($catalogPriceValue !== null) {
$result = $catalogPriceValue;
} else {
$result = $this->_getChargeableOptionPrice(
$_result->getPrice(),
$_result->getPriceType() == 'percent',
$basePrice
);
}
} else {
if ($this->getListener()) {
$this->getListener()->setHasError(true)->setMessage($this->_getWrongConfigurationMessage());
Expand Down Expand Up @@ -329,4 +347,31 @@ protected function _isSingleSelection()
{
return in_array($this->getOption()->getType(), $this->singleSelectionTypes, true);
}

/**
* Returns calculated price of option
*
* @param Option $option
* @param Option\Value $result
* @param float $basePrice
* @return float
*/
protected function getCalculatedOptionValue(Option $option, Value $result, float $basePrice) : float
{
$catalogPriceValue = $this->calculateCustomOptionCatalogRule->execute(
$option->getProduct(),
(float)$result->getPrice(),
$result->getPriceType() === Value::TYPE_PERCENT
);
if ($catalogPriceValue !== null) {
$optionCalculatedValue = $catalogPriceValue;
} else {
$optionCalculatedValue = $this->_getChargeableOptionPrice(
$result->getPrice(),
$result->getPriceType() === Value::TYPE_PERCENT,
$basePrice
);
}
return $optionCalculatedValue;
}
}
Loading

0 comments on commit 9f4fd32

Please sign in to comment.