本文整理汇总了PHP中Mage_Sales_Model_Order_Invoice::setCustomercreditDiscount方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Sales_Model_Order_Invoice::setCustomercreditDiscount方法的具体用法?PHP Mage_Sales_Model_Order_Invoice::setCustomercreditDiscount怎么用?PHP Mage_Sales_Model_Order_Invoice::setCustomercreditDiscount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Sales_Model_Order_Invoice
的用法示例。
在下文中一共展示了Mage_Sales_Model_Order_Invoice::setCustomercreditDiscount方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: collect
public function collect(Mage_Sales_Model_Order_Invoice $invoice)
{
$order = $invoice->getOrder();
if ($order->getCustomercreditDiscount() < 0.0001) {
return;
}
if ($invoice->isLast()) {
$baseDiscount = $order->getBaseCustomercreditDiscount();
$discount = $order->getCustomercreditDiscount();
foreach ($order->getInvoiceCollection() as $existedInvoice) {
if ($baseDiscount > 0.0001) {
$baseDiscount -= $existedInvoice->getBaseCustomercreditDiscount();
$discount -= $existedInvoice->getCustomercreditDiscount();
}
}
} else {
$orderData = $order->getData();
$invoiceData = $invoice->getData();
if ($invoiceData['shipping_incl_tax']) {
$ratio = ($invoiceData['subtotal_incl_tax'] + $invoiceData['shipping_incl_tax']) / ($orderData['subtotal_incl_tax'] + $orderData['shipping_incl_tax']);
} else {
$ratio = $invoiceData['subtotal_incl_tax'] / ($orderData['subtotal_incl_tax'] + $orderData['shipping_incl_tax']);
}
$baseDiscount = $order->getBaseCustomercreditDiscount() * $ratio;
$discount = $order->getCustomercreditDiscount() * $ratio;
$maxBaseDiscount = $order->getBaseCustomercreditDiscount();
$maxDiscount = $order->getCustomercreditDiscount();
foreach ($order->getInvoiceCollection() as $existedInvoice) {
if ($maxBaseDiscount > 0.0001) {
$maxBaseDiscount -= $existedInvoice->getBaseCustomercreditDiscount();
$maxDiscount -= $existedInvoice->getCustomercreditDiscount();
}
}
if ($baseDiscount > $maxBaseDiscount) {
$baseDiscount = $maxBaseDiscount;
$discount = $maxDiscount;
}
}
if ($baseDiscount > 0.0001) {
if ($invoice->getBaseGrandTotal() <= $baseDiscount) {
$invoice->setBaseCustomercreditDiscount($invoice->getBaseGrandTotal());
$invoice->setCustomercreditDiscount($invoice->getGrandTotal());
$invoice->setBaseGrandTotal(0.0);
$invoice->setGrandTotal(0.0);
} else {
$invoice->setBaseCustomercreditDiscount($baseDiscount);
$invoice->setCustomercreditDiscount($discount);
$invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() - $baseDiscount);
$invoice->setGrandTotal($invoice->getGrandTotal() - $discount);
}
}
}
示例2: collect
public function collect(Mage_Sales_Model_Order_Invoice $invoice)
{
$order = $invoice->getOrder();
if ($order->getCustomercreditDiscount() < 0.0001) {
return;
}
$invoice->setBaseCustomercreditDiscount(0);
$invoice->setCustomercreditDiscount(0);
$totalDiscountInvoiced = 0;
$totalBaseDiscountInvoiced = 0;
$totalDiscountAmount = 0;
$totalBaseDiscountAmount = 0;
$totalHiddenTax = 0;
$totalBaseHiddenTax = 0;
$hiddenTaxInvoiced = 0;
$baseHiddenTaxInvoiced = 0;
$checkAddShipping = true;
foreach ($order->getInvoiceCollection() as $previousInvoice) {
if ($previousInvoice->getCustomercreditDiscount()) {
$checkAddShipping = false;
$totalBaseDiscountInvoiced += $previousInvoice->getBaseCustomercreditDiscount();
$totalDiscountInvoiced += $previousInvoice->getCustomercreditDiscount();
$hiddenTaxInvoiced += $previousInvoice->getCustomercreditHiddenTax();
$baseHiddenTaxInvoiced += $previousInvoice->getBaseCustomercreditHiddenTax();
}
}
if ($checkAddShipping) {
$totalBaseDiscountAmount += $order->getBaseCustomercreditDiscountForShipping();
$totalDiscountAmount += $order->getCustomercreditDiscountForShipping();
$totalBaseHiddenTax += $order->getBaseCustomercreditShippingHiddenTax();
$totalHiddenTax += $order->getCustomercreditShippingHiddenTax();
}
if ($invoice->isLast()) {
$totalBaseDiscountAmount = $order->getBaseCustomercreditDiscount() - $totalBaseDiscountInvoiced;
$totalDiscountAmount = $order->getCustomercreditDiscount() - $totalDiscountInvoiced;
$totalHiddenTax = $order->getCustomercreditHiddenTax() - $hiddenTaxInvoiced;
$totalBaseHiddenTax = $order->getBaseCustomercreditHiddenTax() - $baseHiddenTaxInvoiced;
} else {
foreach ($invoice->getAllItems() as $item) {
$orderItem = $item->getOrderItem();
if ($orderItem->isDummy()) {
continue;
}
$baseOrderItemCustomercreditDiscount = (double) $orderItem->getBaseCustomercreditDiscount();
$orderItemCustomercreditDiscount = (double) $orderItem->getCustomercreditDiscount();
$baseOrderItemHiddenTax = (double) $orderItem->getBaseCustomercreditHiddenTax();
$orderItemHiddenTax = (double) $orderItem->getCustomercreditHiddenTax();
$orderItemQty = $orderItem->getQtyOrdered();
$invoiceItemQty = $item->getQty();
if ($baseOrderItemCustomercreditDiscount && $orderItemQty) {
if (version_compare(Mage::getVersion(), '1.7.0.0', '>=')) {
$totalBaseDiscountAmount += $invoice->roundPrice($baseOrderItemCustomercreditDiscount / $orderItemQty * $invoiceItemQty, 'base', true);
$totalDiscountAmount += $invoice->roundPrice($orderItemCustomercreditDiscount / $orderItemQty * $invoiceItemQty, 'regular', true);
$totalHiddenTax += $invoice->roundPrice($orderItemHiddenTax / $orderItemQty * $invoiceItemQty, 'regular', true);
$totalBaseHiddenTax += $invoice->roundPrice($baseOrderItemHiddenTax / $orderItemQty * $invoiceItemQty, 'base', true);
} else {
$totalBaseDiscountAmount += $baseOrderItemCustomercreditDiscount / $orderItemQty * $invoiceItemQty;
$totalDiscountAmount += $orderItemCustomercreditDiscount / $orderItemQty * $invoiceItemQty;
$totalHiddenTax += $orderItemHiddenTax / $orderItemQty * $invoiceItemQty;
$totalBaseHiddenTax += $baseOrderItemHiddenTax / $orderItemQty * $invoiceItemQty;
}
}
}
}
$invoice->setBaseCustomercreditDiscount($totalBaseDiscountAmount);
$invoice->setCustomercreditDiscount($totalDiscountAmount);
$invoice->setBaseCustomercreditHiddenTax($totalBaseHiddenTax);
$invoice->setCustomercreditHiddenTax($totalHiddenTax);
$invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() - $totalBaseDiscountAmount + $totalBaseHiddenTax);
$invoice->setGrandTotal($invoice->getGrandTotal() - $totalDiscountAmount + $totalHiddenTax);
}