Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CustomOptionPriceCalculator.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
10 use Magento\Catalog\Model\Product\Option\Value as ProductOptionValue;
11 
16 {
33  public function getOptionPriceByPriceCode(
34  ProductOptionValue $optionValue,
35  string $priceCode = BasePrice::PRICE_CODE
36  ) {
37  if ($optionValue->getPriceType() === ProductOptionValue::TYPE_PERCENT) {
38  $basePrice = $optionValue->getOption()->getProduct()->getPriceInfo()->getPrice($priceCode)->getValue();
39  $price = $basePrice * ($optionValue->getData(ProductOptionValue::KEY_PRICE) / 100);
40 
41  return $price;
42  }
43 
44  return $optionValue->getData(ProductOptionValue::KEY_PRICE);
45  }
46 }
$price
getOptionPriceByPriceCode(ProductOptionValue $optionValue, string $priceCode=BasePrice::PRICE_CODE)