Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConfiguredPrice.php
Go to the documentation of this file.
1 <?php
8 
12 use Magento\Catalog\Pricing\Price\FinalPrice as CatalogFinalPrice;
14 
15 class ConfiguredPrice extends CatalogFinalPrice implements ConfiguredPriceInterface
16 {
21 
25  protected $item;
26 
31  public function setItem(ItemInterface $item)
32  {
33  $this->item = $item;
34  return $this;
35  }
36 
42  protected function calculatePrice()
43  {
44  $value = 0.;
46  $typeInstance = $this->getProduct()->getTypeInstance();
47  $associatedProducts = $typeInstance
48  ->setStoreFilter($this->getProduct()->getStore(), $this->getProduct())
49  ->getAssociatedProducts($this->getProduct());
50 
51  foreach ($associatedProducts as $product) {
54  $customOption = $this->getProduct()
55  ->getCustomOption('associated_product_' . $product->getId());
56  if (!$customOption) {
57  continue;
58  }
59  $finalPrice = $product->getPriceInfo()
60  ->getPrice(FinalPrice::PRICE_CODE)
61  ->getValue();
62  $value += $finalPrice * ($customOption->getValue() ? $customOption->getValue() : 1);
63  }
64  return $value;
65  }
66 
72  public function getValue()
73  {
74  return $this->item ? $this->calculatePrice() : parent::getValue();
75  }
76 }
$customOption
Definition: products.php:73