Files
2026-09-15 10:35:56 +08:00

22 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
namespace Esun\Reward\Block\Cart;
use Esun\Reward\Model\BalanceManager;
use Esun\Reward\Model\Config;
use Magento\Checkout\Model\Session;
use Magento\Customer\Model\Session as CustomerSession;
use Magento\Framework\View\Element\Template;
class Reward extends Template
{
public function __construct(Template\Context $context, private readonly Session $checkoutSession, private readonly CustomerSession $customerSession, private readonly BalanceManager $balances, private readonly Config $config, array $data = []) { parent::__construct($context, $data); }
public function isLoggedIn(): bool { return $this->customerSession->isLoggedIn(); }
public function getBalance(): int { $quote = $this->checkoutSession->getQuote(); return $this->isLoggedIn() ? (int)$this->balances->getAccount((int)$this->customerSession->getCustomerId(), (int)$quote->getStore()->getWebsiteId())['balance'] : 0; }
public function getAppliedPoints(): int { return (int)$this->checkoutSession->getQuote()->getData('reward_points_used'); }
public function getMaximum(): int { return $this->config->maxCheckoutPoints((int)$this->checkoutSession->getQuote()->getStoreId()); }
public function getRate(): int { return $this->config->redemptionRate((int)$this->checkoutSession->getQuote()->getStoreId()); }
public function getApplyUrl(): string { return $this->getUrl('reward/cart/apply'); }
}