@@ -134,10 +134,17 @@ public function getFormDefinition(FAPI\Form $form, array &$form_state): FAPI\For
134134
135135 case 'view ' :
136136
137- if (in_array ($ order ->getOrderStatus ()?->getStatus(), [OrderStatus:: PAID , OrderStatus:: WAITING_FOR_PAYMENT ] )) {
137+ if (! is_null ($ order ->getOrderPayment () )) {
138138 $ orderPayment = OrderPayment::getCollection ()->where (['order_id ' => $ order ->getId ()])->addOrder (['created_at ' => 'DESC ' ])->getFirst ();
139139 if ($ orderPayment ) {
140- $ this ->addActionLink ('payment-btn ' , 'payment-btn ' , $ this ->getHtmlRenderer ()->getIcon ('dollar-sign ' ) . ' ' . $ this ->getUtils ()->translate ('Payment ' , locale: $ this ->getCurrentLocale ()), $ this ->getUrl ('admin.commerce.orderpayments ' ) . '? ' . http_build_query (['action ' => 'view ' , 'payment_id ' => $ orderPayment ->getId ()]) );
140+ $ this ->addActionLink (
141+ 'payment-btn ' ,
142+ 'payment-btn ' ,
143+ $ this ->getHtmlRenderer ()->getIcon ('dollar-sign ' ) . ' ' . $ this ->getUtils ()->translate ('Payment ' , locale: $ this ->getCurrentLocale ()),
144+ //$this->getUrl('admin.commerce.orderpayments') . '?' . http_build_query(['action' => 'view', 'payment_id' => $orderPayment->getId()]) ,
145+ $ this ->getUrl ('crud.app.base.controllers.admin.json.orderpayment ' , ['id ' => $ this ->getRequest ()->query ->get ('order_id ' )]) . '?order_id= ' . $ this ->getRequest ()->query ->get ('order_id ' ) . '&action=payment ' ,
146+ 'btn btn-sm btn-light inToolSidePanel '
147+ );
141148 }
142149 }
143150
@@ -311,7 +318,7 @@ public function getFormDefinition(FAPI\Form $form, array &$form_state): FAPI\For
311318 ])->addField ('ship_ ' .$ orderItem ->getId ().'_qty ' , [
312319 'type ' => 'number ' ,
313320 'title ' => 'Quantity ' ,
314- 'default_value ' => $ orderItem ->getQuantity (),
321+ 'default_value ' => $ orderItem ->remainingShippableQuantity (),
315322 'label_class ' => 'mr-2 ' ,
316323 'container_class ' => 'col-11 d-flex ' ,
317324 ]);
@@ -350,8 +357,30 @@ protected function getCardHtml(string $title, string $content): string
350357 */
351358 public function formValidate (FAPI \Form $ form , &$ form_state ): bool |string
352359 {
353- //$values = $form->values();
354- // @todo : check if page language is in page website languages?
360+ /**
361+ * @var OrderModel $order
362+ */
363+ $ order = $ this ->getObject ();
364+
365+ $ values = $ form ->values ();
366+
367+ switch ($ values ['action ' ]) {
368+ case 'ship ' :
369+ $ hasAtLeastOne = false ;
370+ foreach ($ order ->getItems () as $ orderItem ) {
371+ /** @var OrderItem $orderItem */
372+ if ($ orderItem ->requireShipping ()) {
373+ if ($ values ['row_ ' .$ orderItem ->getId ()]['ship_ ' .$ orderItem ->getId ()]) {
374+ $ hasAtLeastOne = true ;
375+ }
376+ }
377+ }
378+ if (!$ hasAtLeastOne ) {
379+ return $ this ->getUtils ()->translate ('You must select at least one item to ship. ' , locale: $ this ->getCurrentLocale ());
380+ }
381+ break ;
382+ }
383+
355384 return true ;
356385 }
357386
@@ -424,6 +453,16 @@ public function formSubmitted(FAPI\Form $form, &$form_state): mixed
424453
425454 $ order ->ship ($ values ['shipping_method ' ], $ values ['shipment_code ' ], $ shipmentItems );
426455
456+ if (!$ order ->requiresShipping ()) {
457+ $ order ->setOrderStatus (OrderStatus::getCollection ()->where (['status ' => OrderStatus::SHIPPED ])->getFirst ())->persist ();
458+
459+ $ this ->setAdminActionLogData ('Order ' . $ order ->getId () . ' marked as shipped. ' );
460+
461+ $ this ->addInfoFlashMessage ($ this ->getUtils ()->translate ("Order marked as shipped. " ));
462+
463+ return new JsonResponse (['success ' => true , 'js ' => '$( \'#admin \').appAdmin( \'closeSidePanel \'); document.location.reload() ' ]);
464+ }
465+
427466// $this->addInfoFlashMessage($this->getUtils()->translate("Shipment created."));
428467
429468 return new JsonResponse (['success ' => true , 'js ' => '$( \'#admin \').appAdmin( \'closeSidePanel \') ' ]);
0 commit comments