Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConfiguredRegularPrice.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
14 
19 {
24 
28  private $item;
29 
35  {
36  $this->item = $item;
37 
38  return $this;
39  }
40 
46  protected function calculatePrice(): float
47  {
48  $value = 0.;
50  $typeInstance = $this->getProduct()->getTypeInstance();
51  $associatedProducts = $typeInstance
52  ->setStoreFilter($this->getProduct()->getStore(), $this->getProduct())
53  ->getAssociatedProducts($this->getProduct());
54 
55  foreach ($associatedProducts as $product) {
58  $customOption = $this->getProduct()
59  ->getCustomOption('associated_product_' . $product->getId());
60  if (!$customOption) {
61  continue;
62  }
63  $finalPrice = $product->getPriceInfo()
64  ->getPrice(\Magento\Catalog\Pricing\Price\RegularPrice::PRICE_CODE)
65  ->getValue();
66  $value += $finalPrice * ($customOption->getValue() ?: 1);
67  }
68 
69  return $value;
70  }
71 
77  public function getValue()
78  {
79  if ($this->item) {
80  return $this->calculatePrice();
81  } else {
82  if ($this->value === null) {
83  $price = $this->product->getPrice();
84  $priceInCurrentCurrency = $this->priceCurrency->convertAndRound($price);
85  $this->value = $priceInCurrentCurrency ? (float)$priceInCurrentCurrency : false;
86  }
87 
88  return $this->value;
89  }
90  }
91 }
$block setTitle( 'CMS Block Title') -> setIdentifier('fixture_block') ->setContent('< h1 >Fixture Block Title</h1 >< a href=" store url</a><p> Config value
Definition: block.php:9
$customOption
Definition: products.php:73
$price