Had a conversation with bojanz in Slack.

The crux of my issue is this paragraph:

The problem I have is that if I create a custom packer to do this [remove items from being packed], then no other packer can ever run on the site, because my packer would have to be the first one that runs. There doesn't seem to be any flexibility there. I'm working with another developer on commerce_fedex, with a custom packer there to handle things such as special packing for dry ice and hazmat shipments. That is a good use case for a custom packer it seems, but I would't be able to use it on my site because I want to remove quote items from being packed and that requires me to take over the entire packing process.

His idea for a potential solution to that:

I guess we could refactor $order->getItems() into a helper method on the DefaultPacker that runs an event afterwards

I just about have a patch ready for testing and further discussion on this issue, as well.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bmcclure created an issue. See original summary.

bmcclure’s picture

Issue summary: View changes
bmcclure’s picture

Status: Active » Needs review
FileSize
6.81 KB

Patch for review, creates a CommerceShippingEvents::BEFORE_PACK event.

googletorp’s picture

Status: Needs review » Needs work

We need test coverage for this.

bojanz’s picture

I approve of the approach, but wanted to bikeshed the event name.

googletorp’s picture

I feel like we can do better as well, BEFORE_PACK seems a bit weird.

bmcclure’s picture

My thinking was that a packer's purpose is to pack, so a natural event system to modify that behavior seems like it would be BEFORE_PACK and AFTER_PACK. However I can definitely see how, outside of the context of a packer, the name doesn't make much sense, and since the name's used globally, maybe something more descriptive would be helpful.

amklose’s picture

Not seeing any further discussion on this, I rerolled the patch from #3 to apply to the current 8.x-2.x dev branch.

bmcclure’s picture

Re-rolling this again for the latest conflicting changes, mainly in DefaultPacker

bamberjp’s picture

FileSize
7.15 KB

Not familiar with this issue but noted patch #9 removes BeforePackEvent and CommerceShippingEvents. Not found in current 8.x-2.x-dev.