I am had the following weird situation, and I believe I have to post it here to hear your thought. It seems to be a bug, and as far as I can tell checking existing custom code it is not related to my custom behavior but something core related.

How the problem has been identified
Hey! It seems that there are two products within the same order with the same SKU, that should be merged, but still they are shown in two different rows.

How debugging info is given
Because products are added through AJAX, and in order to identify what happens, I have put here there watchdog requests that printed the status of the order. For this problem, I was printing (print_r) the current order just *before* and immediately *after* the "add to cart request.

Debugging info
00:10 User adds something in the cart (Product 1). Before add to cart: Cart is empty
00:10 User adds something in the cart (Product 1). After add to cart: Order ID 15821 Line item IDs 159808

00:23 User registers and logins
00:25 User logs out

00:26 User adds something in the cart (Product 1). Before add to cart: Cart is empty
00:26 User adds something in the cart (Product 1). After add to cart: Order ID 15822 Line item IDs 159809

00:31 User adds something in the cart (Product 2). Before add to cart: Order ID 15822 Line item IDs 159809
00:31 User adds something in the cart (Product 2). After add to cart: Order ID 15822 Line item IDs 159809, 159810

00:33 User adds something in the cart (Product 3). Before add to cart: Order ID 15822 Line item IDs 159809, 159810
00:33 User adds something in the cart (Product 3). After add to cart: Order ID 15822 Line item IDs 159809, 159810, 159811

00:33 User adds something in the cart (Product 4). Before add to cart: Order ID 15822 Line item IDs 159809, 159810, 159811
00:33 User adds something in the cart (Product 4). After add to cart: Order ID 15822 Line item IDs 159809, 159810, 159811, 159812

00:35 User adds something in the cart (Product 5). Before add to cart: Order ID 15822 Line item IDs 159809, 159810, 159811, 159812
00:35 User adds something in the cart (Product 5). After add to cart: Order ID 15822 Line item IDs 159809, 159810, 159811, 159812, 159813

00:40 User adds something in the cart (Product 6). Before add to cart: Order ID 15822 Line item IDs 159809, 159810, 159811, 159812, 159813
00:40 User adds something in the cart (Product 6). After add to cart: Order ID 15822 Line item IDs 159809, 159810, 159811, 159812, 159813, 159814

00:48 User checks out

Viewing the above log, somebody would assume that this user has bought 6 different products.
However, currently we have the following situation.

Order 15821 does not exist ( /admin/commerce/orders/15821 ), and gives error not found
Order 15822 exists with 7 line items, 6 different products. Line IDs are 159808, 159809, 159810, 159811, 159812, 159813, 159814

Line items 159808 and 159809 refer to the same SKU product. Please note that Line item 159808 was initially created in order 15821 but eventually showed up in order 15822.

Any thoughts are welcome!

Comments

xaris.tsimpouris’s picture

Issue summary: View changes
rszrama’s picture

Category: Bug report » Support request
Status: Active » Closed (cannot reproduce)

I'm sorry, this is not core behavior, so you must have some module or Rules configuration working to combine line items into a single order this way. I don't know of any off the top of my head that do that, so you'll have to just research that in your own configuration. Sorry I can't be more help.

vishal.sirsodiya’s picture

Hi
I am facing same problem

anybody please help me ...

vishal.sirsodiya’s picture

Status: Closed (cannot reproduce) » Active
rszrama’s picture

Status: Active » Closed (cannot reproduce)

My comment in #2 still applies.

vishal.sirsodiya’s picture

I have solved this, by custom code.
First you create a login handler like.

function custom_module_form_alter(&$form, $form_state, $form_id) {
    
    if($form_id == 'commerce_checkout_form_checkout'){
        $form['buttons']['continue']['#submit'][2] = 'paypal_check_handler';
    }
}

function paypal_check_handler(&$form, $form_state){
    
    $order_number = $form_state['order']->order_number;
    $return = _get_current_stock($order_number);
    
    if($return['status']=='goto_paypal'){
      
     }else{   
       db_query("UPDATE commerce_order SET status = 'cart' where order_id='$order_number'");
       drupal_set_message("We are sorry - Following items are no longer available in stock after you added them in shopping cart. <br/>".'&ldquo; '.$return['product_name'].' &rdquo;');
       drupal_goto('cart');
    }
}

/**
 * This function check current stock.
 */
function _get_current_stock($order_id) {

    global $user;
    $order = commerce_cart_order_load($user->uid); // get user order details
    // get all product id of current order
    $results = db_query("SELECT cp.product_id AS product_id, cli.quantity AS order_qty,fcs.commerce_stock_value AS stock_qty FROM commerce_line_item AS cli LEFT JOIN commerce_product AS cp ON cli.line_item_label=cp.sku LEFT JOIN field_data_commerce_stock AS fcs ON cp.product_id=fcs.entity_id WHERE cli.order_id='$order_id' AND cli.type IN ('product','commerce_auction_lineitem') ")->fetchAll();
    $product_ids = $qty = $stock_qty = array();
    /*
     * @var $product_ids            : Product ID array.
     * @var $qty[$product_ids]      : get each Product order quantity.
     * @var $stock_qty[$product_ids]: get each Product stock quantity.
     */
    foreach($results As $value){
        if(!empty($value->product_id)){
            $product_ids[] = $value->product_id;
            $qty[$value->product_id] = (int)$value->order_qty;
            $stock_qty[$value->product_id] = (int)$value->stock_qty;
        }
    }
    // product id array convert in string forn sql.
    $product_ids_query = implode($product_ids, ',');
    /*
     * Here get product remaining stock
     * @stock   : Stock
     * @order   : Order qty in order table ( status is checkout_payment).
     * @avail   : available qty
     * @stock - @order = @avail
     */
    $results2 = db_query("SELECT cp.title AS product_name, cli.line_item_label AS line_item, cp.product_id AS product_id,cli.quantity AS order_qty, FORMAT(SUM(cli.quantity),0) total_order_qty,  FORMAT(fcs.commerce_stock_value,0) AS total_stock_qty, FORMAT((fcs.commerce_stock_value - SUM(cli.quantity)),0) As available_qty FROM commerce_line_item AS cli LEFT JOIN commerce_product AS cp ON cli.line_item_label=cp.sku LEFT JOIN field_data_commerce_stock AS fcs ON cp.product_id=fcs.entity_id LEFT JOIN commerce_order AS co ON co.order_id=cli.order_id WHERE co.`status`='checkout_payment' AND fcs.commerce_stock_value!=0 AND cp.product_id IN ($product_ids_query) GROUP BY cp.product_id")->fetchAll();
    $available_qty = array();
    foreach($results2 As $value2){
        $available_qty[$value2->product_id] = $value2->available_qty;
        $available_product_name[$value2->product_id] = $value2->product_name;
        
    }
    $redirection_var = array();
    $redirection_var['status'] = 'goto_paypal';
    foreach($product_ids AS $product_chk){
        if(!empty($available_qty[$product_chk])){
            $current_stock_qty = (int)$available_qty[$product_chk]; 
        } else {
            $current_stock_qty = (int)$stock_qty[$product_chk];
        }

        $ordered_qty = $qty[$product_chk];
        if($current_stock_qty > 0){
            // go to paypal
             $redirection_var;
        } else {
            $current_product_name = $available_product_name[$product_chk];
            $redirection_var['product_name'] = $current_product_name;
            $redirection_var['status'] = 'not_goto_paypal';
            return $redirection_var;
        }
    }
    return $redirection_var;
}

Thankyou :)