0

I am using Drupal commerce. For particular reasons, I found it necessary to programatically add items to the cart one the review page. The problem is: when I do this, I get redirected back to the checkout page, which I don't want. Here is my code:

foreach($registrants as $key=>$registrant) {  //for each additional registrant in the event order object  
          if($key == 0 && $memberStatus == "Member") { //the first additional registrant gets the member price free, if the applicant is a member
            //$line_item = commerce_product_line_item_new($product, $quantity);
            //$line_item = commerce_cart_product_add($event->product_id, $line_item, TRUE);
            commerce_cart_product_add_by_id($memberGuestId);
            $order = commerce_order_status_update($order, 'checkout_review', FALSE, TRUE, t('Additional registrants have been added to the cart'));
            drupal_goto('checkout/' . $order->order_id . '/review');
          }
          else {
            commerce_cart_product_add_by_id($nonMemberGuestId);
            $order = commerce_order_status_update($order, 'checkout_review', FALSE, TRUE, t('Additional registrants have been added to the cart'));
            drupal_goto('checkout/' . $order->order_id . '/review');
          }
        }  

I even tried forcing it back to the review page with a goto, and no luck. What is happening here?

  • 1
    Probably the Rule to "Redirect to cart" is causing the redirect, you'll have to modify or disable it. – David Thomas Jan 10 '14 at 0:48
  • I actually just found that myself, that was exactly the issue. Thanks. – user1015214 Jan 10 '14 at 17:49
0

I had this exact same problem with a very similar workflow. I created a workaround to this issue by integrating the commerce_cart_product_add($uid, $line_item) function from the Commerce Cart module into my custom module. This way I could test what was happening in Commerce without hacking the contrib module. From there I discovered that the issue stemmed from an invoked rule at the bottom of this function:

 rules_invoke_all('commerce_cart_product_add', $order, $product, $quantity, $line_item);

Removing this rule from my local version of this function solved the redirect issue. I looked through the Commerce Settings and the Rules UI in the Drupal admin to see if I could find this rule to disable it, but I could not find a reference to it anywhere. This is not the best solution, but for now it solves the redirect issue. I would be interested to hear if anyone else has run into a similar issue though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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