![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/cartforge.co/vendor/magento/module-downloadable/Block/Catalog/Product/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ namespace Magento\Downloadable\Block\Catalog\Product; use Magento\Catalog\Pricing\Price\FinalPrice; use Magento\Downloadable\Model\Link; use Magento\Downloadable\Pricing\Price\LinkPrice; use Magento\Framework\Json\EncoderInterface; /** * Downloadable Product Links part block * * @api * @since 100.0.2 */ class Links extends \Magento\Catalog\Block\Product\AbstractProduct { /** * @var \Magento\Framework\Pricing\Helper\Data */ protected $pricingHelper; /** * @var EncoderInterface */ protected $encoder; /** * @param \Magento\Catalog\Block\Product\Context $context * @param \Magento\Framework\Pricing\Helper\Data $pricingHelper * @param EncoderInterface $encoder * @param array $data */ public function __construct( \Magento\Catalog\Block\Product\Context $context, \Magento\Framework\Pricing\Helper\Data $pricingHelper, EncoderInterface $encoder, array $data = [] ) { $this->pricingHelper = $pricingHelper; $this->encoder = $encoder; parent::__construct($context, $data); } /** * Enter description here... * * @return boolean * @SuppressWarnings(PHPMD.BooleanGetMethodName) */ public function getLinksPurchasedSeparately() { return $this->getProduct()->getLinksPurchasedSeparately(); } /** * @return boolean * @SuppressWarnings(PHPMD.BooleanGetMethodName) */ public function getLinkSelectionRequired() { return $this->getProduct()->getTypeInstance()->getLinkSelectionRequired($this->getProduct()); } /** * @return boolean */ public function hasLinks() { return $this->getProduct()->getTypeInstance()->hasLinks($this->getProduct()); } /** * @return array */ public function getLinks() { return $this->getProduct()->getTypeInstance()->getLinks($this->getProduct()); } /** * Returns price converted to current currency rate * * @param float $price * @return float */ public function getCurrencyPrice($price) { $store = $this->getProduct()->getStore(); return $this->pricingHelper->currencyByStore($price, $store, false); } /** * @return string */ public function getJsonConfig() { $finalPrice = $this->getProduct()->getPriceInfo() ->getPrice(FinalPrice::PRICE_CODE); $linksConfig = []; foreach ($this->getLinks() as $link) { $amount = $finalPrice->getCustomAmount($link->getPrice()); $linksConfig[$link->getId()] = [ 'finalPrice' => $amount->getValue(), 'basePrice' => $amount->getBaseAmount() ]; } return $this->encoder->encode(['links' => $linksConfig]); } /** * @param Link $link * @return string */ public function getLinkSampleUrl($link) { $store = $this->getProduct()->getStore(); return $store->getUrl('downloadable/download/linkSample', ['link_id' => $link->getId()]); } /** * Return title of links section * * @return string */ public function getLinksTitle() { if ($this->getProduct()->getLinksTitle()) { return $this->getProduct()->getLinksTitle(); } return $this->_scopeConfig->getValue( \Magento\Downloadable\Model\Link::XML_PATH_LINKS_TITLE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); } /** * Return true if target of link new window * * @return bool * @SuppressWarnings(PHPMD.BooleanGetMethodName) */ public function getIsOpenInNewWindow() { return $this->_scopeConfig->isSetFlag( \Magento\Downloadable\Model\Link::XML_PATH_TARGET_NEW_WINDOW, \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); } /** * Returns whether link checked by default or not * * @param Link $link * @return bool * @SuppressWarnings(PHPMD.BooleanGetMethodName) */ public function getIsLinkChecked($link) { $configValue = $this->getProduct()->getPreconfiguredValues()->getLinks(); if (!$configValue || !is_array($configValue)) { return false; } return $configValue && in_array($link->getId(), $configValue); } /** * Returns value for link's input checkbox - either 'checked' or '' * * @param Link $link * @return string */ public function getLinkCheckedValue($link) { return $this->getIsLinkChecked($link) ? 'checked' : ''; } /** * @param Link $link * @return \Magento\Framework\Pricing\Amount\AmountInterface */ protected function getLinkAmount($link) { return $this->getPriceType()->getLinkAmount($link); } /** * @param Link $link * @return string */ public function getLinkPrice(Link $link) { return $this->getLayout()->getBlock('product.price.render.default')->renderAmount( $this->getLinkAmount($link), $this->getPriceType(), $this->getProduct() ); } /** * Get LinkPrice Type * * @return \Magento\Framework\Pricing\Price\PriceInterface */ protected function getPriceType() { return $this->getProduct()->getPriceInfo()->getPrice(LinkPrice::PRICE_CODE); } }