public function taxrulesAction() { $this->_authenticate(); $ruleNodes = ''; /* $collection = Mage::getModel('tax/calculation_rule')->getCollection(); foreach($collection as $item) { $node = array('taxRule' => array( 'taxRuleID' => $item->getData('tax_calculation_rule_id'), 'description' => $item->getData('code'), )); $ruleNodes .= Vikont_EVOConnector_Helper_Data::array2xml($node); } /**/ foreach (Vikont_EVOConnector_Model_Source_Taxrules::getTaxRules() as $ruleId => $ruleName) { $node = array('taxRule' => array('taxRuleID' => $ruleId, 'description' => $ruleName)); $ruleNodes .= Vikont_EVOConnector_Helper_Data::array2xml($node); } $result = str_replace('%tax_nodes%', CR . $ruleNodes, Vikont_EVOConnector_Helper_Data::array2xml(array('taxRules' => '%tax_nodes%'))); Vikont_EVOConnector_Helper_Data::sendResponse($result); }
public function testAction() { Vikont_EVOConnector_Helper_Data::sendResponse(Vikont_EVOConnector_Helper_Data::array2xml(array('root' => array('a' => 'b', 'spec' => '<&">', 'rus' => 'ёпрст')))); }
public function getOustandingActivity() { $globalXML = Vikont_EVOConnector_Helper_Data::array2xml(array('outstandingActivityResponse' => array('orders' => '%order_nodes%', 'cancellations' => '%cancellation_nodes%'))); // filling up the <orders> node $orderNodesXML = ''; $ordersCollection = Mage::getModel('sales/order')->getCollection(); $orderId = (string) Mage::app()->getRequest()->getParam('order'); if ($orderId) { $ordersCollection->addFieldToFilter('increment_id', array('eq' => $orderId)); } else { $ordersCollection->addFieldToFilter(Vikont_EVOConnector_Helper_Data::ORDER_EVO_STATUS_FIELD, array('eq' => Vikont_EVOConnector_Helper_Data::ORDER_EVO_STATUS_NEW)); } foreach ($ordersCollection as $order) { $customerIsWholesale = $this->_isCustomerWholesale($order); // initializing global variable; dirty but cheap // order comment //Related Skus: PU: 1112332 WP: 222552 //Customer Comment: some comment here //Warehouse: Tucker Rocky - Warehouse 5 //Customer Type: Retail $commentsXML = self::$_commentsXMLTemplate; $commentsXML = str_replace('%skus%', implode("\n", $orderCommentInfo), $commentsXML); $commentsXML = str_replace('%customer_comment%', implode(',' . CR, $this->_getOrderComments($order)), $commentsXML); $commentsXML = str_replace('%warehouse%', $orderCommentInfoItem['warehouse'], $commentsXML); $commentsXML = str_replace('%customer_type%', Mage::helper('evoc/customer')->getCustomerType(), $commentsXML); $payment = $order->getPaymentsCollection()->getFirstItem(); if ('purchaseorder' == $payment->getMethod()) { $commentsXML .= "\nPO Number: " . $payment->getPoNumber(); } list($carrierCode) = explode('_', $order->getData('shipping_method')); $shippingDescription = explode(' - ', $order->getData('shipping_description'), 2); $carrierMethod = isset($shippingDescription[1]) ? $shippingDescription[1] : ''; $shippingCost = $order->getData('shipping_amount'); $shippingVendor = strtoupper($carrierCode); $shippingMethod = strtoupper($carrierMethod); if ('PICKUPATSTORE' == $shippingVendor) { $shippingVendor = 'WC'; $shippingMethod = 'WC'; } else { if ($customerIsWholesale) { $shippingCost = 0; /* $shippingVendor = 'UPS'; $shippingMethod = 'GROUND'; /**/ $shippingVendor = 'DSO'; $shippingTypes = array('COMPLETE' => 'SHIP COMPLETE | ', 'PARTIAL' => 'SHIP PARTIAL | '); $shippingType = false !== strpos($commentsXML, $shippingTypes['COMPLETE']) ? 'COMPLETE' : 'PARTIAL'; $commentsXML = str_replace($shippingTypes, '', $commentsXML); // removing from comments section $shippingMethod = $shippingType; } } $taxRule = Vikont_EVOConnector_Model_Source_Taxrules::detectTaxRule($order->getShippingAddress(), $customerIsWholesale); $orderNode = array('webOrder' => array('orderID' => $order->getData('increment_id'), 'date' => Vikont_EVOConnector_Helper_Data::getDateFormatted($order->getData('created_at')) . '.000', 'shippingCost' => $shippingCost, 'shippingVendor' => $shippingVendor, 'shippingMethod' => $shippingMethod, 'comment' => $commentsXML, 'taxRuleID' => $taxRule['id'], 'taxAmount' => sprintf('%.2f', $order->getData('tax_amount')), 'customers' => '%customers%', 'payments' => '%payments%', 'orderItems' => '%order_items%')); $orderNodeXML = Vikont_EVOConnector_Helper_Data::array2xml($orderNode); // billing address $billingAddress = $order->getBillingAddress(); $billingAddress['address_type'] = 'BILLING'; // shipping address $shippingAddress = $order->getShippingAddress(); $shippingAddress['address_type'] = 'SHIPPING'; // fixing Paypal caused issue if (!$shippingAddress->getLastname()) { $shippingAddress->setLastname($billingAddress->getLastname()); $shippingAddress->setFirstname($billingAddress->getFirstname()); } $billingAddressXML = Vikont_EVOConnector_Helper_Data::array2xml($this->_getCustomerNode($billingAddress, 'billing')); $shippingAddressXML = Vikont_EVOConnector_Helper_Data::array2xml($this->_getCustomerNode($shippingAddress, 'shipping')); $orderNodeXML = str_replace('%customers%', CR . $billingAddressXML . $shippingAddressXML, $orderNodeXML); // order items $orderItemNodesXML = ''; $orderCommentInfo = array(); // to be put to the order's <comment> node $orderCommentInfoItem['warehouse'] = ''; // TODO !!! foreach ($order->getAllVisibleItems() as $itemNumber => $orderItem) { $orderItem->setData('item_number', $itemNumber); $orderItemNode = $this->_getOrderItemNode($orderItem); if ($orderItemNode['orderItem']['comment']) { // $orderCommentInfoItem['warehouse'] = ''; // TODO !!! if (in_array($orderItemNode['orderItem']['manufacturerID'], array('TR', 'WP', 'PU'))) { $orderCommentInfo[] = sprintf("Part numbers for %s \n SKU = %s: %s", $orderItem->getData('name'), $orderItem->getData('sku'), $orderItemNode['orderItem']['comment']); } else { $orderCommentInfo[] = sprintf('Part numbers for SKU = %s: %s', $orderItem->getData('sku'), $orderItemNode['orderItem']['comment']); } } unset($orderItemNode['orderItem']['comment']); $orderItemNodesXML .= Vikont_EVOConnector_Helper_Data::array2xml($orderItemNode); } $orderNodeXML = str_replace('%order_items%', CR . $orderItemNodesXML, $orderNodeXML); // payments section $paymentsXML = ''; foreach ($order->getPaymentsCollection() as $payment) { @(list($paymentType) = explode('_', $payment->getMethod())); $paymentType = strtoupper($paymentType); switch ($paymentType) { case 'PURCHASEORDER': $paymentType = 'OTHER'; break; case 'CCSAVE': case 'HPS': $paymentType = 'VISA'; break; } $paymentsXML .= Vikont_EVOConnector_Helper_Data::array2xml(array('payment' => array('type' => $paymentType, 'amount' => sprintf('%.2f', $payment->getData('amount_ordered'))))); } $orderNodeXML = str_replace('%payments%', CR . $paymentsXML, $orderNodeXML); // and finally adding order node XML to the nodes list $orderNodesXML .= CR . $orderNodeXML; } $globalXML = str_replace('%order_nodes%', $orderNodesXML, $globalXML); // filling up the <cancellations> node $cancellationNodesXML = ''; $globalXML = str_replace('%cancellation_nodes%', $cancellationNodesXML, $globalXML); return $globalXML; }