1

注文が複数ある場合は、注文からいくつかのアイテムを削除して、注文を更新する必要があります。その後、注文を更新する必要があります。

今、私はテーブルを見つけました:すべての注文アイテムがあるsales_flat_order_item。

$items = $order->getAllItems();

    foreach($items as $item){

        if($item->getParentItemId() == '' || $item->getParentItemId() == null){

            $product_id = $item->getProductId();
            if($product_id == $booking_product_id){             

                         // this item have to be deleted

            }

        }

    }

$order->save();

助言がありますか ?

4

2 に答える 2

3

この方法で成功しました。

    $base_grand_total = $order->getBaseGrandTotal();
    $base_subtotal = $order->getBaseSubtotal();
    $grand_total = $order->getGrandTotal();
    $subtotal = $order->getSubtotal();

    $base_subtotal_incl_tax = $order->getBaseSubtotalInclTax();
    $subtotal_incl_tax = $order->getSubtotalInclTax();
    $total_item_count = $order->getTotalItemCount();

    $items = $order->getAllItems(); 
    foreach($items as $item){       

        if($item->getParentItemId() == '' || $item->getParentItemId() == null){

            $product_id = $item->getProductId();
            if($product_id == $booking_product_id){             

            //remove item price from total price of order
            $item_price = $item->getPrice();
            $item->delete();

            $order->setBaseGrandTotal($base_grand_total-$item_price);
            $order->setBaseSubtotal($base_subtotal-$item_price);
                $order->setGrandTotal($grand_total-$item_price);
            $order->setSubtotal($subtotal-$item_price);

            $order->setBaseSubtotalInclTax($base_subtotal_incl_tax-$item_price);
            $order->setSubtotalInclTax($subtotal_incl_tax-$item_price);
            $order->setTotalItemCount($total_item_count-1);
            $order->save(); 
            }

        }

    }
于 2012-09-14T05:33:56.767 に答える