Example #1
0
 /**
  * Get one line item key-value array
  *
  * @param Mage_Core_Model_Abstract $salesEntity
  * @param Varien_Object $item
  * @return array
  */
 protected function _prepareLineItemFields(Mage_Core_Model_Abstract $salesEntity, Varien_Object $item)
 {
     if ($salesEntity instanceof Mage_Sales_Model_Order) {
         $qty = $item->getQtyOrdered();
         $amount = $item->getBasePrice();
     } else {
         $qty = $item->getTotalQty();
         $amount = $item->getBaseCalculationPrice();
     }
     // workaround in case if item subtotal precision is not compatible with PayPal (.2)
     $subAggregatedLabel = '';
     if ((double) $amount - round((double) $amount, 2)) {
         $amount = $amount * $qty;
         $subAggregatedLabel = ' x' . $qty;
         $qty = 1;
     }
     return array('id' => $item->getSku(), 'name' => $item->getName() . $subAggregatedLabel, 'qty' => $qty, 'amount' => (double) $amount);
 }
Example #2
0
 /**
  * Retrieve include tax html formated content
  *
  * @param Varien_Object $item
  * @return string
  */
 public function displayPriceInclTax(Varien_Object $item)
 {
     $qty = $item->getQtyOrdered() ? $item->getQtyOrdered() : ($item->getQty() ? $item->getQty() : 1);
     $baseTax = $item->getTaxBeforeDiscount() ? $item->getTaxBeforeDiscount() : ($item->getTaxAmount() ? $item->getTaxAmount() : 0);
     $tax = $item->getBaseTaxBeforeDiscount() ? $item->getBaseTaxBeforeDiscount() : ($item->getBaseTaxAmount() ? $item->getBaseTaxAmount() : 0);
     $basePriceTax = 0;
     $priceTax = 0;
     if (floatval($qty)) {
         $basePriceTax = $item->getBasePrice() + $baseTax / $qty;
         $priceTax = $item->getPrice() + $tax / $qty;
     }
     return $this->displayPrices($this->getOrder()->getStore()->roundPrice($basePriceTax), $this->getOrder()->getStore()->roundPrice($priceTax));
 }
Example #3
0
 /**
  * Add a usual line item with amount and qty
  *
  * @param Varien_Object $salesItem
  * @return Varien_Object
  */
 protected function _addRegularItem(Varien_Object $salesItem)
 {
     if ($this->_salesEntity instanceof Mage_Sales_Model_Order) {
         $qty = (int) $salesItem->getQtyOrdered();
         $amount = (double) $salesItem->getBasePrice();
         // TODO: nominal item for order
     } else {
         $qty = (int) $salesItem->getTotalQty();
         $amount = $salesItem->isNominal() ? 0 : (double) $salesItem->getBaseCalculationPrice();
     }
     // workaround in case if item subtotal precision is not compatible with PayPal (.2)
     $subAggregatedLabel = '';
     if ($amount - round($amount, 2)) {
         $amount = $amount * $qty;
         $subAggregatedLabel = ' x' . $qty;
         $qty = 1;
     }
     // aggregate item price if item qty * price does not match row total
     if ($amount * $qty != $salesItem->getBaseRowTotal()) {
         $amount = (double) $salesItem->getBaseRowTotal();
         $subAggregatedLabel = ' x' . $qty;
         $qty = 1;
     }
     return $this->addItem($salesItem->getName() . $subAggregatedLabel, $qty, $amount, $salesItem->getSku());
 }
 /**
  * charge money for recurring item
  */
 protected function _checkoutRecurring()
 {
     /** @var Mage_Sales_Model_Order $order */
     $order = Mage::getModel('sales/order');
     $item = new Varien_Object($this->_recurringProfile->getOrderItemInfo());
     $this->_price = $item->getBasePrice() * $item->getQty();
     $additionalInfo = $this->_recurringProfile->getAdditionalInfo();
     // check isset TrialBilling
     // Trial Billing Frequency <= 0 or isn't numeric => failure
     if ($this->_recurringProfile->getTrialBillingAmount() && $this->_recurringProfile->getTrialPeriodFrequency() && $this->_recurringProfile->getTrialPeriodMaxCycles() && $this->_recurringProfile->getTrialPeriodUnit() && (string) (int) $this->_recurringProfile->getTrialPeriodFrequency() === ltrim($this->_recurringProfile->getTrialPeriodFrequency(), '0') && (int) $this->_recurringProfile->getTrialPeriodFrequency() > 0) {
         $trialPeriodMaxCycles = (int) $this->_recurringProfile->getTrialPeriodMaxCycles();
         if (!isset($additionalInfo['trialPeriodMaxCycles'])) {
             $additionalInfo['trialPeriodMaxCycles'] = $trialPeriodMaxCycles;
             $this->_recurringProfile->setAdditionalInfo($additionalInfo);
             $this->_price = $this->_recurringProfile->getTrialBillingAmount();
             $this->_periodType = Mage_Sales_Model_Recurring_Profile::PAYMENT_TYPE_TRIAL;
         } elseif (isset($additionalInfo['trialPeriodMaxCycles']) && $additionalInfo['trialPeriodMaxCycles'] > 0) {
             $this->_price = $this->_recurringProfile->getTrialBillingAmount();
             $this->_periodType = Mage_Sales_Model_Recurring_Profile::PAYMENT_TYPE_TRIAL;
         }
     }
     // calculate total amount
     $this->_shippingAmount = $item->getBaseShippingAmount();
     $this->_taxAmount = $item->getBaseTaxAmount();
     $this->_amount = $this->_price + $this->_shippingAmount + $this->_taxAmount;
     // init order
     /** @var Mage_Sales_Model_Order_Item $orderItem */
     $orderItem = Mage::getModel('sales/order_item')->setName($item->getName())->setSku($item->getSku())->setDescription($item->getDescription())->setQtyOrdered($item->getQty())->setBasePrice($item->getBasePrice())->setBaseTaxAmount($item->getBaseTaxAmount())->setBaseRowTotalInclTax($item->getBaseRowTotalInclTax());
     $order->addItem($orderItem);
     $shippingInfo = $this->_recurringProfile->getShippingAddressInfo();
     $shippingAddress = Mage::getModel('sales/order_address')->setData($shippingInfo)->setId(null);
     // get base currency code
     $orderInfo = new Varien_Object($this->_recurringProfile->getOrderInfo());
     $currencyCode = $orderInfo->getBaseCurrencyCode();
     $order->setShippingAddress($shippingAddress);
     $order->setBaseCurrencyCode($currencyCode);
     /** @var Mage_Sales_Model_Order_Payment $payment */
     $payment = Mage::getModel('sales/order_payment');
     $payment->setOrder($order);
     $payment->setIsRecurring(true);
     $payment->setIsInitialFee(true);
     $customerId = $this->_recurringProfile->getCustomerId();
     $payment->setCustomerId($customerId);
     $tokenId = $additionalInfo['token']['saved_token'];
     $payment->setTokenId($tokenId);
     /** @var Eway_Rapid31_Model_Method_Saved $ewaySave */
     $ewaySave = Mage::getModel('ewayrapid/method_saved');
     $paymentAction = Mage::getStoreConfig('payment/ewayrapid_general/payment_action');
     if ($paymentAction == Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE) {
         $ewaySave->authorize($payment, $this->_amount);
     } elseif ($paymentAction == Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE) {
         $ewaySave->capture($payment, $this->_amount);
     }
     if (!$payment->getTransactionId()) {
         throw new Exception('Transaction is not available');
     } else {
         $this->_txdId = $payment->getTransactionId();
     }
     /** @todo: change status of order = "eWAY Authorised"
      *         now status order = "processing"
      */
 }
 /**
  * calculate earning for quote/order item
  * 
  * @param Varien_Object $item
  * @param int $customerGroupId
  * @param int $websiteId
  * @param string $date
  * @return int
  */
 public function getCatalogItemEarningPoints($item, $customerGroupId = null, $websiteId = null, $date = null)
 {
     $product = Mage::getModel('catalog/product')->load($item->getProductId());
     //webpos
     $customerId = Mage::getSingleton('checkout/session')->getData('webpos_customerid');
     if ($customerId) {
         $customerGroupId = Mage::getModel('customer/customer')->load($customerId)->getGroupId();
     } else {
         $customerGroupId = Mage_Customer_Model_Group::NOT_LOGGED_IN_ID;
     }
     if (is_null($websiteId)) {
         $websiteId = Mage::app()->getStore($item->getStoreId())->getWebsiteId();
     }
     if (is_null($date)) {
         $date = date('Y-m-d', strtotime($item->getCreatedAt()));
     }
     $cacheKey = "catalog_item_earning:{$item->getId()}:{$customerGroupId}:{$websiteId}";
     if ($this->hasCache($cacheKey)) {
         return $this->getCache($cacheKey);
     }
     $points = 0;
     $collectionKey = "catalog_earning_collection:{$customerGroupId}:{$websiteId}";
     if (!$this->hasCache($collectionKey)) {
         $rules = Mage::getResourceModel('rewardpointsrule/earning_catalog_collection')->setAvailableFilter($customerGroupId, $websiteId, $date);
         foreach ($rules as $rule) {
             $rule->afterLoad();
         }
         $this->saveCache($collectionKey, $rules);
     } else {
         $rules = $this->getCache($collectionKey);
     }
     if ($item->getHasChildren() && $item->isChildrenCalculated()) {
         $price = 0;
         $profit = 0;
         foreach ($item->getChildren() as $child) {
             $price += $child->getQty() * $child->getBasePrice();
             $profit += $child->getQty() * ($child->getBasePrice() - $child->getBaseCost());
         }
     } else {
         $price = $item->getBasePrice();
         if (!$price && $item->getPrice()) {
             $price = $item->getPrice() / Mage::app()->getStore($item->getStoreId())->convertPrice(1);
         }
         $profit = $price - $item->getBaseCost();
     }
     foreach ($rules as $rule) {
         if ($rule->validate($product)) {
             $points += $this->calcCatalogPoint($rule->getSimpleAction(), $rule->getPointsEarned(), $price, $profit, $rule->getMoneyStep(), $rule->getMaxPointsEarned());
             if ($rule->getStopRulesProcessing()) {
                 break;
             }
         }
     }
     $this->saveCache($cacheKey, $points * $item->getQty());
     return $this->getCache($cacheKey);
 }