$line_item_types = variable_get('commerce_discount_line_item_types', array_diff(commerce_product_line_item_types(), array('product_discount')));
and then
if (in_array($line_item_wrapper->type->value(), $line_item_types)) {
Does work as a valid check because the FAPI saves an array element as 'shipping' => 0 which will pass the in_array check.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | 2640018-9-pass.patch | 4.6 KB | joelpittet |
| #9 | 2640018-9-test-only-fail.patch | 2.06 KB | joelpittet |
Comments
Comment #2
andyg5000This issue happens because in_array passes whenever there are values of 0 in the array.
Here's a patch that uses empty checks instead of in_array so that we don't have to worry about sites with the array set with 0 values (from FAPI).
Comment #3
mglamanWon't work in PHP 5.3, return on context or some crazy thing.
Comment #4
andyg5000Crap you're right
Comment #6
dmurphy1 commentedI ran into the same problem today after I unchecked a few "Line item types to use for discounts" at admin/commerce/discounts/settings. They still passed the in_array check because they're stored as 'shipping' => 0 as mentioned above. I believe simply passing the optional strict parameter set to TRUE for in_array fixes the problem. Per http://php.net/manual/en/function.in-array.php "if the third parameter strict is set to TRUE then the in_array() function will also check the types of the needle in the haystack."
Comment #7
dmurphy1 commentedComment #8
joelpittetJust to confirm you I understand the problem. You are seeing this right?
https://3v4l.org/TjuYO
Would any of you mind writing a test so this doesn't regress in the future?
Comment #9
joelpittetHere's a test only and the fix. I split the variable from getBundle() out because it's easier to debug.
Comment #12
joelpittetThanks everyone, I've pushed #9 to -dev.
Comment #14
andyg5000