Issue Summary
* Tax Rate creation through hook_commerce_tax_rate_info() and taking advantage of the calculation_callback property
* Shows a programmatic way of determining tax amount on a line items based on variables on the order.
* Perfect for use cases where you want your module to not only just declare a static tax rate but instead dynamically determine tax rate or tax amount applied depending on situation.
For example the code shown throughout most tax implementations is this:
function hook_commerce_tax_rate_info() {
$tax_rates = array();
$tax_rates['ky_sales_tax'] = array(
'title' => t('KY sales tax'),
'rate' => .06,
'type' => 'sales_tax',
);
return $tax_rates;
}
The disadvantage of the example shown above is the tax rate provided is always stuck in 6%; The example code shown by the patch lets you do a dynamic tax rate or tax amount applied to the line item depending on the situation by making use of the "calculation_callback" property callback and then lets that call back do its own calculation.
Comment | File | Size | Author |
---|---|---|---|
#9 | commerce_examples.tax_example_revamp_1374198_09.patch | 4.85 KB | rfay |
#3 | example-of-tax-price-instead-of-tax-rate-1374198-3.patch | 2.77 KB | chriscalip |
Comments
Comment #1
rfayWhat is a tax price? Glad you're interested!
Comment #2
chriscalip CreditAttribution: chriscalip commentedPulled it off, will clean code and submit patch.
Comment #3
chriscalip CreditAttribution: chriscalip commentedComment #4
chriscalip CreditAttribution: chriscalip commentedRandy,
The purpose of this example is to show our fellow commerce developers an example of setting a tax amount on a line item manually; instead of the paradigm of tax rate based on examples.
kind regards,
Chris Calip
Comment #5
rfayCongratulations! I still need you to make a better issue summary of what you're trying to accomplish here. Please edit the node to provide an issue summary that explains what you're trying to accomplish and why. Thanks so much!
Comment #6
rfayX-post :-) I'd still like you to explain with more words in the issue summary. One of the questions is "Why do this?" What would be the use case? What is your use case? What are some others? What techniques are being used?
Comment #7
chriscalip CreditAttribution: chriscalip commentedupdated issue summary per your request.
Comment #7.0
chriscalip CreditAttribution: chriscalip commentedbetter description per rfay request
Comment #7.1
chriscalip CreditAttribution: chriscalip commentedbetter description
Comment #7.2
chriscalip CreditAttribution: chriscalip commenteduse case description
Comment #8
rfayExcellent, thanks so much!
Comment #9
rfayVery nicely done - I've gone through and redone some things and would appreciate your review.
Comment #10
rfayAlthough this works fine, I think rszrama would say he'd implement it differently.
Comment #11
bobbyaldol CreditAttribution: bobbyaldol commented@rfay: Reviewed and good to commit.
Comment #11.0
bobbyaldol CreditAttribution: bobbyaldol commentedgrammar correction
Comment #12
MD3 CreditAttribution: MD3 commentedThanks for this amazingly clear example. While I'd be curious to see how rszrama would implement it, we should probably get this rolled into the module! It was a fantastic help!
Comment #14
joelpittetJust a couple of notes, but looks like this needs a re-roll too?
Should start with a capital letter and end with a period.
Was resolved.