| Current Path : /home/rtorresani/www/vendor/magento/module-catalog-rule/Pricing/Price/ |
| Current File : //home/rtorresani/www/vendor/magento/module-catalog-rule/Pricing/Price/CatalogRulePrice.php |
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\CatalogRule\Pricing\Price;
use Magento\Catalog\Model\Product;
use Magento\CatalogRule\Model\ResourceModel\Rule;
use Magento\Customer\Model\Session;
use Magento\Framework\Pricing\Adjustment\Calculator;
use Magento\Framework\Pricing\Price\AbstractPrice;
use Magento\Framework\Pricing\Price\BasePriceProviderInterface;
use Magento\Framework\Pricing\PriceCurrencyInterface;
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
use Magento\Store\Model\StoreManagerInterface;
/**
* Class CatalogRulePrice
*
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
*/
class CatalogRulePrice extends AbstractPrice implements BasePriceProviderInterface
{
/**
* Price type identifier string
*/
const PRICE_CODE = 'catalog_rule_price';
/**
* @var TimezoneInterface
*/
protected $dateTime;
/**
* @var StoreManagerInterface
*/
protected $storeManager;
/**
* @var Session
*/
protected $customerSession;
/**
* @var Rule
*/
private $ruleResource;
/**
* @param Product $saleableItem
* @param float $quantity
* @param Calculator $calculator
* @param PriceCurrencyInterface $priceCurrency
* @param TimezoneInterface $dateTime
* @param StoreManagerInterface $storeManager
* @param Session $customerSession
* @param Rule $ruleResource
*/
public function __construct(
Product $saleableItem,
$quantity,
Calculator $calculator,
PriceCurrencyInterface $priceCurrency,
TimezoneInterface $dateTime,
StoreManagerInterface $storeManager,
Session $customerSession,
Rule $ruleResource
) {
parent::__construct($saleableItem, $quantity, $calculator, $priceCurrency);
$this->dateTime = $dateTime;
$this->storeManager = $storeManager;
$this->customerSession = $customerSession;
$this->ruleResource = $ruleResource;
}
/**
* Returns catalog rule value
*
* @return float|boolean
*/
public function getValue()
{
if (null === $this->value) {
if ($this->product->hasData(self::PRICE_CODE)) {
$value = $this->product->getData(self::PRICE_CODE);
$this->value = $value ? (float)$value : false;
} else {
$this->value = $this->ruleResource->getRulePrice(
$this->dateTime->scopeDate($this->storeManager->getStore()->getId()),
$this->storeManager->getStore()->getWebsiteId(),
$this->customerSession->getCustomerGroupId(),
$this->product->getId()
);
$this->value = $this->value ? (float)$this->value : false;
}
if ($this->value) {
$this->value = $this->priceCurrency->convertAndRound($this->value);
}
}
return $this->value;
}
}