Skip to content

REVERT for public PR:22917 #28380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

/**
* Product options abstract type block
*
* @author Magento Core Team <core@magentocommerce.com>
*/

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

Expand Down Expand Up @@ -168,15 +161,6 @@ protected function _formatPrice($value, $flag = true)
$priceStr = $sign;

$customOptionPrice = $this->getProduct()->getPriceInfo()->getPrice('custom_option_price');

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

$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: 9 additions & 23 deletions app/code/Magento/Catalog/Model/Product/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Catalog\Model\Product;

Expand All @@ -17,10 +16,8 @@
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\CalculateCustomOptionCatalogRule;
use Magento\Framework\App\ObjectManager;
use Magento\Catalog\Pricing\Price\BasePrice;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Model\AbstractExtensibleModel;
Expand Down Expand Up @@ -126,11 +123,6 @@ 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 @@ -146,7 +138,6 @@ class Option extends AbstractExtensibleModel implements ProductCustomOptionInter
* @param ProductCustomOptionValuesInterfaceFactory|null $customOptionValuesFactory
* @param array $optionGroups
* @param array $optionTypesToGroups
* @param CalculateCustomOptionCatalogRule $calculateCustomOptionCatalogRule
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand All @@ -163,17 +154,14 @@ public function __construct(
array $data = [],
ProductCustomOptionValuesInterfaceFactory $customOptionValuesFactory = null,
array $optionGroups = [],
array $optionTypesToGroups = [],
CalculateCustomOptionCatalogRule $calculateCustomOptionCatalogRule = null
array $optionTypesToGroups = []
) {
$this->productOptionValue = $productOptionValue;
$this->optionTypeFactory = $optionFactory;
$this->string = $string;
$this->validatorPool = $validatorPool;
$this->customOptionValuesFactory = $customOptionValuesFactory ?:
ObjectManager::getInstance()->get(ProductCustomOptionValuesInterfaceFactory::class);
$this->calculateCustomOptionCatalogRule = $calculateCustomOptionCatalogRule ??
ObjectManager::getInstance()->get(CalculateCustomOptionCatalogRule::class);
\Magento\Framework\App\ObjectManager::getInstance()->get(ProductCustomOptionValuesInterfaceFactory::class);
$this->optionGroups = $optionGroups ?: [
self::OPTION_GROUP_DATE => Date::class,
self::OPTION_GROUP_FILE => File::class,
Expand Down Expand Up @@ -474,12 +462,10 @@ public function afterSave()
*/
public function getPrice($flag = false)
{
if ($flag) {
return $this->calculateCustomOptionCatalogRule->execute(
$this->getProduct(),
(float)$this->getData(self::KEY_PRICE),
$this->getPriceType() === Value::TYPE_PERCENT
);
if ($flag && $this->getPriceType() == self::$typePercent) {
$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 Expand Up @@ -966,7 +952,7 @@ public function setExtensionAttributes(
private function getOptionRepository()
{
if (null === $this->optionRepository) {
$this->optionRepository = ObjectManager::getInstance()
$this->optionRepository = \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Catalog\Model\Product\Option\Repository::class);
}
return $this->optionRepository;
Expand All @@ -980,7 +966,7 @@ private function getOptionRepository()
private function getMetadataPool()
{
if (null === $this->metadataPool) {
$this->metadataPool = ObjectManager::getInstance()
$this->metadataPool = \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Framework\EntityManager\MetadataPool::class);
}
return $this->metadataPool;
Expand Down
67 changes: 23 additions & 44 deletions app/code/Magento/Catalog/Model/Product/Option/Type/DefaultType.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,17 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

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

use Magento\Catalog\Api\Data\ProductCustomOptionInterface;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Product\Configuration\Item\ItemInterface;
use Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface;
use Magento\Catalog\Model\Product\Option;
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\Api\Data\ProductCustomOptionInterface;

/**
* Catalog product option default type
*
* @api
* @author Magento Core Team <core@magentocommerce.com>
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @since 100.0.2
*/
Expand All @@ -31,14 +22,14 @@ class DefaultType extends \Magento\Framework\DataObject
/**
* Option Instance
*
* @var Option
* @var \Magento\Catalog\Model\Product\Option
*/
protected $_option;

/**
* Product Instance
*
* @var Product
* @var \Magento\Catalog\Model\Product
*/
protected $_product;

Expand All @@ -63,36 +54,27 @@ 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 $calculateCustomOptionCatalogRule
*/
public function __construct(
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
array $data = [],
CalculateCustomOptionCatalogRule $calculateCustomOptionCatalogRule = null
array $data = []
) {
$this->_checkoutSession = $checkoutSession;
parent::__construct($data);
$this->_scopeConfig = $scopeConfig;
$this->calculateCustomOptionCatalogRule = $calculateCustomOptionCatalogRule ?? ObjectManager::getInstance()
->get(CalculateCustomOptionCatalogRule::class);
}

/**
* Option Instance setter
*
* @param Option $option
* @param \Magento\Catalog\Model\Product\Option $option
* @return $this
*/
public function setOption($option)
Expand All @@ -104,12 +86,12 @@ public function setOption($option)
/**
* Option Instance getter
*
* @return Option
* @throws \Magento\Framework\Exception\LocalizedException
* @return \Magento\Catalog\Model\Product\Option
*/
public function getOption()
{
if ($this->_option instanceof Option) {
if ($this->_option instanceof \Magento\Catalog\Model\Product\Option) {
return $this->_option;
}
throw new LocalizedException(__('The option instance type in options group is incorrect.'));
Expand All @@ -118,7 +100,7 @@ public function getOption()
/**
* Product Instance setter
*
* @param Product $product
* @param \Magento\Catalog\Model\Product $product
* @return $this
*/
public function setProduct($product)
Expand All @@ -130,12 +112,12 @@ public function setProduct($product)
/**
* Product Instance getter
*
* @return Product
* @throws \Magento\Framework\Exception\LocalizedException
* @return \Magento\Catalog\Model\Product
*/
public function getProduct()
{
if ($this->_product instanceof Product) {
if ($this->_product instanceof \Magento\Catalog\Model\Product) {
return $this->_product;
}
throw new LocalizedException(__('The product instance type in options group is incorrect.'));
Expand All @@ -144,12 +126,15 @@ public function getProduct()
/**
* Getter for Configuration Item Option
*
* @return OptionInterface
* @return \Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface
* @throws LocalizedException
*/
public function getConfigurationItemOption()
{
if ($this->_getData('configuration_item_option') instanceof OptionInterface) {
if ($this->_getData(
'configuration_item_option'
) instanceof \Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface
) {
return $this->_getData('configuration_item_option');
}

Expand All @@ -164,12 +149,14 @@ public function getConfigurationItemOption()
/**
* Getter for Configuration Item
*
* @return ItemInterface
* @return \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getConfigurationItem()
{
if ($this->_getData('configuration_item') instanceof ItemInterface
if ($this->_getData(
'configuration_item'
) instanceof \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface
) {
return $this->_getData('configuration_item');
}
Expand Down Expand Up @@ -354,11 +341,7 @@ public function getOptionPrice($optionValue, $basePrice)
{
$option = $this->getOption();

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

/**
Expand All @@ -385,14 +368,14 @@ public function getProductOptions()
$options = $this->getProduct()->getOptions();
if ($options != null) {
foreach ($options as $_option) {
/* @var $option Option */
/* @var $option \Magento\Catalog\Model\Product\Option */
$this->_productOptions[$this->getProduct()->getId()][$_option->getTitle()] = [
'option_id' => $_option->getId(),
];
if ($_option->getGroupByType() == ProductCustomOptionInterface::OPTION_GROUP_SELECT) {
$optionValues = [];
foreach ($_option->getValues() as $_value) {
/* @var $value Value */
/* @var $value \Magento\Catalog\Model\Product\Option\Value */
$optionValues[$_value->getTitle()] = $_value->getId();
}
$this->_productOptions[$this
Expand All @@ -412,14 +395,12 @@ public function getProductOptions()
}

/**
* Return final chargeable price for option
*
* @param float $price Price of option
* @param boolean $isPercent Price type - percent or fixed
* @param float $basePrice For percent price type
* @return float
* @deprecated 102.0.4 typo in method name
* @see CalculateCustomOptionCatalogRule::execute
* @see _getChargeableOptionPrice
*/
protected function _getChargableOptionPrice($price, $isPercent, $basePrice)
{
Expand All @@ -433,8 +414,6 @@ protected function _getChargableOptionPrice($price, $isPercent, $basePrice)
* @param boolean $isPercent Price type - percent or fixed
* @param float $basePrice For percent price type
* @return float
* @deprecated
* @see CalculateCustomOptionCatalogRule::execute
*/
protected function _getChargeableOptionPrice($price, $isPercent, $basePrice)
{
Expand Down
Loading