0

注文にカスタム割引を追加する必要があります。以下に示すように、オブザーバーを作成しました。

$shippingDiscountValue = 20;
$currentAddress = $quote->getShippingAddress();
$currentDiscount = (-1) * $currentAddress->getDiscountAmount();
$newDiscount = $currentDiscount + $shippingDiscountValue;
$quote->setGrandTotal($quote->getBaseSubtotal() - $shippingDiscountValue)
    ->setBaseGrandTotal($quote->getBaseSubtotal() - $shippingDiscountValue)
    ->setSubtotalWithDiscount($quote->getBaseSubtotal() - $shippingDiscountValue)
    ->setBaseSubtotalWithDiscount($quote->getBaseSubtotal() - $shippingDiscountValue)
    ->save();  

$currentAddress->setSubtotalWithDiscount((float) $currentAddress->getSubtotalWithDiscount() - $shippingDiscountValue);
$currentAddress->setGrandTotal((float) $currentAddress->getGrandTotal() - $shippingDiscountValue);
$currentAddress->setBaseSubtotalWithDiscount((float) $currentAddress->getBaseSubtotalWithDiscount() - $shippingDiscountValue);
$currentAddress->setBaseGrandTotal((float) $currentAddress->getBaseGrandTotal() - $shippingDiscountValue);        

$currentAddress->setBaseDiscountAmount($newDiscount * (-1));
$currentAddress->setDiscountAmount($newDiscount * (-1));

$currentAddress->save();
$quote->save();

カートの変更 (追加、削除、数量の更新) の後に、このオブザーバーを呼び出します。カートの詳細ではすべて問題ありません - 割引は正しく計算されますが、チェックアウト (および注文) では割引の基本額があり、$shippingDiscountValue.

4

0 に答える 0