如何从一个Magento订单获得总运费


How to get grand total without shipping costs from a Magento order?

我正试图实现并从成功中获得一些从属计算。phtml页面。一切都很好,除了"bd",这应该是不含运费的总金额。我可能在"bd"代码中遗漏了一些东西。我是新的php代码。请帮助我解决这个问题!请查看截图

<?php
// Add this to the file in the following path: app/design/frontend/[package]/[theme]/template/checkout/success.phtml
$iProgramId = 9560; // Insert your Program ID here
// Add the matching domain here. 
$sMatchingDomain = 'https://dt51.net'; //For example: ds1.nl or dt51.net

// Retrieve order details and billing address
$oOrderDetails = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
$aBillingAddressData = $oOrderDetails->getBillingAddress();
$amount = $order->getGrandTotal() - $order->getShippingAmount();

foreach ($oOrderDetails->getAllItems() as $oItem) 
{
     break;
}
$aVariables = array(
    'si' => $iProgramId,
    'ti' => $this->getOrderId(),
    'oa' => substr($oItem->getName(), 0, 50),
    'om' => substr($oItem->getName(), 0, 50),
    'bd' => number_format($oOrderDetails->getGrandTotal - $oOrderDetails->getShippingAmount(), 2, '.', ''),
    'ln' => $aBillingAddressData['country_id'],
    'pc' => $aBillingAddressData['postcode'],
    'rv' => number_format($oOrderDetails->getGrandTotal(), 2, '.', ''),
    'e1' => $oOrderDetails->getPayment()->getMethodInstance()->getTitle(),
    'e2' => $oItem->getSku(),
    'e3' => round($oItem->getQtyOrdered(), 0)
);
$sUrl = "".$sMatchingDomain."/t/";
$sGlue = "?";
foreach ($aVariables as $sKey => $mValue)
{
    $sUrl .= $sGlue.$sKey."=".urlencode($mValue);
    $sGlue = "&";
} 
echo '<img src="'.$sUrl.'" style="border: 0px; height: 1px; width: 1px;" alt="Affiliate Marketing" />';
?>

您在下一行中犯了一个错误。getGrandTotal()

'bd' => number_format($oOrderDetails->getGrandTotal - $oOrderDetails->getShippingAmount(), 2, '.', '')

替换为

'bd' => number_format($oOrderDetails->getGrandTotal() - $oOrderDetails->getShippingAmount(), 2, '.', ''),