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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rfay’s picture

What is a tax price? Glad you're interested!

chriscalip’s picture

Pulled it off, will clean code and submit patch.

chriscalip’s picture

chriscalip’s picture

Randy,

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

rfay’s picture

Status: Active » Needs review

Congratulations! 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!

rfay’s picture

X-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?

chriscalip’s picture

updated issue summary per your request.

chriscalip’s picture

Issue summary: View changes

better description per rfay request

chriscalip’s picture

Issue summary: View changes

better description

chriscalip’s picture

Issue summary: View changes

use case description

rfay’s picture

Excellent, thanks so much!

rfay’s picture

Title: Example of tax price instead of tax rate. » Tax Example
FileSize
4.85 KB

Very nicely done - I've gone through and redone some things and would appreciate your review.

rfay’s picture

Although this works fine, I think rszrama would say he'd implement it differently.

bobbyaldol’s picture

Status: Needs review » Reviewed & tested by the community

@rfay: Reviewed and good to commit.

bobbyaldol’s picture

Issue summary: View changes

grammar correction

MD3’s picture

Thanks 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!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 9: commerce_examples.tax_example_revamp_1374198_09.patch, failed testing.

joelpittet’s picture

Issue summary: View changes

Just a couple of notes, but looks like this needs a re-roll too?

  1. +++ b/tax_example/tax_example.module
    @@ -0,0 +1,106 @@
    +      // change title here on sub totals
    ...
    +      // actual calculation happens here
    

    Should start with a capital letter and end with a period.

  2. +++ b/tax_example/tax_example.module
    @@ -0,0 +1,106 @@
    +      // dummy rate, since we're actually going to calculate it. This is just
    +      // ignored, but until http://drupal.org/node/1410990 is resolved it
    +      // must be nonzero.
    

    Was resolved.