Adventos_OrderExport - Version 1.3.9

Version Notes

Add Handling Fee NL

Download this release

Release Info

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


Code changes from version 1.3.8 to 1.3.9

app/code/local/Adventos/OrderExport/Model/Observer.php CHANGED
@@ -13,320 +13,410 @@
13
  * 20120210 ADD TAGS TaxVat Umsatzsteuer ID and Currency
14
  * 20120228 REMOVE netDiscount Calc
15
  * 20121011 ADD generateCatalogInventoryFile
 
 
16
  */
17
- class Adventos_OrderExport_Model_Observer
18
- {
19
  /**
20
  * Generate OrderExport
21
  *
22
- * @param Varien_Event_Observer $observer
23
  */
24
- public function createOrderExport($observer)
25
- {
26
- Mage::log("ADVENTOS OrderExport Event - START");
27
- if (Mage::getStoreConfig('catalog/orderexport/process')){
28
- Mage::log("ADVENTOS OrderExport Event - Generate Export enable");
29
- try
30
- {
31
- $order = $observer->getEvent()->getOrder();
32
-
33
- $storeId = $order->getStoreId();
34
- $webSite = Mage::getModel('core/store')->load($storeId)->getWebsiteId();
35
-
36
- $this->_exportOrder($order);
37
- Mage::log("ADVENTOS OrderExport Event - Store: ".$storeId);
38
- }
39
- catch (Exception $e)
40
- {
41
- Mage::logException($e);
42
  }
43
- }else{
44
- Mage::log("ADVENTOS OrderExport Event - Generate Export disable");
45
  }
46
- Mage::log("ADVENTOS OrderExport Event - END");
47
  }
48
-
49
-
50
-
51
  /**
52
  * write OrderDetails in XML-File
53
  *
54
- * @param Mage_Sales_Model_Order $order
55
  * @return Adventos_OrderExport_Model_Observer
56
  */
57
- protected function _exportOrder(Mage_Sales_Model_Order $order)
58
- {
59
- $ordArray = $this->createOrder($order);
60
- $ordXml = $this->toXml($ordArray,'salesOrder');
61
- $file = "SalesOrder_".$order->getId().".xml";
62
-
63
- $varExport = Mage::getBaseDir('export');
64
-
65
- if (Mage::getStoreConfig('catalog/orderexport/export_path') != null){
66
- if (Mage::getStoreConfig('catalog/orderexport/export_path') != ""){
67
- $OrderExportPath = Mage::getStoreConfig('catalog/orderexport/export_path');
68
- if(!is_dir($varExport.DS.$OrderExportPath)){
69
- Mage::log("ADVENTOS OrderExport Event - MultiShop ExportPath Folder not exist [".$OrderExportPath."]");
70
- mkdir($varExport.DS.$OrderExportPath);
71
  }
72
- $file = $OrderExportPath."/".$file;
73
- Mage::log("ADVENTOS OrderExport Event - Add MultiShop ExportPath [".$OrderExportPath."]");
74
  }
75
  }
76
-
77
- $exportPath = $varExport.DS.$file;
78
-
79
- $handle = fopen($exportPath,"w+");
80
- fwrite($handle,$ordXml);
81
- fclose($handle);
82
-
83
  return $this;
84
  }
85
-
86
- public function _translateLiteral2NumericEntities($xmlSource, $reverse=FALSE) {
87
  static $literal2NumericEntity;
88
-
89
- if (empty($literal2NumericEntity)) {
90
- $transTbl = get_html_translation_table(HTML_ENTITIES);
91
- foreach ($transTbl as $char => $entity) {
92
- if (strpos('&"<>', $char) !== FALSE) continue;
93
- $literal2NumericEntity[$entity] = '&#'.ord($char).';';
 
94
  }
95
  }
96
  if ($reverse) {
97
- return strtr($xmlSource, array_flip($literal2NumericEntity));
98
  } else {
99
- return strtr($xmlSource, $literal2NumericEntity);
100
  }
101
  }
102
-
103
- public function toXML($data, $rootNodeName='base',$xml=null){
104
- if ($xml == null){
105
- /*$xml = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><$rootNodeName />");
106
- * Change encoding from UTF-8 to CP850
107
- */
108
- $xml = simplexml_load_string("<?xml version='1.0' encoding='cp850'?><$rootNodeName />");
109
  }
110
-
111
  // loop through the data passed in.
112
-
113
- foreach($data as $key => $value){
114
  // no numeric keys in our xml please!
115
- if (is_numeric($key)){
116
  // make item key for product array ...
117
- $key = "item"; //.$key;
118
  }
119
  // replace anything not alpha numeric
120
- $key = preg_replace('/[^a-z0-9]/i', '', $key);
121
  // if there is another array found recrusively call this function
122
-
123
- if (is_array($value)){
124
- $node = $xml->addChild($key);
125
  // recrusive call.
126
- Adventos_OrderExport_Model_Observer::toXML($value, $rootNodeName, $node);
127
  } else {
128
  // add single node.
129
- $value = str_replace('€','EUR',$value);
130
- Mage::log("ADVENTOS XML before value: ".$value);
131
- $value = htmlspecialchars($value);
132
- Mage::log("ADVENTOS XML encoded value: ".$value);
133
- $xml->addChild($key,$value);
134
  }
135
-
136
  }
137
-
138
  // we want the XML to be formatted,
139
- //20110722 add encoding CP850 for incredible stupid HOFAKT
140
- $doc = new DOMDocument('1.0', 'cp850');
141
  $doc->preserveWhiteSpace = false;
142
- $doc->loadXML( $xml->asXML() );
143
  $doc->formatOutput = true;
144
- return $doc->saveXML();
145
  }
146
-
147
- public function createOrder($order){
148
-
149
- $productArray = array(); // sale order line product wrapper
150
-
151
  // Magento required models
152
- $customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
153
-
154
  // walk the sale order lines
155
- foreach ($order->getAllVisibleItems() as $item) //getAllItems() - getItemCollection()
156
  {
157
- $tax_amount = $item->getTaxAmount();
158
- $discount_percent = $item->getDiscountPercent();
159
- $discountAmount = $item->getDiscountAmount();
160
-
161
- //typo in discount_percent
162
- if ($discount_percent > 0) {
163
- $product_row_price = $item->getQtyOrdered() * $item->getOrginalPrice() - $item->getDiscountAmount();
164
- }else{
165
- $product_row_price = $item->getQtyOrdered() * $item->getPrice() - $item->getDiscountAmount();
166
 
167
- //when fixed amount per product calc discount percent value
168
- // rowDiscountPercent = (rowqty * rowproductprice) / rowdiscountamount
169
-
170
- if ($discountAmount > 0) {
171
- $discount_percent = round(100 * $discountAmount / ($item->getQtyOrdered() * $item->getPrice()),2);
172
- if ($discount_percent == 100.00){
173
- $discount_percent = 99.99;
 
 
 
 
 
 
 
 
 
 
 
174
  }
175
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
  }
177
-
178
- //Mage::log($item);
179
- //Mage:log(print_r($item));
180
- $productArray[] = array(
181
- "product_sku" => $item->getSku(),
182
- "product_magento_id" => $item->getProductId(),
183
- "product_name" => $item->getName(),
184
- "product_qty" => $item->getQtyOrdered(),
185
- "product_price" => $item->getPrice(),
186
- "product_discount_percent" => $item->getDiscountPercent(),
187
- "product_row_discount_amount" => $item->getDiscountAmount(),
188
- "product_row_price" => $product_row_price,
189
- "product_order_id" => $order->getRealOrderId(),
190
- "product_order_item_id" => $item->getId(),
191
- "product_description" => "", //$item->getQtyOrdered()."-".$item->getPrice()."-".$item->getOrginalPrice()."-".$item->getDiscountAmount(),
192
- );
193
  }
194
-
195
- $streetBA = $order->getBillingAddress()->getStreet();
196
- $streetSA = $order->getShippingAddress()->getStreet();
197
-
198
- $customerGroupId = $order->getCustomerGroupId();
199
  $customerGroupName = "";
200
-
201
- $group = Mage::getModel ('customer/group')->load ($customerGroupId);
202
- if ($group->getId()){
203
- $customerGroupName = $group->getCode();
204
  }
205
-
206
- if($customer->getEmail() == "") {
207
- $customerEmail = $order->getCustomerEmail();
208
  } else {
209
- $customerEmail = $customer->getEmail();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
210
  }
211
-
212
- $exportVatGroup = Mage::getStoreConfig('catalog/orderexport/B2B_HomeGroup');
213
- $exportVatGroup = explode(",", $exportVatGroup);
214
-
215
- if (in_array($customerGroupId, $exportVatGroup)) {
216
- $order->getBillingAddress()->getvat_id() ? $billing_vat_id = $order->getBillingAddress()->getCountry().$order->getBillingAddress()->getvat_id() : $billing_vat_id = "";
217
- $order->getShippingAddress()->getvat_id() ? $shipping_vat_id = $order->getShippingAddress()->getCountry().$order->getShippingAddress()->getvat_id() : $shipping_vat_id = "";
218
- }else{
219
- $billing_vat_id = "";
220
- $shipping_vat_id = "";
221
- }
222
-
223
- $saleorder = array(
224
- "id" => $order->getRealOrderId(),
225
- "store_id" => $order->getStoreId(),
226
- "store_name" => Mage::getModel('core/store')->load($order->getStoreID())->getName(),
227
- "hofakt_lager" => Mage::getStoreConfig('catalog/orderexport/storage_id'),
228
- "hofakt_language" => Mage::getStoreConfig('catalog/orderexport/store_language'),
229
- "payment" => $order->getPayment()->getMethod(),
230
- "shipping_amount" => $order->getShippingAmount(),
231
- "discount_amount" => 0,
232
- "discount_descr" => $order->getDiscountDescription(),
233
- "net_total" => $order->getSubtotal(),
234
- "tax_amount" => $order->getTaxAmount(),
235
- "grand_total" => $order->getGrandTotal(),
236
- "currency" => $order->getOrderCurrencyCode(),
237
- "date" => $order->getCreatedAt(),
238
- "customer" => array(
239
- "customer_id" => $customer->getId(),
240
- "customer_name" => $customer->getName(),
241
- "customer_vatid" => $order->getCustomerTaxvat(),
242
- "customer_email" => $customerEmail,
243
- "customergroup" => $customerGroupName
244
- ),
245
- "shipping_address" => array(
246
- "firstname" => $order->getShippingAddress()->getFirstname(),
247
- "lastname" => $order->getShippingAddress()->getLastname(),
248
- "company" => $order->getShippingAddress()->getCompany(),
249
- "street" => $streetSA[0],
250
- "street2" => (count($streetSA)==2)?$streetSA[1]:'',
251
- "city" => $order->getShippingAddress()->getCity(),
252
- "postcode" => $order->getShippingAddress()->getPostcode(),
253
- "country" => $order->getShippingAddress()->getCountry(),
254
- "versadr1" => $order->getShippingAddress()->getRegionCode(),
255
- "phone" => $order->getShippingAddress()->getTelephone(),
256
- "addressid" => $order->getShippingAddress()->getCustomerAddressId(),
257
- "vatid" => $shipping_vat_id
258
- ),
259
- "billing_address" => array(
260
- "firstname" => $order->getBillingAddress()->getFirstname(),
261
- "lastname" => $order->getBillingAddress()->getLastname(),
262
- "company" => $order->getBillingAddress()->getCompany(),
263
- "street" => $streetBA[0],
264
- "street2" => (count($streetBA)==2)?$streetBA[1]:'',
265
- "city" => $order->getBillingAddress()->getCity(),
266
- "postcode" => $order->getBillingAddress()->getPostcode(),
267
- "country" => $order->getBillingAddress()->getCountry(),
268
- "versadr1" => $order->getBillingAddress()->getRegionCode(),
269
- "phone" => $order->getBillingAddress()->getTelephone(),
270
- "addressid" => $order->getBillingAddress()->getCustomerAddressId(),
271
- "vatid" => $billing_vat_id
272
- ),
273
- "lines" => $productArray,
274
- );
275
-
276
  return $saleorder;
277
  }
278
-
279
- public function generateCatalogInventoryFile($schedule){
280
- Mage::log("ADVENTOS OrderExport CatalogInventoryExport - START");
281
- try
282
- {
283
- $inventoryArray = array();
284
- $collection = Mage::getModel('catalog/product')->getCollection();
285
- foreach ($collection->load() as $item)
286
- {
287
- $inventoryArray[] = array(
288
- "sku" => $item->getSku(),
289
- "qty" => (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($item)->getQty(),
290
  );
291
  }
292
- $Xml = $this->toXml($inventoryArray,'catalogInventory');
293
  $file = "CatalogInventoryExport.xml";
294
- $varExport = Mage::getBaseDir('export');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
295
  }
296
- catch (Exception $e)
297
- {
298
- Mage::logException($e);
299
- }
300
-
301
- $web_exported = @array();
302
- $allStores = Mage::app()->getStores();
303
- foreach ($allStores as $_eachStoreId => $val) {
304
- $exportXml = $Xml;
305
- $exportFile = $file;
306
- $_storeId = Mage::app()->getStore($_eachStoreId)->getId();
307
- $_webId = Mage::app()->getStore($_eachStoreId)->getWebsiteId();
308
- $app = Mage::app()->setCurrentStore($_storeId);
309
- if (Mage::getStoreConfig('catalog/orderexport/process')){
310
- if (!in_array($_webId, $web_exported)){
311
- if (Mage::getStoreConfig('catalog/orderexport/export_path') != null){
312
- if (Mage::getStoreConfig('catalog/orderexport/export_path') != ""){
313
- $orderExportPath = Mage::getStoreConfig('catalog/orderexport/export_path');
314
- if(!is_dir($varExport.DS.$orderExportPath)){
315
- mkdir($varExport.DS.$orderExportPath);
316
- Mage::log("ADVENTOS OrderExport Event - Add MultiShop ExportPath [".$orderExportPath."]");
317
- }
318
- $exportFile = $orderExportPath."/".$exportFile;
319
- }
320
- }
321
- $exportPath = $varExport.DS.$exportFile;
322
- $handle = fopen($exportPath,"w+");
323
- fwrite($handle,$exportXml);
324
- fclose($handle);
325
- Mage::log("ADVENTOS OrderExport CatalogInventoryExport - [".$orderExportPath."] Done");
326
- }
327
- array_push($web_exported, $_webId);
328
- }
329
- }
330
- Mage::log("ADVENTOS OrderExport CatalogInventoryExport - END");
331
  }
332
  }
13
  * 20120210 ADD TAGS TaxVat Umsatzsteuer ID and Currency
14
  * 20120228 REMOVE netDiscount Calc
15
  * 20121011 ADD generateCatalogInventoryFile
16
+ * TODO Add new Tag <fee> for Shell payment fee invoice 10 Bucks
17
+ * TODO Handle Bundle Product > Split into Simple
18
  */
19
+ class Adventos_OrderExport_Model_Observer {
 
20
  /**
21
  * Generate OrderExport
22
  *
23
+ * @param Varien_Event_Observer $observer
24
  */
25
+ public function createOrderExport($observer) {
26
+ Mage::log ( "ADVENTOS OrderExport Event - START" );
27
+ if (Mage::getStoreConfig ( 'catalog/orderexport/process' )) {
28
+ Mage::log ( "ADVENTOS OrderExport Event - Generate Export enable" );
29
+ try {
30
+ $order = $observer->getEvent ()->getOrder ();
31
+
32
+ $storeId = $order->getStoreId ();
33
+ $webSite = Mage::getModel ( 'core/store' )->load ( $storeId )->getWebsiteId ();
34
+
35
+ $this->_exportOrder ( $order );
36
+ Mage::log ( "ADVENTOS OrderExport Event - Store: " . $storeId );
37
+ } catch ( Exception $e ) {
38
+ Mage::logException ( $e );
 
 
 
 
39
  }
40
+ } else {
41
+ Mage::log ( "ADVENTOS OrderExport Event - Generate Export disable" );
42
  }
43
+ Mage::log ( "ADVENTOS OrderExport Event - END" );
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
+ $ordArray = $this->createOrder ( $order );
54
+ $ordXml = $this->toXml ( $ordArray, 'salesOrder' );
55
+ $file = "SalesOrder_" . $order->getId () . ".xml";
56
+
57
+ $varExport = Mage::getBaseDir ( 'export' );
58
+
59
+ if (Mage::getStoreConfig ( 'catalog/orderexport/export_path' ) != null) {
60
+ if (Mage::getStoreConfig ( 'catalog/orderexport/export_path' ) != "") {
61
+ $OrderExportPath = Mage::getStoreConfig ( 'catalog/orderexport/export_path' );
62
+ if (! is_dir ( $varExport . DS . $OrderExportPath )) {
63
+ Mage::log ( "ADVENTOS OrderExport Event - MultiShop ExportPath Folder not exist [" . $OrderExportPath . "]" );
64
+ mkdir ( $varExport . DS . $OrderExportPath );
 
65
  }
66
+ $file = $OrderExportPath . "/" . $file;
67
+ Mage::log ( "ADVENTOS OrderExport Event - Add MultiShop ExportPath [" . $OrderExportPath . "]" );
68
  }
69
  }
70
+
71
+ $exportPath = $varExport . DS . $file;
72
+
73
+ $handle = fopen ( $exportPath, "w+" );
74
+ fwrite ( $handle, $ordXml );
75
+ fclose ( $handle );
76
+
77
  return $this;
78
  }
79
+ public function _translateLiteral2NumericEntities($xmlSource, $reverse = FALSE) {
 
80
  static $literal2NumericEntity;
81
+
82
+ if (empty ( $literal2NumericEntity )) {
83
+ $transTbl = get_html_translation_table ( HTML_ENTITIES );
84
+ foreach ( $transTbl as $char => $entity ) {
85
+ if (strpos ( '&"<>', $char ) !== FALSE)
86
+ continue;
87
+ $literal2NumericEntity [$entity] = '&#' . ord ( $char ) . ';';
88
  }
89
  }
90
  if ($reverse) {
91
+ return strtr ( $xmlSource, array_flip ( $literal2NumericEntity ) );
92
  } else {
93
+ return strtr ( $xmlSource, $literal2NumericEntity );
94
  }
95
  }
96
+ public function toXML($data, $rootNodeName = 'base', $xml = null) {
97
+ if ($xml == null) {
98
+ /*
99
+ * $xml = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><$rootNodeName />"); Change encoding from UTF-8 to CP850
100
+ */
101
+ $xml = simplexml_load_string ( "<?xml version='1.0' encoding='cp850'?><$rootNodeName />" );
 
102
  }
103
+
104
  // loop through the data passed in.
105
+
106
+ foreach ( $data as $key => $value ) {
107
  // no numeric keys in our xml please!
108
+ if (is_numeric ( $key )) {
109
  // make item key for product array ...
110
+ $key = "item"; // .$key;
111
  }
112
  // replace anything not alpha numeric
113
+ $key = preg_replace ( '/[^a-z0-9]/i', '', $key );
114
  // if there is another array found recrusively call this function
115
+
116
+ if (is_array ( $value )) {
117
+ $node = $xml->addChild ( $key );
118
  // recrusive call.
119
+ Adventos_OrderExport_Model_Observer::toXML ( $value, $rootNodeName, $node );
120
  } else {
121
  // add single node.
122
+ $value = str_replace ( '€', 'EUR', $value );
123
+ $value = htmlspecialchars ( $value );
124
+ $xml->addChild ( $key, $value );
 
 
125
  }
 
126
  }
127
+
128
  // we want the XML to be formatted,
129
+ // 20110722 add encoding CP850 for incredible stupid HOFAKT
130
+ $doc = new DOMDocument ( '1.0', 'cp850' );
131
  $doc->preserveWhiteSpace = false;
132
+ $doc->loadXML ( $xml->asXML () );
133
  $doc->formatOutput = true;
134
+ return $doc->saveXML ();
135
  }
136
+ public function createOrder($order) {
137
+ $productArray = array (); // sale order line product wrapper
138
+
 
 
139
  // Magento required models
140
+ $customer = Mage::getModel ( 'customer/customer' )->load ( $order->getCustomerId () );
141
+
142
  // walk the sale order lines
143
+ foreach ( $order->getAllItems () as $item ) // getAllVisibleItems() - getAllItems() - getItemCollection()
144
  {
145
+ // Check if Item is Bundled
146
+ if ($item->getHasChildren () && $item->getData ( 'product_type' ) != Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
147
+ //if ($item->getData ( 'product_type' ) == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE && $item->getHasChildren ()) {
148
+ Mage::log ( "ADVENTOS Skip Item Type with children = " . $item->getData ('product_type'));
149
+ } else {
 
 
 
 
150
 
151
+ $tax_amount = $item->getTaxAmount ();
152
+ $discount_percent = $item->getDiscountPercent ();
153
+ $discountAmount = $item->getDiscountAmount ();
154
+
155
+ // typo in discount_percent
156
+ if ($discount_percent > 0) {
157
+ $product_row_price = $item->getQtyOrdered () * $item->getOrginalPrice () - $item->getDiscountAmount ();
158
+ } else {
159
+ $product_row_price = $item->getQtyOrdered () * $item->getPrice () - $item->getDiscountAmount ();
160
+
161
+ // when fixed amount per product calc discount percent value
162
+ // rowDiscountPercent = (rowqty * rowproductprice) / rowdiscountamount
163
+
164
+ if ($discountAmount > 0) {
165
+ $discount_percent = round ( 100 * $discountAmount / ($item->getQtyOrdered () * $item->getPrice ()), 2 );
166
+ if ($discount_percent == 100.00) {
167
+ $discount_percent = 99.99;
168
+ }
169
  }
170
  }
171
+
172
+ // Mage:log(print_r($item));
173
+ $productArray [] = array (
174
+ "product_sku" => $item->getSku (),
175
+ "product_magento_id" => $item->getProductId (),
176
+ "product_name" => $item->getName (),
177
+ "product_qty" => $item->getQtyOrdered (),
178
+ "product_price" => $item->getPrice (),
179
+ "product_discount_percent" => $item->getDiscountPercent (),
180
+ "product_row_discount_amount" => $item->getDiscountAmount (),
181
+ "product_row_price" => $product_row_price,
182
+ "product_order_id" => $order->getRealOrderId (),
183
+ "product_order_item_id" => $item->getId (),
184
+ "product_description" => ""
185
+ );
186
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187
  }
188
+
189
+ $streetBA = $order->getBillingAddress ()->getStreet ();
190
+ $streetSA = $order->getShippingAddress ()->getStreet ();
191
+
192
+ $customerGroupId = $order->getCustomerGroupId ();
193
  $customerGroupName = "";
194
+
195
+ $group = Mage::getModel ( 'customer/group' )->load ( $customerGroupId );
196
+ if ($group->getId ()) {
197
+ $customerGroupName = $group->getCode ();
198
  }
199
+
200
+ if ($customer->getEmail () == "") {
201
+ $customerEmail = $order->getCustomerEmail ();
202
  } else {
203
+ $customerEmail = $customer->getEmail ();
204
+ }
205
+
206
+ $exportVatGroup = Mage::getStoreConfig ( 'catalog/orderexport/B2B_HomeGroup' );
207
+ $exportVatGroup = explode ( ",", $exportVatGroup );
208
+
209
+ if (in_array ( $customerGroupId, $exportVatGroup )) {
210
+ $order->getBillingAddress ()->getvat_id () ? $billing_vat_id = $order->getBillingAddress ()->getCountry () . $order->getBillingAddress ()->getvat_id () : $billing_vat_id = "";
211
+ $order->getShippingAddress ()->getvat_id () ? $shipping_vat_id = $order->getShippingAddress ()->getCountry () . $order->getShippingAddress ()->getvat_id () : $shipping_vat_id = "";
212
+ } else {
213
+ $billing_vat_id = "";
214
+ $shipping_vat_id = "";
215
+ }
216
+
217
+ // Check if SalesOrder Fee is set
218
+
219
+ // Check if SalesOrder Fee is set
220
+ if ($order->getFeeAmount () != null) {
221
+ $saleorder = array (
222
+ "id" => $order->getRealOrderId (),
223
+ "store_id" => $order->getStoreId (),
224
+ "store_name" => Mage::getModel ( 'core/store' )->load ( $order->getStoreID () )->getName (),
225
+ "hofakt_lager" => Mage::getStoreConfig ( 'catalog/orderexport/storage_id' ),
226
+ "hofakt_language" => Mage::getStoreConfig ( 'catalog/orderexport/store_language' ),
227
+ "payment" => $order->getPayment ()->getMethod (),
228
+ "shipping_amount" => $order->getShippingAmount (),
229
+ "fee" => round ( $order->getFeeAmount (), 4 ),
230
+ "discount_amount" => 0,
231
+ "discount_descr" => $order->getDiscountDescription (),
232
+ "net_total" => $order->getSubtotal (),
233
+ "tax_amount" => $order->getTaxAmount (),
234
+ "grand_total" => $order->getGrandTotal (),
235
+ "currency" => $order->getOrderCurrencyCode (),
236
+ "date" => $order->getCreatedAt (),
237
+ "customer" => array (
238
+ "customer_id" => $customer->getId (),
239
+ "customer_name" => $customer->getName (),
240
+ "customer_vatid" => $order->getCustomerTaxvat (),
241
+ "customer_email" => $customerEmail,
242
+ "customergroup" => $customerGroupName
243
+ ),
244
+ "shipping_address" => array (
245
+ "firstname" => $order->getShippingAddress ()->getFirstname (),
246
+ "lastname" => $order->getShippingAddress ()->getLastname (),
247
+ "company" => $order->getShippingAddress ()->getCompany (),
248
+ "street" => $streetSA [0],
249
+ "street2" => (count ( $streetSA ) == 2) ? $streetSA [1] : '',
250
+ "city" => $order->getShippingAddress ()->getCity (),
251
+ "postcode" => $order->getShippingAddress ()->getPostcode (),
252
+ "country" => $order->getShippingAddress ()->getCountry (),
253
+ "versadr1" => $order->getShippingAddress ()->getRegionCode (),
254
+ "phone" => $order->getShippingAddress ()->getTelephone (),
255
+ "addressid" => $order->getShippingAddress ()->getCustomerAddressId (),
256
+ "vatid" => $shipping_vat_id
257
+ ),
258
+ "billing_address" => array (
259
+ "firstname" => $order->getBillingAddress ()->getFirstname (),
260
+ "lastname" => $order->getBillingAddress ()->getLastname (),
261
+ "company" => $order->getBillingAddress ()->getCompany (),
262
+ "street" => $streetBA [0],
263
+ "street2" => (count ( $streetBA ) == 2) ? $streetBA [1] : '',
264
+ "city" => $order->getBillingAddress ()->getCity (),
265
+ "postcode" => $order->getBillingAddress ()->getPostcode (),
266
+ "country" => $order->getBillingAddress ()->getCountry (),
267
+ "versadr1" => $order->getBillingAddress ()->getRegionCode (),
268
+ "phone" => $order->getBillingAddress ()->getTelephone (),
269
+ "addressid" => $order->getBillingAddress ()->getCustomerAddressId (),
270
+ "vatid" => $billing_vat_id
271
+ ),
272
+ "lines" => $productArray
273
+ );
274
+ } else {
275
+ $saleorder = array (
276
+ "id" => $order->getRealOrderId (),
277
+ "store_id" => $order->getStoreId (),
278
+ "store_name" => Mage::getModel ( 'core/store' )->load ( $order->getStoreID () )->getName (),
279
+ "hofakt_lager" => Mage::getStoreConfig ( 'catalog/orderexport/storage_id' ),
280
+ "hofakt_language" => Mage::getStoreConfig ( 'catalog/orderexport/store_language' ),
281
+ "payment" => $order->getPayment ()->getMethod (),
282
+ "shipping_amount" => $order->getShippingAmount (),
283
+ "discount_amount" => 0,
284
+ "discount_descr" => $order->getDiscountDescription (),
285
+ "net_total" => $order->getSubtotal (),
286
+ "tax_amount" => $order->getTaxAmount (),
287
+ "grand_total" => $order->getGrandTotal (),
288
+ "currency" => $order->getOrderCurrencyCode (),
289
+ "date" => $order->getCreatedAt (),
290
+ "customer" => array (
291
+ "customer_id" => $customer->getId (),
292
+ "customer_name" => $customer->getName (),
293
+ "customer_vatid" => $order->getCustomerTaxvat (),
294
+ "customer_email" => $customerEmail,
295
+ "customergroup" => $customerGroupName
296
+ ),
297
+ "shipping_address" => array (
298
+ "firstname" => $order->getShippingAddress ()->getFirstname (),
299
+ "lastname" => $order->getShippingAddress ()->getLastname (),
300
+ "company" => $order->getShippingAddress ()->getCompany (),
301
+ "street" => $streetSA [0],
302
+ "street2" => (count ( $streetSA ) == 2) ? $streetSA [1] : '',
303
+ "city" => $order->getShippingAddress ()->getCity (),
304
+ "postcode" => $order->getShippingAddress ()->getPostcode (),
305
+ "country" => $order->getShippingAddress ()->getCountry (),
306
+ "versadr1" => $order->getShippingAddress ()->getRegionCode (),
307
+ "phone" => $order->getShippingAddress ()->getTelephone (),
308
+ "addressid" => $order->getShippingAddress ()->getCustomerAddressId (),
309
+ "vatid" => $shipping_vat_id
310
+ ),
311
+ "billing_address" => array (
312
+ "firstname" => $order->getBillingAddress ()->getFirstname (),
313
+ "lastname" => $order->getBillingAddress ()->getLastname (),
314
+ "company" => $order->getBillingAddress ()->getCompany (),
315
+ "street" => $streetBA [0],
316
+ "street2" => (count ( $streetBA ) == 2) ? $streetBA [1] : '',
317
+ "city" => $order->getBillingAddress ()->getCity (),
318
+ "postcode" => $order->getBillingAddress ()->getPostcode (),
319
+ "country" => $order->getBillingAddress ()->getCountry (),
320
+ "versadr1" => $order->getBillingAddress ()->getRegionCode (),
321
+ "phone" => $order->getBillingAddress ()->getTelephone (),
322
+ "addressid" => $order->getBillingAddress ()->getCustomerAddressId (),
323
+ "vatid" => $billing_vat_id
324
+ ),
325
+ "lines" => $productArray
326
+ );
327
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
328
  return $saleorder;
329
  }
330
+ public function generateCatalogInventoryFile($schedule) {
331
+ Mage::log ( "ADVENTOS OrderExport CatalogInventoryExport - START" );
332
+ try {
333
+ $inventoryArray = array ();
334
+ $collection = Mage::getModel ( 'catalog/product' )->getCollection ();
335
+ foreach ( $collection->load () as $item ) {
336
+ $inventoryArray [] = array (
337
+ "sku" => $item->getSku (),
338
+ "qty" => ( int ) Mage::getModel ( 'cataloginventory/stock_item' )->loadByProduct ( $item )->getQty ()
 
 
 
339
  );
340
  }
341
+ $Xml = $this->toXml ( $inventoryArray, 'catalogInventory' );
342
  $file = "CatalogInventoryExport.xml";
343
+ $varExport = Mage::getBaseDir ( 'export' );
344
+ } catch ( Exception $e ) {
345
+ Mage::logException ( $e );
346
+ }
347
+
348
+ $web_exported = @array ();
349
+ $allStores = Mage::app ()->getStores ();
350
+ foreach ( $allStores as $_eachStoreId => $val ) {
351
+ $exportXml = $Xml;
352
+ $exportFile = $file;
353
+ $_storeId = Mage::app ()->getStore ( $_eachStoreId )->getId ();
354
+ $_webId = Mage::app ()->getStore ( $_eachStoreId )->getWebsiteId ();
355
+ $app = Mage::app ()->setCurrentStore ( $_storeId );
356
+ if (Mage::getStoreConfig ( 'catalog/orderexport/process' )) {
357
+ if (! in_array ( $_webId, $web_exported )) {
358
+ if (Mage::getStoreConfig ( 'catalog/orderexport/export_path' ) != null) {
359
+ if (Mage::getStoreConfig ( 'catalog/orderexport/export_path' ) != "") {
360
+ $orderExportPath = Mage::getStoreConfig ( 'catalog/orderexport/export_path' );
361
+ if (! is_dir ( $varExport . DS . $orderExportPath )) {
362
+ mkdir ( $varExport . DS . $orderExportPath );
363
+ Mage::log ( "ADVENTOS OrderExport Event - Add MultiShop ExportPath [" . $orderExportPath . "]" );
364
+ }
365
+ $exportFile = $orderExportPath . "/" . $exportFile;
366
+ }
367
+ }
368
+ $exportPath = $varExport . DS . $exportFile;
369
+ $handle = fopen ( $exportPath, "w+" );
370
+ fwrite ( $handle, $exportXml );
371
+ fclose ( $handle );
372
+ Mage::log ( "ADVENTOS OrderExport CatalogInventoryExport - [" . $orderExportPath . "] Done" );
373
+ }
374
+ array_push ( $web_exported, $_webId );
375
+ }
376
+ }
377
+ Mage::log ( "ADVENTOS OrderExport CatalogInventoryExport - END" );
378
+ }
379
+
380
+ /**
381
+ * Adds the "Export to HOFAKT" item to the drop down in admin > orders
382
+ * @param object $observer
383
+ */
384
+ public function addExportMassAction($observer) {
385
+ $block = $observer->getEvent()->getBlock();
386
+ // Check if this block is a MassAction block
387
+ if ($block instanceof Mage_Adminhtml_Block_Widget_Grid_Massaction) {
388
+ // Check if we're dealing with the Orders grid
389
+ if ($block->getParentBlock() instanceof Mage_Adminhtml_Block_Sales_Order_Grid) {
390
+ // The first parameter has to be unique, or you'll overwrite the old action.
391
+ $block->addItem('orderexport', array(
392
+ 'label' => 'Export to HOFAKT',
393
+ 'url' => $block->getUrl('order_export/adminhtml_index/export'),
394
+ )
395
+ );
396
+ }
397
+ }
398
+
399
+ }
400
+
401
+ /**
402
+ * Exports the order when the status of the order is updated from "pending" to processing
403
+ *
404
+ * @param object $observer
405
+ */
406
+ public function exportOnStatusChange($observer) {
407
+
408
+ $order = $observer->getEvent()->getOrder();
409
+
410
+ $oldStatus = $order->getOrigData('state');
411
+ $newStatus = $order->getState();
412
+ Mage::Log("==== Status Change Begin ===");
413
+ Mage::Log("Old Status: ".$oldStatus);
414
+ Mage::Log("New Status: ".$newStatus);
415
+
416
+ if ($oldStatus == Mage_Sales_Model_Order::STATE_NEW && $newStatus == Mage_Sales_Model_Order::STATE_PROCESSING) {
417
+ Mage::dispatchEvent('adventos_orderexport_export_single_order' , array('order' => $order));
418
+ Mage::Log("==== Export Event Fired ===");
419
  }
420
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
421
  }
422
  }
app/code/local/Adventos/OrderExport/Model/Observer.php.def DELETED
@@ -1,313 +0,0 @@
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
- * 20121011 ADD generateCatalogInventoryFile
15
- */
16
- class Adventos_OrderExport_Model_Observer
17
- {
18
- /**
19
- * Generate OrderExport
20
- *
21
- * @param Varien_Event_Observer $observer
22
- */
23
- public function createOrderExport($observer)
24
- {
25
- Mage::log("ADVENTOS OrderExport Event - START");
26
- if (Mage::getStoreConfig('catalog/orderexport/process')){
27
- Mage::log("ADVENTOS OrderExport Event - Generate Export enable");
28
- try
29
- {
30
- $order = $observer->getEvent()->getOrder();
31
-
32
- $storeId = $order->getStoreId();
33
- $webSite = Mage::getModel('core/store')->load($storeId)->getWebsiteId();
34
-
35
- $this->_exportOrder($order);
36
- Mage::log("ADVENTOS OrderExport Event - Store: ".$storeId);
37
- }
38
- catch (Exception $e)
39
- {
40
- Mage::logException($e);
41
- }
42
- }else{
43
- Mage::log("ADVENTOS OrderExport Event - Generate Export disable");
44
- }
45
- Mage::log("ADVENTOS OrderExport Event - END");
46
- }
47
-
48
-
49
-
50
- /**
51
- * write OrderDetails in XML-File
52
- *
53
- * @param Mage_Sales_Model_Order $order
54
- * @return Adventos_OrderExport_Model_Observer
55
- */
56
- protected function _exportOrder(Mage_Sales_Model_Order $order)
57
- {
58
- $ordArray = $this->createOrder($order);
59
- $ordXml = $this->toXml($ordArray,'salesOrder');
60
- $file = "SalesOrder_".$order->getId().".xml";
61
-
62
- $varExport = Mage::getBaseDir('export');
63
-
64
- if (Mage::getStoreConfig('catalog/orderexport/export_path') != null){
65
- if (Mage::getStoreConfig('catalog/orderexport/export_path') != ""){
66
- $OrderExportPath = Mage::getStoreConfig('catalog/orderexport/export_path');
67
- if(!is_dir($varExport.DS.$OrderExportPath)){
68
- Mage::log("ADVENTOS OrderExport Event - MultiShop ExportPath Folder not exist [".$OrderExportPath."]");
69
- mkdir($varExport.DS.$OrderExportPath);
70
- }
71
- $file = $OrderExportPath."/".$file;
72
- Mage::log("ADVENTOS OrderExport Event - Add MultiShop ExportPath [".$OrderExportPath."]");
73
- }
74
- }
75
-
76
- $exportPath = $varExport.DS.$file;
77
-
78
- $handle = fopen($exportPath,"w+");
79
- fwrite($handle,$ordXml);
80
- fclose($handle);
81
-
82
- return $this;
83
- }
84
-
85
- public function toXML($data, $rootNodeName='base',$xml=null){
86
- if ($xml == null){
87
- /*$xml = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><$rootNodeName />");
88
- * Change encoding from UTF-8 to CP850
89
- */
90
- $xml = simplexml_load_string("<?xml version='1.0' encoding='cp850'?><$rootNodeName />");
91
- }
92
-
93
- // loop through the data passed in.
94
-
95
- foreach($data as $key => $value){
96
- // no numeric keys in our xml please!
97
- if (is_numeric($key)){
98
- // make item key for product array ...
99
- $key = "item"; //.$key;
100
- }
101
- // replace anything not alpha numeric
102
- $key = preg_replace('/[^a-z0-9]/i', '', $key);
103
- // if there is another array found recrusively call this function
104
-
105
- if (is_array($value)){
106
- $node = $xml->addChild($key);
107
- // recrusive call.
108
- Adventos_OrderExport_Model_Observer::toXML($value, $rootNodeName, $node);
109
- } else {
110
- // add single node.
111
- $value = str_replace('€','EUR',$value);
112
- $xml->addChild($key,$value);
113
- }
114
-
115
- }
116
-
117
- // we want the XML to be formatted,
118
- //20110722 add encoding CP850 for incredible stupid HOFAKT
119
- $doc = new DOMDocument('1.0', 'cp850');
120
- $doc->preserveWhiteSpace = false;
121
- $doc->loadXML( $xml->asXML() );
122
- $doc->formatOutput = true;
123
- return $doc->saveXML();
124
- }
125
-
126
- public function createOrder($order){
127
-
128
- $productArray = array(); // sale order line product wrapper
129
-
130
- // Magento required models
131
- $customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
132
-
133
- // walk the sale order lines
134
- foreach ($order->getAllVisibleItems() as $item) //getAllItems() - getItemCollection()
135
- {
136
- $tax_amount = $item->getTaxAmount();
137
- if ($tax_amount > 0) {
138
- $product_row_price = ($item->getQtyOrdered() * $item->getData('original_price') - $item->getDiscountAmount()) / $item->getQtyOrdered();
139
- }else{
140
- $product_row_price = ($item->getQtyOrdered() * $item->getPrice() - $item->getDiscountAmount()) / $item->getQtyOrdered();
141
- }
142
- <<<<<<< .mine
143
- // if (!defined('OUTPUTLIKE')){
144
- $attributes = array_keys($item->getData());
145
- Mage::log($attributes);
146
- Mage:log(print_r($attributes));
147
- Mage::log($item->getQtyOrdered()."-".$item->getPrice()."-".$item->getOrginalPrice()."-".$item->getDiscountAmount()."-".$item->getData('original_price'));
148
- //$item->getAttributes();
149
- // foreach ($attributes as $attribute) {
150
- // if ($attribute->getIsVisibleOnFront()) {
151
- // $value = $attribute->getValue($item);
152
- // Mage::log("itemarray - ".$attribute."=".$value."|");
153
- // // do something with $value here
154
- // }
155
- // }
156
- // define('OUTPUTLIKE', "FALSE");
157
- // }
158
-
159
- =======
160
- //Mage::log($item);
161
- //Mage:log(print_r($item));
162
- >>>>>>> .r31
163
- $productArray[] = array(
164
- "product_sku" => $item->getSku(),
165
- "product_magento_id" => $item->getProductId(),
166
- "product_name" => $item->getName(),
167
- "product_qty" => $item->getQtyOrdered(),
168
- "product_price" => $item->getPrice(),
169
- "product_discount_percent" => $item->getDiscountPercent(),
170
- "product_row_discount_amount" => $item->getDiscountAmount(),
171
- "product_row_price" => $product_row_price,
172
- "product_order_id" => $order->getRealOrderId(),
173
- "product_order_item_id" => $item->getId(),
174
- "product_description" => "",
175
- );
176
- }
177
-
178
- $streetBA = $order->getBillingAddress()->getStreet();
179
- $streetSA = $order->getShippingAddress()->getStreet();
180
-
181
- $customerGroupId = $order->getCustomerGroupId();
182
- $customerGroupName = "";
183
-
184
- $group = Mage::getModel ('customer/group')->load ($customerGroupId);
185
- if ($group->getId()){
186
- $customerGroupName = $group->getCode();
187
- }
188
-
189
- if($customer->getEmail() == "") {
190
- $customerEmail = $order->getCustomerEmail();
191
- } else {
192
- $customerEmail = $customer->getEmail();
193
- }
194
-
195
- $exportVatGroup = Mage::getStoreConfig('catalog/orderexport/B2B_HomeGroup');
196
- $exportVatGroup = explode(",", $exportVatGroup);
197
-
198
- if (in_array($customerGroupId, $exportVatGroup)) {
199
- $order->getBillingAddress()->getvat_id() ? $billing_vat_id = $order->getBillingAddress()->getCountry().$order->getBillingAddress()->getvat_id() : $billing_vat_id = "";
200
- $order->getShippingAddress()->getvat_id() ? $shipping_vat_id = $order->getShippingAddress()->getCountry().$order->getShippingAddress()->getvat_id() : $shipping_vat_id = "";
201
- }else{
202
- $billing_vat_id = "";
203
- $shipping_vat_id = "";
204
- }
205
-
206
- $saleorder = array(
207
- "id" => $order->getRealOrderId(),
208
- "store_id" => $order->getStoreId(),
209
- "store_name" => Mage::getModel('core/store')->load($order->getStoreID())->getName(),
210
- "hofakt_lager" => Mage::getStoreConfig('catalog/orderexport/storage_id'),
211
- "hofakt_language" => Mage::getStoreConfig('catalog/orderexport/store_language'),
212
- "payment" => $order->getPayment()->getMethod(),
213
- "shipping_amount" => $order->getShippingAmount(),
214
- "discount_amount" => 0,
215
- "discount_descr" => $order->getDiscountDescription(),
216
- "net_total" => $order->getSubtotal(),
217
- "tax_amount" => $order->getTaxAmount(),
218
- "grand_total" => $order->getGrandTotal(),
219
- "currency" => $order->getOrderCurrencyCode(),
220
- "date" => $order->getCreatedAt(),
221
- "customer" => array(
222
- "customer_id" => $customer->getId(),
223
- "customer_name" => $customer->getName(),
224
- "customer_vatid" => $order->getCustomerTaxvat(),
225
- "customer_email" => $customerEmail,
226
- "customergroup" => $customerGroupName
227
- ),
228
- "shipping_address" => array(
229
- "firstname" => $order->getShippingAddress()->getFirstname(),
230
- "lastname" => $order->getShippingAddress()->getLastname(),
231
- "company" => $order->getShippingAddress()->getCompany(),
232
- "street" => $streetSA[0],
233
- "street2" => (count($streetSA)==2)?$streetSA[1]:'',
234
- "city" => $order->getShippingAddress()->getCity(),
235
- "postcode" => $order->getShippingAddress()->getPostcode(),
236
- "country" => $order->getShippingAddress()->getCountry(),
237
- "phone" => $order->getShippingAddress()->getTelephone(),
238
- "addressid" => $order->getShippingAddress()->getCustomerAddressId(),
239
- "vatid" => $shipping_vat_id
240
- ),
241
- "billing_address" => array(
242
- "firstname" => $order->getBillingAddress()->getFirstname(),
243
- "lastname" => $order->getBillingAddress()->getLastname(),
244
- "company" => $order->getBillingAddress()->getCompany(),
245
- "street" => $streetBA[0],
246
- "street2" => (count($streetBA)==2)?$streetBA[1]:'',
247
- "city" => $order->getBillingAddress()->getCity(),
248
- "postcode" => $order->getBillingAddress()->getPostcode(),
249
- "country" => $order->getBillingAddress()->getCountry(),
250
- "phone" => $order->getBillingAddress()->getTelephone(),
251
- "addressid" => $order->getBillingAddress()->getCustomerAddressId(),
252
- "vatid" => $billing_vat_id
253
- ),
254
- "lines" => $productArray,
255
- );
256
-
257
- return $saleorder;
258
- }
259
-
260
- public function generateCatalogInventoryFile($schedule){
261
- Mage::log("ADVENTOS OrderExport CatalogInventoryExport - START");
262
- try
263
- {
264
- $inventoryArray = array();
265
- $collection = Mage::getModel('catalog/product')->getCollection();
266
- foreach ($collection->load() as $item)
267
- {
268
- $inventoryArray[] = array(
269
- "sku" => $item->getSku(),
270
- "qty" => (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($item)->getQty(),
271
- );
272
- }
273
- $Xml = $this->toXml($inventoryArray,'catalogInventory');
274
- $file = "CatalogInventoryExport.xml";
275
- $varExport = Mage::getBaseDir('export');
276
- }
277
- catch (Exception $e)
278
- {
279
- Mage::logException($e);
280
- }
281
-
282
- $web_exported = @array();
283
- $allStores = Mage::app()->getStores();
284
- foreach ($allStores as $_eachStoreId => $val) {
285
- $exportXml = $Xml;
286
- $exportFile = $file;
287
- $_storeId = Mage::app()->getStore($_eachStoreId)->getId();
288
- $_webId = Mage::app()->getStore($_eachStoreId)->getWebsiteId();
289
- $app = Mage::app()->setCurrentStore($_storeId);
290
- if (Mage::getStoreConfig('catalog/orderexport/process')){
291
- if (!in_array($_webId, $web_exported)){
292
- if (Mage::getStoreConfig('catalog/orderexport/export_path') != null){
293
- if (Mage::getStoreConfig('catalog/orderexport/export_path') != ""){
294
- $orderExportPath = Mage::getStoreConfig('catalog/orderexport/export_path');
295
- if(!is_dir($varExport.DS.$orderExportPath)){
296
- mkdir($varExport.DS.$orderExportPath);
297
- Mage::log("ADVENTOS OrderExport Event - Add MultiShop ExportPath [".$orderExportPath."]");
298
- }
299
- $exportFile = $orderExportPath."/".$exportFile;
300
- }
301
- }
302
- $exportPath = $varExport.DS.$exportFile;
303
- $handle = fopen($exportPath,"w+");
304
- fwrite($handle,$exportXml);
305
- fclose($handle);
306
- Mage::log("ADVENTOS OrderExport CatalogInventoryExport - [".$orderExportPath."] Done");
307
- }
308
- array_push($web_exported, $_webId);
309
- }
310
- }
311
- Mage::log("ADVENTOS OrderExport CatalogInventoryExport - END");
312
- }
313
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Adventos/OrderExport/controllers/Adminhtml/IndexController.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Adventos_OrderExport_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action {
3
+ /**
4
+ * Export selected orders to XML files in order to be used by HOFAKT
5
+ */
6
+ public function exportAction() {
7
+ try {
8
+ $orderIds = $this->getRequest()->getParam('order_ids');
9
+ foreach($orderIds as $orderId) {
10
+ $order = Mage::getModel('sales/order')->load($orderId);
11
+ // Triggering this event causes oberver's createOrderExport method to be run
12
+ Mage::dispatchEvent('adventos_orderexport_export_single_order' , array('order' => $order));
13
+ }
14
+ Mage::getSingleton('core/session')->addSuccess('Selected orders have been successfully exported');
15
+ }
16
+ catch (Exception $e) {
17
+ Mage::getSingleton('core/session')->addError('Error exporting orders. Details: '.$e->getMessage());
18
+ }
19
+ $this->_redirectReferer(); // return to the admin page
20
+ }
21
+ }
22
+ ?>
app/code/local/Adventos/OrderExport/etc/config.xml CHANGED
@@ -2,9 +2,20 @@
2
  <config>
3
  <modules>
4
  <Adventos_OrderExport>
5
- <version>1.3.6</version>
6
  </Adventos_OrderExport>
7
  </modules>
 
 
 
 
 
 
 
 
 
 
 
8
  <global>
9
  <models>
10
  <orderexport>
@@ -17,7 +28,7 @@
17
  </orderexport>
18
  </helpers>
19
  <events>
20
- <sales_order_place_after>
21
  <observers>
22
  <orderexport>
23
  <type>singleton</type>
@@ -25,7 +36,34 @@
25
  <method>createOrderExport</method>
26
  </orderexport>
27
  </observers>
28
- </sales_order_place_after>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  </events>
30
  </global>
31
  <crontab>
2
  <config>
3
  <modules>
4
  <Adventos_OrderExport>
5
+ <version>1.3.9</version>
6
  </Adventos_OrderExport>
7
  </modules>
8
+ <admin>
9
+ <routers>
10
+ <adventos_orderexport>
11
+ <use>admin</use>
12
+ <args>
13
+ <module>Adventos_OrderExport</module>
14
+ <frontName>order_export</frontName>
15
+ </args>
16
+ </adventos_orderexport>
17
+ </routers>
18
+ </admin>
19
  <global>
20
  <models>
21
  <orderexport>
28
  </orderexport>
29
  </helpers>
30
  <events>
31
+ <!--sales_order_place_after>
32
  <observers>
33
  <orderexport>
34
  <type>singleton</type>
36
  <method>createOrderExport</method>
37
  </orderexport>
38
  </observers>
39
+ </sales_order_place_after-->
40
+ <core_block_abstract_to_html_before>
41
+ <observers>
42
+ <exportmassaction>
43
+ <type>singleton</type>
44
+ <class>orderexport/observer</class>
45
+ <method>addExportMassAction</method>
46
+ </exportmassaction>
47
+ </observers>
48
+ </core_block_abstract_to_html_before>
49
+ <adventos_orderexport_export_single_order>
50
+ <observers>
51
+ <orderexport>
52
+ <type>singleton</type>
53
+ <class>orderexport/observer</class>
54
+ <method>createOrderExport</method>
55
+ </orderexport>
56
+ </observers>
57
+ </adventos_orderexport_export_single_order>
58
+ <sales_order_save_commit_after>
59
+ <observers>
60
+ <ordersaved>
61
+ <type>singleton</type>
62
+ <class>orderexport/observer</class>
63
+ <method>exportOnStatusChange</method>
64
+ </ordersaved>
65
+ </observers>
66
+ </sales_order_save_commit_after>
67
  </events>
68
  </global>
69
  <crontab>
package.xml CHANGED
@@ -1,19 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Adventos_OrderExport</name>
4
- <version>1.3.8</version>
5
  <stability>stable</stability>
6
  <license>OSL</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Magento integration for HeadOffice</summary>
10
  <description>Create Order XML file to integrate Magento with HeadOffice and synchronize stock, order status, invoice, shipments and credit memos.</description>
11
- <notes>add state to address&#xD;
12
- php XML bug workaround</notes>
13
  <authors><author><name>Karsten Hoffmann</name><user>adventos</user><email>karsten@adventos.de</email></author></authors>
14
- <date>2013-09-10</date>
15
- <time>11:22:04</time>
16
- <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="797a58eedbbe8bf1a0c20d7c8599f8be"/></dir><file name="Api.php" hash="c41e82cf79235d51f25d248719e93f92"/></dir><dir name="Invoice"><dir name="Api"><file name="V2.php" hash="3596dc5fe58a597ba5f244b52687288e"/></dir><file name="Api.php" hash="280512b1ae37690871384b3cba0a3a2b"/></dir><file name="Observer.php" hash="edeb43ec4129f24a099c9c3f9d864dab"/><file name="Observer.php.def" hash="8849a673153fbab13536e3f83d605c3c"/><dir name="Shipment"><dir name="Api"><file name="V2.php" hash="3d7824e13e4d5cedb755b4858398f23e"/></dir><file name="Api.php" hash="0b9bf452b7e36c1ee5cefbb3d6c5eb3b"/></dir></dir><dir name="etc"><file name="api.xml" hash="c1b2bc277e329b8191bcc5358cb96581"/><file name="config.xml" hash="cdbbf42811356eed0919a776765e98c9"/><file name="system.xml" hash="d7feaf247eed064d617138508dd88fe4"/><file name="wsdl.xml" hash="1538d2cb05f819c45e807f992c1b7cb3"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Adventos_OrderExport.xml" hash="479b13bf3a08de9f93f5f58d77d3f9bb"/></dir></target></contents>
17
  <compatible/>
18
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
19
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Adventos_OrderExport</name>
4
+ <version>1.3.9</version>
5
  <stability>stable</stability>
6
  <license>OSL</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Magento integration for HeadOffice</summary>
10
  <description>Create Order XML file to integrate Magento with HeadOffice and synchronize stock, order status, invoice, shipments and credit memos.</description>
11
+ <notes>Add Handling Fee NL</notes>
 
12
  <authors><author><name>Karsten Hoffmann</name><user>adventos</user><email>karsten@adventos.de</email></author></authors>
13
+ <date>2014-08-21</date>
14
+ <time>08:02:50</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="797a58eedbbe8bf1a0c20d7c8599f8be"/></dir><file name="Api.php" hash="c41e82cf79235d51f25d248719e93f92"/></dir><dir name="Invoice"><dir name="Api"><file name="V2.php" hash="3596dc5fe58a597ba5f244b52687288e"/></dir><file name="Api.php" hash="280512b1ae37690871384b3cba0a3a2b"/></dir><file name="Observer.php" hash="2a4b8e9b630b15a107093b24506d9a85"/><dir name="Shipment"><dir name="Api"><file name="V2.php" hash="3d7824e13e4d5cedb755b4858398f23e"/></dir><file name="Api.php" hash="0b9bf452b7e36c1ee5cefbb3d6c5eb3b"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="IndexController.php" hash="b9e0e5a0baabed9482061f5c7c12a5ff"/></dir></dir><dir name="etc"><file name="api.xml" hash="c1b2bc277e329b8191bcc5358cb96581"/><file name="config.xml" hash="7ffaa5d955b3bd7bcd31d559752be89a"/><file name="system.xml" hash="d7feaf247eed064d617138508dd88fe4"/><file name="wsdl.xml" hash="1538d2cb05f819c45e807f992c1b7cb3"/></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.1.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>