コード例 #1
0
ファイル: Payment.php プロジェクト: Rinso/magento-mirror
 /**
  * Cancel invoice
  *
  * @param   unknown_type $invoice
  * @return  unknown
  */
 public function cancelInvoice($invoice)
 {
     $this->setAmountPaid($this->getAmountPaid() - $invoice->getGrandTotal());
     $this->setBaseAmountPaid($this->getBaseAmountPaid() - $invoice->getBaseGrandTotal());
     $this->setShippingCaptured($this->getShippingCaptured() - $invoice->getShippingAmount());
     $this->setBaseShippingCaptured($this->getBaseShippingCaptured() - $invoice->getBaseShippingAmount());
     Mage::dispatchEvent('sales_order_payment_cancel_invoice', array('payment' => $this, 'invoice' => $invoice));
     return $this;
 }
コード例 #2
0
ファイル: Payment.php プロジェクト: arslbbt/mangentovies
 /**
  * Cancel invoice
  *
  * @param   unknown_type $invoice
  * @return  unknown
  */
 public function cancelInvoice($invoice)
 {
     $this->setAmountPaid($this->getAmountPaid() - $invoice->getGrandTotal());
     $this->setBaseAmountPaid($this->getBaseAmountPaid() - $invoice->getBaseGrandTotal());
     $this->setShippingCaptured($this->getShippingCaptured() - $invoice->getShippingAmount());
     $this->setBaseShippingCaptured($this->getBaseShippingCaptured() - $invoice->getBaseShippingAmount());
     return $this;
 }
コード例 #3
0
 /**
  * Calculate shipping price
  * 
  * @param unknown_type $address
  * @param unknown_type $quote
  * @param unknown_type $inclTax
  * @param unknown_type $toSmallerUnit
  */
 public function calculateShippingPrice($address, $quote, $inclTax, $toSmallerUnit = false)
 {
     $shipping = $address->getShippingAmount();
     if ($inclTax) {
         $shipping += $address->getShippingTaxAmount() + $quote->getBillpayChargedFee();
         // Mageworx MultiFee addition
         //if ($address->getMultifees()) {
         //	$shipping += $address->getMultifees();
         //}
     } else {
         $shipping += $quote->getBillpayChargedFeeNet();
         // Mageworx MultiFee addition
         //if ($address->getMultifeesExclTax()) {
         //	$shipping += $address->getMultifeesExclTax();
         //}
     }
     return $toSmallerUnit ? $this->currencyToSmallerUnit($shipping) : $shipping;
 }
コード例 #4
0
ファイル: Validator.php プロジェクト: rajarshc/Rooja
 /**
  * @author Jared Ty <*****@*****.**>
  * 
  * @param unknown_type $quote
  * @param unknown_type $address
  * @param unknown_type $item
  * @param unknown_type $rule_id
  */
 protected function recalculateDiscounts($quote, $address, $item, $rule_id)
 {
     $rule = $this->getRule($rule_id);
     $store = $item->getQuote()->getStore();
     //@nelkaake 17/03/2010 5:01:35 AM
     //@nelkaake -a 16/11/10:
     if (Mage::helper('rewards')->isBaseMageVersionAtLeast('1.4.1.0')) {
         $addrFixedCartRules = $address->getCartRules();
     }
     if (!$rule->getId()) {
         return $this;
     }
     if (!$rule->getActions()->validate($item)) {
         return $this;
     }
     Mage::getSingleton('rewards/salesrule_validator')->addItemAppliedRuleId($item, $rule_id);
     $qty = $item->getQty();
     if ($item->getParentItem()) {
         $qty *= $item->getParentItem()->getQty();
     }
     $qty = $rule->getDiscountQty() ? min($qty, $rule->getDiscountQty()) : $qty;
     $rulePercent = min(100, $rule->getDiscountAmount());
     $discountAmount = 0;
     $baseDiscountAmount = 0;
     //@nelkaake 17/03/2010 5:09:27 AM : is this the last item?
     $all_items = $item->getQuote()->getAllItems();
     $shipping_amount = $address->getShippingAmount();
     $base_shipping_amount = $address->getBaseShippingAmount();
     $itemPrice = $item->getDiscountCalculationPrice();
     if ($itemPrice !== null) {
         $baseItemPrice = $item->getBaseDiscountCalculationPrice();
     } else {
         $itemPrice = $item->getCalculationPrice();
         $baseItemPrice = $item->getBaseCalculationPrice();
     }
     Mage::getSingleton('rewards/redeem')->refactorRedemptions($all_items, false);
     switch ($rule->getSimpleAction()) {
         case 'to_percent':
             //@nelkaake -a 16/11/10: THIS TYPE OF DISCOUNT WAS ABANDONED BY MAGENTO
             //$rulePercent = max(0, 100-$rule->getDiscountAmount());
             //no break;
         //@nelkaake -a 16/11/10: THIS TYPE OF DISCOUNT WAS ABANDONED BY MAGENTO
         //$rulePercent = max(0, 100-$rule->getDiscountAmount());
         //no break;
         case 'by_percent':
             //@mhadianfard -c 16/11/10:
             $cartRules = $this->cart_fixed_rules;
             // WDCA CODE BEGIN
             //@nelkaake -a 28/11/10: First calculate the total discount on the cart
             if (!isset($cartRules[$rule->getId()])) {
                 $totalDiscountOnCart = $this->_getTotalPercentDiscount($item, $address, $rule, $qty);
                 $cartRules[$rule->getId()] = $totalDiscountOnCart;
                 //@nelkaake -a 28/11/10: if this was a by points spent
                 if ($rule->getPointsAction() == TBT_Rewards_Model_Salesrule_Actions::ACTION_DISCOUNT_BY_POINTS_SPENT) {
                     $this->_registerPointsSpentDiscount($rule, $cartRules[$rule->getId()]);
                 }
                 $addrCartRules = is_array($address->getCartFixedRules()) ? $address->getCartFixedRules() : array();
                 $addrCartRules[$rule->getId()] = $cartRules[$rule->getId()];
                 $address->setCartFixedRules($addrCartRules);
             }
             //@nelkaake -a 28/11/10: If we've already calculated the total discount on the cart, start trying to discount per item.
             if ($cartRules[$rule->getId()] > 0) {
                 list($discountAmount, $baseDiscountAmount) = $this->_getTotalPercentDiscountOnitem($item, $address, $rule, $cartRules, $qty);
                 if (!$this->isCfrProcessed($item, $rule_id)) {
                     $cartRules[$rule->getId()] -= $baseDiscountAmount;
                     $this->setIsCfrProcessed($item, $rule_id);
                 }
             }
             // WDCA CODE END
             $this->cart_fixed_rules = $cartRules;
             $address->setCartFixedRules($cartRules);
             break;
         case 'to_fixed':
             $quoteAmount = $quote->getStore()->convertPrice($rule->getDiscountAmount());
             $discountAmount = $qty * ($item->getCalculationPrice() - $quoteAmount);
             $baseDiscountAmount = $qty * ($item->getBaseCalculationPrice() - $rule->getDiscountAmount());
             break;
         case 'by_fixed':
             if ($step = $rule->getDiscountStep()) {
                 $qty = floor($qty / $step) * $step;
             }
             $quoteAmount = $quote->getStore()->convertPrice($rule->getDiscountAmount());
             $discountAmount = $qty * $quoteAmount;
             $baseDiscountAmount = $qty * $rule->getDiscountAmount();
             break;
         case 'cart_fixed':
             $cartRules = $this->cart_fixed_rules;
             // WDCA CODE BEGIN
             if (Mage::helper('rewards')->isBaseMageVersionAtLeast('1.4.2')) {
                 if (empty($this->_rulesItemTotals[$rule->getId()])) {
                     Mage::throwException(Mage::helper('salesrule')->__('Item totals are not set for rule.'));
                 }
             }
             if (!isset($cartRules[$rule->getId()])) {
                 $cartRules[$rule->getId()] = $this->_getTotalFixedDiscountOnCart($item, $address, $rule);
                 if ($rule->getPointsAction() == TBT_Rewards_Model_Salesrule_Actions::ACTION_DISCOUNT_BY_POINTS_SPENT) {
                     $this->_registerPointsSpentDiscount($rule, $cartRules[$rule->getId()]);
                 }
                 $addrCartRules = is_array($address->getCartFixedRules()) ? $address->getCartFixedRules() : array();
                 $addrCartRules[$rule->getId()] = $cartRules[$rule->getId()];
                 $address->setCartFixedRules($addrCartRules);
             }
             //@nelkaake Wednesday May 5, 2010 RM:
             if ($cartRules[$rule->getId()] > 0) {
                 list($discountAmount, $baseDiscountAmount) = $this->_getTotalFixedDiscountOnitem($item, $address, $rule, $cartRules);
                 //@nelkaake Changed on Monday August 23, 2010:
                 if (!$this->isCFRProcessed($item, $rule->getId())) {
                     if (Mage::helper('rewards')->isBaseMageVersionAtLeast('1.4.2')) {
                         $cartRules2 = $cartRules;
                         $cartRules2[$rule->getId()] -= $baseDiscountAmount;
                         $address->setCartFixedRules2($cartRules2);
                         $cartRules[$rule->getId()] -= $baseDiscountAmount;
                     } else {
                         $cartRules[$rule->getId()] -= $baseDiscountAmount;
                     }
                     $this->setIsCFRProcessed($item, $rule->getId());
                 }
             }
             if (Mage::helper('rewards')->isBaseMageVersionAtLeast('1.4.2')) {
                 $address->setCartFixedRules($cartRules);
             }
             // WDCA CODE END
             $this->cart_fixed_rules = $cartRules;
             $address->setCartFixedRules($cartRules);
             break;
         case 'buy_x_get_y':
             $x = $rule->getDiscountStep();
             $y = $rule->getDiscountAmount();
             if (!$x || $y >= $x) {
                 break;
             }
             $buy = 0;
             $free = 0;
             while ($buy + $free < $qty) {
                 $buy += $x;
                 if ($buy + $free >= $qty) {
                     break;
                 }
                 $free += min($y, $qty - $buy - $free);
                 if ($buy + $free >= $qty) {
                     break;
                 }
             }
             $discountAmount = $free * $item->getCalculationPrice();
             $baseDiscountAmount = $free * $item->getBaseCalculationPrice();
             break;
     }
     $this->total_discount_reversed += $discountAmount;
     $this->total_base_discount_reversed += $baseDiscountAmount;
     //WDCA BEGIN
     $discountAmount = $quote->getStore()->roundPrice($discountAmount);
     $baseDiscountAmount = $quote->getStore()->roundPrice($baseDiscountAmount);
     //@nelkaake This is the discount applied twice, the first time raw second time rounded
     $dada = $item->getDiscountAmount() + $discountAmount;
     $base_dada = $item->getBaseDiscountAmount() + $baseDiscountAmount;
     $row_total = $item->getRowTotal();
     $base_row_total = $item->getBaseRowTotal();
     if (Mage::helper('tax')->discountTax($store) && !Mage::helper('tax')->applyTaxAfterDiscount($store)) {
         $row_total += $item->getTaxAmount() / $item->getQty() * $qty;
         $base_row_total += $item->getBaseTaxAmount() / $item->getQty() * $qty;
     }
     $discountAmount = min($dada, $row_total + $shipping_amount);
     $baseDiscountAmount = min($base_dada, $base_row_total + $base_shipping_amount);
     //@nelkaake Added on Wednesday May 5, 2010: Check to make sure that the new disocunt does not increase max
     // discounts more than row total.
     $discount_diff = $dada - ($row_total + $shipping_amount);
     if ($discount_diff > 0) {
         $base_discount_diff = $base_dada - ($base_row_total + $base_shipping_amount);
         $fullDiscountAmount = $discountAmount + $discount_diff;
         $fullBaseDiscountAmount = $baseDiscountAmount + $base_discount_diff;
     } else {
         $fullDiscountAmount = $dada;
         $fullBaseDiscountAmount = $base_dada;
     }
     //WDCA END
     //@nelkaake Added on Wednesday May 5, 2010:
     Mage::getSingleton('rewards/salesrule_discountmanager')->setDiscount($rule, $fullDiscountAmount - $item->getDiscountAmount(), $fullBaseDiscountAmount - $item->getBaseDiscountAmount());
     $item->setDiscountAmount($discountAmount);
     $item->setBaseDiscountAmount($baseDiscountAmount);
     return $this;
 }