init
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\Customer\Block\Account;
|
||||
|
||||
use Esun\Customer\Model\Order\AccountOrderProvider;
|
||||
use Esun\CustomerCoupon\Model\Coupon\ListProvider;
|
||||
use Esun\Review\Model\Order\AwaitingReviewProvider;
|
||||
use Esun\Reward\Model\BalanceManager;
|
||||
use Magento\Catalog\Helper\Image;
|
||||
use Magento\Customer\Model\Session;
|
||||
use Magento\Framework\View\Element\Template;
|
||||
use Magento\Wishlist\Helper\Data as WishlistHelper;
|
||||
|
||||
class Dashboard extends Template
|
||||
{
|
||||
public function __construct(
|
||||
Template\Context $context,
|
||||
private readonly Session $session,
|
||||
private readonly AccountOrderProvider $orders,
|
||||
private readonly AwaitingReviewProvider $awaitingReviews,
|
||||
private readonly BalanceManager $balances,
|
||||
private readonly ListProvider $coupons,
|
||||
private readonly WishlistHelper $wishlist,
|
||||
private readonly Image $imageHelper,
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct($context, $data);
|
||||
}
|
||||
|
||||
public function getCustomerName(): string
|
||||
{
|
||||
return trim((string)$this->session->getCustomer()->getName());
|
||||
}
|
||||
|
||||
public function getPoints(): int
|
||||
{
|
||||
$account = $this->balances->getAccount(
|
||||
(int)$this->session->getCustomerId(),
|
||||
(int)$this->_storeManager->getWebsite()->getId()
|
||||
);
|
||||
return (int)($account['balance'] ?? 0);
|
||||
}
|
||||
|
||||
public function getCounts(): array
|
||||
{
|
||||
$counts = $this->orders->getStatusCounts((int)$this->session->getCustomerId());
|
||||
$counts['awaiting_review'] = $this->awaitingReviews->getCount((int)$this->session->getCustomerId());
|
||||
return $counts;
|
||||
}
|
||||
|
||||
public function getLatestPending(): ?\Magento\Sales\Model\Order
|
||||
{
|
||||
return $this->orders->getLatestPending((int)$this->session->getCustomerId());
|
||||
}
|
||||
|
||||
public function getAvailableCoupons(): array
|
||||
{
|
||||
$items = $this->coupons->getForCustomer(
|
||||
(int)$this->session->getCustomerId(),
|
||||
(int)$this->_storeManager->getWebsite()->getId(),
|
||||
(int)$this->session->getCustomerGroupId()
|
||||
);
|
||||
return array_slice(array_values(array_filter($items, static fn(array $item): bool => $item['status'] === 'available')), 0, 2);
|
||||
}
|
||||
|
||||
public function getWishlistItems(): array
|
||||
{
|
||||
$collection = $this->wishlist->getWishlistItemCollection();
|
||||
$collection->setPageSize(4)->setCurPage(1);
|
||||
return array_values($collection->getItems());
|
||||
}
|
||||
|
||||
public function getProductImageUrl(\Magento\Catalog\Model\Product $product): string
|
||||
{
|
||||
return $this->imageHelper->init($product, 'wishlist_thumbnail')->getUrl();
|
||||
}
|
||||
|
||||
public function getOrderItemImageUrl(\Magento\Sales\Model\Order\Item $item): string
|
||||
{
|
||||
$product = $item->getProduct();
|
||||
return $product ? $this->getProductImageUrl($product) : $this->imageHelper->getDefaultPlaceholderUrl('thumbnail');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user