The variables should keep their same name here. The method is getting the item id, not the order id:
- $shipment_item_id = $shipment_item->getOrderItemId(); - $shipment_item_defaults[$shipment_item_id] = $shipment_item_id; - $shipment_item_options[$shipment_item_id] = $shipment_item->getTitle(); + $shipment_order_id = $shipment_item->getOrderItemId(); + $shipment_item_defaults[$shipment_order_id] = $shipment_order_id; + $shipment_item_options[$shipment_order_id] = [ + 'checked' => TRUE, + 'label' => $shipment_item->getTitle(), + 'quantity' => $shipment_item->getQuantity(), + 'quantity_shipment' => $already_on_shipment[$shipment_order_id] ?? 0, + 'quantity_order' => 0, + ];
Also, if you don't select the shipment item, and you save the shipment, you get a crash:
Warning: Undefined variable $price_currency in Drupal\commerce_shipping\Form\ShipmentForm->addShippingItems() (line 443 of /var/www/html/web/modules/contrib/commerce_shipping/src/Form/ShipmentForm.php)
I don't think we should restrict the number of items by the the number of how many have been sent.
What if a user wants to ships 5/5 books in an order, and then one gets lost or damaged, and they want to send a shipment with a replacement item?
I also don't think we should prevent editing if a shipment has been shipped:
+ // Prevent editing if Shipment shipped. + if ($shipment->getState()->getId() == 'shipped') { + $form['shipment_item_fieldset']['shipment_items'][$item_id]['checked']['#disabled'] = TRUE; + $form['shipment_item_fieldset']['shipment_items'][$item_id]['quantity']['#disabled'] = TRUE; + }
I think a better table would be:
Label - Quantity ordered - Quantity already shipped - Quantity to ship.Removed the extra sku, and the price stuff that rszrama mentioned. Also removed disabling the form, and added a column for the total of order items in the order.
Total shipped has been changed to reflect the total shipped in all shipments including the current shipment.
Some minor coding standard stuff too.
Whoops, I missed the declared value. That was showing in my diff as already existing. but we can remove.
The logic needs cleaned up, but I think this approach will be a little more universal.
- Status changed to Needs review
almost 2 years ago 3:59pm 31 January 2023 - First commit to issue fork.
- last update
over 1 year ago 149 pass - @abx opened merge request.
Patch #21 does what the title described which is to add quantity in front of the label in this format :
"2.00 Γ Product One"
However, quantity shows only in Edit Shipment which is kind of strange. So, I modified code a bit to also show quantity when Add Shipment too. ( MR !20 )
For those looking at this functionality, I posted a dev module to quickly create shipments from the order edit form.
- last update
about 1 year ago 140 pass, 2 fail - last update
about 1 year ago 149 pass