I am trying to form a shipping rule which is triggered by line items having a given term. So far so good and this module has been a big help.

I now need to refine my rule so that it is only triggered if ALL line items have this term.

I do not know how to go about this, can anyone help?

Comments

MarcElbichon’s picture

StatusFileSize
new10.14 KB

I've added an new quantity field to commerce_order. This field is the total quantity of products of the commerce_order.
So now, you can create a condition Total quantity of selected products comparaison and choose commerce-order:commerce-order-quantity in the data selector as quantity comparaison (quantity field).

mrpauldriver’s picture

Thank you that is a massive help.

MarcElbichon’s picture

Does this work for you ?

mrpauldriver’s picture

I haven't yet had time to try, but will take a look tomorrow. I'll report back and let you know.

mrpauldriver’s picture

I'm struggling with this.

The data selector 'commerce-order:commerce-order-quantity' does not appear to be available to the quantity field.

MarcElbichon’s picture

Have you flushed cache ?

mrpauldriver’s picture

I had not flushed the cache but have done so now and find the same:-(
Thank you for the suggestion though.

This is how my condition is formed...
1. Condition to add: Total quantity of selected product comparison
2. Order data selector: commerce-order
3. Tern Reference Field: Value Shipping Options (Vocab)
4. Taxonomy Term Value: Allow discount delivery - £1 per item
5. Search terms in product display, not in product: is not selected.
6. Require All: is not selected
7. Product Type: Product Options
8. Exclude content_type: is not selected
9. Operator is set to =
10. Quantity: Data selector 'commerce-order:commerce-order-quantity' seems not to be available.

Do I understand correctly that the premise of your suggestion is that if the quantity of products with the defined term equals the total quantity of products in the order, then the condition is met? Or put another way, if all commerce-order products have the same term, then the condition is met.

Background info. In most cases my shipping rules are based on order value. However, I wish to trigger different rule of base-rate * quantity, where all items have the term 'Allow discount delivery - £1 per item' term.

MarcElbichon’s picture

StatusFileSize
new47.25 KB

Below Quantity field, you must have "switch to data selection" button.When clicking, data selector must appear. Select commerce-order. You should see like attachment.
Select commerce-order-quantity.

This means that condition will be fired if total quantity of selected items (by terms and/or content-type) is equal to total quantity of order, in order term, that all products have terms and/or content-type.

Is that what you want ?

mrpauldriver’s picture

StatusFileSize
new20.41 KB

This is what I am seeing. I'll double check all my settings and modules

MarcElbichon’s picture

Bizarre.
Can you have a look to commerce_rules_extra/commerce_rules_extra.rules.inc and search for commerce_rules_extra_entity_property_info_alter() method (bottom of file).
If found, can you retry to clear cache (registry cache).
If this does'nt work, can you add in commerce_rules_extra_entity_property_info_alter() method this line just after function declaration

drupal_set_message("commerce_rules_extra_entity_property_info_alter() is triggered");

Clear the cache again, message must be printed.

mrpauldriver’s picture

I am not a coder, but copied below is the entirety of what is in commerce_rules_extra.rules.inc
As the zip file at #1, also dev and commit 5e02c5d

If this is all as it should be then I need to take a close look at my rule.

<?php

/**
 *  Implements hook_rules_event_info()
 **/
function commerce_rules_extra_rules_event_info() {
    global $cre_includes;
    foreach ( $cre_includes ["events"] as $file ) {
        $rule = basename($file, ".inc");
        $f = $rule . "_event_info";
        $events [$rule] = $f();
    }
    
    return $events;
}

/**
 * Implements hook_rules_conditions_info()
 */
function commerce_rules_extra_rules_condition_info() {
    global $cre_includes;
    foreach ( $cre_includes ["conditions"] as $file ) {
        $rule = basename($file, ".inc");
        $f = $rule . "_condition_info";
        $conditions [$rule] = $f();
    }
    
    return $conditions;
}

/**
 * Implements hook_rules_action_info().
 */
function commerce_rules_extra_rules_action_info() {
    global $cre_includes;
    $actions = array ();
    foreach ( $cre_includes ["actions"] as $file ) {
        $rule = basename($file, ".inc");
        $f = $rule . "_action_info";
        $actions [$rule] = $f();
    }
    
    return $actions;
}

/** Add Total quantity in order object 
 * 
 * @param unknown $info
 */
function commerce_rules_extra_entity_property_info_alter(&$info) {
    $info['commerce_order']['properties']['commerce_order_quantity'] = array(
            'type' => 'integer',
            'label' => t('Total quantity'),
            'description' => t('Total quantity of the order.'),
            'getter callback' => 'commerce_rules_extra_get_quantity_property',
            'computed' => TRUE,
    );
}
MarcElbichon’s picture

Can you replace

function commerce_rules_extra_entity_property_info_alter(&$info) {
    $info['commerce_order']['properties']['commerce_order_quantity'] = array(
            'type' => 'integer',
            'label' => t('Total quantity'),
            'description' => t('Total quantity of the order.'),
            'getter callback' => 'commerce_rules_extra_get_quantity_property',
            'computed' => TRUE,
    );
}

by

function commerce_rules_extra_entity_property_info_alter(&$info) {
    drupal_set_message("commerce_rules_extra_entity_property_info_alter() is triggered");
    $info['commerce_order']['properties']['commerce_order_quantity'] = array(
            'type' => 'integer',
            'label' => t('Total quantity'),
            'description' => t('Total quantity of the order.'),
            'getter callback' => 'commerce_rules_extra_get_quantity_property',
            'computed' => TRUE,
    );
}

in commerce_rules_extra.rules.inc.
Clear cache and see if the message is printed. This is to be sure hook is done, so you should have commerce-order-quantity field in data selector.

mrpauldriver’s picture

Still no data selector I'm afraid.

You are investing so much time on this, if it turns out that I have done something fundamentally wrong in setting up the rule, I will need to kick myself and you can too:-) Would it help if you had access to my site?

MarcElbichon’s picture

I don't think this is a rule configuration problem.
Have you seen message when you have cleared the cache ?
Yes, access to your site can be useful.

mrpauldriver’s picture

No messages when clearing the cache.

I'll PM some credentials

mrpauldriver’s picture

That appears to be working now. Thank you

When I have my rule finished I will write up the procedure for the benefit of anybody that follows.

MarcElbichon’s picture

OK. Commit this to dev version and wait for your procedure to close issue

mrpauldriver’s picture

Just a quick bit of feedback

When updating or deleting certain rules the following is printed as a system message

Quantity field added to order component
Quantity field added to order component
Quantity field added to order component
Quantity field added to order component
Quantity field added to order component
Quantity field added to order component
Quantity field added to order component
Quantity field added to order component
Quantity field added to order component
The flat rate service Discount has been deleted.

Was this something that for added in earlier for debugging purposes?

MarcElbichon’s picture

yes, they are debug messages. Install official dev version, messages should be removed.

mrpauldriver’s picture

Thank you

mrpauldriver’s picture

There seems still to be a remanent of the debug message in dev.

The following is displayed when system messages are shown.

sites/all/modules/commerce_rules_extra
sites/all/modules/commerce_rules_extra
The configuration options have been saved.
sites/all/modules/commerce_rules_extra

MarcElbichon’s picture

You're right. Commited to dev.
Sorry for the inconvenience

mrpauldriver’s picture

no problem, thank you for your help

mrpauldriver’s picture

StatusFileSize
new69.62 KB

Sorry to inform, but the the latest dev is broken, something which has just come out in testing. The taxonomy (quantity) based shipping rules that I was working on, have ceased to function. Rolling back to 997cf9e corrects the situation for me.

As mentioned above, the last commit which worked correctly was 997cf9e. After this was 47dc84c and then 88e9e2f which both dealt with the removal of debugging messages. Having double checked, it seems that something that was changed or overlooked in 47dc84c which causes the new functionality to fail.

I notice with 47dc84c and 88e9e2f that part of the UI is broken (screenshot) and suspect that this of relevance.

MarcElbichon’s picture

As described at https://drupal.org/node/2059325#comment-7900965, term comparison rules has been modified.
A new field, operator (like in your screenshot) allows you to select one of these values (is one of, is all of, is none of, is empty, is not empty).
For your needs, can you try selecting is all of ?

I'm confused about broken rules due to new features. I will try to release a version soon to prevent inconveniences.

mrpauldriver’s picture

Point taken about the new operator and I'll do some double checking with the later releases, with this in mind.

Thanks again for your continued help with this.

jcl324’s picture

Issue summary: View changes

I am having this issue too. Can't find the "commerce-order:commerce-order-quantity" data selector, no matter what I do. I have looked at the code and it appears to be moved to the .module file, out of the .inc. One thing I'm not clear on is what event type this condition happens on. I'm assuming "Process checkout pane"?

I'm using 7.x-2.0-alpha3, should I be using the dev version? MrPaulDriver, if you would be so kind as to post your write-up you mentioned in #16? :)

Also, I'm using Kickstart 2.6. Has there ever been a reported problem with this module and KS?

MarcElbichon’s picture

To be sure, can you try with dev version ?
Don't forget to flush caches.

jcl324’s picture

Thanks for the quick reply Marc. I tried the dev version and still same problem. Interesting though is that Drush was confused, even though I specified the dev version it wanted to do the alpha, so I did it manually.

Can you please confirm that the event type should be "Process checkout pane"?

MarcElbichon’s picture

Field is available for any event using commerce_order but only for data comparison condition.

MarcElbichon’s picture

To be more precise, field is also avalaible in QUANTITY data selector for Total quantity of selected product comparison or Total product quantity comparison

jcl324’s picture

StatusFileSize
new122.83 KB

Still not seeing it. What am I doing wrong?

MarcElbichon’s picture

Which condition do you use ?

jcl324’s picture

Total quantity of selected product comparison. All I'm trying to do is calculate FedEx shipping rates based on a taxonomy term.

MarcElbichon’s picture

For this condition, you do not need quantity field.
Select term and set quantity and operator (for example > 1).
For this example, if total quantity of products with specified term (calculated by the rule) is greater than 1 , action can be ran.

Quantity field could be selected in Data comparaison condition

jcl324’s picture

So sorry, I was totally looking for it in the wrong place. There is an ORDER data selector, and a QUANTITY one where I did find commerce-order:commerce-order-quantity. Reading back through this thread, it now makes much sense and realize that I didn't need it after all. MrPaulDriver's use case was not the same as mine.

So I have the rule firing correctly and the FedEx or Flat rate (free) is working on the proper terms of a product. However, if I have one product in the cart that gets the FedEx rate and another that gets the free rate, the rates that FedEx come back with are based on both items. Not sure whether this is a rule issue or a FedEx module one, any insights?

MarcElbichon’s picture

Status: Active » Closed (fixed)

I don't know shipping rates, but i suppose you code your rule like (if order contains a product for xxx term then apply fedex rate).
So you will apply rate to all products if only one product is for tem xxx.
If you want to test if ALL products are for term xxx, you could choose equal operator and quantity field in QUANTITY data selector so rule will be fired only if number of products of term x is equal to total quantity of order.
I close this issue because this is a rule conception problem.