Adventos_OrderExport - Version 1.0.1

Version Notes

generate XML-File with Orderdetails in var/export/SalesOrder_*.xml

Download this release

Release Info

Developer Karsten Hoffmann
Extension Adventos_OrderExport
Version 1.0.1
Comparing to
See all releases


Version 1.0.1

app/code/local/Adventos/OrderExport/Helper/Data.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Adventos_OrderExport_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+
6
+ }
app/code/local/Adventos/OrderExport/Model/Creditmemo/Api.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+ class Adventos_OrderExport_Model_Creditmemo_Api extends Mage_Api_Model_Resource_Abstract
3
+ {
4
+
5
+ }
6
+ ?>
app/code/local/Adventos/OrderExport/Model/Creditmemo/Api/V2.php ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Adventos_OrderExport_Model_Creditmemo_Api_V2 extends Adventos_OrderExport_Model_Creditmemo_Api
3
+ {
4
+
5
+ /**
6
+ * Initialize attributes' mapping
7
+ */
8
+ public function __construct()
9
+ {
10
+ $this->_attributesMap['creditmemo'] = array(
11
+ 'creditmemo_id' => 'entity_id'
12
+ );
13
+ $this->_attributesMap['creditmemo_item'] = array(
14
+ 'item_id' => 'entity_id'
15
+ );
16
+ $this->_attributesMap['creditmemo_comment'] = array(
17
+ 'comment_id' => 'entity_id'
18
+ );
19
+ }
20
+
21
+ /**
22
+ * Retrieve credit memos by filters
23
+ *
24
+ * @param array|null $filter
25
+ * @return array
26
+ */
27
+ public function items($filter = null)
28
+ {
29
+ $filter = $this->_prepareListFilter($filter);
30
+ try {
31
+ $result = array();
32
+ /** @var $creditmemoModel Mage_Sales_Model_Order_Creditmemo */
33
+ $creditmemoModel = Mage::getModel('sales/order_creditmemo');
34
+ // map field name entity_id to creditmemo_id
35
+ foreach ($creditmemoModel->getFilteredCollectionItems($filter) as $creditmemo) {
36
+ $result[] = $this->_getAttributes($creditmemo, 'creditmemo');
37
+ }
38
+ } catch (Exception $e) {
39
+ $this->_fault('invalid_filter', $e->getMessage());
40
+ }
41
+ return $result;
42
+ }
43
+
44
+ /**
45
+ * Prepare filters
46
+ *
47
+ * @param null|object $filters
48
+ * @return array
49
+ */
50
+ protected function _prepareListFilter($filters = null)
51
+ {
52
+ $preparedFilters = array();
53
+ $helper = Mage::helper('api');
54
+ if (isset($filters->filter)) {
55
+ $helper->associativeArrayUnpack($filters->filter);
56
+ $preparedFilters += $filters->filter;
57
+ }
58
+ if (isset($filters->complex_filter)) {
59
+ $helper->associativeArrayUnpack($filters->complex_filter);
60
+ foreach ($filters->complex_filter as &$filter) {
61
+ $helper->associativeArrayUnpack($filter);
62
+ }
63
+ $preparedFilters += $filters->complex_filter;
64
+ }
65
+ foreach ($preparedFilters as $field => $value) {
66
+ if (isset($this->_attributesMap['creditmemo'][$field])) {
67
+ $preparedFilters[$this->_attributesMap['creditmemo'][$field]] = $value;
68
+ unset($preparedFilters[$field]);
69
+ }
70
+ }
71
+
72
+ return $preparedFilters;
73
+ }
74
+
75
+ /**
76
+ * Create new credit memo for order
77
+ *
78
+ * @param string $orderId
79
+ * @param array $data array('qtys' => array('sku1' => qty1, ... , 'skuN' => qtyN),
80
+ * 'shipping_amount' => value, 'adjustment_positive' => value, 'adjustment_negative' => value)
81
+ * @param string $refundToStoreCreditAmount
82
+ * @param string|null $comment
83
+ * @param bool $notifyCustomer
84
+ * @param bool $includeComment
85
+ * @param string $refundToStoreCreditAmount
86
+ * @return string $creditmemoId
87
+ */
88
+ public function create($orderId, $data = null, $creditmemoNr = null, $comment = null, $notifyCustomer = false,
89
+ $includeComment = false, $refundToStoreCreditAmount = null)
90
+ {
91
+ /** @var $order Mage_Sales_Model_Order */
92
+ $order = Mage::getModel('sales/order')->load($orderId, 'increment_id');
93
+ if (!$order->getId()) {
94
+ $this->_fault('order_not_exists');
95
+ }
96
+ if (!$order->canCreditmemo()) {
97
+ $this->_fault('cannot_create_creditmemo');
98
+ }
99
+ $data = $this->_prepareCreateData($data);
100
+
101
+ /** @var $service Mage_Sales_Model_Service_Order */
102
+ $service = Mage::getModel('sales/service_order', $order);
103
+ /** @var $creditmemo Mage_Sales_Model_Order_Creditmemo */
104
+ $creditmemo = $service->prepareCreditmemo($data);
105
+
106
+ if ($creditmemoNr !== null) {
107
+ $creditmemo->setIncrementId($creditmemoNr);
108
+ }
109
+
110
+ // refund to Store Credit
111
+ if ($refundToStoreCreditAmount) {
112
+ // check if refund to Store Credit is available
113
+ if ($order->getCustomerIsGuest()) {
114
+ $this->_fault('cannot_refund_to_storecredit');
115
+ }
116
+ $refundToStoreCreditAmount = max(
117
+ 0,
118
+ min($creditmemo->getBaseCustomerBalanceReturnMax(), $refundToStoreCreditAmount)
119
+ );
120
+ if ($refundToStoreCreditAmount) {
121
+ $refundToStoreCreditAmount = $creditmemo->getStore()->roundPrice($refundToStoreCreditAmount);
122
+ $creditmemo->setBaseCustomerBalanceTotalRefunded($refundToStoreCreditAmount);
123
+ $refundToStoreCreditAmount = $creditmemo->getStore()->roundPrice(
124
+ $refundToStoreCreditAmount*$order->getStoreToOrderRate()
125
+ );
126
+ // this field can be used by customer balance observer
127
+ $creditmemo->setBsCustomerBalTotalRefunded($refundToStoreCreditAmount);
128
+ // setting flag to make actual refund to customer balance after credit memo save
129
+ $creditmemo->setCustomerBalanceRefundFlag(true);
130
+ }
131
+ }
132
+ $creditmemo->setPaymentRefundDisallowed(true)->register();
133
+ // add comment to creditmemo
134
+ if (!empty($comment)) {
135
+ $creditmemo->addComment($comment, $notifyCustomer);
136
+ }
137
+ try {
138
+ Mage::getModel('core/resource_transaction')
139
+ ->addObject($creditmemo)
140
+ ->addObject($order)
141
+ ->save();
142
+ // send email notification
143
+ $creditmemo->sendEmail($notifyCustomer, ($includeComment ? $comment : ''));
144
+ } catch (Mage_Core_Exception $e) {
145
+ $this->_fault('data_invalid', $e->getMessage());
146
+ }
147
+ return $creditmemo->getIncrementId();
148
+ }
149
+
150
+ /**
151
+ * Prepare data
152
+ *
153
+ * @param null|object $data
154
+ * @return array
155
+ */
156
+ protected function _prepareCreateData($data)
157
+ {
158
+ // convert data object to array, if it's null turn it into empty array
159
+ $data = (isset($data) and is_object($data)) ? get_object_vars($data) : array();
160
+ // convert qtys object to array
161
+ if (isset($data['qtys']) && count($data['qtys'])) {
162
+ $qtysArray = array();
163
+ foreach ($data['qtys'] as &$item) {
164
+ if (isset($item->order_item_id) && isset($item->qty)) {
165
+ $qtysArray[$item->order_item_id] = $item->qty;
166
+ }
167
+ }
168
+ $data['qtys'] = $qtysArray;
169
+ }
170
+ return $data;
171
+ }
172
+
173
+
174
+ /**
175
+ * Load CreditMemo by IncrementId
176
+ *
177
+ * @param mixed $incrementId
178
+ * @return Mage_Core_Model_Abstract|Mage_Sales_Model_Order_Creditmemo
179
+ */
180
+ protected function _getCreditmemo($incrementId)
181
+ {
182
+ /** @var $creditmemo Mage_Sales_Model_Order_Creditmemo */
183
+ $creditmemo = Mage::getModel('sales/order_creditmemo')->load($incrementId, 'increment_id');
184
+ if (!$creditmemo->getId()) {
185
+ $this->_fault('not_exists');
186
+ }
187
+ return $creditmemo;
188
+ }
189
+ }
190
+ ?>
app/code/local/Adventos/OrderExport/Model/Invoice/Api.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+ class Adventos_OrderExport_Model_Invoice_Api extends Mage_Api_Model_Resource_Abstract
3
+ {
4
+
5
+ }
6
+ ?>
app/code/local/Adventos/OrderExport/Model/Invoice/Api/V2.php ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Adventos_OrderExport_Model_Invoice_Api_V2 extends Adventos_OrderExport_Model_Invoice_Api
3
+ {
4
+ /**
5
+ * Retrive invoices by filters
6
+ *
7
+ * @param array $filters
8
+ * @return array
9
+ */
10
+ public function items($filters = null)
11
+ {
12
+ //TODO: add full name logic
13
+ $collection = Mage::getModel('sales/order_invoice')->getCollection()
14
+ ->addAttributeToSelect('order_id')
15
+ ->addAttributeToSelect('increment_id')
16
+ ->addAttributeToSelect('created_at')
17
+ ->addAttributeToSelect('state')
18
+ ->addAttributeToSelect('grand_total')
19
+ ->addAttributeToSelect('order_currency_code')
20
+ ->joinAttribute('billing_firstname', 'order_address/firstname', 'billing_address_id', null, 'left')
21
+ ->joinAttribute('billing_lastname', 'order_address/lastname', 'billing_address_id', null, 'left')
22
+ ->joinAttribute('order_increment_id', 'order/increment_id', 'order_id', null, 'left')
23
+ ->joinAttribute('order_created_at', 'order/created_at', 'order_id', null, 'left');
24
+
25
+ $preparedFilters = array();
26
+ if (isset($filters->filter)) {
27
+ foreach ($filters->filter as $_filter) {
28
+ $preparedFilters[][$_filter->key] = $_filter->value;
29
+ }
30
+ }
31
+ if (isset($filters->complex_filter)) {
32
+ foreach ($filters->complex_filter as $_filter) {
33
+ $_value = $_filter->value;
34
+ if(is_object($_value)) {
35
+ $preparedFilters[][$_filter->key] = array(
36
+ $_value->key => $_value->value
37
+ );
38
+ } elseif(is_array($_value)) {
39
+ $preparedFilters[][$_filter->key] = array(
40
+ $_value['key'] => $_value['value']
41
+ );
42
+ } else {
43
+ $preparedFilters[][$_filter->key] = $_value;
44
+ }
45
+ }
46
+ }
47
+
48
+ if (!empty($preparedFilters)) {
49
+ try {
50
+ foreach ($preparedFilters as $preparedFilter) {
51
+ foreach ($preparedFilter as $field => $value) {
52
+ if (isset($this->_attributesMap['order'][$field])) {
53
+ $field = $this->_attributesMap['order'][$field];
54
+ }
55
+
56
+ $collection->addFieldToFilter($field, $value);
57
+ }
58
+ }
59
+ } catch (Mage_Core_Exception $e) {
60
+ $this->_fault('filters_invalid', $e->getMessage());
61
+ }
62
+ }
63
+
64
+ $result = array();
65
+
66
+ foreach ($collection as $invoice) {
67
+ $result[] = $this->_getAttributes($invoice, 'invoice');
68
+ }
69
+
70
+ return $result;
71
+ }
72
+
73
+ protected function _prepareItemQtyData($data)
74
+ {
75
+ $_data = array();
76
+ foreach ($data as $item) {
77
+ if (isset($item->order_item_id) && isset($item->qty)) {
78
+ $_data[$item->order_item_id] = $item->qty;
79
+ }
80
+ }
81
+ return $_data;
82
+ }
83
+
84
+ /* Create new invoice for order
85
+ *
86
+ * @param string $orderIncrementId
87
+ * @param array $itemsQty
88
+ * @param string $invoiceNr
89
+ * @param string $comment
90
+ * @param booleam $email
91
+ * @param boolean $includeComment
92
+ * @return string
93
+ * public function invoiceCreate($orderIncrementId, $invoiceNr, $itemsQty, $comment = null, $email = false, $includeComment = false)
94
+ */
95
+ public function create($orderIncrementId, $itemsQty, $invoiceNr = null, $comment = null, $email = false, $includeComment = false)
96
+ {
97
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
98
+ $itemsQty = $this->_prepareItemQtyData($itemsQty);
99
+ /* @var $order Mage_Sales_Model_Order */
100
+ /**
101
+ * Check order existing
102
+ */
103
+ if (!$order->getId()) {
104
+ $this->_fault('order_not_exists');
105
+ }
106
+
107
+ /**
108
+ * Check invoice create availability
109
+ */
110
+ if (!$order->canInvoice()) {
111
+ $this->_fault('data_invalid', Mage::helper('sales')->__('Cannot do invoice for order.'));
112
+ }
113
+
114
+ $invoice = $order->prepareInvoice($itemsQty);
115
+
116
+ $invoice->register();
117
+
118
+ if ($comment !== null) {
119
+ $invoice->addComment($comment, $email);
120
+ }
121
+
122
+ if ($email) {
123
+ $invoice->setEmailSent(true);
124
+ }
125
+
126
+ if ($invoiceNr !== null) {
127
+ $invoice->setIncrementId($invoiceNr);
128
+ }
129
+
130
+ $invoice->getOrder()->setIsInProcess(true);
131
+
132
+ try {
133
+ $transactionSave = Mage::getModel('core/resource_transaction')
134
+ ->addObject($invoice)
135
+ ->addObject($invoice->getOrder())
136
+ ->save();
137
+
138
+ $invoice->sendEmail($email, ($includeComment ? $comment : ''));
139
+ } catch (Mage_Core_Exception $e) {
140
+ $this->_fault('data_invalid', $e->getMessage());
141
+ }
142
+
143
+ return $invoice->getIncrementId();
144
+ }
145
+ }
146
+ ?>
app/code/local/Adventos/OrderExport/Model/Observer.php ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author ADVENTOS GmbH, Karsten Hoffmann
4
+ * Export Sales Order for Import into HOFAKT ERP
5
+ * Output as XML in var/export directory
6
+ *
7
+ * 20110722 ADD codepage conversion to CP850 because german special characters weren't imported correct to HOFAKT
8
+ * 20110916 REMOVE WebSite Selector, activate SalesOrderExport for all Shops/Stores/Storeviews
9
+ * 20111206 ADD attribute discount_Descr to Sales_Order XML as item-text
10
+ * 20120111 CHANGE OrderId to realOrderId
11
+ * 10120122 CHANGE DiscountAmount to netDiscountAmount
12
+ * 20120210 ADD TAGS TaxVat Umsatzsteuer ID and Currency
13
+ * 20120228 REMOVE netDiscount Calc
14
+ * 20120424 ADD shippingMethod + productorderid for Cache
15
+ */
16
+ class Adventos_OrderExport_Model_Observer
17
+ {
18
+ /**
19
+ * Export Order
20
+ *
21
+ * @param Varien_Event_Observer $observer
22
+ */
23
+ public function createOrderExport($observer)
24
+ {
25
+ if (Mage::getStoreConfig('catalog/orderexport/process')){
26
+ try
27
+ {
28
+ /*
29
+ * Create Object with Orderdetails from Event
30
+ */
31
+ $order = $observer->getEvent()->getOrder();
32
+ // lookup for BSK Orders
33
+ $storeId = $order->getStoreId();
34
+ $webSite = Mage::getModel('core/store')->load($storeId)->getWebsiteId();
35
+
36
+ $this->_exportOrder($order);
37
+ Mage::log("ADVENTOS OrderExport done Store: ".$storeId);
38
+ }
39
+ catch (Exception $e)
40
+ {
41
+ Mage::logException($e);
42
+ }
43
+ }
44
+ }
45
+
46
+ /**
47
+ * write Orderdetails in XML-File
48
+ *
49
+ * @param Mage_Sales_Model_Order $order
50
+ * @return Adventos_OrderExport_Model_Observer
51
+ */
52
+ protected function _exportOrder(Mage_Sales_Model_Order $order)
53
+ {
54
+ $ordArray = $this->createOrder($order);
55
+ $ordXml = $this->toXml($ordArray,'salesOrder');
56
+ $file = "SalesOrder_".$order->getId().".xml";
57
+
58
+ $varExport = Mage::getBaseDir('export');
59
+ $exportPath = $varExport.DS.$file;
60
+
61
+ $handle = fopen($exportPath,"w+");
62
+ fwrite($handle,$ordXml);
63
+ fclose($handle);
64
+
65
+ return $this;
66
+ }
67
+
68
+ public function toXML($data, $rootNodeName='base',$xml=null){
69
+ if ($xml == null){
70
+ /*$xml = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><$rootNodeName />");
71
+ * Change encoding from UTF-8 to CP850
72
+ */
73
+ $xml = simplexml_load_string("<?xml version='1.0' encoding='cp850'?><$rootNodeName />");
74
+ }
75
+
76
+ // loop through the data passed in.
77
+
78
+ foreach($data as $key => $value){
79
+ // no numeric keys in our xml please!
80
+ if (is_numeric($key)){
81
+ // make string key...
82
+ $key = "item_".$key;
83
+ }
84
+ // replace anything not alpha numeric
85
+ $key = preg_replace('/[^a-z]/i', '', $key);
86
+ // if there is another array found recrusively call this function
87
+
88
+ if (is_array($value)){
89
+ $node = $xml->addChild($key);
90
+ // recrusive call.
91
+ Adventos_OrderExport_Model_Observer::toXML($value, $rootNodeName, $node);
92
+ } else {
93
+ // add single node.
94
+ $value = str_replace('€','EUR',$value);
95
+ $xml->addChild($key,$value);
96
+ }
97
+
98
+ }
99
+
100
+ // we want the XML to be formatted,
101
+ // 20110722 add encoding CP850 for incredible stupid HOFAKT
102
+ $doc = new DOMDocument('1.0', 'cp850');
103
+ $doc->preserveWhiteSpace = false;
104
+ $doc->loadXML( $xml->asXML() );
105
+ $doc->formatOutput = true;
106
+ return $doc->saveXML();
107
+
108
+ //return $xml->asXML();
109
+
110
+ }
111
+
112
+
113
+
114
+ public function createOrder($order){
115
+
116
+ $productArray = array(); // sale order line product wrapper
117
+
118
+ // Magento required models
119
+ $customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
120
+
121
+ // walk the sale order lines
122
+ foreach ($order->getAllVisibleItems() as $item) //getAllItems() - getItemCollection()
123
+ {
124
+ $productArray[] = array(
125
+ "product_sku" => $item->getSku(),
126
+ "product_magento_id" => $item->getProductId(),
127
+ "product_name" => $item->getName(),
128
+ "product_qty" => $item->getQtyOrdered(),
129
+ "product_price" => $item->getPrice(),
130
+ "product_row_discount_amount" => $item->getDiscountAmount(),
131
+ "product_row_price" => $item->getQtyOrdered() * $item->getPrice() - $item->getDiscountAmount(),
132
+ "product_order_id" => $order->getRealOrderId(),
133
+ "product_order_item_id" => $item->getId(),
134
+ );
135
+ }
136
+
137
+ $streetBA = $order->getBillingAddress()->getStreet();
138
+ $streetSA = $order->getShippingAddress()->getStreet();
139
+
140
+ $customerGroupId = $order->getCustomerGroupId ();
141
+
142
+ $group = Mage::getModel ('customer/group')->load ($customerGroupId);
143
+ if ($group->getId()){
144
+ $customerGroupName = $group->getCode();
145
+ }
146
+
147
+ if($customer->getEmail()=="") {
148
+ $customerEmail = $order->getCustomerEmail();
149
+ } else {
150
+ $customerEmail = $customer->getEmail();
151
+ }
152
+
153
+ $saleorder = array(
154
+ "id" => $order->getRealOrderId(),
155
+ "store_id" => $order->getStoreId(),
156
+ "store_name" => Mage::getModel('core/store')->load($order->getStoreID())->getName(),
157
+ "hofakt_lager" => Mage::getStoreConfig('catalog/orderexport/storage_id'),
158
+ "payment" => $order->getPayment()->getMethod(),
159
+ "shipping_amount" => $order->getShippingAmount(),
160
+ "discount_amount" => $order->getDiscountAmount(),
161
+ "discount_descr" => $order->getDiscountDescription(),
162
+ "net_total" => $order->getSubtotal(),
163
+ "tax_amount" => $order->getTaxAmount(),
164
+ "grand_total" => $order->getGrandTotal(),
165
+ "currency" => $order->getOrderCurrencyCode(),
166
+ "date" => $order->getCreatedAt(),
167
+ "customer" => array(
168
+ "customer_id" => $customer->getId(),
169
+ "customer_name" => $customer->getName(),
170
+ "customer_vatid" => $order->getCustomerTaxvat(),
171
+ "customer_email" => $customerEmail,
172
+ "customergroup" => $customerGroupName
173
+ ),
174
+ "shipping_address" => array(
175
+ "firstname" => $order->getShippingAddress()->getFirstname(),
176
+ "lastname" => $order->getShippingAddress()->getLastname(),
177
+ "company" => $order->getShippingAddress()->getCompany(),
178
+ "street" => $streetSA[0],
179
+ "street2" => (count($streetSA)==2)?$streetSA[1]:'',
180
+ "city" => $order->getShippingAddress()->getCity(),
181
+ "postcode" => $order->getShippingAddress()->getPostcode(),
182
+ "country" => $order->getShippingAddress()->getCountry(),
183
+ "phone" => $order->getShippingAddress()->getTelephone()
184
+ ),
185
+ "billing_address" => array(
186
+ "firstname" => $order->getBillingAddress()->getFirstname(),
187
+ "lastname" => $order->getBillingAddress()->getLastname(),
188
+ "company" => $order->getBillingAddress()->getCompany(),
189
+ "street" => $streetBA[0],
190
+ "street2" => (count($streetBA)==2)?$streetBA[1]:'',
191
+ "city" => $order->getBillingAddress()->getCity(),
192
+ "postcode" => $order->getBillingAddress()->getPostcode(),
193
+ "country" => $order->getBillingAddress()->getCountry(),
194
+ "phone" => $order->getBillingAddress()->getTelephone()
195
+ ),
196
+ "lines" => $productArray,
197
+ );
198
+
199
+ return $saleorder;
200
+ }
201
+ }
app/code/local/Adventos/OrderExport/Model/Shipment/Api.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+ class Adventos_OrderExport_Model_Shipment_Api extends Mage_Api_Model_Resource_Abstract
3
+ {
4
+
5
+ }
6
+ ?>
app/code/local/Adventos/OrderExport/Model/Shipment/Api/V2.php ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Adventos_OrderExport_Model_Shipment_Api_V2 extends Adventos_OrderExport_Model_Shipment_Api
3
+ {
4
+ /**
5
+ * Retrive shipments by filters
6
+ *
7
+ * @param array $filters
8
+ * @return array
9
+ */
10
+ public function items($filters = null)
11
+ {
12
+ //TODO: add full name logic
13
+ $collection = Mage::getResourceModel('sales/order_shipment_collection')
14
+ ->addAttributeToSelect('increment_id')
15
+ ->addAttributeToSelect('created_at')
16
+ ->addAttributeToSelect('total_qty')
17
+ ->joinAttribute('shipping_firstname', 'order_address/firstname', 'shipping_address_id', null, 'left')
18
+ ->joinAttribute('shipping_lastname', 'order_address/lastname', 'shipping_address_id', null, 'left')
19
+ ->joinAttribute('order_increment_id', 'order/increment_id', 'order_id', null, 'left')
20
+ ->joinAttribute('order_created_at', 'order/created_at', 'order_id', null, 'left');
21
+
22
+ $preparedFilters = array();
23
+ if (isset($filters->filter)) {
24
+ foreach ($filters->filter as $_filter) {
25
+ $preparedFilters[$_filter->key] = $_filter->value;
26
+ }
27
+ }
28
+ if (isset($filters->complex_filter)) {
29
+ foreach ($filters->complex_filter as $_filter) {
30
+ $_value = $_filter->value;
31
+ $preparedFilters[$_filter->key] = array(
32
+ $_value->key => $_value->value
33
+ );
34
+ }
35
+ }
36
+
37
+ if (!empty($preparedFilters)) {
38
+ try {
39
+ foreach ($preparedFilters as $field => $value) {
40
+ if (isset($this->_attributesMap['shipment'][$field])) {
41
+ $field = $this->_attributesMap['shipment'][$field];
42
+ }
43
+
44
+ $collection->addFieldToFilter($field, $value);
45
+ }
46
+ } catch (Mage_Core_Exception $e) {
47
+ $this->_fault('filters_invalid', $e->getMessage());
48
+ }
49
+ }
50
+
51
+ $result = array();
52
+
53
+ foreach ($collection as $shipment) {
54
+ $result[] = $this->_getAttributes($shipment, 'shipment');
55
+ }
56
+
57
+ return $result;
58
+ }
59
+
60
+ protected function _prepareItemQtyData($data)
61
+ {
62
+ $_data = array();
63
+ foreach ($data as $item) {
64
+ if (isset($item->order_item_id) && isset($item->qty)) {
65
+ $_data[$item->order_item_id] = $item->qty;
66
+ }
67
+ }
68
+ return $_data;
69
+ }
70
+
71
+ /**
72
+ * Create new shipment for order
73
+ *
74
+ * @param string $orderIncrementId
75
+ * @param array $itemsQty
76
+ * @param string $comment
77
+ * @param booleam $email
78
+ * @param boolean $includeComment
79
+ * @return string
80
+ */
81
+ public function create($orderIncrementId, $itemsQty = array(), $shipmentNr = null, $comment = null, $email = false, $includeComment = false)
82
+ {
83
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
84
+ $itemsQty = $this->_prepareItemQtyData($itemsQty);
85
+ /**
86
+ * Check order existing
87
+ */
88
+ if (!$order->getId()) {
89
+ $this->_fault('order_not_exists');
90
+ }
91
+
92
+ /**
93
+ * Check shipment create availability
94
+ */
95
+ if (!$order->canShip()) {
96
+ $this->_fault('data_invalid', Mage::helper('sales')->__('Cannot do shipment for order.'));
97
+ }
98
+
99
+ /* @var $shipment Mage_Sales_Model_Order_Shipment */
100
+ $shipment = $order->prepareShipment($itemsQty);
101
+ if ($shipment) {
102
+ $shipment->register();
103
+ $shipment->addComment($comment, $email && $includeComment);
104
+ if ($email) {
105
+ $shipment->setEmailSent(true);
106
+ }
107
+ if ($shipmentNr !== null) {
108
+ $shipment->setIncrementId($shipmentNr);
109
+ }
110
+ $shipment->getOrder()->setIsInProcess(true);
111
+ try {
112
+ $transactionSave = Mage::getModel('core/resource_transaction')
113
+ ->addObject($shipment)
114
+ ->addObject($shipment->getOrder())
115
+ ->save();
116
+ $shipment->sendEmail($email, ($includeComment ? $comment : ''));
117
+ } catch (Mage_Core_Exception $e) {
118
+ $this->_fault('data_invalid', $e->getMessage());
119
+ }
120
+ return $shipment->getIncrementId();
121
+ }
122
+ return null;
123
+ }
124
+
125
+ /**
126
+ * Retrieve allowed shipping carriers for specified order
127
+ *
128
+ * @param string $orderIncrementId
129
+ * @return array
130
+ */
131
+ public function getCarriers($orderIncrementId)
132
+ {
133
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
134
+
135
+ /**
136
+ * Check order existing
137
+ */
138
+ if (!$order->getId()) {
139
+ $this->_fault('order_not_exists');
140
+ }
141
+ $carriers = array();
142
+ foreach ($this->_getCarriers($order) as $key => $value) {
143
+ $carriers[] = array('key' => $key, 'value' => $value);
144
+ }
145
+
146
+ return $carriers;
147
+ }
148
+ }
149
+ ?>
app/code/local/Adventos/OrderExport/etc/api.xml ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <api>
4
+ <resources>
5
+ <adventos_invoice translate="title" module="adventos_orderexport">
6
+ <title>Custom Invoice functions for OrderExport</title>
7
+ <model>orderexport/invoice_api</model>
8
+ <acl>sales/order/invoice</acl>
9
+ <methods>
10
+ <create translate="title" module="adventos_orderexport">
11
+ <title>Create new invoice for order</title>
12
+ <acl>sales/order/invoice/create</acl>
13
+ </create>
14
+ </methods>
15
+ </adventos_invoice>
16
+ <adventos_shipment translate="title" module="adventos_orderexport">
17
+ <title>Custom Shipment functions for OrderExport</title>
18
+ <model>orderexport/shipment_api</model>
19
+ <acl>sales/order/shipment</acl>
20
+ <methods>
21
+ <create translate="title" module="adventos_orderexport">
22
+ <title>Create new shipment for order</title>
23
+ <acl>sales/order/shipment/create</acl>
24
+ </create>
25
+ </methods>
26
+ </adventos_shipment>
27
+ <adventos_creditmemo translate="title" module="adventos_orderexport">
28
+ <title>Custom Credit memo functions for OrderExport</title>
29
+ <model>orderexport/creditmemo_api</model>
30
+ <acl>sales/order/creditmemo</acl>
31
+ <methods>
32
+ <create translate="title" module="adventos_orderexport">
33
+ <title>Create new Credit memo for order</title>
34
+ <acl>sales/order/creditmemo/create</acl>
35
+ </create>
36
+ </methods>
37
+ </adventos_creditmemo>
38
+ </resources>
39
+ <resources_alias>
40
+ <adventos_invoice>adventos_invoice</adventos_invoice>
41
+ <adventos_shipment>adventos_shipment</adventos_shipment>
42
+ <adventos_creditmemo>adventos_creditmemo</adventos_creditmemo>
43
+ </resources_alias>
44
+ <v2>
45
+ <resources_function_prefix>
46
+ <adventos_invoice>adventosInvoice</adventos_invoice>
47
+ <adventos_shipment>adventosShipment</adventos_shipment>
48
+ <adventos_creditmemo>adventosCreditmemo</adventos_creditmemo>
49
+ </resources_function_prefix>
50
+ </v2>
51
+ </api>
52
+ </config>
app/code/local/Adventos/OrderExport/etc/config.xml ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Adventos_OrderExport>
5
+ <version>0.3.2</version>
6
+ </Adventos_OrderExport>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <orderexport>
11
+ <class>Adventos_OrderExport_Model</class>
12
+ </orderexport>
13
+ </models>
14
+ <helpers>
15
+ <orderexport>
16
+ <class>Adventos_OrderExport_Helper</class>
17
+ </orderexport>
18
+ </helpers>
19
+ <events>
20
+ <sales_order_place_after>
21
+ <observers>
22
+ <orderexport>
23
+ <type>singleton</type>
24
+ <class>orderexport/observer</class>
25
+ <method>createOrderExport</method>
26
+ </orderexport>
27
+ </observers>
28
+ </sales_order_place_after>
29
+ </events>
30
+ </global>
31
+ <default>
32
+ <catalog>
33
+ <orderexport>
34
+ <process>0</process>
35
+ <storage_id>2</storage_id>
36
+ </orderexport>
37
+ </catalog>
38
+ </default>
39
+ </config>
app/code/local/Adventos/OrderExport/etc/system.xml ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <catalog translate="label" module="catalog">
5
+ <groups>
6
+ <orderexport translate="label">
7
+ <label>OrderExport</label>
8
+ <frontend_type>text</frontend_type>
9
+ <sort_order>500</sort_order>
10
+ <show_in_default>1</show_in_default>
11
+ <show_in_website>1</show_in_website>
12
+ <show_in_store>1</show_in_store>
13
+ <fields>
14
+ <process translate="label">
15
+ <label>Export Orders</label>
16
+ <frontend_type>select</frontend_type>
17
+ <source_model>adminhtml/system_config_source_yesno</source_model>
18
+ <sort_order>1</sort_order>
19
+ <show_in_default>1</show_in_default>
20
+ <show_in_website>1</show_in_website>
21
+ <show_in_store>1</show_in_store>
22
+ </process>
23
+ <storage_id translate="label">
24
+ <label>LagerId</label>
25
+ <frontend_type>text</frontend_type>
26
+ <sort_order>2</sort_order>
27
+ <show_in_default>1</show_in_default>
28
+ <show_in_website>1</show_in_website>
29
+ <show_in_store>1</show_in_store>
30
+ </storage_id>
31
+ </fields>
32
+ </orderexport>
33
+ </groups>
34
+ </catalog>
35
+ </sections>
36
+ </config>
app/code/local/Adventos/OrderExport/etc/wsdl.xml ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <definitions xmlns:typens="urn:{{var wsdl.name}}" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
3
+ xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/"
4
+ name="{{var wsdl.name}}" targetNamespace="urn:{{var wsdl.name}}">
5
+ <types>
6
+ <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:Magento">
7
+ <import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="http://schemas.xmlsoap.org/soap/encoding/" />
8
+ <complexType name="orderItemIdQty">
9
+ <all>
10
+ <element name="order_item_id" type="xsd:int" />
11
+ <element name="qty" type="xsd:double" />
12
+ </all>
13
+ </complexType>
14
+ <complexType name="orderItemIdQtyArray">
15
+ <complexContent>
16
+ <restriction base="soapenc:Array">
17
+ <attribute ref="soapenc:arrayType" wsdl:arrayType="typens:orderItemIdQty[]" />
18
+ </restriction>
19
+ </complexContent>
20
+ </complexType>
21
+ <complexType name="salesOrderCreditmemoData">
22
+ <all>
23
+ <element name="qtys" type="typens:orderItemIdQtyArray" minOccurs="0" />
24
+ <element name="shipping_amount" type="xsd:double" minOccurs="0" />
25
+ <element name="adjustment_positive" type="xsd:double" minOccurs="0" />
26
+ <element name="adjustment_negative" type="xsd:double" minOccurs="0" />
27
+ </all>
28
+ </complexType>
29
+ </schema>
30
+ </types>
31
+ <portType name="{{var wsdl.handler}}PortType">
32
+ <operation name="adventosCreditmemoCreate">
33
+ <documentation>Create new Credit memo for order</documentation>
34
+ <input message="typens:adventosCreditmemoCreateRequest" />
35
+ <output message="typens:adventosCreditmemoCreateResponse" />
36
+ </operation>
37
+ <operation name="adventosInvoiceCreate">
38
+ <documentation>Create new invoice for order</documentation>
39
+ <input message="typens:adventosInvoiceCreateRequest" />
40
+ <output message="typens:adventosInvoiceCreateResponse" />
41
+ </operation>
42
+ <operation name="adventosShipmentCreate">
43
+ <documentation>Create new shipment for order</documentation>
44
+ <input message="typens:adventosShipmentCreateRequest" />
45
+ <output message="typens:adventosShipmentCreateResponse" />
46
+ </operation>
47
+ </portType>
48
+ <binding name="{{var wsdl.handler}}Binding" type="typens:{{var wsdl.handler}}PortType">
49
+ <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
50
+ <operation name="adventosCreditmemoCreate">
51
+ <soap:operation soapAction="urn:{{var wsdl.handler}}Action" />
52
+ <input>
53
+ <soap:body namespace="urn:{{var wsdl.name}}" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
54
+ </input>
55
+ <output>
56
+ <soap:body namespace="urn:{{var wsdl.name}}" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
57
+ </output>
58
+ </operation>
59
+ <operation name="adventosInvoiceCreate">
60
+ <soap:operation soapAction="urn:{{var wsdl.handler}}Action" />
61
+ <input>
62
+ <soap:body namespace="urn:{{var wsdl.name}}" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
63
+ </input>
64
+ <output>
65
+ <soap:body namespace="urn:{{var wsdl.name}}" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
66
+ </output>
67
+ </operation>
68
+ <operation name="adventosShipmentCreate">
69
+ <soap:operation soapAction="urn:{{var wsdl.handler}}Action" />
70
+ <input>
71
+ <soap:body namespace="urn:{{var wsdl.name}}" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
72
+ </input>
73
+ <output>
74
+ <soap:body namespace="urn:{{var wsdl.name}}" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
75
+ </output>
76
+ </operation>
77
+ </binding>
78
+ <service name="{{var wsdl.name}}Service">
79
+ <port name="{{var wsdl.handler}}Port" binding="typens:{{var wsdl.handler}}Binding">
80
+ <soap:address location="{{var wsdl.url}}" />
81
+ </port>
82
+ </service>
83
+ <message name="adventosCreditmemoCreateRequest">
84
+ <part name="sessionId" type="xsd:string" />
85
+ <part name="orderId" type="xsd:string" />
86
+ <part name="creditmemoData" type="typens:salesOrderCreditmemoData" />
87
+ <part name="creditmemoNr" type="xsd:string" />
88
+ <part name="comment" type="xsd:string" />
89
+ <part name="notifyCustomer" type="xsd:int" />
90
+ <part name="includeComment" type="xsd:int" />
91
+ <part name="refundToStoreCreditAmount" type="xsd:string" />
92
+ </message>
93
+ <message name="adventosCreditmemoCreateResponse">
94
+ <part name="creditmemoIncrementId" type="xsd:int" />
95
+ </message>
96
+ <message name="adventosInvoiceCreateRequest">
97
+ <part name="sessionId" type="xsd:string" />
98
+ <part name="orderId" type="xsd:string" />
99
+ <part name="itemsQty" type="typens:orderItemIdQtyArray" />
100
+ <part name="invoiceNr" type="xsd:string" />
101
+ <part name="comment" type="xsd:string" />
102
+ <part name="email" type="xsd:string" />
103
+ <part name="includeComment" type="xsd:string" />
104
+ </message>
105
+ <message name="adventosInvoiceCreateResponse">
106
+ <part name="invoiceIncrementId" type="xsd:int" />
107
+ </message>
108
+ <message name="adventosShipmentCreateRequest">
109
+ <part name="sessionId" type="xsd:string" />
110
+ <part name="orderId" type="xsd:string" />
111
+ <part name="itemsQty" type="typens:orderItemIdQtyArray" />
112
+ <part name="shipmentNr" type="xsd:string" />
113
+ <part name="comment" type="xsd:string" />
114
+ <part name="email" type="xsd:int" />
115
+ <part name="includeComment" type="xsd:int" />
116
+ </message>
117
+ <message name="adventosShipmentCreateResponse">
118
+ <part name="shipmentIncrementId" type="xsd:int" />
119
+ </message>
120
+ </definitions>
app/etc/modules/Adventos_OrderExport.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <Adventos_OrderExport>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ </Adventos_OrderExport>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Adventos_OrderExport</name>
4
+ <version>1.0.1</version>
5
+ <stability>stable</stability>
6
+ <license>OSL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>OrderExport</summary>
10
+ <description>export Order 2 Hofakt</description>
11
+ <notes>generate XML-File with Orderdetails in var/export/SalesOrder_*.xml</notes>
12
+ <authors><author><name>ADVENTOS GmbH</name><user>adventos</user><email>magentomodules@adventos.de</email></author></authors>
13
+ <date>2012-05-11</date>
14
+ <time>10:10:09</time>
15
+ <contents><target name="magelocal"><dir name="Adventos"><dir name="OrderExport"><dir name="Helper"><file name="Data.php" hash="f90dd7d2136cfb6349ba1d7ee939cd15"/></dir><dir name="Model"><dir name="Creditmemo"><dir name="Api"><file name="V2.php" hash="afba3391027e1ebe798253cdc034d034"/></dir><file name="Api.php" hash="c41e82cf79235d51f25d248719e93f92"/></dir><dir name="Invoice"><dir name="Api"><file name="V2.php" hash="ed0e742f85e0f450c3387bb8a7738033"/></dir><file name="Api.php" hash="280512b1ae37690871384b3cba0a3a2b"/></dir><file name="Observer.php" hash="58bdcc404a42474761bd2cdf3b3ac532"/><dir name="Shipment"><dir name="Api"><file name="V2.php" hash="22acaee0fe176a65fc1071d4dab5d6f5"/></dir><file name="Api.php" hash="0b9bf452b7e36c1ee5cefbb3d6c5eb3b"/></dir></dir><dir name="etc"><file name="api.xml" hash="538bba91e396d0493fe236d6385d9049"/><file name="config.xml" hash="c542e81042d14fe59dddbe7ad511b23a"/><file name="system.xml" hash="5c5f13a808798403227d3fedd43c877f"/><file name="wsdl.xml" hash="b3e1086c7e06ece8e0c0e5f537b1480f"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Adventos_OrderExport.xml" hash="479b13bf3a08de9f93f5f58d77d3f9bb"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>