Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BundlePrice.php
Go to the documentation of this file.
1 <?php
8 
11 use Magento\Catalog\Api\Data\ProductRender\PriceInfoInterfaceFactory;
16 
24 {
28  const PRODUCT_TYPE = "bundle";
29 
33  private $priceCurrency;
34 
38  private $excludeAdjustments;
39 
43  private $priceInfoFactory;
44 
48  private $formattedPriceInfoBuilder;
49 
57  public function __construct(
58  PriceCurrencyInterface $priceCurrency,
59  PriceInfoInterfaceFactory $priceInfoFactory,
60  FormattedPriceInfoBuilder $formattedPriceInfoBuilder,
61  array $excludeAdjustments = []
62  ) {
63  $this->priceCurrency = $priceCurrency;
64  $this->excludeAdjustments = $excludeAdjustments;
65  $this->priceInfoFactory = $priceInfoFactory;
66  $this->formattedPriceInfoBuilder = $formattedPriceInfoBuilder;
67  }
68 
72  public function collect(ProductInterface $product, ProductRenderInterface $productRender)
73  {
74  if ($product->getTypeId() == self::PRODUCT_TYPE) {
75  $priceInfo = $productRender->getPriceInfo();
76 
77  if (!$productRender->getPriceInfo()) {
79  $priceInfo = $this->priceInfoFactory->create();
80  }
81 
82  $priceInfo->setMaxPrice(
83  $product
84  ->getPriceInfo()
85  ->getPrice('final_price')
86  ->getMaximalPrice()
87  ->getValue()
88  );
89 
90  $priceInfo->setMaxRegularPrice(
91  $product
92  ->getPriceInfo()
93  ->getPrice('regular_price')
94  ->getMaximalPrice()
95  ->getValue()
96  );
97 
98  $priceInfo->setMinimalPrice(
99  $product
100  ->getPriceInfo()
101  ->getPrice('final_price')
102  ->getMinimalPrice()
103  ->getValue()
104  );
105 
106  $priceInfo->setMinimalRegularPrice(
107  $product
108  ->getPriceInfo()
109  ->getPrice('regular_price')
110  ->getMinimalPrice()
111  ->getValue()
112  );
113  $this->formattedPriceInfoBuilder->build(
114  $priceInfo,
115  $productRender->getStoreId(),
116  $productRender->getCurrencyCode()
117  );
118 
119  $productRender->setPriceInfo($priceInfo);
120  }
121  }
122 }
setPriceInfo(PriceInfoInterface $priceInfo)
__construct(PriceCurrencyInterface $priceCurrency, PriceInfoInterfaceFactory $priceInfoFactory, FormattedPriceInfoBuilder $formattedPriceInfoBuilder, array $excludeAdjustments=[])
Definition: BundlePrice.php:57
collect(ProductInterface $product, ProductRenderInterface $productRender)