Many shipping modules will need the entire transaction instead of just the items in order to calculate the shipping. This is especially true of address based shipping modules like UPS, USPS, Fedex, Australia Post etc. . .
I have changed the shipping.module and it's two included shipping methods (quantity of items and price of items) to handle the api form. I will be happy to help any other module developers make this change as well. It isn't hard.
*note. For this patch to work, you also have to change a line in cart.module. I can only attach one patch file, so I will paste the patch file for cart.module below:
283c283
< $edit->shipping_cost = (float) shipping_calculate_cost($data->items);
---
> $edit->shipping_cost = (float) shipping_calculate_cost($data);
311c311
< $edit->shipping_cost = (float) shipping_calculate_cost($edit->items);
---
> $edit->shipping_cost = (float) shipping_calculate_cost($edit);
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | paypalpro.module_0.patch | 566 bytes | Andy_Lowe |
| shipping.module_2.patch | 764 bytes | Andy_Lowe |
Comments
Comment #1
Andy_Lowe commentedComment #2
mariuss commentedI am running into this issue right now, so I will use your patch. It would be greate if this could make it into the next release.
Thanks,
Marius
Comment #3
mariuss commentedI applied your patch to Drupal 4.6.5 and it works fine (you have to manually search and replace for this version).
A few notes:
- a proper fix should change $items in a few more places, there are functions where $items is a pass through parameter so it does not matter, but for readability it should be changed
- the full shipping address is not on the transaction object, only the id for the ec_address table, you can get this id with: $txn->shipping_address
Thanks again and please add this patch to the main code.
Comment #4
simeLooking through the CVS, some other changes:
First, there is a call to shipping_calculate_cost() in paypalpro, line 591, which might need changing:
$shipping_cost = shipping_calculate_cost($edit->items);However, looking at the context, there is no $txn variable available to pass. So, it's not a simple change.
Also in shipping.module, on line 403, shouldn't:
return shipping_calculate($items);become:
return shipping_calculate($txn);That change seems to suffer the same problem. There is no $txn in the scope of the code, AFAICT.
Perhaps to achieve your goal, shipping_calculate() and shipping_calculate_cost() should be changed to allow either a transaction array or an items array.
Comment #5
Andy_Lowe commentedSime,
Thanks for pointing these mistakes out. I have attached a patch for paypalpro.module which will make it work with the change to shipping_api. In paypalpro.module $txn is $edit, so I just had to change the function call from:
$shipping_cost = shipping_calculate_cost($edit->items);
to:
$shipping_cost = shipping_calculate_cost($edit);
as for the shipping.module call to $shipping_calculate_cost, I am in the middle of rewriting shipping.module to support multiple active shipping modules, and this will be fixed in that patch.
Thanks again,
Andy
Comment #6
neclimdulGoing to go ahead and change the title back since its missleading. the patch is just part of the shipping.module change. And it sounds like everything might not quite be ready to be committed.
And the line 403 sime mentions is the core of the whole change. We're calling the api with a entire transaction structure rather than the items array. So the api call need to be changed to take the txn instead of the transaction instead of the items.
This could be kinda far reaching so lets make sure we've got all the patch(es) lined up. We need to look at every shippingapi hook and every shippingapi invoking and make sure they're in the right context and nothing is broken.
This is some good ideas and work! :)
Comment #7
neclimdulLooking at the patch I see an issue. You're taking the $txn by reference which is good but module_invoke doesn't take or use that arguement by reference. This is an issue that gordon has mentioned before and why the calling of the e-commerce api's is often done by building a function name which might look like this.
I haven't tested this but it should work the same.
Comment #8
simeClosing, please follow http://drupal.org/node/62126 (Upgrade and refactor shipcalc)
I have put a link on that ticket to here as there may be useful info.
.s