init
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\LegacyOrder\Block\Account;
|
||||
|
||||
use Magento\Customer\Model\Session;
|
||||
use Magento\Framework\App\ResourceConnection;
|
||||
use Magento\Framework\Serialize\Serializer\Json;
|
||||
use Magento\Framework\View\Element\Template;
|
||||
|
||||
class OrderView extends Template
|
||||
{
|
||||
/** @var array<string, mixed>|null */
|
||||
private ?array $order = null;
|
||||
|
||||
public function __construct(
|
||||
Template\Context $context,
|
||||
private readonly Session $customerSession,
|
||||
private readonly ResourceConnection $resource,
|
||||
private readonly Json $json,
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct($context, $data);
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
public function getOrder(): array
|
||||
{
|
||||
if ($this->order !== null) {
|
||||
return $this->order;
|
||||
}
|
||||
$connection = $this->resource->getConnection();
|
||||
return $this->order = $connection->fetchRow(
|
||||
$connection->select()
|
||||
->from($this->resource->getTableName('esun_legacy_order'))
|
||||
->where('legacy_order_id = ?', (int)$this->getRequest()->getParam('id'))
|
||||
->where('customer_id = ?', (int)$this->customerSession->getCustomerId())
|
||||
) ?: [];
|
||||
}
|
||||
|
||||
/** @return array<int, array<string, mixed>> */
|
||||
public function getItems(): array
|
||||
{
|
||||
$order = $this->getOrder();
|
||||
if (!$order) {
|
||||
return [];
|
||||
}
|
||||
$connection = $this->resource->getConnection();
|
||||
return $connection->fetchAll(
|
||||
$connection->select()
|
||||
->from($this->resource->getTableName('esun_legacy_order_item'))
|
||||
->where('legacy_order_id = ?', (int)$order['legacy_order_id'])
|
||||
->order('line_number ASC')
|
||||
);
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
public function decodeAddress(?string $value): array
|
||||
{
|
||||
try {
|
||||
return $value ? (array)$this->json->unserialize($value) : [];
|
||||
} catch (\Throwable) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user