Price.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Downloadable products price model
  8. *
  9. * @author Magento Core Team <core@magentocommerce.com>
  10. */
  11. namespace Magento\Downloadable\Model\Product;
  12. class Price extends \Magento\Catalog\Model\Product\Type\Price
  13. {
  14. /**
  15. * Retrieve product final price
  16. *
  17. * @param integer $qty
  18. * @param \Magento\Catalog\Model\Product $product
  19. * @return float
  20. */
  21. public function getFinalPrice($qty, $product)
  22. {
  23. if ($qty === null && $product->getCalculatedFinalPrice() !== null) {
  24. return $product->getCalculatedFinalPrice();
  25. }
  26. $finalPrice = parent::getFinalPrice($qty, $product);
  27. /**
  28. * links prices are added to base product price only if they can be purchased separately
  29. */
  30. if ($product->getLinksPurchasedSeparately()) {
  31. if ($linksIds = $product->getCustomOption('downloadable_link_ids')) {
  32. $linkPrice = 0;
  33. $links = $product->getTypeInstance()->getLinks($product);
  34. foreach (explode(',', $linksIds->getValue()) as $linkId) {
  35. if (isset($links[$linkId])) {
  36. $linkPrice += $links[$linkId]->getPrice();
  37. }
  38. }
  39. $finalPrice += $linkPrice;
  40. }
  41. }
  42. $product->setData('final_price', $finalPrice);
  43. return max(0, $product->getData('final_price'));
  44. }
  45. }