Ejemplo n.º 1
0
 /**
  * Send order to MailChimp
  *
  * @param Mage_Sales_Model_Order $order
  * @return bool|array
  */
 public function logSale($order)
 {
     $this->_order = $order;
     $api = Mage::getSingleton('monkey/api', array('store' => $this->_order->getStoreId()));
     if (!$api) {
         return false;
     }
     $subtotal = $this->_order->getSubtotal();
     $discount = (double) $this->_order->getDiscountAmount();
     if ($discount != 0) {
         $subtotal = $subtotal + $discount;
     }
     $this->_info = array('id' => $this->_order->getIncrementId(), 'total' => $subtotal, 'shipping' => $this->_order->getShippingAmount(), 'tax' => $this->_order->getTaxAmount(), 'store_id' => $this->_order->getStoreId(), 'store_name' => $this->_order->getStoreName(), 'plugin_id' => 1215, 'items' => array());
     $emailCookie = $this->_getEmailCookie();
     $campaignCookie = $this->_getCampaignCookie();
     $this->setItemstoSend();
     if ($emailCookie && $campaignCookie) {
         $this->_info['email_id'] = $emailCookie;
         $this->_info['campaign_id'] = $campaignCookie;
         //Send order to MailChimp
         $rs = $api->campaignEcommOrderAdd($this->_info);
     } else {
         $this->_info['email'] = $this->_order->getCustomerEmail();
         $rs = $api->ecommOrderAdd($this->_info);
     }
     if ($rs === TRUE) {
         $this->_logCall();
         return true;
     } else {
         return $rs;
     }
 }
Ejemplo n.º 2
0
 /**
  * @return array
  */
 protected function _prepareOrderData()
 {
     // magento 1.5 compat
     $shipping_method_c = $this->_order->getShippingMethod(true);
     $shipping_method = $this->_order->getData('shipping_method');
     $shipping_method_code = $shipping_method_c ? $shipping_method_c->getData('carrier_code') : $shipping_method;
     $data = array_filter(array('currency_code' => $this->_order->getOrderCurrencyCode(), 'shipping_method_code' => $shipping_method_code, 'shipping_method_title' => $this->_order->getShippingDescription(), 'created_on' => $this->_order->getCreatedAt(), 'updated_on' => $this->_order->getUpdatedAt(), 'state' => $this->_order->getState(), 'status' => $this->_order->getStatus(), 'is_gift' => $this->_order->getGiftMessageId() != null, 'ref_quote_id' => $this->_order->getQuoteId(), 'order_subtotal_with_tax' => $this->_order->getSubtotalInclTax(), 'order_subtotal' => $this->_order->getSubtotal(), 'order_tax' => $this->_order->getTaxAmount(), 'order_hidden_tax' => $this->_order->getHiddenTaxAmount(), 'order_shipping_with_tax' => $this->_order->getShippingInclTax(), 'order_shipping' => $this->_order->getShippingAmount(), 'order_discount' => $this->_order->getDiscountAmount(), 'order_shipping_discount' => $this->_order->getShippingDiscountAmount(), 'order_total' => $this->_order->getGrandTotal(), 'order_total_items' => $this->_order->getTotalItemCount()));
     return $data;
 }
Ejemplo n.º 3
0
 /**
  * @param Varien_Event_Observer $observer
  *
  * @return $this
  */
 public function buckaroo3extended_request_addcustomvars(Varien_Event_Observer $observer)
 {
     if ($this->_isChosenMethod($observer) === false) {
         return $this;
     }
     $request = $observer->getRequest();
     $this->_billingInfo = $request->getBillingInfo();
     $this->_order = $request->getOrder();
     $vars = $request->getVars();
     if (Mage::getStoreConfig('buckaroo/buckaroo3extended_' . $this->_method . '/use_creditmanagement', Mage::app()->getStore()->getStoreId())) {
         $this->_addCustomerVariables($vars);
         $this->_addCreditManagement($vars);
         $this->_addAdditionalCreditManagementVariables($vars);
     }
     $shippingCosts = round($this->_order->getBaseShippingInclTax(), 2);
     $discount = null;
     if (Mage::helper('buckaroo3extended')->isEnterprise()) {
         if ((double) $this->_order->getGiftCardsAmount() > 0) {
             $discount = (double) $this->_order->getGiftCardsAmount();
         }
     }
     if (abs((double) $this->_order->getDiscountAmount()) > 0) {
         $discount += abs((double) $this->_order->getDiscountAmount());
     }
     $array = array('Discount' => $discount, 'ShippingCosts' => $shippingCosts, 'ShippingSuppression' => 'TRUE');
     $products = $this->_order->getAllItems();
     $group = array();
     foreach ($products as $item) {
         /** @var Mage_Sales_Model_Order_Item $item */
         if (empty($item) || $item->hasParentItemId()) {
             continue;
         }
         // Changed calculation from unitPrice to orderLinePrice due to impossible to recalculate unitprice,
         // because of differences in outcome between TAX settings: Unit, OrderLine and Total.
         // Quantity will always be 1 and quantity ordered will be in the article description.
         $productPrice = $item->getBasePrice() * $item->getQtyOrdered() + $item->getBaseTaxAmount() + $item->getBaseHiddenTaxAmount();
         $productPrice = round($productPrice, 2);
         $article['ArticleDescription']['value'] = (int) $item->getQtyOrdered() . 'x ' . $item->getName();
         $article['ArticleQuantity']['value'] = 1;
         $article['ArticleUnitPrice']['value'] = (string) $productPrice;
         $group[] = $article;
     }
     $paymentFeeArray = $this->_getPaymentFeeLine();
     if (false !== $paymentFeeArray && is_array($paymentFeeArray)) {
         $group[] = $paymentFeeArray;
     }
     $array['Articles'] = $group;
     if (array_key_exists('customVars', $vars) && array_key_exists($this->_method, $vars['customVars']) && is_array($vars['customVars'][$this->_method])) {
         $vars['customVars'][$this->_method] = array_merge($vars['customVars'][$this->_method], $array);
     } else {
         $vars['customVars'][$this->_method] = $array;
     }
     $request->setVars($vars);
     return $this;
 }
Ejemplo n.º 4
0
 /**
  * (re)Render all items and totals
  */
 protected function _render()
 {
     if (!$this->_shouldRender) {
         return;
     }
     // regular items from the sales entity
     $this->_items = array();
     foreach ($this->_salesEntity->getAllItems() as $item) {
         if (!$item->getParentItem()) {
             $this->_addRegularItem($item);
         }
     }
     end($this->_items);
     $lastRegularItemKey = key($this->_items);
     // regular totals
     $shippingDescription = '';
     if ($this->_salesEntity instanceof Mage_Sales_Model_Order) {
         $shippingDescription = $this->_salesEntity->getShippingDescription();
         $this->_totals = array(self::TOTAL_SUBTOTAL => $this->_salesEntity->getSubtotal(), self::TOTAL_TAX => $this->_salesEntity->getTaxAmount(), self::TOTAL_SHIPPING => $this->_salesEntity->getShippingAmount(), self::TOTAL_DISCOUNT => abs($this->_salesEntity->getDiscountAmount()));
         $this->_applyHiddenTaxWorkaround($this->_salesEntity);
     } else {
         $address = $this->_salesEntity->getIsVirtual() ? $this->_salesEntity->getBillingAddress() : $this->_salesEntity->getShippingAddress();
         $shippingDescription = $address->getShippingDescription();
         $this->_totals = array(self::TOTAL_SUBTOTAL => $this->_salesEntity->getSubtotal(), self::TOTAL_TAX => $address->getTaxAmount(), self::TOTAL_SHIPPING => $address->getShippingAmount(), self::TOTAL_DISCOUNT => abs($address->getDiscountAmount()));
         $this->_applyHiddenTaxWorkaround($address);
     }
     $originalDiscount = $this->_totals[self::TOTAL_DISCOUNT];
     // arbitrary items, total modifications
     Mage::dispatchEvent('paypal_prepare_line_items', array('paypal_cart' => $this));
     // distinguish original discount among the others
     if ($originalDiscount > 0.0001 && isset($this->_totalLineItemDescriptions[self::TOTAL_DISCOUNT])) {
         $this->_totalLineItemDescriptions[self::TOTAL_DISCOUNT][] = Mage::helper('sales')->__('Discount (%s)', Mage::app()->getStore()->convertPrice($originalDiscount, true, false));
     }
     // discount, shipping as items
     if ($this->_isDiscountAsItem && $this->_totals[self::TOTAL_DISCOUNT]) {
         $this->addItem(Mage::helper('paypal')->__('Discount'), 1, -1.0 * $this->_totals[self::TOTAL_DISCOUNT], $this->_renderTotalLineItemDescriptions(self::TOTAL_DISCOUNT));
     }
     $shippingItemId = $this->_renderTotalLineItemDescriptions(self::TOTAL_SHIPPING, $shippingDescription);
     if ($this->_isShippingAsItem && (double) $this->_totals[self::TOTAL_SHIPPING]) {
         $this->addItem(Mage::helper('paypal')->__('Shipping'), 1, (double) $this->_totals[self::TOTAL_SHIPPING], $shippingItemId);
     }
     $this->_validate();
     // if cart items are invalid, prepare cart for transfer without line items
     if (!$this->_areItemsValid) {
         $this->removeItem($shippingItemId);
     }
     // compound non-regular items into subtotal
     foreach ($this->_items as $key => $item) {
         if ($key > $lastRegularItemKey && $item->getAmount() != 0) {
             $this->_totals[self::TOTAL_SUBTOTAL] += $item->getAmount();
         }
     }
     $this->_shouldRender = false;
 }
Ejemplo n.º 5
0
 public static function crateFromOrder(Mage_Sales_Model_Order $order)
 {
     $aOrder = new self();
     $aOrder->id = $order->getIncrementId();
     $aOrder->currency = $order->getOrderCurrencyCode();
     $aOrder->total_amount = Aplazame_Sdk_Serializer_Decimal::fromFloat($order->getTotalDue());
     $aOrder->articles = array_map(array('Aplazame_Aplazame_BusinessModel_Article', 'crateFromOrderItem'), $order->getAllVisibleItems());
     if (($discounts = $order->getDiscountAmount()) !== null) {
         $aOrder->discount = Aplazame_Sdk_Serializer_Decimal::fromFloat(-$discounts);
     }
     return $aOrder;
 }
 /** Send order to MailChimp Automatically by Order Status
  *
  *
  */
 public function autoExportJobs()
 {
     $allow_sent = false;
     $orderIds[] = '0';
     $ecommerceOrders = Mage::getModel('monkey/ecommerce')->getCollection()->getData();
     if ($ecommerceOrders) {
         foreach ($ecommerceOrders as $ecommerceOrder) {
             $orderIds[] = $ecommerceOrder['order_id'];
         }
     }
     $orders = Mage::getResourceModel('sales/order_collection');
     //Get ALL orders which has not been sent to MailChimp
     $orders->getSelect()->where('main_table.entity_id NOT IN(?)', $orderIds);
     //Get status options selected in the Configuration
     $states = explode(',', Mage::helper('monkey')->config('order_status'));
     foreach ($orders as $order) {
         foreach ($states as $state) {
             if ($order->getStatus() == $state || $state == 'all_status') {
                 $allow_sent = true;
             }
         }
         if ($allow_sent == true) {
             $this->_order = $order;
             $api = Mage::getSingleton('monkey/api', array('store' => $this->_order->getStoreId()));
             if (!$api) {
                 return false;
             }
             $subtotal = $this->_order->getSubtotal();
             $discount = (double) $this->_order->getDiscountAmount();
             if ($discount != 0) {
                 $subtotal = $subtotal + $discount;
             }
             $this->_info = array('id' => $this->_order->getIncrementId(), 'total' => $subtotal, 'shipping' => $this->_order->getShippingAmount(), 'tax' => $this->_order->getTaxAmount(), 'store_id' => $this->_order->getStoreId(), 'store_name' => $this->_order->getStoreName(), 'plugin_id' => 1215, 'items' => array());
             $email = $this->_order->getCustomerEmail();
             $campaign = $this->_order->getEbizmartsMagemonkeyCampaignId();
             $this->setItemstoSend();
             if ($email && $campaign) {
                 $this->_info['email_id'] = $email;
                 $this->_info['campaign_id'] = $campaign;
                 //Send order to MailChimp
                 $rs = $api->campaignEcommOrderAdd($this->_info);
             } else {
                 $this->_info['email'] = $email;
                 $rs = $api->ecommOrderAdd($this->_info);
             }
             $allow_sent = false;
             if ($rs === TRUE) {
                 $this->_logCall();
             }
         }
     }
 }
Ejemplo n.º 7
0
 /**
  * Add PayEx Single Order Line
  * @param string $orderRef
  * @param Mage_Sales_Model_Order $order
  * @return bool
  */
 public function addOrderLine($orderRef, $order)
 {
     // add Order Items
     $items = $order->getAllVisibleItems();
     $i = 1;
     /** @var $item Mage_Sales_Model_Order_Item */
     foreach ($items as $item) {
         // @todo Calculate prices using Discount Rules
         // @todo Get children products from bundle
         //if (!$item->getNoDiscount()) {
         //    Mage::helper('payexautopay/tools')->addToDebug('Warning: The product has a discount. There might be problems.', $order->getIncrementId());
         //}
         $itemQty = (int) $item->getQtyOrdered();
         //$taxPrice = $item->getTaxAmount();
         $taxPrice = $itemQty * $item->getPriceInclTax() - $itemQty * $item->getPrice();
         $taxPercent = $item->getTaxPercent();
         $priceWithTax = $itemQty * $item->getPriceInclTax();
         // Calculate tax percent for Bundle products
         if ($item->getProductType() === Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
             $taxPercent = $taxPrice > 0 ? round(100 / (($priceWithTax - $taxPrice) / $taxPrice)) : 0;
         }
         $params = array('accountNumber' => '', 'orderRef' => $orderRef, 'itemNumber' => $i, 'itemDescription1' => $item->getName(), 'itemDescription2' => '', 'itemDescription3' => '', 'itemDescription4' => '', 'itemDescription5' => '', 'quantity' => $itemQty, 'amount' => (int) (100 * $priceWithTax), 'vatPrice' => (int) (100 * $taxPrice), 'vatPercent' => (int) (100 * $taxPercent));
         $result = Mage::helper('payexautopay/api')->getPx()->AddSingleOrderLine2($params);
         Mage::helper('payexautopay/tools')->debugApi($result, 'PxOrder.AddSingleOrderLine2');
         $i++;
     }
     // add Shipping
     if (!$order->getIsVirtual()) {
         $shipping = $order->getShippingAmount();
         $shippingIncTax = $order->getShippingInclTax();
         $shippingTax = $order->getShippingTaxAmount();
         $params = array('accountNumber' => '', 'orderRef' => $orderRef, 'itemNumber' => $i, 'itemDescription1' => $order->getShippingDescription(), 'itemDescription2' => '', 'itemDescription3' => '', 'itemDescription4' => '', 'itemDescription5' => '', 'quantity' => 1, 'amount' => (int) (100 * $shippingIncTax), 'vatPrice' => (int) (100 * $shippingTax), 'vatPercent' => $shipping != 0 ? round(100 * 100 * $shippingTax / $shipping) : 0);
         $result = Mage::helper('payexautopay/api')->getPx()->AddSingleOrderLine2($params);
         Mage::helper('payexautopay/tools')->debugApi($result, 'PxOrder.AddSingleOrderLine2');
         $i++;
     }
     // add Discount
     $discount = $order->getDiscountAmount() + $order->getShippingDiscountAmount();
     if (abs($discount) > 0) {
         $params = array('accountNumber' => '', 'orderRef' => $orderRef, 'itemNumber' => $i, 'itemDescription1' => $order->getDiscountDescription() !== null ? Mage::helper('sales')->__('Discount (%s)', $order->getDiscountDescription()) : Mage::helper('sales')->__('Discount'), 'itemDescription2' => '', 'itemDescription3' => '', 'itemDescription4' => '', 'itemDescription5' => '', 'quantity' => 1, 'amount' => (int) (100 * $discount), 'vatPrice' => 0, 'vatPercent' => 0);
         $result = Mage::helper('payexautopay/api')->getPx()->AddSingleOrderLine2($params);
         Mage::helper('payexautopay/tools')->debugApi($result, 'PxOrder.AddSingleOrderLine2');
         $i++;
     }
     // Add reward points
     if ((double) $order->getBaseRewardCurrencyAmount() > 0) {
         $params = array('accountNumber' => '', 'orderRef' => $orderRef, 'itemNumber' => $i, 'itemDescription1' => Mage::helper('payexautopay')->__('Reward points'), 'itemDescription2' => '', 'itemDescription3' => '', 'itemDescription4' => '', 'itemDescription5' => '', 'quantity' => 1, 'amount' => -1 * (int) (100 * $order->getBaseRewardCurrencyAmount()), 'vatPrice' => 0, 'vatPercent' => 0);
         $result = Mage::helper('payexautopay/api')->getPx()->AddSingleOrderLine2($params);
         Mage::helper('payexautopay/tools')->debugApi($result, 'PxOrder.AddSingleOrderLine2');
         $i++;
     }
     return true;
 }
Ejemplo n.º 8
0
 /**
  * @param Mage_Sales_Model_Order $order
  *
  * @return array
  */
 public function buildPlanItemsForSubscription($order)
 {
     $list = [];
     $orderItems = $order->getItemsCollection();
     $orderSubtotal = $order->getQuote()->getSubtotal();
     $orderDiscount = $order->getDiscountAmount() * -1;
     $discount = null;
     if (!empty($orderDiscount)) {
         $discountPercentage = $orderDiscount * 100 / $orderSubtotal;
         $discountPercentage = number_format(floor($discountPercentage * 100) / 100, 2);
         $discount = [['discount_type' => 'percentage', 'percentage' => $discountPercentage]];
     }
     foreach ($orderItems as $item) {
         $product = Mage::getModel('catalog/product')->load($item->getProductId());
         if ($product->getTypeID() !== 'subscription') {
             Mage::throwException("O produto {$item->getName()} não é uma assinatura.");
             return false;
         }
         $productVindiId = $this->findOrCreateProduct(array('sku' => $item->getSku(), 'name' => $item->getName()));
         for ($i = 1; $i <= $item->getQtyOrdered(); $i++) {
             $list[] = ['product_id' => $productVindiId, 'pricing_schema' => ['price' => $item->getPrice()], 'discounts' => $discount];
         }
     }
     // Create product for shipping
     $productVindiId = $this->findOrCreateProduct(array('sku' => 'frete', 'name' => 'Frete'));
     $list[] = ['product_id' => $productVindiId, 'pricing_schema' => ['price' => $order->getShippingAmount()]];
     return $list;
 }
Ejemplo n.º 9
0
 /**
  * @param Mage_Sales_Model_Order $order
  * @return array
  */
 protected function _getCouponsFormatted($order)
 {
     $result = array();
     if ($order->getCouponCode()) {
         if (Mage::helper("shopgate/config")->getIsMagentoVersionLower1410()) {
             $mageRule = Mage::getModel('salesrule/rule')->load($order->getCouponCode(), 'coupon_code');
             $mageCoupon = $mageRule;
         } else {
             $mageCoupon = Mage::getModel('salesrule/coupon')->load($order->getCouponCode(), 'code');
             $mageRule = Mage::getModel('salesrule/rule')->load($mageCoupon->getRuleId());
         }
         $externalCoupon = new ShopgateExternalCoupon();
         $couponInfo = array();
         $couponInfo["coupon_id"] = $mageCoupon->getId();
         $couponInfo["rule_id"] = $mageRule->getId();
         $externalCoupon->setCode($order->getCouponCode());
         $externalCoupon->setCurrency($order->getOrderCurrencyCode());
         $externalCoupon->setName($mageRule->getName());
         $externalCoupon->setDescription($mageRule->getDescription());
         $externalCoupon->setInternalInfo($this->_getConfig()->jsonEncode($couponInfo));
         $externalCoupon->setAmount($order->getDiscountAmount());
         array_push($result, $externalCoupon);
     }
     return $result;
 }
Ejemplo n.º 10
0
 /**
  * Convert order to shipping address
  *
  * @param   Mage_Sales_Model_Order $order
  * @return  Mage_Sales_Model_Quote_Address
  */
 public function toQuoteShippingAddress(Mage_Sales_Model_Order $order)
 {
     $address = $this->addressToQuoteAddress($order->getShippingAddress());
     $address->setWeight($order->getWeight())->setShippingMethod($order->getShippingMethod())->setShippingDescription($order->getShippingDescription())->setShippingRate($order->getShippingRate())->setSubtotal($order->getSubtotal())->setTaxAmount($order->getTaxAmount())->setDiscountAmount($order->getDiscountAmount())->setShippingAmount($order->getShippingAmount())->setGiftcertAmount($order->getGiftcertAmount())->setCustbalanceAmount($order->getCustbalanceAmount())->setGrandTotal($order->getGrandTotal())->setBaseSubtotal($order->getBaseSubtotal())->setBaseTaxAmount($order->getBaseTaxAmount())->setBaseDiscountAmount($order->getBaseDiscountAmount())->setBaseShippingAmount($order->getBaseShippingAmount())->setBaseGiftcertAmount($order->getBaseGiftcertAmount())->setBaseCustbalanceAmount($order->getBaseCustbalanceAmount())->setBaseGrandTotal($order->getBaseGrandTotal());
     return $address;
 }
 /**
  * Calculates the "Exta" value that corresponds to Tax values minus Discount given
  * It makes the correct discount to be shown correctly on PagSeguro
  * @param Mage_Sales_Model_Order $order
  *
  * @return float
  */
 public function getExtraAmount($order)
 {
     $discount = $order->getDiscountAmount();
     $taxAmount = $order->getTaxAmount();
     $extra = $discount + $taxAmount;
     if ($this->_shouldSplit($order)) {
         $extra = $extra + 0.01;
     }
     return number_format($extra, 2, '.', '');
 }
 /**
  * Calcula o valor "Extra", que será o valor das Taxas subtraído do valor dos impostos
  * @param Mage_Sales_Model_Order $order
  *
  * @return string
  */
 public function getExtraAmount($order)
 {
     $discount = $order->getDiscountAmount();
     $tax_amount = $order->getTaxAmount();
     $extra = $discount + $tax_amount;
     return number_format($extra, 2, '.', '');
 }
Ejemplo n.º 13
0
 /**
  * Generate Invoice Print XML
  * @param Mage_Sales_Model_Order $order
  * @return mixed
  */
 public function getInvoiceExtraPrintBlocksXML($order)
 {
     $dom = new DOMDocument('1.0', 'utf-8');
     $OnlineInvoice = $dom->createElement('OnlineInvoice');
     $dom->appendChild($OnlineInvoice);
     $OnlineInvoice->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
     $OnlineInvoice->setAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'xsd', 'http://www.w3.org/2001/XMLSchema');
     $OrderLines = $dom->createElement('OrderLines');
     $OnlineInvoice->appendChild($OrderLines);
     // Add Order Lines
     $items = $order->getAllVisibleItems();
     /** @var $item Mage_Sales_Model_Order_Item */
     foreach ($items as $item) {
         // @todo Calculate prices using Discount Rules
         // @todo Get children products from bundle
         //if (!$item->getNoDiscount()) {
         //    Mage::helper('partpayment/tools')->addToDebug('Warning: The product has a discount. There might be problems.', $order->getIncrementId());
         //}
         $itemQty = (int) $item->getQtyOrdered();
         //$taxPrice = $item->getTaxAmount();
         $taxPrice = $itemQty * $item->getPriceInclTax() - $itemQty * $item->getPrice();
         $taxPercent = $item->getTaxPercent();
         $priceWithTax = $itemQty * $item->getPriceInclTax();
         // Calculate tax percent for Bundle products
         if ($item->getProductType() === Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
             $taxPercent = $taxPrice > 0 ? round(100 / (($priceWithTax - $taxPrice) / $taxPrice)) : 0;
         }
         $OrderLine = $dom->createElement('OrderLine');
         $OrderLine->appendChild($dom->createElement('Product', $item->getName()));
         $OrderLine->appendChild($dom->createElement('Qty', $itemQty));
         $OrderLine->appendChild($dom->createElement('UnitPrice', sprintf("%.2f", $item->getPrice())));
         $OrderLine->appendChild($dom->createElement('VatRate', sprintf("%.2f", $taxPercent)));
         $OrderLine->appendChild($dom->createElement('VatAmount', sprintf("%.2f", $taxPrice)));
         $OrderLine->appendChild($dom->createElement('Amount', sprintf("%.2f", $priceWithTax)));
         $OrderLines->appendChild($OrderLine);
     }
     // Add Shipping Line
     if (!$order->getIsVirtual()) {
         $shipping = $order->getShippingAmount();
         //$shippingIncTax = $order->getShippingInclTax();
         $shippingTax = $order->getShippingTaxAmount();
         $shippingTaxPercent = $shipping != 0 ? (int) (100 * $shippingTax / $shipping) : 0;
         $OrderLine = $dom->createElement('OrderLine');
         $OrderLine->appendChild($dom->createElement('Product', $order->getShippingDescription()));
         $OrderLine->appendChild($dom->createElement('Qty', 1));
         $OrderLine->appendChild($dom->createElement('UnitPrice', sprintf("%.2f", $shipping)));
         $OrderLine->appendChild($dom->createElement('VatRate', sprintf("%.2f", $shippingTaxPercent)));
         $OrderLine->appendChild($dom->createElement('VatAmount', sprintf("%.2f", $shippingTax)));
         $OrderLine->appendChild($dom->createElement('Amount', sprintf("%.2f", $shipping + $shippingTax)));
         $OrderLines->appendChild($OrderLine);
     }
     // add Payment Fee
     $fee = $order->getPartpaymentPaymentFee();
     if ($fee > 0) {
         $OrderLine = $dom->createElement('OrderLine');
         $OrderLine->appendChild($dom->createElement('Product', Mage::helper('partpayment')->__('Payment fee')));
         $OrderLine->appendChild($dom->createElement('Qty', 1));
         $OrderLine->appendChild($dom->createElement('UnitPrice', sprintf("%.2f", $fee)));
         $OrderLine->appendChild($dom->createElement('VatRate', 0));
         $OrderLine->appendChild($dom->createElement('VatAmount', 0));
         $OrderLine->appendChild($dom->createElement('Amount', sprintf("%.2f", $fee)));
         $OrderLines->appendChild($OrderLine);
     }
     // add Discount
     $discount = $order->getDiscountAmount() + $order->getShippingDiscountAmount();
     if (abs($discount) > 0) {
         $discount_description = $order->getDiscountDescription() !== null ? Mage::helper('sales')->__('Discount (%s)', $order->getDiscountDescription()) : Mage::helper('sales')->__('Discount');
         $OrderLine = $dom->createElement('OrderLine');
         $OrderLine->appendChild($dom->createElement('Product', $discount_description));
         $OrderLine->appendChild($dom->createElement('Qty', 1));
         $OrderLine->appendChild($dom->createElement('UnitPrice', sprintf("%.2f", $discount)));
         $OrderLine->appendChild($dom->createElement('VatRate', 0));
         $OrderLine->appendChild($dom->createElement('VatAmount', 0));
         $OrderLine->appendChild($dom->createElement('Amount', sprintf("%.2f", $discount)));
         $OrderLines->appendChild($OrderLine);
     }
     // Add reward points
     if ((double) $order->getBaseRewardCurrencyAmount() > 0) {
         $OrderLine = $dom->createElement('OrderLine');
         $OrderLine->appendChild($dom->createElement('Product', Mage::helper('partpayment')->__('Reward points')));
         $OrderLine->appendChild($dom->createElement('Qty', 1));
         $OrderLine->appendChild($dom->createElement('UnitPrice', -1 * $order->getBaseRewardCurrencyAmount()));
         $OrderLine->appendChild($dom->createElement('VatRate', 0));
         $OrderLine->appendChild($dom->createElement('VatAmount', 0));
         $OrderLine->appendChild($dom->createElement('Amount', -1 * $order->getBaseRewardCurrencyAmount()));
         $OrderLines->appendChild($OrderLine);
     }
     return str_replace("\n", '', $dom->saveXML());
 }