Weight behavior goes against the convention i.e. lighter weights don't float to the top as they should.

I created 2 tax types: Tax type A and Tax type B. I then created 2 tax rates: Tax rate 1 (type A) and tax rate 2 (type B). Initially, both tax types have a weight of '0'. In the checkout, by default, Tax 1 is displayed above Tax 2.

If, for some reason, I want Tax rate 2 to be displayed above Tax rate 1, logically I would assign e.g. '-5' to Tax type B so that it is lighter than Tax type A. But when I do that, nothing changes. When Tax type B weight is set to '+5' (compared to '0' for Tax type A), it then is displayed above Tax type A.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rszrama’s picture

Category: Bug report » Support request
Status: Active » Closed (works as designed)

I'm actually not sure what you're referring to; the documentation for these hooks and implementation of them includes no weight property at all. Perhaps that's why you don't perceive it as working?

If I'm reading you right, what you want is to alter the weight of the tax rates' related price component types.

bisonbleu’s picture

Hey Ryan, sorry for being unclear.

Indeed, if I could alter the weight of individual tax rates as they appear in the cart, I would be able to choose which tax should be displayed first (above) and which one should be displayed second (below). But as far as I can see, one cannot assign a weight to a tax rate Component.

On the other hand, it is possible to assign a weight to a tax type Rule. This is what I'm referring to.

To avoid more confusion, see the attached screen captures.
- provincial-tax-weight+5.jpg shows the cart when the weight of TVQ is set to +5 (heavier); the weight of GST is set to 0.
- provincial-tax-weight-5.jpg shows the cart when the weight of TVQ is set to -5 (lighter); the weight of GST is set to 0.

In the end I'm able to achieve what I want. That being said, and afaik, the weight logic is reversed. Either that or I seriously need a vacation! ;-)

rszrama’s picture

Status: Closed (works as designed) » Closed (fixed)

Honestly, I think you've discovered an accidental feature. The weight of the rules really just determines the execution order of the rules and isn't necessarily correlated to the sort order in the price component breakdown. I'm not exactly sure why it's an inverse relationship, but I am glad it worked out in the end. ^_^

I hesitate to put too much effort into improving this in 1.x. In the future, you might consider using hook_commerce_price_component_type_info() in a custom module to tweak the display order of the price components, but ultimately we just need to rethink the whole implementation in Commerce 2.x.