The "product" object passed in does not have the flatrate attached to it, so I created a query to find the correct flatrate shipping override.

The patch works on my test site. It uses overrides for the nodes that have one, and uses the defaults for those that do not have an overridden shipping rate for that flatrate method.

Hope this patch is useful.

CommentFileSizeAuthor
#3 1098192.patch837 bytestr
flatrateOverride.patch842 bytesneomenlo

Comments

inolen’s picture

Copying from my duplicate issue..

I was having an issue with overriding flat rate prices using the prices specified in the actual product nodes. The flaterate array was not being set on the products in my cart and I noticed that while uc_flatrate implements hook_node_load to setup the flatrate array, in uc_cart_get_contents when it calls node_load, it then manually copies off the loaded fields to a custom object like so:

      $product = node_load($item->nid);
      $item->cost = $product->cost;
      $item->price = $product->sell_price;

The flatrate member is not in that list, so therefor it's never copied to the actual item that is added to your cart.

To fix this, I added this to uc_flatrate.module:

function uc_flatrate_uc_cart_item($op, $item) {
  switch ($op) {
    case 'load':
      $product = node_load($item->nid);
      if (isset($product->flatrate)) {
        $item->flatrate = $product->flatrate;
      }
      break;
  }
}

It seems silly to call node_load again, but it was the easiest way to get up and running. I didn't make an actual patch as I don't know if this is the preferred way to fix this.

tr’s picture

Status: Needs review » Needs work

I don't think either solution corrects the root problem. This works properly in Ubercart 6.x-2.x. The flatrate data gets attached to the product object during a node_load(), so the question is where is the missing node_load() in Ubercart 7.x-3.x?

Note that it's not just the flatrate module that's affected - it's also weightquote and all the other shipping modules, which implies the real problem is somewhere in uc_quote. And that's where it should be fixed, so it fixes all the shipping methods.

tr’s picture

Status: Needs work » Needs review
StatusFileSize
new837 bytes

Try this. I'm not too thrilled with the code - it could probably be done more efficiently with a re-write - but it's a straight port of code out of the D6 version of uc_quote.module so it should have "known" behavior.

inolen’s picture

Hey TR,

The fix works for me. My patch still had another issue I found out and ended up sleeping on, and then I woke up to your fix, thanks!

longwave’s picture

longwave’s picture

Status: Needs review » Fixed

Committed #3.

Status: Fixed » Closed (fixed)

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

pnigro’s picture

Status: Closed (fixed) » Active

Hello,

I just installed 7.x-3.0 beta 4 and noticed that the patch attached to comment #3 was not added. I also checked 7.x-3.x-dev and it wasn't added there either. I just thought I would let you know.

Thanks,
Paul

longwave’s picture

Status: Active » Fixed

Not sure what happened there, but it's definitely committed now: http://drupalcode.org/project/ubercart.git/commitdiff/9807480

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Definitely not in the latest recommended version as the issue persists… Also the patch errors when you try to apply it

"patching file b/shipping/uc_quote/uc_quote.pages.inc
Hunk #1 FAILED at 16.
1 out of 1 hunk FAILED -- saving rejects to file b/shipping/uc_quote/uc_quote.pages.inc.rej"

longwave’s picture

The fix is not present in beta4, but is in -dev and will be in the next recommended release.

ssssmashing’s picture

I just loaded Dev and it is still not obeying the override.

rcharamella’s picture

I'm running 7.x-3.0-beta4 and it does have the latest patch. I have multiple flat rate shipping levels. With that setup, and with the patch in place (beta4 has the patch included), the flat rate override does work.