Hello,

I have been trying to figure out a way to hide the shipping address, shipping options, and removing the shipping line item for orders where the product for sale isn't shippable. Example include a downloadable product, buying the right to accomplish an action or access content on the website. I still have traditional products like hats, t-shirts, thermal nuclear mines, toxic whoopie cushions, etc that require shipping. For now I'm using flat rate shipping instead of calculating based on weight.

Could I?

1) Extend Product Entities
Add a flag (boolean) shippable yes/no

2) Add evaluation rules
On checkout or entering checkout validate all product line items in the cart and if none are shippable:
a) hide shipping address panel
b) Hide shipping step for checkout -> direct customer to review order from checkout start
c) On cart view remove shipping line item entry for good measure

3) Profit?

So can I accomplish items 2a, 2b, and 2c using rules or should I look at writing a custom module to hook into the process? Worst case I'd have to hack the commerce_shipping module to support my particular use case.

Thoughts? Recommendations?

CommentFileSizeAuthor
#27 commerce_shipping_jump.zip1.6 KBduaelfr

Comments

mxwitkowski’s picture

I need this exact functionality as well. Willing to help out on this.

googletorp’s picture

Status: Active » Fixed

Shipping options is displayed by rules and hidden if no options is available, so you can setup rules to hide/show the options. The shipping line item is only created if a shipping is selected and you can add rules logic or code to delete shipping line items.

Customer profiles is created by commerce so won't comment on that.

emptyvoid’s picture

Hello,

Yes I follow your logic, however if no shipping options exist the shipping panel still appears in the checkout process. Without an attribute or "state" for a given product you won't be able to determine if (once added as a product line item) if it requires shipping or not.

For the moment I'm leveraging the Flat rate shipping module. Which as the name implies provides flat rate shipping options, regardless of the products added to the cart or the number of items added.

So, as I stated before I could added a boolean flag to each product type "shippable" yes/no. Then write a rule when checkout starts, check if the combined list of product line items have a value of "yes". If any have a value of yes the shipping module displays and business logic would run normally. If no, I would use rules or a custom module to hide all shipping panels/options and make sure a shipping line item is not added to the order.

At least, that's the plan; i'll post updates on my progress. If I can accomplish it all using rules and a few fields on each product type I'll post an export of the rules I have built. Honestly I would expect that the shipping modules would cover this use case. Not all products are shippable.

Anywho, wish me luck.

toppen56’s picture

I'll be interested to hear how you handle this. I was searching for a solution to this issue.

ponies’s picture

I've just run into this myself. Luck!

emptyvoid’s picture

Status: Fixed » Needs work

Annoying RANT TIME!

So I only see one rules condition as it pertains to checkout "Checkout is complete" how can I trigger evaluation on cart load?

on Checkout load during pre-render of the checkout page that lists all of the panels (shipping being one of the panels I'd like to hide)?

How do I remove the "Shipping" page from the checkout process if there is no condition nor action to do so?

I'm still working through this (which most likely points to a custom module) and attempt to accomplish it using Rules as you recommended. But after close inspection that direction seems a little too "simplified" of an answer to actually help me.

So I've changed the status as this issue is not resolved... and if I do solve it I am going to attach the exported rules (or custom module) I used to actually solve the problem. I just hope such features can be rolled into the default install of the module. It would be great to have several disabled rules added to the shipping module that users can enable based on their particular business case needs.

emptyvoid’s picture

Follow up of my progress thus far. I have a boolean "shippable" as a filter when evaluating product line items it helps automatically determining if an order has any shippable products.

Second I followed the recommendations of the free online training from Commerce Guys about using "weight" based products and conditionally calculating the shipping price by quantity and weight.

http://vimeo.com/33838479

Next I added evaluation rules for the standard shipping "placeholder" for my shipping method. I added an evaluation that would totally remove the shipping method as an option is no products were shippable. Sure enough the shipping method hides, but what doesn't hide is the Shipping Page in the Checkout Workflow. :(

Nevermind I will also need to write a hook to hide the shipping address panel of the first check out page when shipping is not required. I hope, I can evaluate the order line item products from the first page.

I may have to add a custom validation hook to stomp the shipping panel to force it to hide from the checkout workflow.

valante’s picture

Status: Needs work » Active

Hi,

I'm also in dire need of this functionality. Here's how I see it:

1. Every product must have a checkbox field, whether it's shippable or not
2. Possible to define default based on product-type, to save time
3. On checkout, if no products in the cart are shippable, do not display the shipping profile and the shipping methods

I believe this is a need of many people who sell mixed digital and tangible goods.

I'm willing to fund this at $200. Will that do? Will anyone else join me in offering a bounty?

valante’s picture

Category: support » feature

Any takers on the above bounty?

FAAREIA’s picture

Priority: Normal » Major

mmmm, where are the followers??? I thinks that this issue is very importante for real commerce proyects. Please follow if you are interested. it can't be only 7 followers!

emptyvoid’s picture

Update, so as I have described I have resulted in using the physical product, weight field and boolean "Is Shippable?" on every product type in the store.

Next I added several rules both in the cart, shipping methods, and checkout actions.

Because of time, I have put the effort to actually hide the shipping elements in the GUI. But I hope to have time (we're talking months here) to build a module to override the display of the shipping panel and shipping page in the checkout process.

Based on an initial review of the code for both the panel and pages in the checkout process I don't see an attribute or hook to alter the fields (yet). But that may be where I will start my research, once a hook_alter exists I could then create events, conditions, and actions for Rules.

FAAREIA’s picture

Hi emptyvoid, can you explain me a little more how did you manage to not load Shipping form???
I'm trying something with rules but i can't see any option to do so. Plus, i do not have weights. I just wanna to let the user choose on Checkout:Checkout if he need Shipping or not.

Thanks for all

pixhail’s picture

Hi Emtyvoid,
I have coded a custom module, which is as per your needs.
In this method, there will be a boolean value, in the form of a check box, which will be for items shippable or not.
If not shippable, during checkout, no shipping info pane will be shown. But if shippable, shipping info pane will be shown.

If you want this module, let me know.

pixhail’s picture

Guys, i have given the solution to valante. Tal can you pls confirm?

FAAREIA’s picture

It's good to know there is a solution to this issue, but i think it's only the first step.
For example:
All my products are shippable, but i don't want the items to be shipped because i will go to the store and get my products. In this case, items are shippable but user choose "not to ship".
There could be a second boolean value on checkout:checkout to apply this use case. Or a rule checking the value and enableing or disabling a panel could be nice two.

This are simply some ideas i thought about it,
Greetings

pixhail’s picture

Hi Stakcreativa,

I can add this small thing in my module, if you are interested.

Thanks

pixhail’s picture

Hi Stakcreativa,

I can add this small thing in my module, if you are interested.

Thanks

valante’s picture

I did just get this add-on module from pixhail, no hacking, works great.

FAAREIA’s picture

Hi pixhail, i will really appreciate if you can add my use case to your module. Many thanks for asking and for all the work you have done. =)

Greetings.

pixhail’s picture

How much , you will pay for that?

FAAREIA’s picture

mmmmm, i can't pay you since i do not have credit card but you can ask me something to css or design if you want =). Like a trade.

pixhail’s picture

i am sorry, design stuffs etc, i do my self.
You don't have paypal too?

FAAREIA’s picture

sry pixhail, i'm from Argentina, i never used Paypal (it don't have our currency). Gonna be on other life then. Thanks anyway.

googletorp’s picture

@pixhail if you want to sell code, please take it somewhere else instead of using the issue queue for that stuff.

duaelfr’s picture

I acheived to jump over shipping panel with rules so if your shipping rates does not depend on the address, it could be interesting for you (just ask).

In my case, I have to let my shipping address form out of the shipping panel so I am a bit stuck with this issue.

bradhawkins’s picture

@DuaelFr that sounds like it would work for my situation, can you export and post your rule? Or at least a step by step overview?

duaelfr’s picture

StatusFileSize
new1.6 KB

Ok so you will need Commerce Physical Product with the following patch #1344962-17: Add some helpful rules conditions (Comment #17)
Then you will find a module in the attachment which enables two rules to jump over the shipping pane.

bradhawkins’s picture

Thanks DuaelFr! Works perfectly!

But I should note that your patch in #1344962: Add some helpful rules conditions doesn't seem to have the new condition "commerce_physical_rules_order_is_shippable" that you mentioned. Its not at all a problem for me, (I've only got 1 shippable item, so I can easily setup up a condition to check for that product's sku) but I thought I would mention it because you might want to double check your patch to make sure all your work got included.

Thanks again for your help!

duaelfr’s picture

OMG you are right !
Entire commit is here.
I provided a new patch including the missing file.
Thank you very much :)

bradhawkins’s picture

Cool! Works much better than my single product SKU hack - and is scalable :)

Merci!

muhammad.tanweer’s picture

Hello DuaelFr,

Thanks for the great patch. As mentioned, it works for several people, however, I applied the latest complete patch to commerce_physical module, but still I am unable to see the rules here : http://mywebsite.com/admin/config/workflow/rules
I even uninstalled and re-installed the module, cleared cache, did everything that I understood should work but still no clue. I am stuck, can you please give me a few lines of quick help? Would be appreciated.

Thanks

cherrysuede’s picture

Hey DuaelFr

Question for you - i have installed the patch - I see the condition in rules but when i install the shipping jump module - i don;t see the rules that you talk about

Have I missed something?

Thanks!

duaelfr’s picture

I don't know why it is not working on your installation.
I theory, rules may be shown in the main Rules screen even if their components are not found.

Try to add a file[] = commerce_shipping_jump.rules_default.inc in the info file and to clear cache to see if it changes something.
If not, ask bradhawkins how he acheived this :)

ponies’s picture

Not sure if it was user error, but commerce_shipping_jump didn't apply the rules when I enabled it. I manually entered the rules and they worked like a charm. Now to hide and not require the shipping information.

muhammad.tanweer’s picture

Hi ponies,

Can you please tell me the exact rules that you created? I have spent a lot of time tweaking the commerce shipping jump module here and there but had no luck so far. Sorry if its an easy question but I am not very good at rules so it would be helpful if you give me the steps here.

Thanks

ponies’s picture

@muhammad.tanweer: Importing these did the trick for me.

{ "rules_commerce_shipping_jump_forward_shipping" : {
    "LABEL" : "(Commerce Shipping) Jump forward over shipping step",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "commerce_physical", "commerce_order", "entity" ],
    "ON" : [ "commerce_order_update" ],
    "IF" : [
      { "data_is" : { "data" : [ "commerce-order:status" ], "value" : "checkout_shipping" } },
      { "NOT OR" : [
          { "data_is" : {
              "data" : [ "commerce-order-unchanged:status" ],
              "value" : "checkout_shipping"
            }
          },
          { "data_is" : {
              "data" : [ "commerce-order-unchanged:status" ],
              "value" : "checkout_review"
            }
          }
        ]
      },
      { "NOT commerce_physical_rules_order_is_shippable" : { "commerce_order" : [ "commerce_order" ] } }
    ],
    "DO" : [
      { "commerce_order_update_status" : {
          "commerce_order" : [ "commerce-order" ],
          "order_status" : "checkout_review"
        }
      },
      { "redirect" : { "url" : "checkout\/[commerce-order:order-id]\/review", "force" : 0 } }
    ]
  }
}
{ "rules_commerce_shipping_jump_backward_shipping" : {
    "LABEL" : "(Commerce Shipping) Jump backward over shipping step",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "commerce_physical", "commerce_order", "entity" ],
    "ON" : [ "commerce_order_update" ],
    "IF" : [
      { "data_is" : { "data" : [ "commerce-order:status" ], "value" : "checkout_shipping" } },
      { "data_is" : {
          "data" : [ "commerce-order-unchanged:status" ],
          "value" : "checkout_review"
        }
      },
      { "NOT commerce_physical_rules_order_is_shippable" : { "commerce_order" : [ "commerce_order" ] } }
    ],
    "DO" : [
      { "commerce_order_update_status" : {
          "commerce_order" : [ "commerce_order" ],
          "order_status" : "checkout_checkout"
        }
      },
      { "redirect" : { "url" : "checkout\/[commerce-order:order-id]", "force" : 0 } }
    ]
  }
}
muhammad.tanweer’s picture

Ponies,

GREAT. That worked. It really was a pain as I spent a lot of time on it. Thanks a million.

Muhammad.

torgospizza’s picture

Is it possible we could get the patched version of the module, along with the code/rules posted above, into the proper version of Commerce Shipping? It seems like this is critical, vital functionality to hybrid stores that sell both physical and digital products.

anicode’s picture

Thanks DuaelFr for the patch. Although the jump happens , the shipping info on the review pane still remains. is there a way to hide this. Also the progress block has the shipping tab on it.

Any ideas to hide these so that the user does not get confused.

duaelfr’s picture

I did not found any solution the last time I tried to properly hide all the shipping stuff, sorry...

brephraim’s picture

I'm still looking into disabling the shipping page so it won't show on the checkout progress bar, but as far as the review page goes, this code should take care of it:


/**
* Disable shipping pane if there are no shippable items in the current order.
*/

function mycustommodule_commerce_checkout_pane_info_alter(&$checkout_pane) {

	global $user;
	$order = commerce_cart_order_load($user->uid);

	if(!empty($order)) {
	$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
	$weight = commerce_physical_order_weight($order, 'lb');

		if(is_null($weight) === true) {
		$checkout_pane['customer_profile_shipping']['enabled'] = FALSE;
		}
	}
}

brephraim’s picture

Got the shipping page disabled on the progress bar.

First, you need the patch here http://drupal.org/node/1508472#comment-5806364, but before applying, make the correction noted here http://drupal.org/node/1508472#comment-6645716. (I actually don't know if that patch still applies correctly, I changed the code manually, it's only a few lines.)

Then you can add the following function to your custom module:

function mymodule_commerce_checkout_progress_get_items_alter(&$pages) {

	global $user;
	$order = commerce_cart_order_load($user->uid);
	if(!empty($order)) {
		$weight = commerce_physical_order_weight($order, 'lb');
		if(is_null($weight) === true) {
				foreach (array_keys($pages) as $page_id) {
					if($page_id === 'shipping') {
					$pages[$page_id]['has_item'] = NULL;
					}
				}	
		}
	}
}
shaneonabike’s picture

Component: Documentation » Code

I agree these rules are pretty great... I also was not able to use the module as is and had to manually upload them using the import feature :)

Kudos for posting that!

shaneonabike’s picture

Also I found this code in how to enable/disable panels which I will use for Shipping I hope it aids others - http://digital54.com/drupal-commerce/dependent-shipping

torgospizza’s picture

Cross-posting between this and #1759488: Need To Bypass Shipping Page If No Shippable Products On The Order:

I believe the Commerce Rules Extra module may also hold some value to those of us (like myself) who are looking to disable or hide shipping panes when only non-shippable products are ordered.

torgospizza’s picture

An update: the solutions in #41 and $42, as well as the Commerce Rules Extra module, rely on disabling the Shipping pane(s). Unfortunately this is a global value, and affects the pane's status in the Administration section as well. Therefore I don't think these are workable solutions, at least yet. There is a thread at #1122386: Allow rules to control which panes are visible during checkout that discusses some of these problems, and it seems the root of the solution will be a deeper Commerce fix which allows Rules to adjust the visibility of a pane, not actually disabling it.

EDIT: Upon closer inspection, #41 and #42 seem better than the Commerce Rules Extra module, as the module updates global variable values, as opposed to the above solutions which use alter() hooks to update the pane for a particular order.

headbank’s picture

Hi, this thread has helped me greatly with implementing a shop with mixed shippable/non-shippable items. Thanks to those involved.

(EDITED to remove a non-applicable support query.)

deggertsen’s picture

To simplify the instructions given in this thread, I have compiled them all in this post. Following these instructions should get it so that when non-shippable products (products without width or dimensions) are the only thing in your cart, it will hide the shipping options including on the checkout progress bar if you are using https://drupal.org/project/commerce_checkout_progress.

First, you need the patch here https://drupal.org/node/1508472#comment-7640851. Applies against the latest dev as of July 12 2013.

Then you need to insert the following code into a custom module (replacing "mymodule" with the name of your custom module):

<?php
/**
* Disable shipping pane if there are no shippable items in the current order.
*/

function mymodule_commerce_checkout_pane_info_alter(&$checkout_pane) {

    global $user;
    $order = commerce_cart_order_load($user->uid);

    if(!empty($order)) {
    $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
    $weight = commerce_physical_order_weight($order, 'lb');

        if(is_null($weight) === true) {
        $checkout_pane['customer_profile_shipping']['enabled'] = FALSE;
        }
    }
}

function mymodule_commerce_checkout_progress_get_items_alter(&$pages) {

    global $user;
    $order = commerce_cart_order_load($user->uid);
    if(!empty($order)) {
        $weight = commerce_physical_order_weight($order, 'lb');
        if(is_null($weight) === true) {
                foreach (array_keys($pages) as $page_id) {
                    if($page_id === 'shipping') {
                    $pages[$page_id]['has_item'] = NULL;
                    }
                }    
        }
    }
}
?>

Thanks @brephraim!

Apply the latest patch here: #1344962: Add some helpful rules conditions

Then make sure you have rules setup similar to these, or simply import these rules. Based on the module posted in #27.

{ "rules_commerce_shipping_jump_forward_shipping" : {
    "LABEL" : "(Commerce Shipping) Jump forward over shipping step",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "commerce_physical", "commerce_order", "entity" ],
    "ON" : [ "commerce_order_update" ],
    "IF" : [
      { "data_is" : { "data" : [ "commerce-order:status" ], "value" : "checkout_shipping" } },
      { "NOT OR" : [
          { "data_is" : {
              "data" : [ "commerce-order-unchanged:status" ],
              "value" : "checkout_shipping"
            }
          },
          { "data_is" : {
              "data" : [ "commerce-order-unchanged:status" ],
              "value" : "checkout_review"
            }
          }
        ]
      },
      { "NOT commerce_physical_rules_order_is_shippable" : { "commerce_order" : [ "commerce_order" ] } }
    ],
    "DO" : [
      { "commerce_order_update_status" : {
          "commerce_order" : [ "commerce-order" ],
          "order_status" : "checkout_review"
        }
      },
      { "redirect" : { "url" : "checkout\/[commerce-order:order-id]\/review", "force" : 0 } }
    ]
  }
}
{ "rules_commerce_shipping_jump_backward_shipping" : {
    "LABEL" : "(Commerce Shipping) Jump backward over shipping step",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "commerce_physical", "commerce_order", "entity" ],
    "ON" : [ "commerce_order_update" ],
    "IF" : [
      { "data_is" : { "data" : [ "commerce-order:status" ], "value" : "checkout_shipping" } },
      { "data_is" : {
          "data" : [ "commerce-order-unchanged:status" ],
          "value" : "checkout_review"
        }
      },
      { "NOT commerce_physical_rules_order_is_shippable" : { "commerce_order" : [ "commerce_order" ] } }
    ],
    "DO" : [
      { "commerce_order_update_status" : {
          "commerce_order" : [ "commerce_order" ],
          "order_status" : "checkout_checkout"
        }
      },
      { "redirect" : { "url" : "checkout\/[commerce-order:order-id]", "force" : 0 } }
    ]
  }
}

Thanks for everyone in this thread! It would be nice to not have to use a custom module but to instead have a patch written to include all of this, but for now this works...

rbrownell’s picture

How did you configure a rule to hide a Shipping Service? I keep Googleing this to try to figure it out but all I keep seeing is this issue.

EDIT: It appears that the only way to disable or hide a Shipping Service is via the initial rules that makes the shipping service. I used the Conditional Rules module to create elaborate rules that would then feed into the Conditions of a Shipping Service component rule. As challenging as it was, I would have to say the amount I've learned about rules in the past few days is invaluable. To any people who are trying to do complex shipping rules, keep at it and check out the module I mentioned. There are also a few tutorials out there on how to do specific things, make sure that you pay attention as opposed to blindly following the instructions because you will learn lot.

heddn’s picture

See #1461726: Notice Errors on commerce_checkout_commerce_order_status_info add sane defaults

I've implemented using using hook_commerce_checkout_router(). This removes the shipping option from the navigation.

function example_commerce_checkout_router($order, $checkout_page) {
  $wrapper = entity_metadata_wrapper('commerce_order', $order->order_number);
  $shipable = FALSE;
  foreach ($wrapper->commerce_line_items as $line_item) {
    // Retrieve the product type to see if its a type that allows shipping. If at least one item requires shipping,
    // then the order is considered shipable.
    $product_type = $line_item->commerce_product->field_product_type->value()->name;
    if ($product_type != 'DG') {
      $shipable = TRUE;
      break;
    }
  }
  if (!$shipable) {
      // Support going backwards & forwards in the cart.
      if (t('Customer continued to the next checkout page via a submit button.') == $order->log) {
        $order = commerce_order_status_update($order, 'checkout_' . $checkout_page['next_page'], FALSE, TRUE, t('Shipping was skipped - not required for these products.'));
        drupal_goto('checkout/' . $order->order_id . '/' . $checkout_page['next_page']);
      }
      else {
        $order = commerce_order_status_update($order, 'checkout_checkout', FALSE, TRUE, t('Shipping was skipped - not required for these products.'));
        drupal_goto('checkout/' . $order->order_id . '/checkout');
      }
    }
}
heddn’s picture

This picks up the shipping address pane as well. I've refactored the common code:

function example_commerce_checkout_router($order, $checkout_page) {
  if ($checkout_page['page_id'] == 'shipping') {
    if (!example_is_shipable($order->order_number)) {
      // Support going backwards & forwards in the cart.
      if (t('Customer continued to the next checkout page via a submit button.') == $order->log) {
        $order = commerce_order_status_update($order, 'checkout_' . $checkout_page['next_page'], FALSE, TRUE, t('Shipping was skipped - not required for these products.'));
        drupal_goto('checkout/' . $order->order_id . '/' . $checkout_page['next_page']);
      }
      else {
        $order = commerce_order_status_update($order, 'checkout_checkout', FALSE, TRUE, t('Shipping was skipped - not required for these products.'));
        drupal_goto('checkout/' . $order->order_id . '/checkout');
      }
    }
  }
}

function example_commerce_checkout_pane_info_alter(&$checkout_panes) {
  global $user;
  
  $order = commerce_cart_order_load($user->uid);
  if ($order) {
    if (!example_is_shipable($order->order_number)) {
      unset($checkout_panes['customer_profile_shipping']);
    }
  }
}

function example_is_shipable($order_number) {
  $shipable = FALSE;
  
  $wrapper = entity_metadata_wrapper('commerce_order', $order_number);
  foreach ($wrapper->commerce_line_items as $line_item) {
    // Retrieve the product type to see if its a type that allows shipping. If at least one item requires shipping,
    // then the order is considered shipable.
    $product_type = $line_item->commerce_product->field_product_type->value()->name;
    if ($product_type != 'DG') {
      $shipable = TRUE;
      break;
    }
  }
  
  return $shipable;
}
apmsooner’s picture

This can be done pretty easily with commerce_rules_extra module. I just created a taxonomy called "product attributes" and added a term called "Shippable". I assigned that tag to all products that were shippable and then created a rule to check for that tag.

{ "rules_disable_shipping_panes" : {
    "LABEL" : "Disable Shipping Panes",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "commerce_rules_extra" ],
    "ON" : { "process_checkout_pane" : [  ] },
    "IF" : [
      { "commerce_rules_extra_compare_termed_product_quantity" : {
          "order" : [ "commerce-order" ],
          "field_name" : "field_product_attributes",
          "term_id" : "15",
          "operator" : "\u003C",
          "value" : "1"
        }
      }
    ],
    "DO" : [
      { "commerce_rules_extra_change_pane" : {
          "pane_id" : "customer_profile_shipping",
          "page_id" : "\u003Csame\u003E",
          "enabled" : 0
        }
      },
      { "commerce_rules_extra_change_pane" : { "pane_id" : "commerce_shipping", "page_id" : "review", "enabled" : 0 } }
    ]
  }
}
snaderi’s picture

hello friends!I have problem with this modules!
thats disable allways my shipping pane!
when wieght is 0 or empty shipping disable and when wieght is 10kg shippable pane are disable!please help me!?tanks!

apmsooner’s picture

@snaderi, why not try my solution in #52? I have it working in production environment for several months now... I even provided you the sample rule to modify for your own environment.

snaderi’s picture

tanks for your reply but when import #52'rules recive this error:
Integrity check for the imported configuration failed. Error message: Data selector <em class="placeholder">commerce-order</em> for parameter <em class="placeholder">order</em> is invalid..
please help me!

apmsooner’s picture

It's looking for a term id that doesn't exist on your environment. Just change that in the rule to a term id that does exist and it should be fine.

snaderi’s picture

how I can find term id!?
'vid' in "vocabulary taxonomy" table in my database are equal 11!I modify that but again I receive that error!

snaderi’s picture

wow!!tanks very much for your help!thats work by update Rules!!

snaderi’s picture

+1 for #52

MD3’s picture

Issue summary: View changes

Thanks for @apmsooner for getting me on the right track! Using Commerce Rules Extra is the way to go!

When I tried to import your rule it gave me an SQL integrity error, so I created the rule from scratch. Another way to do this for those of you facing a similar situation is to look at the type of products in the cart. If you have giftcard products, here's a rule to get you started:

{ "rules_disable_shipping_panes" : {
    "LABEL" : "Disable Shipping Panes",
    "PLUGIN" : "reaction rule",
    "TAGS" : [ "Commerce Checkout", "Commerce Giftcard", "Shipping" ],
    "REQUIRES" : [ "commerce_order", "commerce_rules_extra" ],
    "ON" : [ "process_checkout_pane" ],
    "IF" : [
      { "AND" : [
          { "commerce_order_contains_product_type" : {
              "commerce_order" : [ "commerce_order" ],
              "product_type" : { "value" : { "giftcard" : "giftcard" } },
              "operator" : "\u003E=",
              "value" : "1"
            }
          },
          { "commerce_rules_extra_compare_total_product_type_quantity" : {
              "commerce_order" : [ "commerce_order" ],
              "product_type" : "giftcard",
              "exclude" : 1,
              "operator" : "=",
              "value" : "0"
            }
          }
        ]
      }
    ],
    "DO" : [
      { "commerce_rules_extra_change_pane" : {
          "pane_id" : "customer_profile_shipping",
          "page_id" : "\u003Csame\u003E",
          "enabled" : 0
        }
      },
      { "commerce_rules_extra_change_pane" : { "pane_id" : "commerce_shipping", "page_id" : "review", "enabled" : 0 } }
    ]
  }
}

If the rule fails or you have another type of non-shippable product, create a new rule using the following steps:

  1. Create a new rule (/admin/config/workflow/rules)
  2. React on Event: Commerce Checkout -> Commerce checkout pane
  3. In Conditions: Add Condition: Commerce Order -> Order contains products of particular product types. Select the type of non-shippable products
  4. For each type of non-shippable product: Add Condition: Commerce Order -> Total product of type quantity comparison. Select the type of non-shippable product. Exclude: Check (true). Operator: =. Quantity: 0.
  5. In Conditions: Add and.
  6. Drag all of the above conditions under the And
  7. In Actions: For each pane you need to disable (Shipping Information and Shipping Service by default): Add Action: Commerce Checkout->Change pane properties. Value: Pane to be changed. Page to move to: <do not change>. Enabled: Unchecked (false).
  8. For the last pane in the Shipping Step (usually Shipping Service) set Page to move to: Review order.
  9. Test test test!!
ryanfc78’s picture

I am getting the following error on the Checkout page when I try #60

Warning: trim() expects parameter 1 to be string, array given in commerce_rules_extra_compare_product() (line 80 of /home/evansvil/public_html/madeinevansville.com/sites/all/modules/commerce_rules_extra/includes/conditions/commerce_rules_extra_compare_product_quantity.inc).
Warning: trim() expects parameter 1 to be string, array given in commerce_rules_extra_compare_product() (line 80 of /home/evansvil/public_html/madeinevansville.com/sites/all/modules/commerce_rules_extra/includes/conditions/commerce_rules_extra_compare_product_quantity.inc).

What am I doing wrong?
Rule:

{ "rules_disable_shipping_panes" : {
    "LABEL" : "Disable Shipping Panes",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "commerce_order", "commerce_rules_extra" ],
    "ON" : { "commerce_rules_extra_process_checkout_pane" : [] },
    "IF" : [
      { "AND" : [
          { "commerce_order_contains_product_type" : {
              "commerce_order" : [ "commerce_order" ],
              "product_type" : { "value" : { "t_shirt" : "t_shirt" } },
              "operator" : "\u003E=",
              "value" : "1"
            }
          },
          { "commerce_rules_extra_compare_product_quantity" : {
              "order" : [ "commerce-order" ],
              "product_type" : { "value" : { "t_shirt" : "t_shirt" } },
              "exclude" : 1,
              "operator" : "=",
              "value" : "0",
              "term_id" : { "value" : [] },
              "product_display" : 0,
              "term_operator" : "IOO"
            }
          }
        ]
      }
    ],
    "DO" : [
      { "commerce_rules_extra_change_pane" : {
          "pane_id" : "customer_profile_shipping",
          "page_id" : "\u003Csame\u003E",
          "enabled" : 0
        }
      },
      { "commerce_rules_extra_change_pane" : { "pane_id" : "commerce_shipping", "page_id" : "review", "enabled" : 0 } }
    ]
  }
}
pwsherman’s picture

ryanfc78 did you figure it out? The AND goes inbetween the first two conditions.

#60 Works great! Thanks MD3!

mr.andrey’s picture

Issue summary: View changes
mr.andrey’s picture

Issue summary: View changes
mr.andrey’s picture

Besides disabling shipping pane, I also wanted to skip the shipping page. Here are the rules to do that.

"membership_shippable" is the shippable product, all others are not. Change this to whatever you need in both rules.

Commerce 7.x-1.10
Commerce Rules Extra 7.x-2.1-beta4
PHP Input enabled

DISABLE SHIPPING PANE RULE:

{ "rules_shipping_pane_disable" : {
    "LABEL" : "Disable Shipping Pane",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "commerce_order", "commerce_rules_extra" ],
    "ON" : { "commerce_rules_extra_process_checkout_pane" : [] },
    "IF" : [
      { "NOT commerce_order_contains_product_type" : {
          "commerce_order" : [ "commerce_order" ],
          "product_type" : { "value" : { "membership_shippable" : "membership_shippable" } },
          "operator" : "\u003E=",
          "value" : "1"
        }
      }
    ],
    "DO" : [
      { "commerce_rules_extra_change_pane" : {
          "pane_id" : "customer_profile_shipping",
          "page_id" : "\u003Csame\u003E",
          "enabled" : 0
        }
      }
    ]
  }
}

DISABLE SHIPPING PAGE RULE:

{ "rules_shipping_page_disable" : {
    "LABEL" : "Disable Shipping Page",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "commerce_order", "php", "rules", "commerce_rules_extra" ],
    "ON" : { "commerce_rules_extra_process_checkout_pane" : [] },
    "IF" : [
      { "NOT commerce_order_contains_product_type" : {
          "commerce_order" : [ "site:current-cart-order" ],
          "product_type" : { "value" : { "membership_shippable" : "membership_shippable" } },
          "operator" : "\u003E=",
          "value" : "1"
        }
      },
      { "php_eval" : { "code" : "return preg_match(\u0027\/checkout.+shipping\/\u0027, current_path());" } }
    ],
    "DO" : [
      { "component_rules_order_status_checkout_review" : { "order" : [ "commerce-order" ] } },
      { "php_eval" : { "code" : "$new_path = str_replace(\u0027shipping\u0027, \u0027review\u0027, current_path());\r\nif (current_path() != $new_path) {\r\n  drupal_goto($new_path);\r\n}" } }
    ]
  }
}

Cheers,
Andrey.

donbon’s picture

Hi Andrey, thanks so much for sharing your code, it has been very helpful. I just had one question for the Disabling shipping page rule, where does the component "component_rules_order_status_checkout_review" come from? I don't seem to have that one. Is that a custom one you made, or is it from a module? Thanks again for posting your code, I'm currently using the checkout pane and it works perfectly! :)

mr.andrey’s picture

Hi Mattbus,

I'm not sure about that one. Here's a list of all the commerce modules I have installed:

commerce
commerce_add_to_cart_confirmation
commerce_addressbook
commerce_authnet
commerce_backoffice
commerce_cardonfile
commerce_checkout_progress
commerce_checkout_redirect
commerce_custom_product
commerce_discount
commerce_flat_rate
commerce_license
commerce_message
commerce_recurring
commerce_rules_extra
commerce_shipping
commerce_stripe
commerce_subscription
commerce_webform

I hope this helps.

Andrey.

mr.andrey’s picture

I ended up consolidating all the billing and shipping info onto the checkout page, so there's less clicking. The shipping page gets disabled automatically once it has no panes.

This is the rule I'm using to disable both the Shipping Info and Shipping Services on orders with no shippable products:

{ "rules_shipping_pane_disable" : {
    "LABEL" : "Disable Shipping Panes",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "commerce_order", "commerce_rules_extra" ],
    "ON" : { "commerce_rules_extra_process_checkout_pane" : [] },
    "IF" : [
      { "NOT commerce_order_contains_product_type" : {
          "commerce_order" : [ "commerce_order" ],
          "product_type" : { "value" : { "membership_shippable" : "membership_shippable" } },
          "operator" : "\u003E=",
          "value" : "1"
        }
      }
    ],
    "DO" : [
      { "commerce_rules_extra_change_pane" : {
          "pane_id" : "customer_profile_shipping",
          "page_id" : "\u003Csame\u003E",
          "enabled" : 0
        }
      },
      { "commerce_rules_extra_change_pane" : {
          "pane_id" : "commerce_shipping",
          "page_id" : "\u003Csame\u003E",
          "enabled" : 0
        }
      }
    ]
  }
}

Cheers,
Andrey.

googletorp’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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