本文整理汇总了PHP中Mage_Sales_Model_Order_Invoice::setRewardpointsDiscount方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Sales_Model_Order_Invoice::setRewardpointsDiscount方法的具体用法?PHP Mage_Sales_Model_Order_Invoice::setRewardpointsDiscount怎么用?PHP Mage_Sales_Model_Order_Invoice::setRewardpointsDiscount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Sales_Model_Order_Invoice
的用法示例。
在下文中一共展示了Mage_Sales_Model_Order_Invoice::setRewardpointsDiscount方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: collect
/**
* Collect total when create Invoice
*
* @param Mage_Sales_Model_Order_Invoice $invoice
*/
public function collect(Mage_Sales_Model_Order_Invoice $invoice)
{
$order = $invoice->getOrder();
/**
* update 2.0
*/
$earnPoint = 0;
$maxEarn = $order->getRewardpointsEarn();
$maxEarn -= (int) Mage::getResourceModel('rewardpoints/transaction_collection')->addFieldToFilter('action', 'earning_invoice')->addFieldToFilter('order_id', $order->getId())->getFieldTotal();
if ($maxEarn >= 0) {
foreach ($invoice->getAllItems() as $item) {
$orderItem = $item->getOrderItem();
if ($orderItem->isDummy()) {
continue;
}
$itemPoint = (int) $orderItem->getRewardpointsEarn();
$itemPoint = $itemPoint * $item->getQty() / $orderItem->getQtyOrdered();
$earnPoint += floor($itemPoint);
}
if ($invoice->isLast() || $earnPoint >= $maxEarn) {
$earnPoint = $maxEarn;
}
$invoice->setRewardpointsEarn($earnPoint);
}
if ($order->getRewardpointsDiscount() < 0.0001) {
return;
}
if ($invoice->isLast()) {
$baseDiscount = $order->getRewardpointsBaseDiscount();
$discount = $order->getRewardpointsDiscount();
foreach ($order->getInvoiceCollection() as $existedInvoice) {
if ($baseDiscount > 0.0001) {
$baseDiscount -= $existedInvoice->getRewardpointsBaseDiscount();
$discount -= $existedInvoice->getRewardpointsDiscount();
}
}
} else {
$orderTotal = $order->getGrandTotal() + $order->getRewardpointsDiscount();
$ratio = $invoice->getGrandTotal() / $orderTotal;
$baseDiscount = $order->getRewardpointsBaseDiscount() * $ratio;
$discount = $order->getRewardpointsDiscount() * $ratio;
$maxBaseDiscount = $order->getRewardpointsBaseDiscount();
$maxDiscount = $order->getRewardpointsDiscount();
foreach ($order->getInvoiceCollection() as $existedInvoice) {
if ($maxBaseDiscount > 0.0001) {
$maxBaseDiscount -= $existedInvoice->getRewardpointsBaseDiscount();
$maxDiscount -= $existedInvoice->getRewardpointsDiscount();
}
}
if ($baseDiscount > $maxBaseDiscount) {
$baseDiscount = $maxBaseDiscount;
$discount = $maxDiscount;
}
}
if ($baseDiscount > 0.0001) {
if ($invoice->getBaseGrandTotal() <= $baseDiscount) {
$invoice->setRewardpointsBaseDiscount($invoice->getBaseGrandTotal());
$invoice->setRewardpointsDiscount($invoice->getGrandTotal());
$invoice->setBaseGrandTotal(0.0);
$invoice->setGrandTotal(0.0);
} else {
$invoice->setRewardpointsBaseDiscount($baseDiscount);
$invoice->setRewardpointsDiscount($discount);
$invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() - $baseDiscount);
$invoice->setGrandTotal($invoice->getGrandTotal() - $discount);
}
}
}
示例2: collect
/**
* Collect total when create Invoice
*
* @param Mage_Sales_Model_Order_Invoice $invoice
*/
public function collect(Mage_Sales_Model_Order_Invoice $invoice)
{
$order = $invoice->getOrder();
/**
* update 2.0
*/
$earnPoint = 0;
$maxEarn = $order->getRewardpointsEarn();
$maxEarn -= (int) Mage::getResourceModel('rewardpoints/transaction_collection')->addFieldToFilter('action', 'earning_invoice')->addFieldToFilter('order_id', $order->getId())->getFieldTotal();
if ($maxEarn >= 0) {
foreach ($invoice->getAllItems() as $item) {
$orderItem = $item->getOrderItem();
if ($orderItem->isDummy()) {
continue;
}
$itemPoint = (int) $orderItem->getRewardpointsEarn();
$itemPoint = $itemPoint * $item->getQty() / $orderItem->getQtyOrdered();
$earnPoint += floor($itemPoint);
}
if ($invoice->isLast() || $earnPoint >= $maxEarn) {
$earnPoint = $maxEarn;
}
$invoice->setRewardpointsEarn($earnPoint);
}
if ($order->getRewardpointsDiscount() < 0.0001) {
return;
}
$invoice->setRewardpointsDiscount(0);
$invoice->setRewardpointsBaseDiscount(0);
$totalDiscountAmount = 0;
$baseTotalDiscountAmount = 0;
$totalDiscountInvoiced = 0;
$baseTotalDiscountInvoiced = 0;
$hiddenTaxInvoiced = 0;
$baseHiddenTaxInvoiced = 0;
$totalHiddenTax = 0;
$baseTotalHiddenTax = 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 ($order->getInvoiceCollection() as $previusInvoice) {
if ($previusInvoice->getRewardpointsDiscount()) {
$addShippingDicount = false;
$totalDiscountInvoiced += $previusInvoice->getRewardpointsDiscount();
$baseTotalDiscountInvoiced += $previusInvoice->getRewardpointsBaseDiscount();
$hiddenTaxInvoiced += $previusInvoice->getRewardpointsHiddenTaxAmount();
$baseHiddenTaxInvoiced += $previusInvoice->getRewardpointsBaseHiddenTaxAmount();
}
}
if ($addShippingDicount) {
$totalDiscountAmount += $order->getRewardpointsAmount();
$baseTotalDiscountAmount += $order->getRewardpointsBaseAmount();
$totalHiddenTax += $order->getRewardpointsShippingHiddenTaxAmount();
$baseTotalHiddenTax += $order->getRewardpointsBaseShippingHiddenTaxAmount();
}
if ($invoice->isLast()) {
$totalDiscountAmount = $order->getRewardpointsDiscount() - $totalDiscountInvoiced;
$baseTotalDiscountAmount = $order->getRewardpointsBaseDiscount() - $baseTotalDiscountInvoiced;
$totalHiddenTax = $order->getRewardpointsHiddenTaxAmount() - $hiddenTaxInvoiced;
$baseTotalHiddenTax = $order->getRewardpointsBaseHiddenTaxAmount() - $baseHiddenTaxInvoiced;
} else {
/** @var $item Mage_Sales_Model_Order_Invoice_Item */
foreach ($invoice->getAllItems() as $item) {
$orderItem = $item->getOrderItem();
if ($orderItem->isDummy()) {
continue;
}
$orderItemDiscount = (double) $orderItem->getRewardpointsDiscount();
$baseOrderItemDiscount = (double) $orderItem->getRewardpointsBaseDiscount();
$orderItemHiddenTax = (double) $orderItem->getRewardpointsHiddenTaxAmount();
$baseOrderItemHiddenTax = (double) $orderItem->getRewardpointsBaseHiddenTaxAmount();
$orderItemQty = $orderItem->getQtyOrdered();
if ($orderItemDiscount && $orderItemQty) {
$totalDiscountAmount += $invoice->roundPrice($orderItemDiscount / $orderItemQty * $item->getQty(), 'regular', true);
$baseTotalDiscountAmount += $invoice->roundPrice($baseOrderItemDiscount / $orderItemQty * $item->getQty(), 'base', true);
$totalHiddenTax += $invoice->roundPrice($orderItemHiddenTax / $orderItemQty * $item->getQty(), 'regular', true);
$baseTotalHiddenTax += $invoice->roundPrice($baseOrderItemHiddenTax / $orderItemQty * $item->getQty(), 'base', true);
}
}
$allowedBaseHiddenTax = $order->getRewardpointsBaseHiddenTaxAmount() - $baseHiddenTaxInvoiced;
$allowedHiddenTax = $order->getRewardpointsHiddenTaxAmount() - $hiddenTaxInvoiced;
$totalHiddenTax = min($allowedHiddenTax, $totalHiddenTax);
$baseTotalHiddenTax = min($allowedBaseHiddenTax, $baseTotalHiddenTax);
}
$invoice->setRewardpointsDiscount($totalDiscountAmount);
$invoice->setRewardpointsBaseDiscount($baseTotalDiscountAmount);
$invoice->setRewardpointsHiddenTaxAmount($totalHiddenTax);
$invoice->setRewardpointsBaseHiddenTaxAmount($baseTotalHiddenTax);
$invoice->setGrandTotal($invoice->getGrandTotal() - $totalDiscountAmount + $totalHiddenTax);
$invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() - $baseTotalDiscountAmount + $baseTotalHiddenTax);
return $this;
}