From 1ebdf3cbce0624f6c6db8f8cb90951e3f535bde0 Mon Sep 17 00:00:00 2001 From: Volodymyr Zaets Date: Tue, 26 May 2020 14:34:13 -0500 Subject: [PATCH] REVERT for public PR:22917 --- .../Product/View/Options/AbstractOptions.php | 30 +- .../Magento/Catalog/Model/Product/Option.php | 32 +-- .../Model/Product/Option/Type/DefaultType.php | 67 ++--- .../Model/Product/Option/Type/Select.php | 31 +- .../Catalog/Model/Product/Option/Value.php | 58 +--- .../CalculateCustomOptionCatalogRule.php | 119 -------- .../Unit/Model/Product/Option/ValueTest.php | 16 +- .../CalculateCustomOptionCatalogRuleTest.php | 266 ------------------ app/code/Magento/CatalogRule/Model/Rule.php | 15 +- .../Product/Option/DataProvider/Type/File.php | 120 ++++---- .../Model/Product/BundlePriceAbstract.php | 21 +- .../Block/Product/View/OptionsTest.php | 62 +--- 12 files changed, 114 insertions(+), 723 deletions(-) delete mode 100644 app/code/Magento/Catalog/Pricing/Price/CalculateCustomOptionCatalogRule.php delete mode 100644 app/code/Magento/Catalog/Test/Unit/Pricing/Price/CalculateCustomOptionCatalogRuleTest.php diff --git a/app/code/Magento/Catalog/Block/Product/View/Options/AbstractOptions.php b/app/code/Magento/Catalog/Block/Product/View/Options/AbstractOptions.php index 0bfdcc678e9f7..030b6e1d2204c 100644 --- a/app/code/Magento/Catalog/Block/Product/View/Options/AbstractOptions.php +++ b/app/code/Magento/Catalog/Block/Product/View/Options/AbstractOptions.php @@ -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 + */ 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. @@ -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); } @@ -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( diff --git a/app/code/Magento/Catalog/Model/Product/Option.php b/app/code/Magento/Catalog/Model/Product/Option.php index 128f420e033c2..3a0920fb1c530 100644 --- a/app/code/Magento/Catalog/Model/Product/Option.php +++ b/app/code/Magento/Catalog/Model/Product/Option.php @@ -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; @@ -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; @@ -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 @@ -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( @@ -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, @@ -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); } @@ -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; @@ -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; diff --git a/app/code/Magento/Catalog/Model/Product/Option/Type/DefaultType.php b/app/code/Magento/Catalog/Model/Product/Option/Type/DefaultType.php index be7f1921afccf..cf2d5a9a3d07f 100644 --- a/app/code/Magento/Catalog/Model/Product/Option/Type/DefaultType.php +++ b/app/code/Magento/Catalog/Model/Product/Option/Type/DefaultType.php @@ -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 - * @SuppressWarnings(PHPMD.CookieAndSessionMisuse) * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @since 100.0.2 */ @@ -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; @@ -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) @@ -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.')); @@ -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) @@ -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.')); @@ -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'); } @@ -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'); } @@ -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); } /** @@ -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 @@ -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) { @@ -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) { diff --git a/app/code/Magento/Catalog/Model/Product/Option/Type/Select.php b/app/code/Magento/Catalog/Model/Product/Option/Type/Select.php index 8eebd3e91c2ee..d2766b1bbb054 100644 --- a/app/code/Magento/Catalog/Model/Product/Option/Type/Select.php +++ b/app/code/Magento/Catalog/Model/Product/Option/Type/Select.php @@ -3,13 +3,9 @@ * 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\Model\Product\Option\Value; -use Magento\Catalog\Pricing\Price\CalculateCustomOptionCatalogRule; -use Magento\Framework\App\ObjectManager; use Magento\Framework\Exception\LocalizedException; /** @@ -41,11 +37,6 @@ 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 @@ -53,7 +44,6 @@ class Select extends \Magento\Catalog\Model\Product\Option\Type\DefaultType * @param \Magento\Framework\Escaper $escaper * @param array $data * @param array $singleSelectionTypes - * @param CalculateCustomOptionCatalogRule $calculateCustomOptionCatalogRule */ public function __construct( \Magento\Checkout\Model\Session $checkoutSession, @@ -61,8 +51,7 @@ public function __construct( \Magento\Framework\Stdlib\StringUtils $string, \Magento\Framework\Escaper $escaper, array $data = [], - array $singleSelectionTypes = [], - CalculateCustomOptionCatalogRule $calculateCustomOptionCatalogRule = null + array $singleSelectionTypes = [] ) { $this->string = $string; $this->_escaper = $escaper; @@ -72,8 +61,6 @@ 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); } /** @@ -261,10 +248,10 @@ public function getOptionPrice($optionValue, $basePrice) foreach (explode(',', $optionValue) as $value) { $_result = $option->getValueById($value); if ($_result) { - $result += $this->calculateCustomOptionCatalogRule->execute( - $option->getProduct(), - (float)$_result->getPrice(), - $_result->getPriceType() === Value::TYPE_PERCENT + $result += $this->_getChargeableOptionPrice( + $_result->getPrice(), + $_result->getPriceType() == 'percent', + $basePrice ); } else { if ($this->getListener()) { @@ -276,10 +263,10 @@ public function getOptionPrice($optionValue, $basePrice) } elseif ($this->_isSingleSelection()) { $_result = $option->getValueById($optionValue); if ($_result) { - $result = $this->calculateCustomOptionCatalogRule->execute( - $option->getProduct(), - (float)$_result->getPrice(), - $_result->getPriceType() === Value::TYPE_PERCENT + $result = $this->_getChargeableOptionPrice( + $_result->getPrice(), + $_result->getPriceType() == 'percent', + $basePrice ); } else { if ($this->getListener()) { diff --git a/app/code/Magento/Catalog/Model/Product/Option/Value.php b/app/code/Magento/Catalog/Model/Product/Option/Value.php index 783bda4699792..25e12e2fad865 100644 --- a/app/code/Magento/Catalog/Model/Product/Option/Value.php +++ b/app/code/Magento/Catalog/Model/Product/Option/Value.php @@ -3,16 +3,13 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -declare(strict_types=1); namespace Magento\Catalog\Model\Product\Option; use Magento\Catalog\Model\Product; use Magento\Catalog\Model\Product\Option; -use Magento\Catalog\Pricing\Price\BasePrice; -use Magento\Catalog\Pricing\Price\CalculateCustomOptionCatalogRule; -use Magento\Framework\App\ObjectManager; use Magento\Framework\Model\AbstractModel; +use Magento\Catalog\Pricing\Price\BasePrice; use Magento\Catalog\Pricing\Price\CustomOptionPriceCalculator; use Magento\Catalog\Pricing\Price\RegularPrice; @@ -72,11 +69,6 @@ class Value extends AbstractModel implements \Magento\Catalog\Api\Data\ProductCu */ private $customOptionPriceCalculator; - /** - * @var CalculateCustomOptionCatalogRule - */ - private $calculateCustomOptionCatalogRule; - /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry @@ -85,7 +77,6 @@ class Value extends AbstractModel implements \Magento\Catalog\Api\Data\ProductCu * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data * @param CustomOptionPriceCalculator|null $customOptionPriceCalculator - * @param CalculateCustomOptionCatalogRule|null $CalculateCustomOptionCatalogRule */ public function __construct( \Magento\Framework\Model\Context $context, @@ -94,14 +85,11 @@ public function __construct( \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = [], - CustomOptionPriceCalculator $customOptionPriceCalculator = null, - CalculateCustomOptionCatalogRule $CalculateCustomOptionCatalogRule = null + CustomOptionPriceCalculator $customOptionPriceCalculator = null ) { $this->_valueCollectionFactory = $valueCollectionFactory; $this->customOptionPriceCalculator = $customOptionPriceCalculator - ?? ObjectManager::getInstance()->get(CustomOptionPriceCalculator::class); - $this->calculateCustomOptionCatalogRule = $CalculateCustomOptionCatalogRule - ?? ObjectManager::getInstance()->get(CalculateCustomOptionCatalogRule::class); + ?? \Magento\Framework\App\ObjectManager::getInstance()->get(CustomOptionPriceCalculator::class); parent::__construct( $context, @@ -123,8 +111,6 @@ protected function _construct() } /** - * Add value. - * * @codeCoverageIgnoreStart * @param mixed $value * @return $this @@ -136,8 +122,6 @@ public function addValue($value) } /** - * Get values. - * * @return array */ public function getValues() @@ -146,8 +130,6 @@ public function getValues() } /** - * Set values. - * * @param array $values * @return $this */ @@ -158,8 +140,6 @@ public function setValues($values) } /** - * Unset values. - * * @return $this */ public function unsetValues() @@ -169,8 +149,6 @@ public function unsetValues() } /** - * Set option. - * * @param Option $option * @return $this */ @@ -181,8 +159,6 @@ public function setOption(Option $option) } /** - * Unset option. - * * @return $this */ public function unsetOption() @@ -192,7 +168,7 @@ public function unsetOption() } /** - * Get option. + * Enter description here... * * @return Option */ @@ -202,8 +178,6 @@ public function getOption() } /** - * Set product. - * * @param Product $product * @return $this */ @@ -216,8 +190,6 @@ public function setProduct($product) //@codeCoverageIgnoreEnd /** - * Get product. - * * @return Product */ public function getProduct() @@ -229,10 +201,7 @@ public function getProduct() } /** - * Save values. - * * @return $this - * @throws \Exception */ public function saveValues() { @@ -258,9 +227,8 @@ public function saveValues() } /** - * Return price. - * - * If $flag is true and price is percent return converted percent to price + * Return price. If $flag is true and price is percent + * return converted percent to price * * @param bool $flag * @return float|int @@ -268,11 +236,7 @@ public function saveValues() public function getPrice($flag = false) { if ($flag) { - return $this->calculateCustomOptionCatalogRule->execute( - $this->getProduct(), - (float)$this->getData(self::KEY_PRICE), - $this->getPriceType() === self::TYPE_PERCENT - ); + return $this->customOptionPriceCalculator->getOptionPriceByPriceCode($this, BasePrice::PRICE_CODE); } return $this->_getData(self::KEY_PRICE); } @@ -288,7 +252,7 @@ public function getRegularPrice() } /** - * Get values collection. + * Enter description here... * * @param Option $option * @return \Magento\Catalog\Model\ResourceModel\Product\Option\Value\Collection @@ -306,8 +270,6 @@ public function getValuesCollection(Option $option) } /** - * Get values by option. - * * @param array $optionIds * @param int $option_id * @param int $store_id @@ -327,8 +289,6 @@ public function getValuesByOption($optionIds, $option_id, $store_id) } /** - * Delete value. - * * @param int $option_id * @return $this */ @@ -339,8 +299,6 @@ public function deleteValue($option_id) } /** - * Delete values. - * * @param int $option_type_id * @return $this */ diff --git a/app/code/Magento/Catalog/Pricing/Price/CalculateCustomOptionCatalogRule.php b/app/code/Magento/Catalog/Pricing/Price/CalculateCustomOptionCatalogRule.php deleted file mode 100644 index b3f3ac7bf68ef..0000000000000 --- a/app/code/Magento/Catalog/Pricing/Price/CalculateCustomOptionCatalogRule.php +++ /dev/null @@ -1,119 +0,0 @@ -priceModifier = $priceModifier; - $this->priceCurrency = $priceCurrency; - } - - /** - * Calculate prices of custom options of the product with catalog rules applied. - * - * @param Product $product - * @param float $optionPriceValue - * @param bool $isPercent - * @return float - */ - public function execute( - Product $product, - float $optionPriceValue, - bool $isPercent - ): float { - $regularPrice = (float)$product->getPriceInfo() - ->getPrice(RegularPrice::PRICE_CODE) - ->getValue(); - $catalogRulePrice = $this->priceModifier->modifyPrice( - $regularPrice, - $product - ); - $basePriceWithOutCatalogRules = (float)$this->getGetBasePriceWithOutCatalogRules($product); - // Apply catalog price rules to product options only if catalog price rules are applied to product. - if ($catalogRulePrice < $basePriceWithOutCatalogRules) { - $optionPrice = $this->getOptionPriceWithoutPriceRule($optionPriceValue, $isPercent, $regularPrice); - $totalCatalogRulePrice = $this->priceModifier->modifyPrice( - $regularPrice + $optionPrice, - $product - ); - $finalOptionPrice = $totalCatalogRulePrice - $catalogRulePrice; - } else { - $finalOptionPrice = $this->getOptionPriceWithoutPriceRule( - $optionPriceValue, - $isPercent, - $this->getGetBasePriceWithOutCatalogRules($product) - ); - } - - return $this->priceCurrency->convertAndRound($finalOptionPrice); - } - - /** - * Get product base price without catalog rules applied. - * - * @param Product $product - * @return float - */ - private function getGetBasePriceWithOutCatalogRules(Product $product): float - { - $basePrice = null; - foreach ($product->getPriceInfo()->getPrices() as $price) { - if ($price instanceof BasePriceProviderInterface - && $price->getPriceCode() !== CatalogRulePrice::PRICE_CODE - && $price->getValue() !== false - ) { - $basePrice = min( - $price->getValue(), - $basePrice ?? $price->getValue() - ); - } - } - - return $basePrice ?? $product->getPrice(); - } - - /** - * Calculate option price without catalog price rule discount. - * - * @param float $optionPriceValue - * @param bool $isPercent - * @param float $basePrice - * @return float - */ - private function getOptionPriceWithoutPriceRule(float $optionPriceValue, bool $isPercent, float $basePrice): float - { - return $isPercent ? $basePrice * $optionPriceValue / 100 : $optionPriceValue; - } -} diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/ValueTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/ValueTest.php index e03ea8c79cc8a..e46884d1637da 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/ValueTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/ValueTest.php @@ -12,13 +12,11 @@ use Magento\Catalog\Model\Product\Option\Value; use Magento\Catalog\Model\ResourceModel\Product\Option\Value\Collection; use Magento\Catalog\Model\ResourceModel\Product\Option\Value\CollectionFactory; -use Magento\Catalog\Pricing\Price\CalculateCustomOptionCatalogRule; use Magento\Catalog\Pricing\Price\CustomOptionPriceCalculator; use Magento\Framework\Pricing\Price\PriceInterface; use Magento\Framework\Pricing\PriceInfoInterface; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; -use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; /** @@ -36,11 +34,6 @@ class ValueTest extends TestCase */ private $customOptionPriceCalculatorMock; - /** - * @var CalculateCustomOptionCatalogRule|MockObject - */ - private $CalculateCustomOptionCatalogRule; - protected function setUp(): void { $mockedResource = $this->getMockedResource(); @@ -50,10 +43,6 @@ protected function setUp(): void CustomOptionPriceCalculator::class ); - $this->CalculateCustomOptionCatalogRule = $this->createMock( - CalculateCustomOptionCatalogRule::class - ); - $helper = new ObjectManager($this); $this->model = $helper->getObject( Value::class, @@ -61,7 +50,6 @@ protected function setUp(): void 'resource' => $mockedResource, 'valueCollectionFactory' => $mockedCollectionFactory, 'customOptionPriceCalculator' => $this->customOptionPriceCalculatorMock, - 'CalculateCustomOptionCatalogRule' => $this->CalculateCustomOptionCatalogRule ] ); $this->model->setOption($this->getMockedOption()); @@ -89,8 +77,8 @@ public function testGetPrice() $this->assertEquals($price, $this->model->getPrice(false)); $percentPrice = 100.0; - $this->CalculateCustomOptionCatalogRule->expects($this->atLeastOnce()) - ->method('execute') + $this->customOptionPriceCalculatorMock->expects($this->atLeastOnce()) + ->method('getOptionPriceByPriceCode') ->willReturn($percentPrice); $this->assertEquals($percentPrice, $this->model->getPrice(true)); } diff --git a/app/code/Magento/Catalog/Test/Unit/Pricing/Price/CalculateCustomOptionCatalogRuleTest.php b/app/code/Magento/Catalog/Test/Unit/Pricing/Price/CalculateCustomOptionCatalogRuleTest.php deleted file mode 100644 index 894408048b536..0000000000000 --- a/app/code/Magento/Catalog/Test/Unit/Pricing/Price/CalculateCustomOptionCatalogRuleTest.php +++ /dev/null @@ -1,266 +0,0 @@ -saleableItemMock = $this->createMock(Product::class); - $this->regularPriceMock = $this->createMock(RegularPrice::class); - $this->specialPriceMock = $this->createMock(SpecialPrice::class); - $this->catalogRulePriceMock = $this->createMock(CatalogRulePrice::class); - $priceInfoMock = $this->createMock(Base::class); - $this->saleableItemMock->expects($this->any()) - ->method('getPriceInfo') - ->willReturn($priceInfoMock); - $this->regularPriceMock->expects($this->any()) - ->method('getPriceCode') - ->willReturn(RegularPrice::PRICE_CODE); - $this->specialPriceMock->expects($this->any()) - ->method('getPriceCode') - ->willReturn(SpecialPrice::PRICE_CODE); - $this->catalogRulePriceMock->expects($this->any()) - ->method('getPriceCode') - ->willReturn(CatalogRulePrice::PRICE_CODE); - $priceInfoMock->expects($this->any()) - ->method('getPrices') - ->willReturn( - [ - 'regular_price' => $this->regularPriceMock, - 'special_price' => $this->specialPriceMock, - 'catalog_rule_price' => $this->catalogRulePriceMock - ] - ); - $priceInfoMock->expects($this->any()) - ->method('getPrice') - ->willReturnMap( - [ - ['regular_price', $this->regularPriceMock], - ['special_price', $this->specialPriceMock], - ['catalog_rule_price', $this->catalogRulePriceMock], - ] - ); - $priceCurrencyMock = $this->createMock(PriceCurrency::class); - $priceCurrencyMock->expects($this->any()) - ->method('convertAndRound') - ->willReturnArgument(0); - $this->priceModifierMock = $this->createMock(PriceModifier::class); - - $this->calculateCustomOptionCatalogRule = $objectManager->getObject( - CalculateCustomOptionCatalogRule::class, - [ - 'priceCurrency' => $priceCurrencyMock, - 'priceModifier' => $this->priceModifierMock, - ] - ); - } - - /** - * Tests correct option price calculation with different catalog rules and special prices combination. - * - * @dataProvider executeDataProvider - * @param array $prices - * @param float $catalogRulePriceModifier - * @param float $optionPriceValue - * @param bool $isPercent - * @param float $expectedResult - */ - public function testExecute( - array $prices, - float $catalogRulePriceModifier, - float $optionPriceValue, - bool $isPercent, - float $expectedResult - ) { - $this->regularPriceMock->expects($this->any()) - ->method('getValue') - ->willReturn($prices['regularPriceValue']); - $this->specialPriceMock->expects($this->any()) - ->method('getValue') - ->willReturn($prices['specialPriceValue']); - $this->priceModifierMock->expects($this->any()) - ->method('modifyPrice') - ->willReturnCallback( - function ($price) use ($catalogRulePriceModifier) { - return $price * $catalogRulePriceModifier; - } - ); - - $finalPrice = $this->calculateCustomOptionCatalogRule->execute( - $this->saleableItemMock, - $optionPriceValue, - $isPercent - ); - - $this->assertSame($expectedResult, $finalPrice); - } - - /** - * Data provider for testExecute. - * - * "Active" means this price type has biggest discount, so other prices doesn't count. - * - * @return array - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) - */ - public function executeDataProvider(): array - { - return [ - 'No special price, no catalog price rules, fixed option price' => [ - 'prices' => [ - 'regularPriceValue' => 1000, - 'specialPriceValue' => 1000, - ], - 'catalogRulePriceModifier' => 1.0, - 'optionPriceValue' => 100.0, - 'isPercent' => false, - 'expectedResult' => 100.0 - ], - 'No special price, no catalog price rules, percent option price' => [ - 'prices' => [ - 'regularPriceValue' => 1000, - 'specialPriceValue' => 1000, - ], - 'catalogRulePriceModifier' => 1.0, - 'optionPriceValue' => 100.0, - 'isPercent' => true, - 'expectedResult' => 1000.0 - ], - 'No special price, catalog price rule set, fixed option price' => [ - 'prices' => [ - 'regularPriceValue' => 1000, - 'specialPriceValue' => 1000, - ], - 'catalogRulePriceModifier' => 0.9, - 'optionPriceValue' => 100.0, - 'isPercent' => false, - 'expectedResult' => 90.0 - ], - 'No special price, catalog price rule set, percent option price' => [ - 'prices' => [ - 'regularPriceValue' => 1000, - 'specialPriceValue' => 1000, - ], - 'catalogRulePriceModifier' => 0.9, - 'optionPriceValue' => 100.0, - 'isPercent' => true, - 'expectedResult' => 900.0 - ], - 'Special price set, no catalog price rule, fixed option price' => [ - 'prices' => [ - 'regularPriceValue' => 1000, - 'specialPriceValue' => 900, - ], - 'catalogRulePriceModifier' => 1.0, - 'optionPriceValue' => 100.0, - 'isPercent' => false, - 'expectedResult' => 100.0 - ], - 'Special price set, no catalog price rule, percent option price' => [ - 'prices' => [ - 'regularPriceValue' => 1000, - 'specialPriceValue' => 900, - ], - 'catalogRulePriceModifier' => 1.0, - 'optionPriceValue' => 100.0, - 'isPercent' => true, - 'expectedResult' => 900.0 - ], - 'Special price set and active, catalog price rule set, fixed option price' => [ - 'prices' => [ - 'regularPriceValue' => 1000, - 'specialPriceValue' => 800, - ], - 'catalogRulePriceModifier' => 0.9, - 'optionPriceValue' => 100.0, - 'isPercent' => false, - 'expectedResult' => 100.0 - ], - 'Special price set and active, catalog price rule set, percent option price' => [ - 'prices' => [ - 'regularPriceValue' => 1000, - 'specialPriceValue' => 800, - ], - 'catalogRulePriceModifier' => 0.9, - 'optionPriceValue' => 100.0, - 'isPercent' => true, - 'expectedResult' => 800.0 - ], - 'Special price set, catalog price rule set and active, fixed option price' => [ - 'prices' => [ - 'regularPriceValue' => 1000, - 'specialPriceValue' => 950, - ], - 'catalogRulePriceModifier' => 0.9, - 'optionPriceValue' => 100.0, - 'isPercent' => false, - 'expectedResult' => 90.0 - ], - 'Special price set, catalog price rule set and active, percent option price' => [ - 'prices' => [ - 'regularPriceValue' => 1000, - 'specialPriceValue' => 950, - ], - 'catalogRulePriceModifier' => 0.9, - 'optionPriceValue' => 100.0, - 'isPercent' => true, - 'expectedResult' => 900.0 - ], - ]; - } -} diff --git a/app/code/Magento/CatalogRule/Model/Rule.php b/app/code/Magento/CatalogRule/Model/Rule.php index cd24201963f25..f2e8e54d34665 100644 --- a/app/code/Magento/CatalogRule/Model/Rule.php +++ b/app/code/Magento/CatalogRule/Model/Rule.php @@ -3,8 +3,6 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -declare(strict_types=1); - namespace Magento\CatalogRule\Model; use Magento\Catalog\Model\Product; @@ -15,7 +13,6 @@ use Magento\CatalogRule\Helper\Data; use Magento\CatalogRule\Model\Data\Condition\Converter; use Magento\CatalogRule\Model\Indexer\Rule\RuleProductProcessor; -use Magento\CatalogRule\Model\ResourceModel\Product\ConditionsToCollectionApplier; use Magento\CatalogRule\Model\ResourceModel\Rule as RuleResourceModel; use Magento\CatalogRule\Model\Rule\Action\CollectionFactory as RuleCollectionFactory; use Magento\CatalogRule\Model\Rule\Condition\CombineFactory; @@ -36,6 +33,7 @@ use Magento\Framework\Stdlib\DateTime; use Magento\Framework\Stdlib\DateTime\TimezoneInterface; use Magento\Store\Model\StoreManagerInterface; +use Magento\CatalogRule\Model\ResourceModel\Product\ConditionsToCollectionApplier; /** * Catalog Rule data model @@ -501,8 +499,7 @@ public function calcProductPriceRule(Product $product, $price) } else { $customerGroupId = $this->_customerSession->getCustomerGroupId(); } - $currentDateTime = new \DateTime(); - $dateTs = $currentDateTime->getTimestamp(); + $dateTs = $this->_localeDate->scopeTimeStamp($storeId); $cacheKey = date('Y-m-d', $dateTs) . "|{$websiteId}|{$customerGroupId}|{$productId}|{$price}"; if (!array_key_exists($cacheKey, self::$_priceRulesData)) { @@ -898,12 +895,4 @@ public function getIdentities() { return ['price']; } - - /** - * Clear price rules cache. - */ - public function clearPriceRulesData(): void - { - self::$_priceRulesData = []; - } } diff --git a/dev/tests/integration/framework/Magento/TestFramework/Catalog/Model/Product/Option/DataProvider/Type/File.php b/dev/tests/integration/framework/Magento/TestFramework/Catalog/Model/Product/Option/DataProvider/Type/File.php index d2aa20a005ec4..35f449a404410 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Catalog/Model/Product/Option/DataProvider/Type/File.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Catalog/Model/Product/Option/DataProvider/Type/File.php @@ -8,7 +8,7 @@ namespace Magento\TestFramework\Catalog\Model\Product\Option\DataProvider\Type; use Magento\Catalog\Api\Data\ProductCustomOptionInterface; -use Magento\Catalog\Model\Product\Option; +use Magento\TestFramework\Catalog\Model\Product\Option\DataProvider\Type\AbstractBase; /** * Data provider for options from file group with type "file". @@ -20,44 +20,41 @@ class File extends AbstractBase */ public function getDataForCreateOptions(): array { - return $this->injectFileExtension( - array_merge_recursive( - parent::getDataForCreateOptions(), - [ - "type_{$this->getType()}_option_file_extension" => [ - [ - 'record_id' => 0, - 'sort_order' => 1, - 'is_require' => 1, - 'sku' => 'test-option-title-1', - 'max_characters' => 30, - 'title' => 'Test option title 1', - 'type' => $this->getType(), - 'price' => 10, - 'price_type' => 'fixed', - 'file_extension' => 'gif', - 'image_size_x' => 10, - 'image_size_y' => 20, - ], + return array_merge_recursive( + parent::getDataForCreateOptions(), + [ + "type_{$this->getType()}_option_file_extension" => [ + [ + 'record_id' => 0, + 'sort_order' => 1, + 'is_require' => 1, + 'sku' => 'test-option-title-1', + 'max_characters' => 30, + 'title' => 'Test option title 1', + 'type' => $this->getType(), + 'price' => 10, + 'price_type' => 'fixed', + 'file_extension' => 'gif', + 'image_size_x' => 10, + 'image_size_y' => 20, ], - "type_{$this->getType()}_option_maximum_file_size" => [ - [ - 'record_id' => 0, - 'sort_order' => 1, - 'is_require' => 1, - 'sku' => 'test-option-title-1', - 'title' => 'Test option title 1', - 'type' => $this->getType(), - 'price' => 10, - 'price_type' => 'fixed', - 'file_extension' => 'gif', - 'image_size_x' => 10, - 'image_size_y' => 20, - ], + ], + "type_{$this->getType()}_option_maximum_file_size" => [ + [ + 'record_id' => 0, + 'sort_order' => 1, + 'is_require' => 1, + 'sku' => 'test-option-title-1', + 'title' => 'Test option title 1', + 'type' => $this->getType(), + 'price' => 10, + 'price_type' => 'fixed', + 'file_extension' => 'gif', + 'image_size_x' => 10, + 'image_size_y' => 20, ], - ] - ), - 'png' + ], + ] ); } @@ -66,24 +63,21 @@ public function getDataForCreateOptions(): array */ public function getDataForUpdateOptions(): array { - return $this->injectFileExtension( - array_merge_recursive( - parent::getDataForUpdateOptions(), - [ - "type_{$this->getType()}_option_file_extension" => [ - [ - 'file_extension' => 'jpg', - ], + return array_merge_recursive( + parent::getDataForUpdateOptions(), + [ + "type_{$this->getType()}_option_file_extension" => [ + [ + 'file_extension' => 'jpg', ], - "type_{$this->getType()}_option_maximum_file_size" => [ - [ - 'image_size_x' => 300, - 'image_size_y' => 815, - ], + ], + "type_{$this->getType()}_option_maximum_file_size" => [ + [ + 'image_size_x' => 300, + 'image_size_y' => 815, ], - ] - ), - '' + ], + ] ); } @@ -94,24 +88,4 @@ protected function getType(): string { return ProductCustomOptionInterface::OPTION_TYPE_FILE; } - - /** - * Add 'file_extension' value to each option. - * - * @param array $data - * @param string $extension - * @return array - */ - private function injectFileExtension(array $data, string $extension): array - { - foreach ($data as &$caseData) { - foreach ($caseData as &$option) { - if (!isset($option[Option::KEY_FILE_EXTENSION])) { - $option[Option::KEY_FILE_EXTENSION] = $extension; - } - } - } - - return $data; - } } diff --git a/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/BundlePriceAbstract.php b/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/BundlePriceAbstract.php index 572a526da07da..3ce2711a25d37 100644 --- a/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/BundlePriceAbstract.php +++ b/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/BundlePriceAbstract.php @@ -3,13 +3,11 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -declare(strict_types=1); namespace Magento\Bundle\Model\Product; /** * Abstract class for testing bundle prices - * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ abstract class BundlePriceAbstract extends \PHPUnit\Framework\TestCase @@ -31,14 +29,6 @@ abstract class BundlePriceAbstract extends \PHPUnit\Framework\TestCase */ protected $productCollectionFactory; - /** - * @var \Magento\CatalogRule\Model\RuleFactory - */ - private $ruleFactory; - - /** - * @inheritdoc - */ protected function setUp(): void { $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); @@ -52,19 +42,15 @@ protected function setUp(): void true, \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); - $this->ruleFactory = $this->objectManager->get(\Magento\CatalogRule\Model\RuleFactory::class); } /** - * Get test cases. - * + * Get test cases * @return array */ abstract public function getTestCases(); /** - * Prepare fixture. - * * @param array $strategyModifiers * @param string $productSku * @return void @@ -75,14 +61,11 @@ abstract public function getTestCases(); */ protected function prepareFixture($strategyModifiers, $productSku) { - $this->ruleFactory->create()->clearPriceRulesData(); - $bundleProduct = $this->productRepository->get($productSku); foreach ($strategyModifiers as $modifier) { if (method_exists($this, $modifier['modifierName'])) { array_unshift($modifier['data'], $bundleProduct); - // phpcs:ignore Magento2.Functions.DiscouragedFunction $bundleProduct = call_user_func_array([$this, $modifier['modifierName']], $modifier['data']); } else { throw new \Magento\Framework\Exception\InputException( @@ -130,8 +113,6 @@ protected function addSimpleProduct(\Magento\Catalog\Model\Product $bundleProduc } /** - * Add custom option. - * * @param \Magento\Catalog\Model\Product $bundleProduct * @param array $optionsData * @return \Magento\Catalog\Model\Product diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Block/Product/View/OptionsTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Block/Product/View/OptionsTest.php index 28357919ed566..57782fc17c9f5 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Block/Product/View/OptionsTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Block/Product/View/OptionsTest.php @@ -3,12 +3,8 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -declare(strict_types=1); - namespace Magento\Catalog\Block\Product\View; -use Magento\CatalogRule\Model\Indexer\IndexBuilder; - /** * Test class for \Magento\Catalog\Block\Product\View\Options. */ @@ -34,19 +30,12 @@ class OptionsTest extends \PHPUnit\Framework\TestCase */ protected $productRepository; - /** - * @var IndexBuilder - */ - private $indexBuilder; - protected function setUp(): void { $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $this->productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class); - $this->indexBuilder = $this->objectManager->create(IndexBuilder::class); - try { $this->product = $this->productRepository->get('simple'); } catch (\Magento\Framework\Exception\NoSuchEntityException $e) { @@ -124,7 +113,9 @@ private function getExpectedJsonConfig() { return [ 0 => [ - 'prices' => ['oldPrice' => ['amount' => 10, 'adjustments' => []], + 'prices' => + ['oldPrice' => + ['amount' => 10, 'adjustments' => []], 'basePrice' => ['amount' => 10], 'finalPrice' => ['amount' => 10] ], @@ -132,7 +123,9 @@ private function getExpectedJsonConfig() 'name' => 'drop_down option 1', ], 1 => [ - 'prices' => ['oldPrice' => ['amount' => 40, 'adjustments' => []], + 'prices' => + ['oldPrice' => + ['amount' => 40, 'adjustments' => []], 'basePrice' => ['amount' => 40], 'finalPrice' => ['amount' => 40], ], @@ -141,47 +134,4 @@ private function getExpectedJsonConfig() ], ]; } - - /** - * Test option prices with catalog price rules applied. - * - * @magentoDbIsolation disabled - * @magentoDataFixture Magento/CatalogRule/_files/two_rules.php - * @magentoDataFixture Magento/Catalog/_files/product_with_dropdown_option.php - */ - public function testGetJsonConfigWithCatalogRules() - { - $this->indexBuilder->reindexFull(); - sleep(1); - $config = json_decode($this->block->getJsonConfig(), true); - $configValues = array_values($config); - $this->assertEquals($this->getExpectedJsonConfigWithCatalogRules(), array_values($configValues[0])); - } - - /** - * Expected data for testGetJsonConfigWithCatalogRules - * - * @return array - */ - private function getExpectedJsonConfigWithCatalogRules() - { - return [ - 0 => [ - 'prices' => ['oldPrice' => ['amount' => 10, 'adjustments' => []], - 'basePrice' => ['amount' => 9.5], - 'finalPrice' => ['amount' => 9.5], - ], - 'type' => 'fixed', - 'name' => 'drop_down option 1', - ], - 1 => [ - 'prices' => ['oldPrice' => ['amount' => 40, 'adjustments' => []], - 'basePrice' => ['amount' => 38], - 'finalPrice' => ['amount' => 38], - ], - 'type' => 'percent', - 'name' => 'drop_down option 2', - ], - ]; - } }