init
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\Reward\Model;
|
||||
|
||||
use Magento\Checkout\Model\Cart as CheckoutCart;
|
||||
use Magento\Checkout\Model\ConfigProviderInterface;
|
||||
use Magento\Customer\Helper\Session\CurrentCustomer;
|
||||
|
||||
class CheckoutConfigProvider implements ConfigProviderInterface
|
||||
{
|
||||
public function __construct(
|
||||
private readonly CheckoutCart $checkoutCart,
|
||||
private readonly CurrentCustomer $currentCustomer,
|
||||
private readonly BalanceManager $balances,
|
||||
private readonly Config $config
|
||||
) {}
|
||||
|
||||
public function getConfig(): array
|
||||
{
|
||||
$quote = $this->checkoutCart->getQuote();
|
||||
$customerId = (int)$this->currentCustomer->getCustomerId()
|
||||
?: (int)$quote->getCustomerId();
|
||||
$balance = $customerId > 0
|
||||
? (int)$this->balances->getAccount(
|
||||
$customerId,
|
||||
(int)$quote->getStore()->getWebsiteId()
|
||||
)['balance']
|
||||
: 0;
|
||||
|
||||
return ['esunReward' => [
|
||||
'logged_in' => $customerId > 0,
|
||||
'balance' => $balance,
|
||||
'applied_points' => (int)$quote->getData('reward_points_used'),
|
||||
'maximum' => $this->config->maxCheckoutPoints((int)$quote->getStoreId()),
|
||||
'rate' => $this->config->redemptionRate((int)$quote->getStoreId()),
|
||||
]];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user