| 1 |
<?php |
| 2 |
|
| 3 |
declare( strict_types=1 ); |
| 4 |
|
| 5 |
namespace Packetery\Module\Order; |
| 6 |
|
| 7 |
use Packetery\Latte\Engine; |
| 8 |
use Packetery\Module\Api\Internal\OrderRouter; |
| 9 |
use Packetery\Module\Framework\WpAdapter; |
| 10 |
|
| 11 |
class Modal { |
| 12 |
|
| 13 |
/** |
| 14 |
* @var Engine |
| 15 |
*/ |
| 16 |
private $latteEngine; |
| 17 |
|
| 18 |
/** |
| 19 |
* @var Form |
| 20 |
*/ |
| 21 |
private $orderForm; |
| 22 |
|
| 23 |
/** |
| 24 |
* @var OrderRouter |
| 25 |
*/ |
| 26 |
private $apiRouter; |
| 27 |
|
| 28 |
/** |
| 29 |
* @var WpAdapter |
| 30 |
*/ |
| 31 |
private $wpAdapter; |
| 32 |
|
| 33 |
public function __construct( |
| 34 |
Engine $latteEngine, |
| 35 |
Form $orderForm, |
| 36 |
OrderRouter $apiRouter, |
| 37 |
WpAdapter $wpAdapter |
| 38 |
) { |
| 39 |
$this->latteEngine = $latteEngine; |
| 40 |
$this->orderForm = $orderForm; |
| 41 |
$this->apiRouter = $apiRouter; |
| 42 |
$this->wpAdapter = $wpAdapter; |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Registers order modal. |
| 47 |
*/ |
| 48 |
public function register(): void { |
| 49 |
add_action( 'admin_head', [ $this, 'renderTemplate' ] ); |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Renders template. |
| 54 |
*/ |
| 55 |
public function renderTemplate(): void { |
| 56 |
$nonce = wp_create_nonce( 'wp_rest' ); |
| 57 |
$orderSaveUrl = $this->apiRouter->getSaveModalUrl(); |
| 58 |
|
| 59 |
$form = $this->orderForm->create(); |
| 60 |
$form->addSubmit( 'submit', $this->wpAdapter->__( 'Save', 'packeta' ) ); |
| 61 |
$form->addButton( 'cancel', $this->wpAdapter->__( 'Cancel', 'packeta' ) ); |
| 62 |
|
| 63 |
$this->latteEngine->render( |
| 64 |
PACKETERY_PLUGIN_DIR . '/template/order/modal-template.latte', |
| 65 |
[ |
| 66 |
'nonce' => $nonce, |
| 67 |
'orderSaveUrl' => $orderSaveUrl, |
| 68 |
'form' => $form, |
| 69 |
'translations' => [ |
| 70 |
// translators: %s: Order number. |
| 71 |
'order#%s' => $this->wpAdapter->__( 'Order #%s', 'packeta' ), |
| 72 |
|
| 73 |
'closeModalPanel' => $this->wpAdapter->__( 'Close modal panel', 'packeta' ), |
| 74 |
'weightIsManual' => $this->wpAdapter->__( 'Weight is manually set. To calculate weight remove the field content and save.', 'packeta' ), |
| 75 |
'codIsManual' => $this->wpAdapter->__( 'COD value is manually set. To calculate the value remove field content and save.', 'packeta' ), |
| 76 |
'valueIsManual' => $this->wpAdapter->__( 'Order value is manually set. To calculate the value remove field content and save.', 'packeta' ), |
| 77 |
'adultContent' => $this->wpAdapter->__( 'Adult content', 'packeta' ), |
| 78 |
], |
| 79 |
] |
| 80 |
); |
| 81 |
} |
| 82 |
} |
| 83 |
|