The _product_specials hook ignores other specials that may be set by other modules.
Instead of returning a new array like return array('special' => $discounts); it should add an entry to the $specials array argument that was passed into the function and return the result. Also, instead of using a generic key like 'special', which can collide with keys set by other modules, use a more specific key:
$specials['role discount'] = $discounts;
return $specials;
The Quantity Discount module for example will definitely conflict with Role Discount. Whichever happens to be processed last will overwrite the discount set by the other (Quantity Discount also has this very same bug).
Comments
Comment #1
mariuss commentedHere is the corresponding Quantity Discount bug report:
http://drupal.org/node/183459
Comment #2
gordon commentedThis is by design, if you use another module which is conflicting namespace then it is going to get over written.
This is done that subsequent calls to the hooks can alter previous discounts
Comment #3
mariuss commentedWhat namespace are you referring to, can you please clarify?
Subsequent calls, subsequent to what? Is Role Discount always called the very first one?
If not, then how is Role Discount altering previous discounts? There is no code us such.
If yes, then that needs to be clarified. Other module implementors have no idea about this. Just as Quantity Discount went ahead an implemented what Role Discount does, and this strategy clearly ends up in discounts being clobbered.
Comment #4
brmassa commentedMarius,
well, the hooks are called following the modules weight. heavier modules will be called later.
this order let you alter the behaviour of the previous module. That is the intention on this issue. the main problem is that the Qty discount module is uding the same names we use. so its replacing the old values. You should ask the Qty discount dev team to fix this. Or, at least, ask them to change the module weight.
regards,
massa
Comment #5
gordon commentedThe names space is the name of the discount in the specials. This means that you are able to overwrite previous specials and replace them with other amounts.
If you want to have multiple specials then just call the name of the special in the array something different.
Comment #6
janusman commentedI'm the Quantity Discount dev... I guess the "intended" final price of any product is the result of applying all possible discounts that apply (quantity, role, etc.):: so would "just" adding a modlue weight to quantity_discount eliminate the problem...?
...Or should every module that uses hook_product_specials() just use a different "namespace" like the one mariuss proposes:
I am also intrigued by the concept of "namespaces" =) Does a namespace simply mean use a different key in the returned array?