本文整理汇总了PHP中Mage_Sales_Model_Order_Invoice::setDiscountAmount方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Sales_Model_Order_Invoice::setDiscountAmount方法的具体用法?PHP Mage_Sales_Model_Order_Invoice::setDiscountAmount怎么用?PHP Mage_Sales_Model_Order_Invoice::setDiscountAmount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Sales_Model_Order_Invoice
的用法示例。
在下文中一共展示了Mage_Sales_Model_Order_Invoice::setDiscountAmount方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: collect
public function collect(Mage_Sales_Model_Order_Invoice $invoice)
{
$invoice->setDiscountAmount(0);
$invoice->setBaseDiscountAmount(0);
$totalDiscountAmount = 0;
$baseTotalDiscountAmount = 0;
/**
* Checking if shipping discount was added in previous invoices.
* So basically if we have invoice with positive discount and it
* was not canceled we don't add shipping discount to this one.
*/
$addShippingDicount = true;
foreach ($invoice->getOrder()->getInvoiceCollection() as $previusInvoice) {
if ($previusInvoice->getDiscountAmount()) {
$addShippingDicount = false;
}
}
if ($addShippingDicount) {
$totalDiscountAmount = $totalDiscountAmount + $invoice->getOrder()->getShippingDiscountAmount();
$baseTotalDiscountAmount = $baseTotalDiscountAmount + $invoice->getOrder()->getBaseShippingDiscountAmount();
}
/** @var $item Mage_Sales_Model_Order_Invoice_Item */
foreach ($invoice->getAllItems() as $item) {
$orderItem = $item->getOrderItem();
if ($orderItem->isDummy()) {
continue;
}
$orderItemDiscount = (double) $orderItem->getDiscountAmount();
$baseOrderItemDiscount = (double) $orderItem->getBaseDiscountAmount();
$orderItemQty = $orderItem->getQtyOrdered();
if ($orderItemDiscount && $orderItemQty) {
/**
* Resolve rounding problems
*
* We dont want to include the weee discount amount as the right amount
* is added when calculating the taxes.
*
* Also the subtotal is without weee
*/
$discount = $orderItemDiscount - $orderItem->getDiscountInvoiced();
$baseDiscount = $baseOrderItemDiscount - $orderItem->getBaseDiscountInvoiced();
if (!$item->isLast()) {
$activeQty = $orderItemQty - $orderItem->getQtyInvoiced();
$discount = $invoice->roundPrice($discount / $activeQty * $item->getQty(), 'regular', true);
$baseDiscount = $invoice->roundPrice($baseDiscount / $activeQty * $item->getQty(), 'base', true);
}
$item->setDiscountAmount($discount);
$item->setBaseDiscountAmount($baseDiscount);
$totalDiscountAmount += $discount;
$baseTotalDiscountAmount += $baseDiscount;
}
}
$invoice->setDiscountAmount(-$totalDiscountAmount);
$invoice->setBaseDiscountAmount(-$baseTotalDiscountAmount);
$invoice->setGrandTotal($invoice->getGrandTotal() - $totalDiscountAmount);
$invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() - $baseTotalDiscountAmount);
return $this;
}
示例2: collect
public function collect(Mage_Sales_Model_Order_Invoice $invoice)
{
$invoice->setDiscountAmount(0);
$invoice->setBaseDiscountAmount(0);
$totalDiscountAmount = 0;
$baseTotalDiscountAmount = 0;
/**
* Checking if shipping discount was added in previous invoices.
* So basically if we have invoice with positive discount and it
* was not canceled we don't add shipping discount to this one.
*/
$addShippingDicount = true;
foreach ($invoice->getOrder()->getInvoiceCollection() as $previusInvoice) {
if ($previusInvoice->getDiscountAmount()) {
$addShippingDicount = false;
}
}
if ($addShippingDicount) {
$totalDiscountAmount = $totalDiscountAmount + $invoice->getOrder()->getShippingDiscountAmount();
$baseTotalDiscountAmount = $baseTotalDiscountAmount + $invoice->getOrder()->getBaseShippingDiscountAmount();
}
foreach ($invoice->getAllItems() as $item) {
if ($item->getOrderItem()->isDummy()) {
continue;
}
$orderItem = $item->getOrderItem();
$orderItemDiscount = (double) $orderItem->getDiscountAmount();
$baseOrderItemDiscount = (double) $orderItem->getBaseDiscountAmount();
$orderItemQty = $orderItem->getQtyOrdered();
if ($orderItemDiscount && $orderItemQty) {
/**
* Resolve rounding problems
*/
if ($item->isLast()) {
$discount = $orderItemDiscount - $orderItem->getDiscountInvoiced();
$baseDiscount = $baseOrderItemDiscount - $orderItem->getBaseDiscountInvoiced();
} else {
$discount = $orderItemDiscount * $item->getQty() / $orderItemQty;
$baseDiscount = $baseOrderItemDiscount * $item->getQty() / $orderItemQty;
$discount = $invoice->getStore()->roundPrice($discount);
$baseDiscount = $invoice->getStore()->roundPrice($baseDiscount);
}
$item->setDiscountAmount($discount);
$item->setBaseDiscountAmount($baseDiscount);
$totalDiscountAmount += $discount;
$baseTotalDiscountAmount += $baseDiscount;
}
}
$invoice->setDiscountAmount($totalDiscountAmount);
$invoice->setBaseDiscountAmount($baseTotalDiscountAmount);
$invoice->setGrandTotal($invoice->getGrandTotal() - $totalDiscountAmount);
$invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() - $baseTotalDiscountAmount);
return $this;
}
示例3: collect
/**
* collect discout total for invoice
*
* - on payment method "sofortrechnung" discount will invoice on first invoice complete including canceled items
*
* @param Mage_Sales_Model_Order_Invoice $invoice
* @return Mage_Sales_Model_Order_Invoice_Total_Discount
* @see app/code/core/Mage/Sales/Model/Order/Invoice/Total/Mage_Sales_Model_Order_Invoice_Total_Discount::collect()
*/
public function collect(Mage_Sales_Model_Order_Invoice $invoice)
{
// special case for modified sofortrechnung
if ($invoice->getOrder()->getPayment()->getMethod() == "sofortrechnung") {
// special special case if configurable product is in basket
$hackDiff = 0;
$enableDiff = false;
$discountTax = 100;
foreach ($invoice->getOrder()->getAllVisibleItems() as $item) {
$enableDiff = $enableDiff || $item->product_type == 'configurable';
if ($item->getTaxPercent() > 0) {
// tax of discount is min of cart-items
$discountTax = min($item->getTaxPercent(), $discountTax);
}
}
$totalDiscountAmount = -$invoice->getOrder()->getDiscountInvoiced() - $invoice->getOrder()->getDiscountAmount();
$baseTotalDiscountAmount = -$invoice->getOrder()->getBaseDiscountInvoiced() - $invoice->getOrder()->getBaseDiscountAmount();
$invoice->setDiscountAmount(-$totalDiscountAmount);
$invoice->setBaseDiscountAmount(-$baseTotalDiscountAmount);
if ($enableDiff) {
$hackDiff = $totalDiscountAmount - $totalDiscountAmount * (100 / ($discountTax + 100));
}
$invoice->setGrandTotal($invoice->getGrandTotal() - $totalDiscountAmount + $hackDiff);
$invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() - $baseTotalDiscountAmount + $hackDiff);
return $this;
}
return parent::collect($invoice);
}
示例4: collect
public function collect(Mage_Sales_Model_Order_Invoice $invoice)
{
$invoice->setDiscountAmount(0);
$invoice->setBaseDiscountAmount(0);
$totalDiscountAmount = 0;
$baseTotalDiscountAmount = 0;
foreach ($invoice->getAllItems() as $item) {
if ($item->getOrderItem()->isDummy()) {
continue;
}
$orderItem = $item->getOrderItem();
$orderItemDiscount = (double) $orderItem->getDiscountAmount();
$baseOrderItemDiscount = (double) $orderItem->getBaseDiscountAmount();
$orderItemQty = $orderItem->getQtyOrdered();
if ($orderItemDiscount && $orderItemQty) {
/**
* Resolve rounding problems
*/
if ($item->isLast()) {
$discount = $orderItemDiscount - $orderItem->getDiscountInvoiced();
$baseDiscount = $baseOrderItemDiscount - $orderItem->getBaseDiscountInvoiced();
} else {
$discount = $orderItemDiscount * $item->getQty() / $orderItemQty;
$baseDiscount = $baseOrderItemDiscount * $item->getQty() / $orderItemQty;
$discount = $invoice->getStore()->roundPrice($discount);
$baseDiscount = $invoice->getStore()->roundPrice($baseDiscount);
}
$item->setDiscountAmount($discount);
$item->setBaseDiscountAmount($baseDiscount);
$totalDiscountAmount += $discount;
$baseTotalDiscountAmount += $baseDiscount;
}
}
$invoice->setDiscountAmount($totalDiscountAmount);
$invoice->setBaseDiscountAmount($baseTotalDiscountAmount);
$invoice->setGrandTotal($invoice->getGrandTotal() - $totalDiscountAmount);
$invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() - $baseTotalDiscountAmount);
return $this;
}