1

Is there a way to pre populate the Shopping cart with all products similar to this example? http://www.taytocrisps.ie/park/book_tickets

I only have 5 products on the site and I want to skip one step and add to all products to the cart. The user then selects the number of the products in the cart and goes straight to billing information and payment.

1
  • Little hint: if you could describe process you want (or the part of it that patters to you) instead of providing link, more people would be able to help. I'm not gonna to checkout on a page just to see what you mean. I doubt many will.
    – Mołot
    Commented Jun 17, 2013 at 6:20

1 Answer 1

1

I implemented a hook_menu with callback that adds specific product variation from the arguments to the cart and then redirects the user to cart. With same logic you could toss in all the products you wish. Mayby just additionally check that that cart is initially empty.

function x_menu(){
    $items['tickets'] = array(
      'page callback' => 'x_tickets_callback',
      'access arguments' => array('access content'),
    );
    return $items;
}

function x_tickets_callback(){
    global $user;

    // mayby check that cart is empty here

    // you should get these really from some variable
    for($i = 1, $i<7,$i++){
      $commerce_product = commerce_product_load($i);
      // create line item from product
      $line_item = commerce_product_line_item_new($commerce_product);
      commerce_cart_product_add($user->uid, $line_item);
    }
    // prevent notification
    $messages = drupal_get_messages();
    drupal_goto('cart');
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.