当前位置: 首页>>代码示例>>PHP>>正文


PHP Mage_Sales_Model_Order_Invoice::setRewardpointsEarn方法代码示例

本文整理汇总了PHP中Mage_Sales_Model_Order_Invoice::setRewardpointsEarn方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Sales_Model_Order_Invoice::setRewardpointsEarn方法的具体用法?PHP Mage_Sales_Model_Order_Invoice::setRewardpointsEarn怎么用?PHP Mage_Sales_Model_Order_Invoice::setRewardpointsEarn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mage_Sales_Model_Order_Invoice的用法示例。


在下文中一共展示了Mage_Sales_Model_Order_Invoice::setRewardpointsEarn方法的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);
         }
     }
 }
开发者ID:sshegde123,项目名称:wmp8,代码行数:73,代码来源:Point.php

示例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;
 }
开发者ID:kanotest15,项目名称:cbmagento,代码行数:100,代码来源:Point.php


注:本文中的Mage_Sales_Model_Order_Invoice::setRewardpointsEarn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。