init
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\ProductInquiry\Block\Adminhtml\Inquiry;
|
||||
|
||||
use Esun\ProductInquiry\Model\Inquiry;
|
||||
use Magento\Backend\Block\Template;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\Framework\Serialize\Serializer\Json;
|
||||
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
|
||||
|
||||
class View extends Template
|
||||
{
|
||||
public function __construct(
|
||||
Template\Context $context,
|
||||
private readonly Registry $registry,
|
||||
private readonly Json $json,
|
||||
private readonly TimezoneInterface $timezone,
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct($context, $data);
|
||||
}
|
||||
|
||||
public function getInquiry(): Inquiry
|
||||
{
|
||||
return $this->registry->registry('current_product_inquiry');
|
||||
}
|
||||
|
||||
public function getSelectedOptions(): array
|
||||
{
|
||||
try {
|
||||
return (array)$this->json->unserialize((string)$this->getInquiry()->getData('selected_options'));
|
||||
} catch (\InvalidArgumentException) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function getStatusOptions(): array
|
||||
{
|
||||
return Inquiry::getStatuses();
|
||||
}
|
||||
|
||||
public function getAvailabilityLabel(): string
|
||||
{
|
||||
return match ((string)$this->getInquiry()->getData('availability_reason')) {
|
||||
'manual_out_of_stock' => (string)__('Out of Stock'),
|
||||
'msi_not_salable' => (string)__('MSI Not Salable'),
|
||||
'both' => (string)__('Out of Stock and MSI Not Salable'),
|
||||
default => (string)__('Unknown'),
|
||||
};
|
||||
}
|
||||
|
||||
public function getFormattedCreatedAt(): string
|
||||
{
|
||||
$timezoneName = (string)$this->timezone->getConfigTimezone() ?: 'UTC';
|
||||
$createdAt = new \DateTimeImmutable(
|
||||
(string)$this->getInquiry()->getData('created_at'),
|
||||
new \DateTimeZone('UTC')
|
||||
);
|
||||
$localCreatedAt = $createdAt->setTimezone(new \DateTimeZone($timezoneName));
|
||||
$formattedDate = $this->timezone->formatDateTime(
|
||||
$createdAt,
|
||||
\IntlDateFormatter::MEDIUM,
|
||||
\IntlDateFormatter::MEDIUM,
|
||||
null,
|
||||
$timezoneName
|
||||
);
|
||||
|
||||
return sprintf('%s (%s, UTC%s)', $formattedDate, $timezoneName, $localCreatedAt->format('P'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user