PluginProbe
Packeta / 2.1
Packeta v2.1
2.3.2 2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 All 56 releases
← All changes | src/Packetery/Module/Order/Metabox.php +334 -315 1.6.12.1 View file →
@@ -1,317 +1,247 @@
1 1 <?php
2 -/**
3 - * Class Metabox
4 - *
5 - * @package Packetery\Order
6 - */
7 2
8 3 declare( strict_types=1 );
9 4
10 5 namespace Packetery\Module\Order;
11 6
7 +use Packetery\Core\CoreHelper;
12 8 use Packetery\Core\Entity;
13 -use Packetery\Core\Helper;
14 9 use Packetery\Core\Validator;
15 -use Packetery\Module;
10 +use Packetery\Latte\Engine;
16 11 use Packetery\Module\Carrier\EntityRepository;
17 12 use Packetery\Module\Exception\InvalidCarrierException;
18 -use Packetery\Module\FormFactory;
19 -use Packetery\Module\FormValidators;
13 +use Packetery\Module\Framework\WpAdapter;
20 14 use Packetery\Module\Log;
15 +use Packetery\Module\Log\Page;
21 16 use Packetery\Module\MessageManager;
22 -use Packetery\Module\Options;
17 +use Packetery\Module\ModuleHelper;
18 +use Packetery\Module\Options\OptionsProvider;
23 19 use Packetery\Module\Plugin;
20 +use Packetery\Module\Transients;
24 21 use Packetery\Module\WidgetOptionsBuilder;
25 -use Packetery\Latte\Engine;
26 -use Packetery\Nette\Forms\Form;
22 +use Packetery\Nette\Forms;
27 23 use Packetery\Nette\Http\Request;
28 24 use WC_Data_Exception;
29 25 use WC_Order;
30 26
31 -/**
32 - * Class Metabox
33 - *
34 - * @package Packetery\Order
35 - */
36 27 class Metabox {
37 28
38 - public const FIELD_WEIGHT = 'packetery_weight';
39 - private const FIELD_ORIGINAL_WEIGHT = 'packetery_original_weight';
40 - public const FIELD_WIDTH = 'packetery_width';
41 - public const FIELD_LENGTH = 'packetery_length';
42 - public const FIELD_HEIGHT = 'packetery_height';
43 - public const FIELD_ADULT_CONTENT = 'packetery_adult_content';
44 - public const FIELD_COD = 'packetery_COD';
45 - public const FIELD_VALUE = 'packetery_value';
46 - public const FIELD_DELIVER_ON = 'packetery_deliver_on';
29 + private const PART_ERROR = 'error';
30 + private const PART_CARRIER_CHANGE = 'carrierChange';
31 + private const PART_MAIN = 'main';
47 32
48 33 /**
49 - * PacketeryLatte engine.
50 - *
51 34 * @var Engine
52 35 */
53 - private $latte_engine;
36 + private $latteEngine;
54 37
55 38 /**
56 - * Message manager.
57 - *
58 39 * @var MessageManager
59 40 */
60 - private $message_manager;
41 + private $messageManager;
61 42
62 43 /**
63 - * Helper.
64 - *
65 - * @var Helper
44 + * @var CoreHelper
66 45 */
67 - private $helper;
46 + private $coreHelper;
68 47
69 48 /**
70 - * HTTP request.
71 - *
72 49 * @var Request
73 50 */
74 51 private $request;
75 52
76 53 /**
77 - * Order form.
78 - *
79 - * @var Form
54 + * @var Forms\Form
80 55 */
81 - private $order_form;
56 + private $form;
82 57
83 58 /**
84 - * Options provider.
85 - *
86 - * @var Options\Provider
59 + * @var Form
87 60 */
88 - private $optionsProvider;
61 + private $orderForm;
89 62
90 63 /**
91 - * Form factory.
92 - *
93 - * @var FormFactory
64 + * @var OptionsProvider
94 65 */
95 - private $formFactory;
66 + private $optionsProvider;
96 67
97 68 /**
98 - * Repository.
99 - *
100 69 * @var Repository
101 70 */
102 71 private $orderRepository;
103 72
104 73 /**
105 - * Log page.
106 - *
107 74 * @var Log\Page
108 75 */
109 76 private $logPage;
110 77
111 78 /**
112 - * OrderFacade.
113 - *
114 79 * @var AttributeMapper
115 80 */
116 81 private $mapper;
117 82
118 83 /**
119 - * Widget options builder.
120 - *
121 84 * @var WidgetOptionsBuilder
122 85 */
123 86 private $widgetOptionsBuilder;
124 87
125 88 /**
126 - * Carrier repository.
127 - *
128 89 * @var EntityRepository
129 90 */
130 91 private $carrierRepository;
131 92
132 93 /**
133 - * Order validator.
134 - *
135 94 * @var Validator\Order
136 95 */
137 96 private $orderValidator;
138 97
139 98 /**
140 - * Order detail common logic.
141 - *
142 99 * @var DetailCommonLogic
143 100 */
144 101 private $detailCommonLogic;
145 102
146 103 /**
147 - * Metabox constructor.
148 - *
149 - * @param Engine $latte_engine PacketeryLatte engine.
150 - * @param MessageManager $message_manager Message manager.
151 - * @param Helper $helper Helper.
152 - * @param Request $request Http request.
153 - * @param Options\Provider $optionsProvider Options provider.
154 - * @param FormFactory $formFactory Form factory.
155 - * @param Repository $orderRepository Order repository.
156 - * @param Log\Page $logPage Log page.
157 - * @param AttributeMapper $mapper AttributeMapper.
158 - * @param WidgetOptionsBuilder $widgetOptionsBuilder Widget options builder.
159 - * @param EntityRepository $carrierRepository Carrier repository.
160 - * @param Validator\Order $orderValidator Order validator.
161 - * @param DetailCommonLogic $detailCommonLogic Detail common logic.
104 + * @var CarrierModal
162 105 */
106 + private $carrierModal;
107 +
108 + /**
109 + * @var WpAdapter
110 + */
111 + private $wpAdapter;
112 +
113 + /**
114 + * @var PacketStatusResolver
115 + */
116 + private $packetStatusResolver;
117 +
163 118 public function __construct(
164 - Engine $latte_engine,
165 - MessageManager $message_manager,
166 - Helper $helper,
119 + Engine $latteEngine,
120 + MessageManager $messageManager,
121 + CoreHelper $coreHelper,
167 122 Request $request,
168 - Options\Provider $optionsProvider,
169 - FormFactory $formFactory,
123 + OptionsProvider $optionsProvider,
170 124 Repository $orderRepository,
171 - Log\Page $logPage,
125 + Page $logPage,
172 126 AttributeMapper $mapper,
173 127 WidgetOptionsBuilder $widgetOptionsBuilder,
174 128 EntityRepository $carrierRepository,
175 - Validator\Order $orderValidator,
176 - DetailCommonLogic $detailCommonLogic
129 + OrderValidatorFactory $orderValidatorFactory,
130 + DetailCommonLogic $detailCommonLogic,
131 + Form $orderForm,
132 + CarrierModal $carrierModal,
133 + WpAdapter $wpAdapter,
134 + PacketStatusResolver $packetStatusResolver
177 135 ) {
178 - $this->latte_engine = $latte_engine;
179 - $this->message_manager = $message_manager;
180 - $this->helper = $helper;
136 + $this->latteEngine = $latteEngine;
137 + $this->messageManager = $messageManager;
138 + $this->coreHelper = $coreHelper;
181 139 $this->request = $request;
182 140 $this->optionsProvider = $optionsProvider;
183 - $this->formFactory = $formFactory;
184 141 $this->orderRepository = $orderRepository;
185 142 $this->logPage = $logPage;
186 143 $this->mapper = $mapper;
187 144 $this->widgetOptionsBuilder = $widgetOptionsBuilder;
188 145 $this->carrierRepository = $carrierRepository;
189 - $this->orderValidator = $orderValidator;
146 + $this->orderValidator = $orderValidatorFactory->create();
190 147 $this->detailCommonLogic = $detailCommonLogic;
148 + $this->orderForm = $orderForm;
149 + $this->carrierModal = $carrierModal;
150 + $this->wpAdapter = $wpAdapter;
151 + $this->packetStatusResolver = $packetStatusResolver;
191 152 }
192 153
193 - /**
194 - * Registers related hooks.
195 - */
196 154 public function register(): void {
197 - add_action(
198 - 'admin_init',
199 - function () {
200 - $this->order_form = $this->formFactory->create();
201 - $this->add_fields();
202 - }
203 - );
204 155 add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
205 156 }
206 157
207 - /**
208 - * Add metaboxes
209 - */
210 158 public function add_meta_boxes(): void {
211 - $orderId = $this->detailCommonLogic->getOrderId();
212 - if ( null === $orderId ) {
159 + if ( ! $this->detailCommonLogic->isPacketeryOrder() ) {
213 160 return;
214 161 }
215 162
216 - try {
217 - $order = $this->orderRepository->getById( $orderId );
218 - if ( null === $order ) {
219 - return;
220 - }
221 - // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
222 - } catch ( InvalidCarrierException $exception ) {
223 - // Let's display message in the box.
163 + $this->initializeForm();
164 + $parts = $this->prepareMetaboxParts();
165 +
166 + if ( count( $parts ) > 0 ) {
167 + add_meta_box(
168 + 'packetery_metabox',
169 + $this->wpAdapter->__( 'Packeta', 'packeta' ),
170 + array(
171 + $this,
172 + 'render_metabox',
173 + ),
174 + ModuleHelper::isHposEnabled() ? wc_get_page_screen_id( 'shop-order' ) : 'shop_order',
175 + 'side',
176 + 'high'
177 + );
224 178 }
179 + }
225 180
226 - add_meta_box(
227 - 'packetery_metabox',
228 - __( 'Packeta', 'packeta' ),
229 - array(
230 - $this,
231 - 'render_metabox',
232 - ),
233 - Module\Helper::isHposEnabled() ? wc_get_page_screen_id( 'shop-order' ) : 'shop_order',
234 - 'side',
235 - 'high'
236 - );
237 - }
181 + public function render_metabox(): void {
182 + $parts = $this->prepareMetaboxParts();
238 183
239 - /**
240 - * Adds packetery fields to order form.
241 - */
242 - public function add_fields(): void {
243 - $this->order_form->addHidden( 'packetery_order_metabox_nonce' );
244 - $this->order_form->addText( self::FIELD_WEIGHT, __( 'Weight (kg)', 'packeta' ) )
245 - ->setRequired( false )
246 - ->addRule( $this->order_form::FLOAT, __( 'Provide numeric value!', 'packeta' ) );
247 - $this->order_form->addHidden( self::FIELD_ORIGINAL_WEIGHT );
248 - $this->order_form->addText( self::FIELD_WIDTH, __( 'Width (mm)', 'packeta' ) )
249 - ->setRequired( false )
250 - ->addRule( $this->order_form::FLOAT, __( 'Provide numeric value!', 'packeta' ) );
251 - $this->order_form->addText( self::FIELD_LENGTH, __( 'Length (mm)', 'packeta' ) )
252 - ->setRequired( false )
253 - ->addRule( $this->order_form::FLOAT, __( 'Provide numeric value!', 'packeta' ) );
254 - $this->order_form->addText( self::FIELD_HEIGHT, __( 'Height (mm)', 'packeta' ) )
255 - ->setRequired( false )
256 - ->addRule( $this->order_form::FLOAT, __( 'Provide numeric value!', 'packeta' ) );
257 - $this->order_form->addCheckbox( self::FIELD_ADULT_CONTENT, __( 'Adult content', 'packeta' ) )
258 - ->setRequired( false );
259 - $this->order_form->addText( self::FIELD_COD, __( 'Cash on delivery', 'packeta' ) )
260 - ->setRequired( false )
261 - ->addRule( $this->order_form::FLOAT );
262 - $this->order_form->addText( self::FIELD_VALUE, __( 'Order value', 'packeta' ) )
263 - ->setRequired( false )
264 - ->addRule( $this->order_form::FLOAT );
265 - $this->order_form->addText( self::FIELD_DELIVER_ON, __( 'Planned dispatch', 'packeta' ) )
266 - ->setHtmlAttribute( 'autocomplete', 'off' )
267 - ->setRequired( false )
268 - // translators: %s: Represents minimal date for delayed delivery.
269 - ->addRule( [ FormValidators::class, 'dateIsLater' ], __( 'Date must be later than %s', 'packeta' ), wp_date( Helper::DATEPICKER_FORMAT ) );
184 + if ( isset( $parts[ self::PART_ERROR ] ) ) {
185 + ModuleHelper::renderString( $parts[ self::PART_ERROR ] );
270 186
271 - foreach ( Attribute::$pickupPointAttrs as $pickupPointAttr ) {
272 - $this->order_form->addHidden( $pickupPointAttr['name'] );
187 + return;
273 188 }
274 189
275 - foreach ( Attribute::$homeDeliveryAttrs as $homeDeliveryAttr ) {
276 - $this->order_form->addHidden( $homeDeliveryAttr['name'] );
190 + if ( isset( $parts[ self::PART_CARRIER_CHANGE ] ) ) {
191 + ModuleHelper::renderString( $parts[ self::PART_CARRIER_CHANGE ] );
277 192 }
278 -
279 - $this->order_form->addButton( 'packetery_pick_pickup_point', __( 'Choose pickup point', 'packeta' ) );
280 - $this->order_form->addButton( 'packetery_pick_address', __( 'Check shipping address', 'packeta' ) );
193 + if ( isset( $parts[ self::PART_CARRIER_CHANGE ], $parts[ self::PART_MAIN ] ) ) {
194 + ModuleHelper::renderString( '<hr>' );
195 + }
196 + if ( isset( $parts[ self::PART_MAIN ] ) ) {
197 + ModuleHelper::renderString( $parts[ self::PART_MAIN ] );
198 + }
281 199 }
282 200
283 201 /**
284 - * Renders metabox
202 + * @return array<string, string>
285 203 */
286 - public function render_metabox(): void {
204 + private function prepareMetaboxParts(): array {
205 + static $partsCache;
206 +
207 + if ( isset( $partsCache ) ) {
208 + return $partsCache;
209 + }
210 +
287 211 $orderId = $this->detailCommonLogic->getOrderId();
288 - if ( null === $orderId ) {
289 - return;
290 - }
212 + if ( $orderId === null ) {
213 + $partsCache = [];
291 214
292 - $wcOrder = $this->orderRepository->getWcOrderById( $orderId );
293 - if ( null === $wcOrder ) {
294 - return;
215 + return $partsCache;
295 216 }
296 217
297 218 try {
298 - $order = $this->orderRepository->getByWcOrder( $wcOrder );
219 + $order = $this->orderRepository->getById( $orderId );
299 220 } catch ( InvalidCarrierException $exception ) {
300 - $this->latte_engine->render(
301 - PACKETERY_PLUGIN_DIR . '/template/order/metabox-form-error.latte',
302 - [
303 - 'errorMessage' => $exception->getMessage(),
304 - ]
305 - );
221 + $partsCache = [
222 + self::PART_ERROR => $this->latteEngine->renderToString(
223 + PACKETERY_PLUGIN_DIR . '/template/order/metabox-form-error.latte',
224 + [
225 + 'errorMessage' => $exception->getMessage(),
226 + ]
227 + ),
228 + ];
306 229
307 - return;
230 + return $partsCache;
308 231 }
309 - if ( null === $order ) {
310 - return;
232 +
233 + $parts = [];
234 + if ( $this->carrierModal->canBeDisplayed() ) {
235 + $parts[ self::PART_CARRIER_CHANGE ] = $this->carrierModal->getMetaboxHtml();
311 236 }
312 - $packetId = $order->getPacketId();
313 237
238 + if ( $order === null ) {
239 + $partsCache = $parts;
240 +
241 + return $partsCache;
242 + }
243 +
314 244 $showLogsLink = null;
315 245 if ( $this->logPage->hasAnyRows( (int) $order->getNumber() ) ) {
316 246 $showLogsLink = $this->logPage->createLogListUrl( (int) $order->getNumber() );
317 247 }
@@ -322,9 +252,9 @@
322 252 }
323 253
324 254 $packetClaimCancelUrl = null;
325 255 $packetClaimTrackingUrl = null;
326 - if ( $order->getPacketClaimId() ) {
256 + if ( $order->getPacketClaimId() !== null ) {
327 257 $packetClaimCancelUrl = $this->getOrderActionLink(
328 258 $order,
329 259 PacketActionsCommonLogic::ACTION_CANCEL_PACKET,
330 260 [
@@ -330,12 +260,16 @@
330 260 [
331 261 PacketActionsCommonLogic::PARAM_PACKET_ID => $order->getPacketClaimId(),
332 262 ]
333 263 );
334 - $packetClaimTrackingUrl = $this->helper->get_tracking_url( $order->getPacketClaimId() );
264 + $packetClaimTrackingUrl = $this->coreHelper->getTrackingUrl( $order->getPacketClaimId() );
335 265 }
266 + $runWizardUrl = $this->wpAdapter->adminUrl( "admin.php?page=wc-orders&action=edit&id={$orderId}&wizard-enabled=true&wizard-order-detail-edit-packet-enabled=true" );
336 267
337 - if ( $packetId ) {
268 + $showRunWizardButton = (bool) $this->wpAdapter->applyFilters( 'packeta_order_detail_show_run_wizard_button', true );
269 +
270 + $packetId = $order->getPacketId();
271 + if ( $packetId !== null ) {
338 272 $packetCancelLink = $this->getOrderActionLink(
339 273 $order,
340 274 PacketActionsCommonLogic::ACTION_CANCEL_PACKET,
341 275 [
@@ -341,68 +275,98 @@
341 275 [
342 276 PacketActionsCommonLogic::PARAM_PACKET_ID => $packetId,
343 277 ]
344 278 );
345 - $this->latte_engine->render(
279 +
280 + $packetStatusTranslatedName = $this->packetStatusResolver->getTranslatedName( $order->getPacketStatus() );
281 + /** @var array<string, string> $statusClasses */
282 + $statusClasses = [
283 + 'received data' => 'received-data',
284 + 'unknown' => 'unknown',
285 + 'delivered' => 'delivered',
286 + 'cancelled' => 'cancelled',
287 + 'returned' => 'returned',
288 + 'rejected by recipient' => 'rejected',
289 + ];
290 +
291 + $statusClass = 'delivery-status';
292 + $statusType = $order->getPacketStatus();
293 +
294 + if ( isset( $statusClasses[ $statusType ] ) ) {
295 + $statusClass = $statusClasses[ $statusType ];
296 + }
297 +
298 + $parts[ self::PART_MAIN ] = $this->latteEngine->renderToString(
346 299 PACKETERY_PLUGIN_DIR . '/template/order/metabox-common.latte',
347 300 [
348 - 'order' => $order,
349 - 'showSubmitPacketButton' => false,
350 - 'packetCancelLink' => $packetCancelLink,
351 - 'packetTrackingUrl' => $this->helper->get_tracking_url( $packetId ),
352 - 'packetClaimTrackingUrl' => $packetClaimTrackingUrl,
353 - 'showLogsLink' => $showLogsLink,
354 - 'packetClaimUrl' => $packetClaimUrl,
355 - 'packetClaimCancelUrl' => $packetClaimCancelUrl,
356 - 'translations' => [
357 - 'packetTrackingOnline' => __( 'Packet tracking online', 'packeta' ),
358 - 'packetClaimTrackingOnline' => __( 'Packet claim tracking', 'packeta' ),
359 - 'showLogs' => __( 'Show logs', 'packeta' ),
301 + 'order' => $order,
302 + 'packetStatusTranslatedName' => $packetStatusTranslatedName,
303 + 'statusClass' => $statusClass,
304 + 'isPacketSubmissionPossible' => false,
305 + 'orderWarningFields' => [],
306 + 'packetCancelLink' => $packetCancelLink,
307 + 'packetTrackingUrl' => $this->coreHelper->getTrackingUrl( $packetId ),
308 + 'packetClaimTrackingUrl' => $packetClaimTrackingUrl,
309 + 'showLogsLink' => $showLogsLink,
310 + 'packetClaimUrl' => $packetClaimUrl,
311 + 'packetClaimCancelUrl' => $packetClaimCancelUrl,
312 + 'runWizardUrl' => $runWizardUrl,
313 + 'showRunWizardButton' => $showRunWizardButton,
314 + 'storedUntil' => $this->coreHelper->getStringFromDateTime( $order->getStoredUntil(), CoreHelper::DATEPICKER_FORMAT ),
315 + 'translations' => [
316 + 'packetTrackingOnline' => $this->wpAdapter->__( 'Packet tracking online', 'packeta' ),
317 + 'packetClaimTrackingOnline' => $this->wpAdapter->__( 'Packet claim tracking', 'packeta' ),
318 + 'showLogs' => $this->wpAdapter->__( 'Show logs', 'packeta' ),
360 319 // translators: %s: Order number.
361 - 'reallyCancelPacketHeading' => sprintf( __( 'Order #%s', 'packeta' ), $order->getCustomNumber() ),
320 + 'reallyCancelPacketHeading' => sprintf( $this->wpAdapter->__( 'Order #%s', 'packeta' ), $order->getCustomNumber() ),
362 321 // translators: %s: Packet number.
363 - 'reallyCancelPacket' => sprintf( __( 'Do you really wish to cancel parcel number %s?', 'packeta' ), $packetId ),
322 + 'reallyCancelPacket' => sprintf( $this->wpAdapter->__( 'Do you really wish to cancel parcel number %s?', 'packeta' ), $packetId ),
364 323 // translators: %s: Packet claim number.
365 - 'reallyCancelPacketClaim' => sprintf( __( 'Do you really wish to cancel packet claim number %s?', 'packeta' ), $order->getPacketClaimId() ),
324 + 'reallyCancelPacketClaim' => sprintf( $this->wpAdapter->__( 'Do you really wish to cancel packet claim number %s?', 'packeta' ), $order->getPacketClaimId() ),
366 325
367 - 'cancelPacket' => __( 'Cancel packet', 'packeta' ),
368 - 'createPacketClaim' => __( 'Create packet claim', 'packeta' ),
369 - 'printPacketLabel' => __( 'Print packet label', 'packeta' ),
370 - 'printPacketClaimLabel' => __( 'Print packet claim label', 'packeta' ),
371 - 'cancelPacketClaim' => __( 'Cancel packet claim', 'packeta' ),
372 - 'packetClaimPassword' => __( 'Packet claim password', 'packeta' ),
373 - 'submissionPassword' => __( 'submission password', 'packeta' ),
326 + 'cancelPacket' => $this->wpAdapter->__( 'Cancel packet', 'packeta' ),
327 + 'createPacketClaim' => $this->wpAdapter->__( 'Create packet claim', 'packeta' ),
328 + 'printPacketLabel' => $this->wpAdapter->__( 'Print packet label', 'packeta' ),
329 + 'printPacketClaimLabel' => $this->wpAdapter->__( 'Print packet claim label', 'packeta' ),
330 + 'cancelPacketClaim' => $this->wpAdapter->__( 'Cancel packet claim', 'packeta' ),
331 + 'packetClaimPassword' => $this->wpAdapter->__( 'Packet claim password', 'packeta' ),
332 + 'submissionPassword' => $this->wpAdapter->__( 'submission password', 'packeta' ),
333 + 'setStoredUntil' => $this->wpAdapter->__( 'Set the pickup date extension', 'packeta' ),
334 + 'runWizard' => $this->wpAdapter->__( 'Run options wizard', 'packeta' ),
374 335 ],
375 336 ]
376 337 );
377 338
378 - return;
339 + $partsCache = $parts;
340 +
341 + return $partsCache;
379 342 }
380 343
381 - $this->order_form->setDefaults(
382 - [
383 - 'packetery_order_metabox_nonce' => wp_create_nonce(),
384 - self::FIELD_WEIGHT => $order->getFinalWeight(),
385 - self::FIELD_ORIGINAL_WEIGHT => $order->getFinalWeight(),
386 - self::FIELD_WIDTH => $order->getWidth(),
387 - self::FIELD_LENGTH => $order->getLength(),
388 - self::FIELD_HEIGHT => $order->getHeight(),
389 - self::FIELD_ADULT_CONTENT => $order->containsAdultContent(),
390 - self::FIELD_COD => $order->getCod(),
391 - self::FIELD_VALUE => $order->getValue(),
392 - self::FIELD_DELIVER_ON => $this->helper->getStringFromDateTime( $order->getDeliverOn(), Helper::DATEPICKER_FORMAT ),
393 - ]
344 + $unit = $this->optionsProvider->getDimensionsUnit();
345 + $this->orderForm->setDefaults(
346 + $this->form,
347 + $order->getFinalWeight(),
348 + $order->getCalculatedWeight(),
349 + $unit === OptionsProvider::DIMENSIONS_UNIT_CM ? ModuleHelper::convertToCentimeters( (int) $order->getLength() ) : $order->getLength(),
350 + $unit === OptionsProvider::DIMENSIONS_UNIT_CM ? ModuleHelper::convertToCentimeters( (int) $order->getWidth() ) : $order->getWidth(),
351 + $unit === OptionsProvider::DIMENSIONS_UNIT_CM ? ModuleHelper::convertToCentimeters( (int) $order->getHeight() ) : $order->getHeight(),
352 + $order->getFinalCod(),
353 + $order->getCalculatedCod(),
354 + $order->getFinalValue(),
355 + $order->getCalculatedValue(),
356 + $order->containsAdultContent(),
357 + $this->coreHelper->getStringFromDateTime( $order->getDeliverOn(), CoreHelper::DATEPICKER_FORMAT )
394 358 );
395 359
396 - $prev_invalid_values = get_transient( 'packetery_metabox_nette_form_prev_invalid_values' );
397 - if ( $prev_invalid_values ) {
398 - $this->order_form->setValues( $prev_invalid_values );
399 - $this->order_form->validate();
360 + $prevInvalidValues = get_transient( Transients::METABOX_NETTE_FORM_PREV_INVALID_VALUES );
361 + if ( $prevInvalidValues !== null && $prevInvalidValues !== false ) {
362 + $this->form->setValues( $prevInvalidValues );
363 + $this->form->validate();
400 364 }
401 - delete_transient( 'packetery_metabox_nette_form_prev_invalid_values' );
365 + delete_transient( Transients::METABOX_NETTE_FORM_PREV_INVALID_VALUES );
402 366
403 - $showSubmitPacketButton = $this->orderValidator->isValid( $order );
404 - $packetSubmitUrl = $this->getOrderActionLink( $order, PacketActionsCommonLogic::ACTION_SUBMIT_PACKET );
367 + $isPacketSubmissionPossible = $this->orderValidator->isValid( $order );
368 + $packetSubmitUrl = $this->getOrderActionLink( $order, PacketActionsCommonLogic::ACTION_SUBMIT_PACKET );
405 369
406 370 $showWidgetButton = $order->isPickupPointDelivery();
407 371 $widgetButtonError = null;
408 372 $shippingCountry = $order->getShippingCountry();
@@ -407,15 +371,15 @@
407 371 $widgetButtonError = null;
408 372 $shippingCountry = $order->getShippingCountry();
409 373 $showHdWidget = $order->isHomeDelivery() && in_array( $shippingCountry, Entity\Carrier::ADDRESS_VALIDATION_COUNTRIES, true );
410 374 if (
411 - null === $shippingCountry ||
375 + $shippingCountry === null ||
412 376 ! $this->carrierRepository->isValidForCountry( $order->getCarrier()->getId(), $shippingCountry )
413 377 ) {
414 378 if ( $order->isPickupPointDelivery() ) {
415 379 $showWidgetButton = false;
416 - if ( empty( $shippingCountry ) ) {
417 - $widgetButtonError = __(
380 + if ( $shippingCountry === null ) {
381 + $widgetButtonError = $this->wpAdapter->__(
418 382 'The pickup point cannot be changed because the shipping address has no country set. First, change the country of delivery in the shipping address.',
419 383 'packeta'
420 384 );
421 385 } else {
@@ -420,9 +384,9 @@
420 384 );
421 385 } else {
422 386 $widgetButtonError = sprintf(
423 387 // translators: %s is country code.
424 - __(
388 + $this->wpAdapter->__(
425 389 'The pickup point cannot be changed because the selected carrier does not deliver to country "%s". First, change the country of delivery in the shipping address.',
426 390 'packeta'
427 391 ),
428 392 $shippingCountry
@@ -429,10 +393,10 @@
429 393 );
430 394 }
431 395 } elseif ( in_array( $order->getCarrier()->getCountry(), Entity\Carrier::ADDRESS_VALIDATION_COUNTRIES, true ) ) {
432 396 $showHdWidget = false;
433 - if ( empty( $shippingCountry ) ) {
434 - $widgetButtonError = __(
397 + if ( $shippingCountry === null ) {
398 + $widgetButtonError = $this->wpAdapter->__(
435 399 'The address cannot be validated because the shipping address has no country set. First, change the country of delivery in the shipping address.',
436 400 'packeta'
437 401 );
438 402 } else {
@@ -437,9 +401,9 @@
437 401 );
438 402 } else {
439 403 $widgetButtonError = sprintf(
440 404 // translators: %s is country code.
441 - __(
405 + $this->wpAdapter->__(
442 406 'The address cannot be validated because the selected carrier does not deliver to country "%s". First, change the country of delivery in the shipping address.',
443 407 'packeta'
444 408 ),
445 409 $shippingCountry
@@ -447,110 +411,126 @@
447 411 }
448 412 }
449 413 }
450 414
451 - $this->latte_engine->render(
415 + $parts[ self::PART_MAIN ] = $this->latteEngine->renderToString(
452 416 PACKETERY_PLUGIN_DIR . '/template/order/metabox-form.latte',
453 417 [
454 - 'form' => $this->order_form,
455 - 'order' => $order,
456 - 'showWidgetButton' => $showWidgetButton,
457 - 'widgetButtonError' => $widgetButtonError,
458 - 'showHdWidget' => $showHdWidget,
459 - 'showSubmitPacketButton' => $showSubmitPacketButton,
460 - 'packetCancelLink' => null,
461 - 'packetTrackingUrl' => null,
462 - 'packetSubmitUrl' => $packetSubmitUrl,
463 - 'packetClaimTrackingUrl' => $packetClaimTrackingUrl,
464 - 'packetClaimUrl' => $packetClaimUrl,
465 - 'packetClaimCancelUrl' => $packetClaimCancelUrl,
466 - 'orderCurrency' => get_woocommerce_currency_symbol( $order->getCurrency() ),
467 - 'isCodPayment' => $wcOrder->get_payment_method() === $this->optionsProvider->getCodPaymentMethod(),
468 - 'logo' => plugin_dir_url( PACKETERY_PLUGIN_DIR . '/packeta.php' ) . 'public/packeta-symbol.png',
469 - 'showLogsLink' => $showLogsLink,
470 - 'hasOrderManualWeight' => $order->hasManualWeight(),
471 - 'isPacketaPickupPoint' => $order->isPacketaInternalPickupPoint(),
472 - 'translations' => [
473 - 'showLogs' => __( 'Show logs', 'packeta' ),
474 - 'weightIsManual' => __( 'Weight is manually set. To calculate weight remove field content and save.', 'packeta' ),
475 - 'submitPacket' => __( 'Submit to packeta', 'packeta' ),
476 - 'packetClaimTrackingOnline' => __( 'Packet claim tracking', 'packeta' ),
477 - 'printPacketClaimLabel' => __( 'Print packet claim label', 'packeta' ),
478 - 'cancelPacketClaim' => __( 'Cancel packet claim', 'packeta' ),
479 - 'packetClaimPassword' => __( 'Packet claim password', 'packeta' ),
480 - 'submissionPassword' => __( 'submission password', 'packeta' ),
418 + 'form' => $this->form,
419 + 'order' => $order,
420 + 'showWidgetButton' => $showWidgetButton,
421 + 'widgetButtonError' => $widgetButtonError,
422 + 'showHdWidget' => $showHdWidget,
423 + 'isPacketSubmissionPossible' => $isPacketSubmissionPossible,
424 + 'orderWarningFields' => Form::getInvalidFieldsFromValidationResult( $this->orderValidator->validate( $order ) ),
425 + 'packetCancelLink' => null,
426 + 'packetTrackingUrl' => null,
427 + 'packetStatusTranslatedName' => null,
428 + 'packetSubmitUrl' => $packetSubmitUrl,
429 + 'packetClaimTrackingUrl' => $packetClaimTrackingUrl,
430 + 'packetClaimUrl' => $packetClaimUrl,
431 + 'packetClaimCancelUrl' => $packetClaimCancelUrl,
432 + 'runWizardUrl' => $runWizardUrl,
433 + 'showRunWizardButton' => $showRunWizardButton,
434 + 'orderCurrency' => get_woocommerce_currency_symbol( $order->getCurrency() ),
435 + 'isCodPayment' => $order->hasCod(),
436 + 'allowsAdultContent' => $order->allowsAdultContent(),
437 + 'requiresSizeDimensions' => $order->getCarrier()->requiresSize(),
438 + 'logo' => plugin_dir_url( PACKETERY_PLUGIN_DIR . '/packeta.php' ) . 'public/images/packeta-symbol.png',
439 + 'showLogsLink' => $showLogsLink,
440 + 'hasOrderManualWeight' => $order->hasManualWeight(),
441 + 'hasOrderManualCod' => $order->hasManualCod(),
442 + 'hasOrderManualValue' => $order->hasManualValue(),
443 + 'isPacketaPickupPoint' => $order->isPacketaInternalPickupPoint(),
444 + 'pickupPointAttributes' => Attribute::$pickupPointAttributes,
445 + 'homeDeliveryAttributes' => Attribute::$homeDeliveryAttributes,
446 + 'translations' => [
447 + 'packetSubmissionValidationErrorTooltip' => $this->wpAdapter->__( 'It is not possible to submit the shipment because all the information required for this shipment is not filled.', 'packeta' ),
448 + 'showLogs' => $this->wpAdapter->__( 'Show logs', 'packeta' ),
449 + 'weightIsManual' => $this->wpAdapter->__( 'Weight is manually set. To calculate weight remove field content and save.', 'packeta' ),
450 + 'codIsManual' => $this->wpAdapter->__( 'COD value is manually set. To calculate the value remove field content and save.', 'packeta' ),
451 + 'valueIsManual' => $this->wpAdapter->__( 'Order value is manually set. To calculate the value remove field content and save.', 'packeta' ),
452 + 'submitPacket' => $this->wpAdapter->__( 'Submit to Packeta', 'packeta' ),
453 + 'runWizard' => $this->wpAdapter->__( 'Run options wizard', 'packeta' ),
454 + 'packetClaimTrackingOnline' => $this->wpAdapter->__( 'Packet claim tracking', 'packeta' ),
455 + 'printPacketClaimLabel' => $this->wpAdapter->__( 'Print packet claim label', 'packeta' ),
456 + 'cancelPacketClaim' => $this->wpAdapter->__( 'Cancel packet claim', 'packeta' ),
457 + 'packetClaimPassword' => $this->wpAdapter->__( 'Packet claim password', 'packeta' ),
458 + 'submissionPassword' => $this->wpAdapter->__( 'submission password', 'packeta' ),
481 459 // translators: %s: Order number.
482 - 'reallyCancelPacketHeading' => sprintf( __( 'Order #%s', 'packeta' ), $order->getCustomNumber() ),
460 + 'reallyCancelPacketHeading' => sprintf( $this->wpAdapter->__( 'Order #%s', 'packeta' ), $order->getCustomNumber() ),
483 461 // translators: %s: Packet claim number.
484 - 'reallyCancelPacketClaim' => sprintf( __( 'Do you really wish to cancel packet claim number %s?', 'packeta' ), $order->getPacketClaimId() ),
462 + 'reallyCancelPacketClaim' => sprintf( $this->wpAdapter->__( 'Do you really wish to cancel packet claim number %s?', 'packeta' ), $order->getPacketClaimId() ),
485 463 ],
486 464 ]
487 465 );
466 +
467 + $partsCache = $parts;
468 +
469 + return $partsCache;
488 470 }
489 471
490 472 /**
491 473 * Saves added packetery form fields to order metas.
492 474 *
493 - * @param Entity\Order $order Order.
475 + * @param Entity\Order $order Order.
476 + * @param WC_Order $wcOrder WC Order.
494 477 *
495 478 * @return void
496 479 * @throws WC_Data_Exception When invalid data are passed during shipping address update.
497 480 */
498 - public function saveFields( Entity\Order $order ): void {
481 + public function saveFields( Entity\Order $order, WC_Order $wcOrder ): void {
482 + $this->initializeForm();
483 +
499 484 $orderId = (int) $order->getNumber();
500 485 if (
501 486 ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) ||
502 - null === $this->request->getPost( 'packetery_order_metabox_nonce' )
487 + $this->request->getPost( 'packetery_order_metabox_nonce' ) === null
503 488 ) {
504 489 return;
505 490 }
506 491
507 - if ( false === $this->order_form->isValid() ) {
508 - set_transient( 'packetery_metabox_nette_form_prev_invalid_values', $this->order_form->getValues( true ) );
509 - $this->message_manager->flash_message( __( 'Packeta: entered data is not valid!', 'packeta' ), MessageManager::TYPE_ERROR );
492 + if ( $this->form->isValid() === false ) {
493 + set_transient( Transients::METABOX_NETTE_FORM_PREV_INVALID_VALUES, $this->form->getValues( 'array' ) );
494 + $this->messageManager->flash_message( $this->wpAdapter->__( 'Packeta: entered data is not valid!', 'packeta' ), MessageManager::TYPE_ERROR );
510 495
511 496 return;
512 497 }
498 + /** @var array<string, string|float|int|true|null> $formValues */
499 + $formValues = $this->form->getValues( 'array' );
513 500
514 - $orderFormValues = $this->order_form->getValues( 'array' );
501 + if ( wp_verify_nonce( $formValues['packetery_order_metabox_nonce'] ) !== 1 ) {
502 + $this->messageManager->flash_message( $this->wpAdapter->__( 'Session has expired! Please try again.', 'packeta' ), MessageManager::TYPE_ERROR );
515 503
516 - if ( ! wp_verify_nonce( $orderFormValues['packetery_order_metabox_nonce'] ) ) {
517 - $this->message_manager->flash_message( __( 'Session has expired! Please try again.', 'packeta' ), MessageManager::TYPE_ERROR );
518 -
519 504 return;
520 505 }
521 506
522 507 if ( ! current_user_can( 'edit_post', $orderId ) ) {
523 - $this->message_manager->flash_message( __( 'You do not have sufficient rights to make changes!', 'packeta' ), MessageManager::TYPE_ERROR );
508 + $this->messageManager->flash_message( $this->wpAdapter->__( 'You do not have sufficient rights to make changes!', 'packeta' ), MessageManager::TYPE_ERROR );
524 509
525 510 return;
526 511 }
527 512
528 - $propsToSave = [
529 - self::FIELD_WIDTH => ( is_numeric( $orderFormValues[ self::FIELD_WIDTH ] ) ? (float) number_format( $orderFormValues[ self::FIELD_WIDTH ], 0, '.', '' ) : null ),
530 - self::FIELD_LENGTH => ( is_numeric( $orderFormValues[ self::FIELD_LENGTH ] ) ? (float) number_format( $orderFormValues[ self::FIELD_LENGTH ], 0, '.', '' ) : null ),
531 - self::FIELD_HEIGHT => ( is_numeric( $orderFormValues[ self::FIELD_HEIGHT ] ) ? (float) number_format( $orderFormValues[ self::FIELD_HEIGHT ], 0, '.', '' ) : null ),
532 - ];
513 + $propsToSave = [];
514 + foreach ( [ Form::FIELD_LENGTH, Form::FIELD_WIDTH, Form::FIELD_HEIGHT ] as $dimension ) {
515 + $propsToSave[ $dimension ] = $this->optionsProvider->getSanitizedDimensionValueInMm( $formValues[ $dimension ] );
516 + }
533 517
534 - if ( ! is_numeric( $orderFormValues[ self::FIELD_WEIGHT ] ) ) {
535 - $propsToSave[ self::FIELD_WEIGHT ] = null;
536 - } elseif ( (float) $orderFormValues[ self::FIELD_WEIGHT ] !== (float) $orderFormValues[ self::FIELD_ORIGINAL_WEIGHT ] ) {
537 - $propsToSave[ self::FIELD_WEIGHT ] = (float) $orderFormValues[ self::FIELD_WEIGHT ];
518 + $formWeightEqualsToCalculated = (float) $formValues[ Form::FIELD_WEIGHT ] === (float) $formValues[ Form::FIELD_ORIGINAL_WEIGHT ];
519 + if ( ! is_numeric( $formValues[ Form::FIELD_WEIGHT ] ) || $formWeightEqualsToCalculated ) {
520 + $propsToSave[ Form::FIELD_WEIGHT ] = null;
521 + } else {
522 + $propsToSave[ Form::FIELD_WEIGHT ] = (float) $formValues[ Form::FIELD_WEIGHT ];
538 523 }
524 + $order->setWeight( $propsToSave[ Form::FIELD_WEIGHT ] );
539 525
540 - if ( $orderFormValues[ Attribute::POINT_ID ] && $order->isPickupPointDelivery() ) {
541 - /**
542 - * Cannot be null due to the condition at the beginning of the method.
543 - *
544 - * @var WC_Order $wcOrder
545 - */
546 - $wcOrder = $this->orderRepository->getWcOrderById( (int) $orderId );
547 - foreach ( Attribute::$pickupPointAttrs as $pickupPointAttr ) {
548 - $pickupPointValue = $orderFormValues[ $pickupPointAttr['name'] ];
526 + if ( $formValues[ Attribute::POINT_ID ] && $order->isPickupPointDelivery() ) {
527 + foreach ( Attribute::$pickupPointAttributes as $pickupPointAttr ) {
528 + $pickupPointValue = $formValues[ $pickupPointAttr['name'] ];
549 529
550 - if ( Attribute::CARRIER_ID === $pickupPointAttr['name'] ) {
551 - if ( ! empty( $orderFormValues[ Attribute::CARRIER_ID ] ) ) {
552 - $pickupPointValue = $orderFormValues[ Attribute::CARRIER_ID ];
530 + if ( $pickupPointAttr['name'] === Attribute::CARRIER_ID ) {
531 + if ( isset( $formValues[ Attribute::CARRIER_ID ] ) && $formValues[ Attribute::CARRIER_ID ] !== '' ) {
532 + $pickupPointValue = $formValues[ Attribute::CARRIER_ID ];
553 533 } else {
554 534 $pickupPointValue = $order->getCarrier()->getId();
555 535 }
556 536 }
@@ -560,22 +540,34 @@
560 540 if ( $this->optionsProvider->replaceShippingAddressWithPickupPointAddress() ) {
561 541 $this->mapper->toWcOrderShippingAddress( $wcOrder, $pickupPointAttr['name'], (string) $pickupPointValue );
562 542 }
563 543 }
564 - $wcOrder->save();
565 544 }
566 545
567 - if ( '1' === $orderFormValues[ Attribute::ADDRESS_IS_VALIDATED ] && $order->isHomeDelivery() ) {
568 - $address = $this->mapper->toValidatedAddress( $orderFormValues );
546 + if ( $formValues[ Attribute::ADDRESS_IS_VALIDATED ] === '1' && $order->isHomeDelivery() ) {
547 + $address = $this->mapper->toValidatedAddress( $formValues );
569 548 $order->setDeliveryAddress( $address );
570 549 $order->setAddressValidated( true );
571 550 }
572 551
573 - $order->setAdultContent( $orderFormValues[ self::FIELD_ADULT_CONTENT ] );
574 - $order->setCod( is_numeric( $orderFormValues[ self::FIELD_COD ] ) ? Helper::simplifyFloat( $orderFormValues[ self::FIELD_COD ], 10 ) : null );
575 - $order->setValue( is_numeric( $orderFormValues[ self::FIELD_VALUE ] ) ? Helper::simplifyFloat( $orderFormValues[ self::FIELD_VALUE ], 10 ) : null );
576 - $order->setDeliverOn( $this->helper->getDateTimeFromString( $orderFormValues[ self::FIELD_DELIVER_ON ] ) );
552 + $order->setAdultContent( $formValues[ Form::FIELD_ADULT_CONTENT ] );
577 553
554 + $formCodEqualsToCalculated = (float) $formValues[ Form::FIELD_COD ] === (float) $formValues[ Form::FIELD_CALCULATED_COD ];
555 + if ( ! is_numeric( $formValues[ Form::FIELD_COD ] ) || $formCodEqualsToCalculated ) {
556 + $order->setManualCod( null );
557 + } else {
558 + $order->setManualCod( is_numeric( $formValues[ Form::FIELD_COD ] ) ? CoreHelper::simplifyFloat( $formValues[ Form::FIELD_COD ], 10 ) : null );
559 + }
560 +
561 + $formValueEqualsToCalculated = (float) $formValues[ Form::FIELD_VALUE ] === (float) $formValues[ Form::FIELD_CALCULATED_VALUE ];
562 + if ( ! is_numeric( $formValues[ Form::FIELD_VALUE ] ) || $formValueEqualsToCalculated ) {
563 + $order->setManualValue( null );
564 + } else {
565 + $order->setManualValue( is_numeric( $formValues[ Form::FIELD_VALUE ] ) ? CoreHelper::simplifyFloat( $formValues[ Form::FIELD_VALUE ], 10 ) : null );
566 + }
567 +
568 + $order->setDeliverOn( $this->coreHelper->getDateTimeFromString( $formValues[ Form::FIELD_DELIVER_ON ] ) );
569 +
578 570 $orderSize = $this->mapper->toOrderSize( $order, $propsToSave );
579 571 $order->setSize( $orderSize );
580 572
581 573 $pickupPoint = $this->mapper->toOrderEntityPickupPoint( $order, $propsToSave );
@@ -586,13 +578,13 @@
586 578
587 579 /**
588 580 * Creates pickup point picker settings.
589 581 *
590 - * @return array|null
582 + * @return array<string, array|string|null>
591 583 */
592 584 public function getPickupPointWidgetSettings(): ?array {
593 585 $order = $this->detailCommonLogic->getOrder();
594 - if ( null === $order || false === $order->isPickupPointDelivery() || null === $order->getShippingCountry() ) {
586 + if ( $order === null || $order->isPickupPointDelivery() === false || $order->getShippingCountry() === null ) {
595 587 return null;
596 588 }
597 589
598 590 $widgetOptions = $this->widgetOptionsBuilder->createPickupPointForAdmin( $order );
@@ -598,9 +590,9 @@
598 590 $widgetOptions = $this->widgetOptionsBuilder->createPickupPointForAdmin( $order );
599 591
600 592 return [
601 593 'packeteryApiKey' => $this->optionsProvider->get_api_key(),
602 - 'pickupPointAttrs' => Attribute::$pickupPointAttrs,
594 + 'pickupPointAttrs' => Attribute::$pickupPointAttributes,
603 595 'widgetOptions' => $widgetOptions,
604 596 ];
605 597 }
606 598
@@ -606,13 +598,13 @@
606 598
607 599 /**
608 600 * Creates address picker settings.
609 601 *
610 - * @return array|null
602 + * @return mixed[]|null
611 603 */
612 604 public function getAddressWidgetSettings(): ?array {
613 605 $order = $this->detailCommonLogic->getOrder();
614 - if ( null === $order || false === $order->isHomeDelivery() ) {
606 + if ( $order === null || $order->isHomeDelivery() === false ) {
615 607 return null;
616 608 }
617 609
618 610 $widgetOptions = $this->widgetOptionsBuilder->createAddressForAdmin( $order );
@@ -618,13 +610,13 @@
618 610 $widgetOptions = $this->widgetOptionsBuilder->createAddressForAdmin( $order );
619 611
620 612 return [
621 613 'packeteryApiKey' => $this->optionsProvider->get_api_key(),
622 - 'homeDeliveryAttrs' => Attribute::$homeDeliveryAttrs,
614 + 'homeDeliveryAttrs' => Attribute::$homeDeliveryAttributes,
623 615 'widgetOptions' => $widgetOptions,
624 616 'translations' => [
625 - 'addressValidationIsOutOfOrder' => __( 'Address validation is out of order.', 'packeta' ),
626 - 'invalidAddressCountrySelected' => __( 'The selected country does not correspond to the destination country.', 'packeta' ),
617 + 'addressValidationIsOutOfOrder' => $this->wpAdapter->__( 'Address validation is out of order.', 'packeta' ),
618 + 'invalidAddressCountrySelected' => $this->wpAdapter->__( 'The selected country does not correspond to the destination country.', 'packeta' ),
627 619 ],
628 620 ];
629 621 }
630 622
@@ -650,5 +642,32 @@
650 642 admin_url( 'admin.php' )
651 643 );
652 644 }
653 645
646 + /**
647 + * Initializes form to render or process.
648 + *
649 + * @return void
650 + */
651 + private function initializeForm(): void {
652 + $this->form = $this->orderForm->create();
653 + $this->form->addHidden( 'packetery_order_metabox_nonce' );
654 + $this->form->setDefaults( [ 'packetery_order_metabox_nonce' => wp_create_nonce() ] );
655 +
656 + foreach ( Attribute::$pickupPointAttributes as $pickupPointAttr ) {
657 + $this->form->addHidden( $pickupPointAttr['name'] );
658 + }
659 +
660 + foreach ( Attribute::$homeDeliveryAttributes as $homeDeliveryAttr ) {
661 + $this->form->addHidden( $homeDeliveryAttr['name'] );
662 + }
663 +
664 + $this->form->addButton(
665 + 'packetery_pick_pickup_point',
666 + $this->wpAdapter->__( 'Choose pickup point', 'packeta' )
667 + );
668 + $this->form->addButton(
669 + 'packetery_pick_address',
670 + $this->wpAdapter->__( 'Check shipping address', 'packeta' )
671 + );
672 + }
654 673 }