Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Price.php
Go to the documentation of this file.
1 <?php
13 
14 class Price extends \Magento\Catalog\Model\Product\Type\Price
15 {
23  public function getFinalPrice($qty, $product)
24  {
25  if ($qty === null && $product->getCalculatedFinalPrice() !== null) {
26  return $product->getCalculatedFinalPrice();
27  }
28 
29  $finalPrice = parent::getFinalPrice($qty, $product);
30 
34  if ($product->getLinksPurchasedSeparately()) {
35  if ($linksIds = $product->getCustomOption('downloadable_link_ids')) {
36  $linkPrice = 0;
37  $links = $product->getTypeInstance()->getLinks($product);
38  foreach (explode(',', $linksIds->getValue()) as $linkId) {
39  if (isset($links[$linkId])) {
40  $linkPrice += $links[$linkId]->getPrice();
41  }
42  }
43  $finalPrice += $linkPrice;
44  }
45  }
46 
47  $product->setData('final_price', $finalPrice);
48  return max(0, $product->getData('final_price'));
49  }
50 }