When adding multiple SKUs for a product discount at: /admin/commerce/store/discounts the rule never fires due to the fact that the condition only evaluates to TRUE for a single product. To make it work it needs something like this:

/**
 * Build callback for commerce_product_contains_products.
 *
 * @param EntityDrupalWrapper $wrapper
 *   Wrapped entity type given by the rule.
 * @param array $sku
 *   Product sku returned by rule condition.
 *
 * @return bool
 *   True if condition is valid. false otherwise.
 */
function commerce_product_contains_products_build(EntityDrupalWrapper $wrapper, $sku) {
  if ($wrapper->getBundle() == 'product') {
    return (in_array($wrapper->commerce_product->sku->value(), array_map('trim', explode(',', $sku))));
  }
  return FALSE;
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

perusio’s picture

Status: Active » Needs review
FileSize
965 bytes

Here's a patch.

jkuma’s picture

Status: Needs review » Reviewed & tested by the community

Thanks perusio for your contribution. The patch is working well.

jkuma’s picture

Status: Reviewed & tested by the community » Fixed

Committed in 7.x-1.x-dev branch.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

MD3’s picture

I believe this needs to be re-opened give the following:
[2420341]