| 1 |
<?php |
| 2 |
|
| 3 |
namespace Packetery\Module\Views; |
| 4 |
|
| 5 |
use Packetery\Latte\Engine; |
| 6 |
use Packetery\Module\Framework\WpAdapter; |
| 7 |
use Packetery\Module\ModuleHelper; |
| 8 |
use Packetery\Module\Order\DetailCommonLogic; |
| 9 |
use Packetery\Module\Order\Repository; |
| 10 |
use WC_Email; |
| 11 |
use WC_Order; |
| 12 |
|
| 13 |
class ViewMail { |
| 14 |
|
| 15 |
/** |
| 16 |
* @var Repository |
| 17 |
*/ |
| 18 |
private $orderRepository; |
| 19 |
|
| 20 |
/** |
| 21 |
* @var Engine |
| 22 |
*/ |
| 23 |
private $latteEngine; |
| 24 |
|
| 25 |
/** |
| 26 |
* @var DetailCommonLogic |
| 27 |
*/ |
| 28 |
private $detailCommonLogic; |
| 29 |
|
| 30 |
/** |
| 31 |
* @var WpAdapter |
| 32 |
*/ |
| 33 |
private $wpAdapter; |
| 34 |
|
| 35 |
public function __construct( |
| 36 |
Repository $orderRepository, |
| 37 |
Engine $latteEngine, |
| 38 |
DetailCommonLogic $detailCommonLogic, |
| 39 |
WpAdapter $wpAdapter |
| 40 |
) { |
| 41 |
$this->orderRepository = $orderRepository; |
| 42 |
$this->latteEngine = $latteEngine; |
| 43 |
$this->detailCommonLogic = $detailCommonLogic; |
| 44 |
$this->wpAdapter = $wpAdapter; |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Renders email footer. |
| 49 |
* |
| 50 |
* @param mixed $email Email data. |
| 51 |
*/ |
| 52 |
public function renderEmailFooter( $email ): void { |
| 53 |
$wcOrder = null; |
| 54 |
if ( ( $email instanceof WC_Email ) && ( $email->object instanceof WC_Order ) ) { |
| 55 |
$wcOrder = $email->object; |
| 56 |
} |
| 57 |
|
| 58 |
if ( $email instanceof WC_Order ) { |
| 59 |
$wcOrder = $email; |
| 60 |
} |
| 61 |
|
| 62 |
if ( $wcOrder === null ) { |
| 63 |
return; |
| 64 |
} |
| 65 |
|
| 66 |
$order = $this->orderRepository->getByWcOrderWithValidCarrier( $wcOrder ); |
| 67 |
if ( $order === null ) { |
| 68 |
return; |
| 69 |
} |
| 70 |
|
| 71 |
if ( $this->detailCommonLogic->shouldHidePacketaInfo( $order ) ) { |
| 72 |
return; |
| 73 |
} |
| 74 |
|
| 75 |
$templateParams = [ |
| 76 |
'displayPickupPointInfo' => $this->detailCommonLogic->shouldDisplayPickupPointInfo(), |
| 77 |
'order' => $order, |
| 78 |
'translations' => [ |
| 79 |
'packeta' => $this->wpAdapter->__( 'Packeta', 'packeta' ), |
| 80 |
'pickupPointDetail' => $this->wpAdapter->__( 'Pickup Point Detail', 'packeta' ), |
| 81 |
'pickupPointName' => $this->wpAdapter->__( 'Pickup Point Name', 'packeta' ), |
| 82 |
'link' => $this->wpAdapter->__( 'Link', 'packeta' ), |
| 83 |
'pickupPointAddress' => $this->wpAdapter->__( 'Pickup Point Address', 'packeta' ), |
| 84 |
'packetTrackingOnline' => $this->wpAdapter->__( 'Packet tracking online', 'packeta' ), |
| 85 |
], |
| 86 |
]; |
| 87 |
$emailHtml = $this->latteEngine->renderToString( |
| 88 |
PACKETERY_PLUGIN_DIR . '/template/email/order.latte', |
| 89 |
$templateParams |
| 90 |
); |
| 91 |
/** |
| 92 |
* This filter allows you to change the HTML of e-mail footer. |
| 93 |
* |
| 94 |
* @since 1.5.3 |
| 95 |
*/ |
| 96 |
ModuleHelper::renderString( (string) $this->wpAdapter->applyFilters( 'packeta_email_footer', $emailHtml, $templateParams ) ); |
| 97 |
} |
| 98 |
} |
| 99 |
|