123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Framework\Pricing\Render;
- use Magento\Framework\Pricing\SaleableInterface;
- use Magento\Framework\Pricing\Price\PriceInterface;
- use Magento\Framework\Pricing\PriceCurrencyInterface;
- use Magento\Framework\View\Element\Template;
- /**
- * Adjustment render abstract
- *
- * @method string getZone()
- */
- abstract class AbstractAdjustment extends Template implements AdjustmentRenderInterface
- {
- /**
- * @var PriceCurrencyInterface
- */
- protected $priceCurrency;
- /**
- * @var AmountRenderInterface
- */
- protected $amountRender;
- /**
- * @param Template\Context $context
- * @param PriceCurrencyInterface $priceCurrency
- * @param array $data
- */
- public function __construct(
- Template\Context $context,
- PriceCurrencyInterface $priceCurrency,
- array $data = []
- ) {
- $this->priceCurrency = $priceCurrency;
- parent::__construct($context, $data);
- }
- /**
- * @param AmountRenderInterface $amountRender
- * @param array $arguments
- * @return string
- */
- public function render(AmountRenderInterface $amountRender, array $arguments = [])
- {
- $this->amountRender = $amountRender;
- $origArguments = $this->getData();
- $this->setData(array_replace($origArguments, $arguments));
- $html = $this->apply();
- // restore original block arguments
- $this->setData($origArguments);
- return $html;
- }
- /**
- * @return AmountRenderInterface
- */
- public function getAmountRender()
- {
- return $this->amountRender;
- }
- /**
- * @param string $priceCode
- * @return PriceInterface
- */
- public function getPriceType($priceCode)
- {
- return $this->getSaleableItem()->getPriceInfo()->getPrice($priceCode);
- }
- /**
- * @return \Magento\Framework\Pricing\Price\PriceInterface
- */
- public function getPrice()
- {
- return $this->amountRender->getPrice();
- }
- /**
- * @return SaleableInterface
- */
- public function getSaleableItem()
- {
- return $this->amountRender->getSaleableItem();
- }
- /**
- * Format price value
- *
- * @param float $amount
- * @param bool $includeContainer
- * @param int $precision
- * @return string
- */
- public function formatCurrency(
- $amount,
- $includeContainer = true,
- $precision = PriceCurrencyInterface::DEFAULT_PRECISION
- ) {
- return $this->priceCurrency->format($amount, $includeContainer, $precision);
- }
- /**
- * Convert and format price value
- *
- * @param float $amount
- * @param bool $includeContainer
- * @param int $precision
- * @return string
- */
- public function convertAndFormatCurrency(
- $amount,
- $includeContainer = true,
- $precision = PriceCurrencyInterface::DEFAULT_PRECISION
- ) {
- return $this->priceCurrency->convertAndFormat($amount, $includeContainer, $precision);
- }
- /**
- * @return \Magento\Framework\Pricing\Adjustment\AdjustmentInterface
- */
- public function getAdjustment()
- {
- return $this->getSaleableItem()->getPriceInfo()->getAdjustment($this->getAdjustmentCode());
- }
- /**
- * @return string
- */
- abstract protected function apply();
- }
|