1

I'm doing something very simple. I have an order where rules fires on completed checkout.

I'm trying to iterate through the existing line items and schedule recurring billing based on a text list that has either yearly or monthly.

It wasn't working so I broke it down it its bases of elements in the actions.

Here is my exported rule:

{ "rules_schedule_next_billing_cloned_" : {
    "LABEL" : "schedule next billing (cloned)",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "commerce_checkout" ],
    "ON" : { "commerce_checkout_complete" : [] },
    "IF" : [
      { "entity_has_field" : {
          "entity" : [ "commerce-order:commerce-line-items:0" ],
          "field" : "commerce_product"
        }
      },
      { "entity_has_field" : {
          "entity" : [ "commerce-order:commerce-line-items:0:commerce-product" ],
          "field" : "field_cycle_start"
        }
      },
      { "entity_has_field" : {
          "entity" : [ "commerce-order:commerce-line-items:0:commerce-product" ],
          "field" : "field_cycle_period_list"
        }
      },
      { "entity_has_field" : {
          "entity" : [ "commerce-order:commerce-line-items:0:commerce-product" ],
          "field" : "field_client"
        }
      },
      { "entity_is_of_bundle" : {
          "entity" : [ "commerce-order:commerce-line-items:0:commerce-product" ],
          "type" : "commerce_product",
          "bundle" : { "value" : { "recurring_service" : "recurring_service" } }
        }
      }
    ],
    "DO" : [
      { "LOOP" : {
          "USING" : { "list" : [ "commerce-order:commerce-line-items" ] },
          "ITEM" : { "cycled_billing_charge" : "cycled billing charge" },
          "DO" : [
            { "drupal_message" : { "message" : "the period is [commerce-order:commerce-line-items:0:commerce-product:field-cycle-period-list]" } }
          ]
        }
      }
    ]
  }
}

What's happening is it iterates through the proper amount of line items but it isn't incrementing; it is only messaging the first line item it sees.

I have looked at several articles and I have done some debugging. I'm at a very rudimentary level.

halfer
  • 19,824
  • 17
  • 99
  • 186
thomedy
  • 93
  • 11

1 Answers1

0

Your Rule seems to "work as implemented", since within your "drupal_message", you're using commerce-order:commerce-line-items:0... (which refers to your very first line item, as per the "0" at the end). Instead, you should use the "current item being processed" (for which you use the variable with machine name cycled_billing_charge)

Try replacing that "commerce-order:commerce-line-items:0:commerce-product:field-cycle-period-list" in your "drupal_message" by (simply) "cycled_billing_charge:commerce-product:field-cycle-period-list", so that your Rules loop looks something like so (also in Rules export format):

      { "LOOP" : {
          "USING" : { "list" : [ "commerce-order:commerce-line-items" ] },
          "ITEM" : { "cycled_billing_charge" : "cycled billing charge" },
          "DO" : [
            { "drupal_message" : { "message" : "the period is [cycled_billing_charge:commerce-product:field-cycle-period-list]" } }
          ]
        }
      }
Pierre.Vriens
  • 2,117
  • 75
  • 29
  • 42