| 1 |
<?php |
| 2 |
|
| 3 |
declare( strict_types=1 ); |
| 4 |
|
| 5 |
namespace Packetery\Module\Views; |
| 6 |
|
| 7 |
use Packetery\Latte\Engine; |
| 8 |
use Packetery\Module\Framework\WpAdapter; |
| 9 |
use Packetery\Module\Order\DetailCommonLogic; |
| 10 |
use Packetery\Module\Order\Repository; |
| 11 |
use Packetery\Module\WcLogger; |
| 12 |
use WC_Order; |
| 13 |
|
| 14 |
class ViewFrontend { |
| 15 |
|
| 16 |
/** |
| 17 |
* @var Repository |
| 18 |
*/ |
| 19 |
private $orderRepository; |
| 20 |
|
| 21 |
/** |
| 22 |
* @var Engine |
| 23 |
*/ |
| 24 |
private $latteEngine; |
| 25 |
|
| 26 |
/** |
| 27 |
* @var DetailCommonLogic |
| 28 |
*/ |
| 29 |
private $detailCommonLogic; |
| 30 |
|
| 31 |
/** |
| 32 |
* @var WpAdapter |
| 33 |
*/ |
| 34 |
private $wpAdapter; |
| 35 |
|
| 36 |
public function __construct( |
| 37 |
Repository $orderRepository, |
| 38 |
Engine $latteEngine, |
| 39 |
DetailCommonLogic $detailCommonLogic, |
| 40 |
WpAdapter $wpAdapter |
| 41 |
) { |
| 42 |
$this->orderRepository = $orderRepository; |
| 43 |
$this->latteEngine = $latteEngine; |
| 44 |
$this->detailCommonLogic = $detailCommonLogic; |
| 45 |
$this->wpAdapter = $wpAdapter; |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Renders delivery detail for packetery orders, on "thank you" page and in frontend detail. |
| 50 |
* |
| 51 |
* @param WC_Order|mixed $wcOrder WordPress order. |
| 52 |
*/ |
| 53 |
public function renderOrderDetail( $wcOrder ): void { |
| 54 |
if ( ! $wcOrder instanceof WC_Order ) { |
| 55 |
WcLogger::logArgumentTypeError( __METHOD__, 'wcOrder', WC_Order::class, $wcOrder ); |
| 56 |
|
| 57 |
return; |
| 58 |
} |
| 59 |
|
| 60 |
$order = $this->orderRepository->getByWcOrderWithValidCarrier( $wcOrder ); |
| 61 |
if ( $order === null ) { |
| 62 |
return; |
| 63 |
} |
| 64 |
|
| 65 |
if ( $this->detailCommonLogic->shouldHidePacketaInfo( $order ) ) { |
| 66 |
return; |
| 67 |
} |
| 68 |
|
| 69 |
$this->latteEngine->render( |
| 70 |
PACKETERY_PLUGIN_DIR . '/template/order/detail.latte', |
| 71 |
[ |
| 72 |
'displayPickupPointInfo' => $this->detailCommonLogic->shouldDisplayPickupPointInfo(), |
| 73 |
'order' => $order, |
| 74 |
'translations' => [ |
| 75 |
'packeta' => $this->wpAdapter->__( 'Packeta', 'packeta' ), |
| 76 |
'pickupPointName' => $this->wpAdapter->__( 'Pickup Point Name', 'packeta' ), |
| 77 |
'pickupPointDetail' => $this->wpAdapter->__( 'Pickup Point Detail', 'packeta' ), |
| 78 |
'address' => $this->wpAdapter->__( 'Address', 'packeta' ), |
| 79 |
'packetTrackingOnline' => $this->wpAdapter->__( 'Packet tracking online', 'packeta' ), |
| 80 |
], |
| 81 |
] |
| 82 |
); |
| 83 |
} |
| 84 |
} |
| 85 |
|