I try to build up a rule condition for different payment methods - in my case bank transfer and paypal. I have 2 different product-types - "normal products" and "file products". File Downloads should be paid via paypal - that means - if you have more than one "file product" in your cart only paypal as a payment is available.

Is it possible to add a rule condition to check for a specific product-type ? I could solve my problem by adding all "file products" to a "Order contains particular product" rule-condition, but that too much work if you have a lot of downloadable products..

Comments

joshmiller’s picture

Category: feature » support

After seeing what's available with Rules, I would almost guarantee there is a magical combination that will make this rule possible. Less of a feature request and more of a support request. You might try the forums on drupalcommerce.org -- very helpful people hang out there.

SteffenR’s picture

@joshmiller: thx for your advice - i was looking for such magic combination but couldn't find it - i'll looking forward to the answers i get at drupal commerce forums..

rphillipsfeynman’s picture

Has anyone found a solution for this issue? I need to do exactly the same and I've tried pretty hard to find the "magic solution" but I've had no success so far. Any tip will be welcome. Thanks in advance!

elperuanito’s picture

As they say, there is a module for that. :-D

Check out Commerce Extra Rules Conditions.

rphillipsfeynman’s picture

Thanks very much @elperuanito. You're right. I wish I had found that module before I implemented my own rule. :S

lsolesen’s picture

@rphillipsfeynman Care to share your solution?

rphillipsfeynman’s picture

Ofcourse @lsolesen. I'm glad to contribute with this forum since I've taken a lot from it. First, I have to say that I haven't checked if the module Commerce Extra Rules Conditions indeed works but I installed and did check that there is a rule for doing what we want. My solution (which works for me), can be found here http://drupal.org/node/1470862#comment-6467442. I hope it works for you as well.

joshmiller’s picture

Status: Active » Fixed

Sounds like this is all fixed :D

Status: Fixed » Closed (fixed)

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

pedrorocha’s picture

Category: support » feature
Status: Closed (fixed) » Active

Actually, there isnt't a Rule Condition to enable us to do such a comparison, so this question is a Feature Request, still open, and in my opinion, the best place to address it is here, in the main Commerce module itself. The linked comment points to a hack on Commerce Order module, that shouldn't be encouraged.

I made such Condition in a project right now, that has the following code:

/**
 * Implements hook_rules_condition_info().
 */
function mymodule_rules_condition_info() {
  $conditions = array();
  $conditions['mymodule_compare_product_types'] = array(
    'label' => t('Check if order has only products of specified types'),
    'parameter' => array(
      'commerce_order' => array(
        'type' => 'commerce_order',
        'label' => t('Order'),
        'description' => t('The order in question.'),
      ),
      'value' => array(
        'type' => 'list<text>',
        'label' => t('Product types'),
        'description' => t('The product types to check in the order.'),
        'options list' => 'mymodule_compare_product_types_options',
        'restriction' => 'input',
      ),
    ),
    'group' => t('Commerce Order'),
  );
  return $conditions;
}

/**
 * Returns options for choosing a field for the selected entity.
 */
function mymodule_compare_product_types_options(RulesAbstractPlugin $element) {
  $options = array();
  foreach (commerce_product_types() as $product_type_name => $product_type) {
    $options[$product_type_name] = $product_type['name'];
  }
  return $options;
}

function mymodule_compare_product_types($order, $settings) {
  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
  $items = $order_wrapper->commerce_line_items->value();
  if (count($items) > 0) {
    foreach ($items as $line_item) {
      $product = commerce_product_load($line_item->commerce_product['und'][0]['product_id']);
      if (!in_array($product->type, array_keys($settings))) {
        return FALSE;
      }
    }
    return TRUE;
  }
  return FALSE;
}

I guess it could be the answer or even a starting point.

rszrama’s picture

Status: Active » Postponed (maintainer needs more info)

You still could do this in Rules using components. We don't really have a line for how specific we want our conditions to be, so I'm happy to entertain proposals for helper functions, but this one may just open the door to others that can be accomplished without a specific condition. : ?

Perhaps someone can rephrase the title and summarize again what you actually want a condition to do?

bojanz’s picture

Issue summary: View changes
Status: Postponed (maintainer needs more info) » Closed (outdated)