if ($this->shouldRepack($order, $shipments)) {
      $first_shipment = reset($shipments);
      $shipping_profile = $first_shipment->getShippingProfile();
      list($shipments, $removed_shipments) = $this->packerManager->packToShipments($order, $shipping_profile, $shipments);
      // @todo Save only the modified shipments.
      foreach ($shipments as $shipment) {
        $shipment->save();
      }

Which means that we need a way to ask the shipment whether it was modified. Probably by having populateFromProposedShipment() set a flag.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bojanz created an issue. See original summary.

jsacksick’s picture

Status: Active » Needs work
FileSize
1.71 KB

I decided to give it a shot, I flag the shipment (I set _updated to TRUE) if a change has been detected.
However, I detected an issue while doing some tests locally, the test I'm relying on for detecting a change will always return TRUE because the default packer will return a list of proposed shipments that don't have the "package_type_id" property set.

jsacksick’s picture

Status: Needs work » Needs review
FileSize
3.39 KB

Since the package type is populated in preSave, the package type set in populateFromProposedShipment was always set to NULL causing the comparison to fail...
As a temporary fix, I don't update the package type if empty.

googletorp’s picture

FileSize
819 bytes

I believe ::hasTranslationChanges should give us what we need. It detects changes for a specific translation which is basically what we want to test.

bojanz’s picture

Interesting, didn't know about this method.

We need a test to prove that it works as promised (especially since Jonathan mentioned that package_type is kinda special)

googletorp’s picture

I was hoping we already would have a test for this, I need to dig into the module a bit more to really get a bearing of it again.

@bojanz Maybe we can hook up on IRC and talk about how to make the test, I'm still a bit fussy for some the architecture.

  • bojanz committed de1f9df on 8.x-2.x authored by googletorp
    Issue #2854034 by jsacksick, googletorp: ShipmentOrderProcessor should...
bojanz’s picture

Status: Needs review » Fixed

Decided to proceed without tests, since we're using a core function here (and we've successfully used it in Profile since then)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.