0

I am creating a new order, and line item (without a product, since this is just a fee we're collecting from the customer). The order is created, with line item, but when I go to /checkout/[order_id], I'm just redirected to the front page.

My code for the order creation is:

function mymod_form_submit($form, &$form_state) {
        global $user;
        $order = commerce_order_new($user->uid, 'checkout_checkout');
        commerce_order_save($order);
ddl($order);

        $line_item = commerce_line_item_new('app_fee_type', $order->order_id);
        $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);

        $line_item_wrapper->line_item_label = t('Application Fee');
        $line_item_wrapper->quantity = 1;
        $line_item_wrapper->commerce_unit_price->amount = 3500;
        $line_item_wrapper->commerce_unit_price->currency_code = 'USD';
        $line_item_wrapper->commerce_total->amount = 0;
        $line_item_wrapper->commerce_unit_price->data = commerce_price_component_add(
                $line_item_wrapper->commerce_unit_price->value(),
                'base_price',
                $line_item_wrapper->commerce_unit_price->value(),
                TRUE,
                FALSE
        );
        commerce_line_item_save($line_item);

ddl($line_item);


        $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
        $order_wrapper->commerce_line_items[] = $line_item;
        commerce_order_save($order);
ddl($order);
        commerce_order_status_update($order, 'checkout_payment');
        drupal_goto('checkout/' . $order->order_id);
}

The customer should just be taken to the checkout screen. What am I missing?

1

It looks like the order ID isn't being saved for the session. Add this:

$_SESSION['commerce_cart_orders'][] = $order->order_id;

Just make sure you do this before you save the final version of your order.

| improve this answer | |

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.