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

Dynamically enabling checkout panes based on cart contents?

I am working on a service booking website and below is a customer scenario:

i) A customer arrives at the site, views the various services and clicks the "make a booking link" for a particular service.

ii) They are redirected, a view of all available services of that type (product with time/date field & service_type_id) is then generated.

iii) The customer selects the timeslot suited and clicks on a "Book now" button (overidden "Add to Cart"), the Review page is skipped and they are redirected to the checkout page

On the checkout page I am trying to dynamically add suggested services that compliment their current selection. The problem I am having is how to dynamically add this checkout pane?

Currently I am using rules to detect what service has been added to cart, using entity has the field (service_type_id) & a data comparison to allow me to know what added service type I should suggest.

What is the best way to go about dynamically adding panes based on the contents of the cart?

I have tried using commerce extra panes & think I will have to write series of rules that enable/disable checkout panes based on the carts contents.

I am wondering if there is a simpler way to get the functionality I am looking for?

Any thoughts/help appreciated.

Asked by: bobondrupal
on June 10, 2012

2 Answers

Vote up!
2
Vote down!

What I have done in the past is just do some custom validation in code based on the current order and when I see that the order has the values that I need I than unset the checkout pane like so:

<?php
function hook_commerce_checkout_pane_info_alter(&$checkout_pane) {
    foreach (
$checkout_pane as $pane_name => & $pane_data) {
        if (
$pane_name == 'customer_profile_shipping') {
           
$order = commerce_cart_order_load($user->uid);
            if (!empty(
$order->data)) {
                    unset(
$checkout_pane['customer_profile_shipping']);
}}}}
?>
Answer by: dannymacom
Posted: Jun 17, 2012
Vote up!
0
Vote down!

Could that be modified like thjis:

<?php
function hook_commerce_checkout_pane_info_alter(&$checkout_pane) {
    foreach (
$checkout_pane as $pane_name => & $pane_data) {
        if (
$pane_name == 'customer_profile_shipping') {
           
$order = commerce_cart_order_load($user->uid);
            if (
$user->uid > 0) {
                    unset(
$checkout_pane['commerce_p2cp_profile']);
}}}}
?>

I would like to hide a profile2 pane only for registered users.

How may I transform that into a rule?

Thanks for your help!

Answer by: Rosamunda
Posted: Apr 29, 2013