Add quantity to the shipment item label in the edit form

Created on 1 December 2021, over 2 years ago
Updated 10 June 2023, about 1 year ago

Problem/Motivation

Shipment items have a quantity, but this quantity is not visible anywhere in the user interface. When you edit a shipment, you even see a list of checkboxes of all of the items by title, but that title is just the title of the product packed into it.

Proposed resolution

Let's add the quantity to the shipment item widget's checkboxes. I don't know if this means prepending the quantity in getTitle(), adding a label method and updating the widget to use it, or altering it into the widget's options. I'm up for any of the above, but the result should be checkboxes titled like so:

"2.00 Γ— Product One"

I don't think trimming the .00 off quantity matters for this issue, and note that the "Γ—" is the multiplied sign, not a lowercase x.

πŸ“Œ Task
Status

Needs review

Version

2.0

Component

User interface

Created by

πŸ‡ΊπŸ‡ΈUnited States rszrama

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 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 over 1 year ago
  • First commit to issue fork.
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update about 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.

    https://www.drupal.org/project/commerce_quick_ship_form β†’

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.4 + Environment: PHP 8.1 & MariaDB 10.3.22
    last update 7 months ago
    140 pass, 2 fail
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update 7 months ago
    149 pass
Production build 0.69.0 2024