Problem/Motivation

When the estimate is performed, we "clone" the order, rather than calling the createDuplicate() method which clears the order ID.

I believe this is necessary so that the initial order isn't affected.

Comments

jsacksick created an issue. See original summary.

jsacksick’s picture

Status: Active » Needs review
StatusFileSize
new1.16 KB
jsacksick’s picture

This patch can't work as commerce_shipping is complaining about a missing order_id when proposed shipment value objects are being created... So this would require additional work in commerce_shipping.

Status: Needs review » Needs work

The last submitted patch, 2: 3251240-2.patch, failed testing. View results

jsacksick’s picture

Title: Duplicate the order when doing the estimate » Commerce cart estimate is causing orphaned shipments (duplicate shipments in the admin)

This is causing shipments to be duplicated (See #3250006: Multiple Duplicate Shipments).

tomtech’s picture

This patch strives to make the cart estimate temporal, avoiding any entity saves.

Note: this depends on commerce_shipping having this patch in place: #3279815-2: Allow LateOrderProcessor to skip shipment saves

This also resolves the related issues: #3239478: Save order items after recalculation and #3253596: Reset owned_by_packer flag during cart estimation

tomtech’s picture

Status: Needs work » Needs review
tomtech’s picture

Changed shouldSave() to accept ShipmentInterface rather than OrderInterface.

jsacksick’s picture

Status: Needs review » Needs work
+++ b/src/LateOrderProcessor.php
@@ -0,0 +1,44 @@
+   *   The shipping order manager.
...
+    $this->inner = $inner;

Do we really need to set the inner class here since we are not using it?

Also, I'm still in favor of defining a custom order refresh service as discussed, instead of decorating the existing one, so we can just invoke it ourselves and don't have to worry about running it for regular orders or not?

Another note, you can also just swap the late order processor and extend the base order processor, via a service provider, just overridding the shouldSave() method.

jsacksick’s picture

Status: Needs work » Needs review
StatusFileSize
new14.77 KB

Made several changes, also shortened the exception class names (no need to prefix by CartEstimate since we have namespaces).

Went with a custom order refresh as mentioned in #9, added a composer.json to require commerce_shipping dev so we can test this.

Also, we need to expand the EstimatorTest to assert that the order is not modified/saved etc etc.

jsacksick’s picture

Aborted the test as it seems that it was stuck in some kind of infinite loop.

jsacksick’s picture

Once we expand a bit the EstimatorTest, we could tag a new commerce_shipping release, require this new shipping version, and commit this.

@TomTech: thoughts?

jsacksick’s picture

Issue summary: View changes
StatusFileSize
new13.47 KB
new14.66 KB

These are all "blind" changes TBH. Wondering if we should skip refreshing prices though?

Experiencing the following locally:

Before the estimate:

After:

The subtotal changed, perhaps we need to refresh prices, not really sure what's missing, would need to dig a bit.

jsacksick’s picture

StatusFileSize
new17.34 KB
new4.04 KB

Realized we need to refresh prices, simply because a promotion reducing the unit price can be applied, which is what was causing the issue from the screenshot.

jsacksick’s picture

StatusFileSize
new20.23 KB

Expanded the tests to ensure the original order is not altered (checking the version and the total price to ensure they remain unaltered).

jsacksick’s picture

Not really sure whether we need custom exceptions or whether we should reuse the CartEstimateException that already exists although it has a different "meaning".

Other than that, I think we're good, I should probably tag a new commerce_shipping release and then update this patch.

jsacksick’s picture

StatusFileSize
new20.23 KB

Require Commerce shipping 2.4 minimum.

jsacksick’s picture

StatusFileSize
new20.23 KB
new637 bytes
jsacksick’s picture

StatusFileSize
new16.97 KB

To avoid the BC with the new OrderRefreshInterface, decided to extend the order refresh service coming from commerce_order.

jsacksick’s picture

StatusFileSize
new18.67 KB
new3.09 KB

Actually seems more right to not extend the base class and simply implement the interfac, this way we don't depend on the services neeeded by the parent.

  • jsacksick committed a23cdbd on 2.x
    Issue #3251240 by jsacksick, TomTech: Commerce cart estimate is causing...
jsacksick’s picture

Status: Needs review » Fixed

Committed! @TomTech: Thanks a lot!

Status: Fixed » Closed (fixed)

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