39 lines
1.1 KiB
PHP
39 lines
1.1 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Esun\LegacyOrder\Block\Account;
|
|
|
|
use Esun\LegacyOrder\Model\ResourceModel\Order\Collection;
|
|
use Esun\LegacyOrder\Model\ResourceModel\Order\CollectionFactory;
|
|
use Magento\Customer\Model\Session;
|
|
use Magento\Framework\View\Element\Template;
|
|
|
|
class History extends Template
|
|
{
|
|
private ?Collection $orders = null;
|
|
|
|
public function __construct(
|
|
Template\Context $context,
|
|
private readonly CollectionFactory $collectionFactory,
|
|
private readonly Session $customerSession,
|
|
array $data = []
|
|
) {
|
|
parent::__construct($context, $data);
|
|
}
|
|
|
|
public function getOrders(): Collection
|
|
{
|
|
if ($this->orders === null) {
|
|
$this->orders = $this->collectionFactory->create()
|
|
->addFieldToFilter('customer_id', (int)$this->customerSession->getCustomerId())
|
|
->setOrder('ordered_at', 'DESC');
|
|
}
|
|
return $this->orders;
|
|
}
|
|
|
|
public function getViewUrl(int $legacyOrderId): string
|
|
{
|
|
return $this->getUrl('legacy_order/account/view', ['id' => $legacyOrderId]);
|
|
}
|
|
}
|