Drupal Commerce has an "Order address component comparison" condition that we should duplicate for use as an inline condition (with the simpler title of "Order address comparison"). The inline condition needs to be defined in commerce_discount.inline_conditions.inc. The configuration callback should imitate the total amount configuration callback - we just have to create form elements that correspond to the parameters expected by the core condition. If I read the module right, we should be able to use the core condition callback as the build callback, but that may need some testing.

Comments

rszrama created an issue. See original summary.

michfuer’s picture

Status: Active » Needs review
StatusFileSize
new3.29 KB

This should take care of it. Just FYI, we are able to use the core commerce_order condition callback as the build callback, granted that we ensure the form elements in the configure callback are named the same as the parameters in the core hook_rules_condition_info().

joelpittet’s picture

Status: Needs review » Needs work

This looks good from the code point of view. Just a couple things I spotted while reviewing:

  1. +++ b/commerce_discount.inline_conditions.inc
    @@ -419,6 +428,66 @@ function commerce_order_has_specific_quantity_products_configure($settings) {
    +  $file = drupal_get_path('module', 'commerce_order') . '/commerce_order.rules.inc';
    +  require_once DRUPAL_ROOT . '/' . $file;
    

    Should be using this.
    module_load_include('inc', 'commerce_order', 'commerce_order.rules');

  2. +++ b/commerce_discount.inline_conditions.inc
    @@ -419,6 +428,66 @@ function commerce_order_has_specific_quantity_products_configure($settings) {
    +    '#suffix' => '<div class="condition-instructions">' . t('The discount is active if the order address component selected matches the entered value. For the entered value bear in mind that addresses using select lists for various components may use a value different from the option you select. For example, countries are selected by name, but the value is the two letter abbreviation. For comparisons with multiple possible values, place separate values on new lines.') . '</div>',
    

    Any reason why #description isn't used here?

michfuer’s picture

Status: Needs work » Needs review
StatusFileSize
new3.23 KB

Here's the updated patch to use module_load_include().

I used '#suffix' to follow the convention of the existing configure callbacks.

rszrama’s picture

Status: Needs review » Fixed

Alrighty, this checks out.

This whole part of the form is hideous, though. No fault of the current patch, but I'm going to spawn a follow-up to do something more appropriate with the theming of condition parameters than a simple "display: inline;" on all divs in the area. As this patch shows, that fails for textareas, and it's what makes the #suffix necessary vs. #description.

  • rszrama committed bb2c957 on 7.x-1.x authored by michfuer
    Issue #2561183 by michfuer: Add an "Order address comparison" inline...

Status: Fixed » Closed (fixed)

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