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

            }

        }

    }

$订单->保存();

有什么建议么 ?

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 回答
0

从现有订单中删除项目。

从 magento 根目录运行以下代码行作为外部代码:

  1. 将其保存为“order_item_remove.php”
  2. 以http://example.com/order_item_remove.php运行它

代码块如下:

<?php

require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app();

try{
$_order = Mage::getModel('sales/order')->loadByIncrementId('100000011'); // Order Increment Id
$items = $_order->getAllItems(); 

foreach ($items as $item){
    Mage::log('All items ' . print_r($item->getData(), true), null, 'items_data.log');
    $base_grand_total = $_order->getBaseGrandTotal();

    $base_subtotal = $_order->getBaseSubtotal();
    $base_tva = $_order->getBaseTaxAmount();

    $grand_total = $_order->getGrandTotal();

    $subtotal = $_order->getSubtotal();
    $tva = $_order->getTaxAmount();


    $base_subtotal_incl_tax = $_order->getBaseSubtotalInclTax();

    $subtotal_incl_tax = $_order->getSubtotalInclTax();

    $total_item_count = $_order->getTotalItemCount();
Mage::log('Items ' . $item->getSku(), null, 'items_data.log');


    if($item->getSku()=='SAMPLEKIT'){
        $item_price = $item->getPrice();
        $item_tva = $item->getTaxAmount();
        Mage::log('Item deleted ' . $item->getSku(), null, 'items_data.log');
        $item->delete();
        $_order->setBaseGrandTotal($base_grand_total-$item_price-$item_tva);

        $_order->setBaseSubtotal($base_subtotal-$item_price);

        $_order->setBaseTaxAmount($base_tva-$item_tva);

        $_order->setGrandTotal($grand_total-$item_price-$item_tva);

        $_order->setSubtotal($subtotal-$item_price);

        $_order->setTaxAmount($tva-$item_tva);


        $_order->setBaseSubtotalInclTax($base_subtotal_incl_tax-$item_price);

        $_order->setSubtotalInclTax($subtotal_incl_tax-$item_price);

        $_order->setTotalItemCount(count($items)-1);

        $_order->save(); 
    }

}
echo "success"; 
} catch(Exception $e) {
    echo "failed";
}
于 2016-07-15T07:41:36.223 回答