Tags/topics: 
2
Answers
Vote up!
0
Vote down!

Disable/Enable commerce panes with Execute custom PHP code in Rule Action

Hi All,

I am using Drupal Commerce 7.x-1.3 and Rules 7.x-2.1.

I have regular Product and custom line item types using 'commerce_custom_product' and 'commerce_fieldgroup_panes' and
depending on line item types I need to Disable/Enable 'Shipping information' and 'Order Fieldgroup' panes using Execute
custom PHP code in Rule Action.

Google gave me some links, for e.g.,:

http://drupal.org/node/1122386
http://drupal.org/node/1228342

But I could not make out how/which PHP code I could use in Execute custom PHP code to Disable/Enable the panes.

Any help will be much appreciated.

Thnaks,

Asked by: Prakash Gautam
on September 23, 2012

Comments

2 Answers

Vote up!
3
Vote down!

I have to write a module for this and coding is poor but it's working perfectly for me. Here's the code:

function disable_pane_commerce_checkout_pane_info_alter(&$checkout_pane) {

  global $user;
  $type_iExists = FALSE;
  $type_bExists = FALSE;
  $type_depoExists = FALSE;
  $order = commerce_cart_order_load($user->uid);
  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);          
                              
    $commerce_line_items = array();                                              
    foreach ($order_wrapper->commerce_line_items as $delta => $line_item_wrapper) {

  $line_item = $line_item_wrapper->value();
  $type = $line_item_wrapper->commerce_product->value()->type;

if(strpos($type,'boxes_and_dongles') !== false) {
$type_bExists = TRUE;
}
if(strpos($type,'iphone_') !== false)  {
  $type_iExists = TRUE;
        }
if(strpos($type,'deposit') !== false)  {
  $type_depoExists = TRUE;
        }
      }
if($type_bExists && !$type_iExists){
foreach ($checkout_pane as $pane_name => & $pane_data) {
unset($checkout_pane['commerce_fieldgroup_pane__group_imei_info__35']);
}
}

if(!$type_bExists && $type_iExists){
foreach ($checkout_pane as $pane_name => & $pane_data) {
//unset($checkout_pane['commerce_fieldgroup_pane__group_imei_info__35']);
unset($checkout_pane['customer_profile_shipping']);
unset($checkout_pane['commerce_shipping']);

}
}
if(!$type_bExists && !$type_iExists && $type_depoExists){
foreach ($checkout_pane as $pane_name => & $pane_data) {
unset($checkout_pane['commerce_fieldgroup_pane__group_imei_info__35']);
unset($checkout_pane['customer_profile_billing']);
unset($checkout_pane['customer_profile_shipping']);
unset($checkout_pane['commerce_shipping']);

}
}
}
Answer by: Prakash Gautam
Posted: Oct 14, 2012
Vote up!
0
Vote down!

I tried all various codes nut to no avail. Could someone tell me why following code is not working in Execute custom PHP code in Rule Action:

function hook_commerce_checkout_pane_info_alter(&$checkout_pane) {
foreach ($checkout_pane as $pane_name => & $pane_data) {
if ($pane_name == 'customer_profile_shipping') {
unset($checkout_pane['customer_profile_shipping']);
}}}
Answer by: Prakash Gautam
Posted: Sep 27, 2012