A nice feature, that will solve almost any shipping cost commission problem, will be to make all shipping cost to use a "calculation rule" component.
I have the following scenario for one of my shipping carriers:
The commissions for a shipping are:
- nr. of kg * 1.65
- "register cost" 1.65 / shippment
- insurance value = declared value (>= 20) * 1/1%
- COD (cash on delivery) value * 1.1% + 2.5 / shippment
I have another scenario at another shipping cariier:
- base rate 12
- nr. of kg * 1
- insurance value = COD * 1%
and so on...
With the current uc_quote module and also uc_weightquote I cannot calculate all those commissions. So I made a module that implements another shipping quote "Rules calculation quote" (attached to this posts).
Basically, my module passes the quote to a rules component (like the one with conditions that is already implemented by uc_quote) for future calculations and gets the returned value. I think this will be a nice feature if is implemented by the core module uc_quote. There is no change in functionality for existing modules that depends on uc_quote module.
I'll make the patch this days and post it here. This feature exist also in commerce_shipping module but there is implemented more "drupal native" because quote is an entity (for Ubercart I defined a wrapper for non-entity quote method).
Is there anyone interested in this functionality?
CAUTION: ATTACHED MODULE IS NOT READY FOR PRODUCTION!!!
Comment | File | Size | Author |
---|---|---|---|
#21 | uc_quote-rules_calculation-1902622-3.patch | 6.83 KB | SilviuChingaru |
Comments
Comment #1
DanZ CreditAttribution: DanZ commentedInteresting idea.
It's generally bad to post zipped modules (you can never modify them). Can you set this up as a sandbox project? See http://drupal.org/node/1011196.
Comment #2
SilviuChingaru CreditAttribution: SilviuChingaru commentedI know Dan but this is intended only to probe the concept and should not be used in production. I'll post a patch and if will get commited will be no need for sandbox project (will be useless). That's why I did it "wrong" way.... :-)
Comment #3
SilviuChingaru CreditAttribution: SilviuChingaru commentedInitial patch. Is fully working.
It works like this:
After uc_quote gets quote from any quote module, it passes that data to rules and allow future calculations. This way we make sure that we don't break any functionality of existing quote modules.
After data is recieved, if rules changed the original data, quote is updated. If same values are returned from rules, quoate remain the same.
In other words rules calculations are optional for any user. If user don't use them, the original quote is received like before, if they use them, they can override from rules any data returned by quote module.
Comment #4
SilviuChingaru CreditAttribution: SilviuChingaru commentedJust to restart postponed test... I don't understand why was "Postponed"?!
Comment #5
mandreato CreditAttribution: mandreato commented@fiftyz your idea is good !
I've applied patch #4 but receive the following error on cart/checkout:
Comment #6
SilviuChingaru CreditAttribution: SilviuChingaru commented@mandreato Because uc_quote.info file is changed by the #4 patch in order to include custom non entity field wrapper for rules and those files are cached by Drupal you nead to "Clear cache" after applying the patch.
Steps are like this:
1. Apply the patch.
2. Go to /admin/config/development/performance and press "Clear Cache".
3. Then go to /admin/store/settings/quotes and select "calculation rules" for any quote you desire to change it's calculation via rules.
Let me know if it works like this (it should work I also tested the patch at checkout and at create / edit order admin page).
Comment #7
mandreato CreditAttribution: mandreato commentedI already did cache clear, but the problem persists. I reach it even browsing /cart page.
Maybe it depends on other modules I have ?
This is the list of other Ubercart modules I use:
uc_addresses
uc_bank_transfer
uc_coupon
uc_extra_fields_pane
uc_out_of_stock
uc_tracking_links
Comment #8
SilviuChingaru CreditAttribution: SilviuChingaru commentedTry disable and enable uc_quote module from admin > modules. Post back if it works after this operation pls!
Comment #9
mandreato CreditAttribution: mandreato commenteduc_quote (Shipping quotes module) was required by the following other modules:
Flat rate, UC Tracking Links, Weight quote, Shipping
So I disabled them first, then disabled uc_quote; finally re-enabled them all and flushed cache again.
The error is gone (thanks) !
Comment #10
mandreato CreditAttribution: mandreato commentedHi fiftyz, I'm trying to use patch #4 but I'm uncertain of the steps to do.
Basically I've 2 shipping methods (normail mail and courier) both divided into ranges:
- normal mail 0..49g
- normal mail 50.99g
- normal mail 100..
- courier 0..29.99€
- courier 30..69.99€
... and so on...
I need to add to every shipping method an additional fee when payment method is COD or an additional fee if shipping destination is on a "black list".
So, I've added the shipping methods on admin/store/settings/quotes (each with its conditions).
Now I'm adding calculation sets for additional fee implementations /admin/store/settings/quotes/manage/calculate_quote_from_flatrate_13/edit/2:
- add an action element "Set a data value"
- selected data: "method:rate"
- PHP evaluation: "return $value +..." (additional fee)
But I cannot understand where to decide if this calculation has to be done (eg when payment method is COD).
Could you describe a detailed example on how to use the patch please ?
Thanks In Advance !
Comment #11
SilviuChingaru CreditAttribution: SilviuChingaru commentedIn fact that part of rules are actions rules so to check for condition should be done in shipping conditions but you could also accomplish it there like this:
- Add action: Execute custom PHP code
- Enter the code:
That should be it...
Comment #12
mandreato CreditAttribution: mandreato commentedThanks for clarification !
Comment #13
SilviuChingaru CreditAttribution: SilviuChingaru commentedYou're welcome. Don't forget to post you feedback after you test this patch.
Comment #14
longwave#1953752: Allow modules to alter shipping quotes proposes something similar, but using a hook instead so contrib modules can alter the shipping rates. It would be nice to combine both ideas and allow both modules and Rules to alter shipping quotes in a similar way.
Comment #15
mandreato CreditAttribution: mandreato commentedSpent some time with patch #4.
Here is a simplified scenario:
Behaviours:
So, whilst this is a good start, I think that other work is needed to reach a complete solution. The biggest issue is the need of button press upon every options change.
Comment #16
mandreato CreditAttribution: mandreato commentedFurther tests: I've enabled "Ubercart Ajax Administration" sub module then added the "Payment: Payment method" triggering form element to update panes "Calculate shipping cost" and "Payment method".
Now, when I switch from bank transfer payment method to COD, nothing occours the first time, but it changes on the next switch (without needing to press the button)...
It seems like the value set by the rule takes a delay.
Comment #17
longwaveI think the behaviour you describe in #16 is the same as #1453306: Selecting an address from the drop down at checkout doesn't trigger shipping costs or triggers incorrect shipping costs
Comment #18
mandreato CreditAttribution: mandreato commentedI drop a testcase here then follow up on #1453306: Selecting an address from the drop down at checkout doesn't trigger shipping costs or triggers incorrect shipping costs
So it seems a matter of panes weight.
Comment #19
SilviuChingaru CreditAttribution: SilviuChingaru commentedI'll try to test it with patch #13 from #1453306: Selecting an address from the drop down at checkout doesn't trigger shipping costs or triggers incorrect shipping costs.
Please, if you have time, test it with patch above also.
Comment #20
mandreato CreditAttribution: mandreato commentedI just started to replicate the #18 testcase.
As first step, I applied both patch #4 of this thread and patch #13 of #1453306: Selecting an address from the drop down at checkout doesn't trigger shipping costs or triggers incorrect shipping costs.
On step number 4 I navigate to admin/store/settings/checkout/ajax and get a list of errors:
Maybe i need to generate a fresh new clone of production and clean every shipping method before testing.
This will take a while... I hope to retry during the weekend.
Comment #21
SilviuChingaru CreditAttribution: SilviuChingaru commentedFixed and tested #18 scenario and is working fine with patch #13 from #1453306: Selecting an address from the drop down at checkout doesn't trigger shipping costs or triggers incorrect shipping costs and this attached patch.
There is still an issue:
If we calculate a new quote rate like the one in #18 based on condition. Reproduce like this:
- select A quote method
-- select COD payment method (the rate is increased)
-- select Bank Transfer (the rate is decreased to default value 10)
-- select COD payment method (the rate is increased)
- select B quote method (Bank Transfer is auto selected because COD is no longer available for this quote method but A rate is not reset to 10 default value but it remains to 15 - this is not a problem at this point because we could not care about an unselected method)
- select A quote method (the values is still 15 but selected payment method is Bank Transfer which remained selected from B quote and that is NOT TRUE).
We change the status to needs review only to force QA to test this patch, will move back to needs work after the test until this issue is fixed.
Comment #23
SilviuChingaru CreditAttribution: SilviuChingaru commented#21 issue seems not to be a bug because in my test environment I forgot to set a checkout ajax action on Quotes to Calculate shipping cost. If I do so the scenario now is like this:
- select A quote method
-- select COD payment method (the rate is increased)
-- select Bank Transfer (the rate is decreased to default value 10)
-- select COD payment method (the rate is increased)
- select B quote method (Bank Transfer is auto selected because COD is no longer available for this quote method but A rate is not reset to 10 default value but it remains to 15 - this is not a problem at this point because we should not care about an unselected method)
- select A quote method (the value is now recalculated to 10 with selected payment method Bank Transfer which remained selected from B quote and that is TRUE).
So, the patch from #21 is fully working and needs a project maintainer review.
Comment #24
mandreato CreditAttribution: mandreato commentedI've tested patch #21 after applying #13 of #1453306: Selecting an address from the drop down at checkout doesn't trigger shipping costs or triggers incorrect shipping costs.
I also had to add one triggering form element in /admin/store/settings/checkout/ajax in addition of what I described in #18: "Quotes: panes][quotes][quotes][quote_option" which updates "Calculate shipping cost" pane.
(I don't know why under the Quotes group I have two elements: "Click to calculate shipping" and panes][quotes][quotes][quote_option" which is a strange name).
Now the behaviour is exactly what fiftyz described in #23. This is fine !
The only thing which prevents me to set status to "reviewed and tested" is that navigation to /admin/store/settings/checkout/ajax raise the following:
Comment #25
longwave"panes][quotes][quotes][quote_option" is the name given for the set of shipping quote radio buttons, as these don't have a single label describing them. We may be able to improve this by adding a #title and #title_display => 'invisible', this would probably be better for accessibility as well.
Comment #25.0
longwave1
Comment #26
SilviuChingaru CreditAttribution: SilviuChingaru commentedNow that #1453306: Selecting an address from the drop down at checkout doesn't trigger shipping costs or triggers incorrect shipping costs was commited, this should be finished too...