Problem/Motivation

While fixing the free product test @mglaman found that it could be shortened by using the wrapper returned from commerce_cart_order_refresh() but then we realized that wasn't returning good results. Tried tracking down why the EMW cache was stale and it turns out to be commerce_discount_commerce_cart_order_refresh() was taking a wrapper then passing in the value to rules_invoke_event('commerce_discount_order', $wrapper->value()); Which then on every rule re-wraps it back again. The controller cache deals with itself but somehow the wrapper doesn't deal with it's cache well with entity references.

Proposed resolution

It may be better to fix entity api by helping clear it's cache better or removing it's cache all together.
But simplest solution is to pass the wrapper in to the order.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

joelpittet’s picture

Status: Active » Needs review
StatusFileSize
new518 bytes
mglaman’s picture

I think it's proper to pass the entire wrapper, since this is part of the hook_commerce_cart_order_refresh() implementation. After Commerce Discount works its magic other modules will be tossed through the following:

  // Allow other modules to alter the entire order on a shopping cart refresh.
  module_invoke_all('commerce_cart_order_refresh', $order_wrapper);

If we're bypassing the wrapper in the module, then we could be disrupting expectations in other modules.

joelpittet’s picture

@mglaman thanks and FYI, #1343196: $wrapper->reset() should unset $wrapper->cache this entity api issue is somewhat related if we want/need to clear the cache of an EMW.

joelpittet’s picture

Title: Wrapper updating » Order Wrapper updating on refresh creates stale EMW cache

Better title

Status: Needs review » Needs work

The last submitted patch, 1: wrapper_updating-2540234-1.patch, failed testing.

mglaman’s picture

Since test bot doesn't like us, here is a build to test patch https://travis-ci.org/mglaman/commerce_discount-travis-/builds/72900108.

Which, after doing this, we should make a test for this!

mglaman’s picture

Status: Needs work » Needs review
StatusFileSize
new2.14 KB

Here is a patch that compliments #1 and provides wrapper test coverage for order refreshes.

EDIT: Travis build with both patches: https://travis-ci.org/mglaman/commerce_discount-travis-/builds/72933245

Status: Needs review » Needs work

The last submitted patch, 7: order_wrapper_updating-2540234-7.patch, failed testing.

joelpittet’s picture

Status: Needs work » Needs review

testbot is being nice, retest

joelpittet’s picture

Status: Needs review » Needs work

#7 pickup!

joelpittet’s picture

Status: Needs work » Needs review
joelpittet’s picture

StatusFileSize
new2.14 KB

Status: Needs review » Needs work

The last submitted patch, 13: order_wrapper_updating-2540234-7.patch, failed testing.

joelpittet’s picture

Status: Needs work » Needs review
StatusFileSize
new2.65 KB

That was tests only and expected to fail. Here is both the tests and the fix from #1

joelpittet’s picture

The tests only were using assertEqual but only passing in one argument. I refactored them and then did all the other ones to clean things up. Hope this works!

The last submitted patch, 16: order_wrapper_updating-2540234-16-tests-only.patch, failed testing.

joelpittet’s picture

Status: Needs review » Fixed

Ok this is committed and pushed to -dev. Thanks for the test @mglaman!

  • joelpittet committed 648e31e on 7.x-1.x
    Issue #2540234 by mglaman, joelpittet: Order Wrapper updating on refresh...

Status: Fixed » Closed (fixed)

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