Indianic_Reviewimportexport - Version 1.0.0.1

Version Notes

Stable version

Download this release

Release Info

Developer muffadal
Extension Indianic_Reviewimportexport
Version 1.0.0.1
Comparing to
See all releases


Version 1.0.0.1

app/code/local/Indianic/Reviewexport/Model/Convert/Adapter/Reviewimport.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Indianic_Reviewexport_Model_Convert_Adapter_Reviewimport extends Mage_Catalog_Model_Convert_Adapter_Product
3
+
4
+ {
5
+ public function saveRow( array $data )
6
+ {
7
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
8
+ $sku = $write->query('select entity_id from `catalog_product_entity` where sku = "'.$data['Sku'].'" ');
9
+ $sku = $sku->fetch();
10
+ if($sku)
11
+ {
12
+ $product_id = $sku['entity_id'];
13
+ if($data['customer_id']=='')
14
+ {
15
+ $customerid = NULL; //Mage::getSingleton('admin/session')->getUser()->getUserId();
16
+ }
17
+ else
18
+ {
19
+ $customerid = $data['customer_id'];
20
+ /* $_customer = Mage::getModel('customer/customer')->load($customerid);
21
+ $_session = Mage::getSingleton('customer/session')->setCustomer($_customer)->setCustomerAsLoggedIn($_customer);*/
22
+ }
23
+ $_review = Mage::getModel('review/review')
24
+ ->setCreatedAt($data['created_at'])
25
+ ->setEntityPkValue($product_id)
26
+ ->setEntityId(1)
27
+ ->setStatusId($data['status_id'])
28
+ ->setTitle($data['title'])
29
+ ->setDetail($data['detail'])
30
+ ->setStoreId(1)
31
+ ->setStores(array(Mage::app()->getStore()->getId()))
32
+ ->setCustomerId($customerid)
33
+ ->setNickname($data['nickname'])
34
+ ->save();
35
+ if($data['option_id'])
36
+ {
37
+ Mage::getModel('rating/rating')
38
+ ->setRatingId(1)
39
+ ->setReviewId($_review->getId())
40
+ ->setCustomerId($customerid)
41
+ ->addOptionVote($data['option_id'], $product_id);
42
+ $_review->aggregate();
43
+
44
+ }
45
+
46
+ }
47
+ }
48
+
49
+ }
50
+
app/code/local/Indianic/Reviewexport/Model/Convert/Parser/Exportorders.php ADDED
@@ -0,0 +1,987 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ExportOrders.php
4
+ * CommerceThemes @ InterSEC Solutions LLC.
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the EULA
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://www.commercethemes.com/LICENSE-M1.txt
12
+ *
13
+ * @category Orders
14
+ * @package Exportorders
15
+ * @copyright Copyright (c) 2003-2009 CommerceThemes @ InterSEC Solutions LLC. (http://www.commercethemes.com)
16
+ * @license http://www.commercethemes.com/LICENSE-M1.txt
17
+ */
18
+
19
+ class Intersec_Orderimportexport_Model_Convert_Parser_Exportorders
20
+ extends Mage_Eav_Model_Convert_Parser_Abstract
21
+ {
22
+ const MULTI_DELIMITER = ' , ';
23
+
24
+ protected $_resource;
25
+
26
+ /**
27
+ * Product collections per store
28
+ *
29
+ * @var array
30
+ */
31
+ protected $_collections;
32
+
33
+ protected $_customerModel;
34
+ protected $_customerAddressModel;
35
+ protected $_newsletterModel;
36
+ protected $_store;
37
+ protected $_storeId;
38
+
39
+ protected $_stores;
40
+
41
+ /**
42
+ * Website collection array
43
+ *
44
+ * @var array
45
+ */
46
+ protected $_websites;
47
+ protected $_attributes = array();
48
+
49
+ protected $_fields;
50
+
51
+ public function getFields()
52
+ {
53
+ if (!$this->_fields) {
54
+ $this->_fields = Mage::getConfig()->getFieldset('customer_dataflow', 'admin');
55
+ }
56
+ return $this->_fields;
57
+ }
58
+
59
+ /**
60
+ * Retrieve customer model cache
61
+ *
62
+ * @return Mage_Customer_Model_Customer
63
+ */
64
+ public function getCustomerModel()
65
+ {
66
+ if (is_null($this->_customerModel)) {
67
+ $object = Mage::getModel('customer/customer');
68
+ $this->_customerModel = Mage::objects()->save($object);
69
+ }
70
+ return Mage::objects()->load($this->_customerModel);
71
+ }
72
+
73
+ /**
74
+ * Retrieve customer address model cache
75
+ *
76
+ * @return Mage_Customer_Model_Address
77
+ */
78
+ public function getCustomerAddressModel()
79
+ {
80
+ if (is_null($this->_customerAddressModel)) {
81
+ $object = Mage::getModel('customer/address');
82
+ $this->_customerAddressModel = Mage::objects()->save($object);
83
+ }
84
+ return Mage::objects()->load($this->_customerAddressModel);
85
+ }
86
+
87
+ /**
88
+ * Retrieve newsletter subscribers model cache
89
+ *
90
+ * @return Mage_Newsletter_Model_Subscriber
91
+ */
92
+ public function getNewsletterModel()
93
+ {
94
+ if (is_null($this->_newsletterModel)) {
95
+ $object = Mage::getModel('newsletter/subscriber');
96
+ $this->_newsletterModel = Mage::objects()->save($object);
97
+ }
98
+ return Mage::objects()->load($this->_newsletterModel);
99
+ }
100
+
101
+ /**
102
+ * Retrieve current store model
103
+ *
104
+ * @return Mage_Core_Model_Store
105
+ */
106
+ public function getStore()
107
+ {
108
+ if (is_null($this->_store)) {
109
+ try {
110
+ $store = Mage::app()->getStore($this->getVar('store'));
111
+ }
112
+ catch (Exception $e) {
113
+ $this->addException(Mage::helper('catalog')->__('Invalid store specified'), Varien_Convert_Exception::FATAL);
114
+ throw $e;
115
+ }
116
+ $this->_store = $store;
117
+ }
118
+ return $this->_store;
119
+ }
120
+
121
+ /**
122
+ * Retrieve store ID
123
+ *
124
+ * @return int
125
+ */
126
+ public function getStoreId()
127
+ {
128
+ if (is_null($this->_storeId)) {
129
+ $this->_storeId = $this->getStore()->getId();
130
+ }
131
+ return $this->_storeId;
132
+ }
133
+
134
+ public function getStoreById($storeId)
135
+ {
136
+ if (is_null($this->_stores)) {
137
+ $this->_stores = Mage::app()->getStores(true);
138
+ }
139
+ if (isset($this->_stores[$storeId])) {
140
+ return $this->_stores[$storeId];
141
+ }
142
+ return false;
143
+ }
144
+
145
+ /**
146
+ * Retrieve website model by id
147
+ *
148
+ * @param int $websiteId
149
+ * @return Mage_Core_Model_Website
150
+ */
151
+ public function getWebsiteById($websiteId)
152
+ {
153
+ if (is_null($this->_websites)) {
154
+ $this->_websites = Mage::app()->getWebsites(true);
155
+ }
156
+ if (isset($this->_websites[$websiteId])) {
157
+ return $this->_websites[$websiteId];
158
+ }
159
+ return false;
160
+ }
161
+
162
+ /**
163
+ * Retrieve eav entity attribute model
164
+ *
165
+ * @param string $code
166
+ * @return Mage_Eav_Model_Entity_Attribute
167
+ */
168
+ public function getAttribute($code)
169
+ {
170
+ if (!isset($this->_attributes[$code])) {
171
+ $this->_attributes[$code] = $this->getCustomerModel()->getResource()->getAttribute($code);
172
+ }
173
+ return $this->_attributes[$code];
174
+ }
175
+
176
+ /**
177
+ * @return Mage_Catalog_Model_Mysql4_Convert
178
+ */
179
+ public function getResource()
180
+ {
181
+ if (!$this->_resource) {
182
+ $this->_resource = Mage::getResourceSingleton('catalog_entity/convert');
183
+ #->loadStores()
184
+ #->loadProducts()
185
+ #->loadAttributeSets()
186
+ #->loadAttributeOptions();
187
+ }
188
+ return $this->_resource;
189
+ }
190
+
191
+ public function getCollection($storeId)
192
+ {
193
+ if (!isset($this->_collections[$storeId])) {
194
+ $this->_collections[$storeId] = Mage::getResourceModel('customer/customer_collection');
195
+ $this->_collections[$storeId]->getEntity()->setStore($storeId);
196
+ }
197
+ return $this->_collections[$storeId];
198
+ }
199
+
200
+ public function unparse()
201
+ {
202
+ #print_r($this->getData());
203
+ $i="";
204
+ //NOTE IN SOME RANDOM CASES ->addAttributeToSelect('increment_id') must be ->addAttributeToSelect('*') or data all blank
205
+ if($this->getVar('date_from') != "" && $this->getVar('date_to') != "" && $this->getVar('filter_by_order_status') != "" ) {
206
+
207
+ $date_from = $this->getVar('date_from'). " 00:00:00";
208
+ $date_to = $this->getVar('date_to'). " 23:59:59";
209
+ $orders = Mage::getModel('sales/order')->getCollection()
210
+ ->addAttributeToSelect('*')
211
+ ->addAttributeToFilter ( 'created_at' , array( "from" => $date_from, "to" => $date_to, "datetime" => true ))
212
+ ->addFieldToFilter ( 'status' , array( "eq" => $this->getVar('filter_by_order_status') ))
213
+ ->load();
214
+ } else if($this->getVar('date_from') != "" && $this->getVar('date_to') != "" && $this->getVar('filter_by_store_id') != "") {
215
+
216
+ $date_from = $this->getVar('date_from'). " 00:00:00";
217
+ $date_to = $this->getVar('date_to'). " 23:59:59";
218
+ $orders = Mage::getModel('sales/order')->getCollection()
219
+ ->addAttributeToSelect('*')
220
+ ->addAttributeToFilter ( 'store_id' , $this->getVar('filter_by_store_id'))
221
+ ->addAttributeToFilter ( 'created_at' , array( "from" => $date_from, "to" => $date_to, "datetime" => true ))
222
+ ->load();
223
+ } else if($this->getVar('date_from') != "" && $this->getVar('date_to') != "" ) {
224
+
225
+ $date_from = $this->getVar('date_from'). " 00:00:00";
226
+ $date_to = $this->getVar('date_to'). " 23:59:59";
227
+ $orders = Mage::getModel('sales/order')->getCollection()
228
+ ->addAttributeToSelect('*')
229
+ ->addAttributeToFilter ( 'created_at' , array( "from" => $date_from, "to" => $date_to, "datetime" => true ))
230
+ ->load();
231
+ } else if($this->getVar('filter_by_order_status') != "" ) {
232
+ $orders = Mage::getModel('sales/order')->getCollection()
233
+ ->addAttributeToSelect('*')
234
+ ->addFieldToFilter ( 'status' , array( "eq" => $this->getVar('filter_by_order_status') ))
235
+ ->load();
236
+ } else if($this->getVar('filter_by_store_id') != "" ) {
237
+
238
+ $orders = Mage::getModel('sales/order')->getCollection()
239
+ ->addAttributeToSelect('*')
240
+ ->addAttributeToFilter ( 'store_id' , $this->getVar('filter_by_store_id'))
241
+ ->load();
242
+ } else {
243
+ $orders = Mage::getModel('sales/order')->getCollection()->addAttributeToSelect('*')->load();
244
+ #$entityIds = $this->getData();
245
+ }
246
+
247
+ $recordlimit = $this->getVar('recordlimit');
248
+ $systemFields = array();
249
+ foreach ($this->getFields() as $code=>$node) {
250
+ if ($node->is('system')) {
251
+ $systemFields[] = $code;
252
+ }
253
+ }
254
+
255
+
256
+ $overallcount = 1;
257
+ foreach ($orders as $entityId) {
258
+
259
+ if ($overallcount < $recordlimit) {
260
+ $order = Mage::getModel('sales/order')->load($entityId->getId());
261
+ #print_r($order);
262
+ //echo "CUSTOMER ID: " . $order->getData('customer_id');
263
+ $customerId = $order->getData('customer_id');
264
+ $store = $this->getStore();
265
+ $storefromorder = Mage::app()->getStore($order->getStoreId());
266
+
267
+ $row = array();
268
+
269
+ $row['order_id'] = $order->getData('increment_id');
270
+ //echo "isguest: " . $order->getCustomerIsGuest();
271
+ /* THIS HERE GETS ARE INFORMATION IF ITS A GUEST THAT CHECKOUT AND NOT AN ACTUAL CUSTOMER */
272
+ if ($order->getCustomerIsGuest()) {
273
+
274
+ $valueid = $store->getData('website_id');
275
+ $website = $this->getWebsiteById($valueid);
276
+ //print($website);
277
+ $row['website'] = $website->getCode();
278
+ #$row['website'] = $storefromorder->getCode();
279
+ $row['group_id'] = $store->getGroup()->getName();
280
+
281
+ if(method_exists($order, 'getBillingAddress') && method_exists($order->getBillingAddress(), 'getData')) {
282
+ $row['prefix'] = $order->getBillingAddress()->getData('prefix');
283
+ $row['firstname'] = $order->getBillingAddress()->getData('firstname');
284
+ $row['middlename'] = $order->getBillingAddress()->getData('middlename');
285
+ $row['lastname'] = $order->getBillingAddress()->getData('lastname');
286
+ $row['suffix'] = $order->getBillingAddress()->getData('suffix');
287
+ $row['password'] = "changeme";
288
+ $row['billing_prefix'] = $order->getBillingAddress()->getData('prefix');
289
+ $row['billing_firstname'] = $order->getBillingAddress()->getData('firstname');
290
+ $row['billing_middlename'] = $order->getBillingAddress()->getData('middlename');
291
+ $row['billing_lastname'] = $order->getBillingAddress()->getData('lastname');
292
+ $row['billing_suffix'] = $order->getBillingAddress()->getData('suffix');
293
+ #$row['billing_street_full'] = $order->getBillingAddress()->getData('street');
294
+ $row['billing_street_full'] = $order->getBillingAddress()->getStreet(1);
295
+ $row['billing_street_2'] = $order->getBillingAddress()->getStreet(2);
296
+ $row['billing_city'] = $order->getBillingAddress()->getData('city');
297
+ $row['billing_region'] = $order->getBillingAddress()->getData('region');
298
+ $row['billing_country'] = $order->getBillingAddress()->getData('country_id');
299
+ $row['billing_postcode'] = $order->getBillingAddress()->getData('postcode');
300
+ $row['billing_telephone'] = $order->getBillingAddress()->getData('telephone');
301
+ $row['billing_company'] = $order->getBillingAddress()->getData('company');
302
+ $row['billing_fax'] = $order->getBillingAddress()->getData('fax');
303
+ } else {
304
+ $row['prefix'] = $order->getData('prefix');
305
+ $row['firstname'] = $order->getData('firstname');
306
+ $row['middlename'] = $order->getData('middlename');
307
+ $row['lastname'] = $order->getData('lastname');
308
+ $row['suffix'] = $order->getData('suffix');
309
+ $row['password'] = "changeme";
310
+ $row['billing_prefix'] = $order->getData('prefix');
311
+ $row['billing_firstname'] = $order->getData('firstname');
312
+ $row['billing_middlename'] = $order->getData('middlename');
313
+ $row['billing_lastname'] = $order->getData('lastname');
314
+ $row['billing_suffix'] = $order->getData('suffix');
315
+ $row['billing_street_full'] = $order->getData('street');
316
+ $row['billing_street_2'] = "";
317
+ $row['billing_city'] = $order->getData('city');
318
+ $row['billing_region'] = $order->getData('region');
319
+ $row['billing_country'] = $order->getData('country_id');
320
+ $row['billing_postcode'] = $order->getData('postcode');
321
+ $row['billing_telephone'] = $order->getData('telephone');
322
+ $row['billing_company'] = $order->getData('company');
323
+ $row['billing_fax'] = $order->getData('fax');
324
+ }
325
+ //THIS CHECKS TO MAKE SURE WE ALSO HAVE A SHIPPING ADDDRESS FOR THIS ORDER IN SOMECASE WE MAY NOT.
326
+ if(method_exists($order, 'getShippingAddress') && method_exists($order->getShippingAddress(), 'getData')) {
327
+ $row['shipping_prefix'] = $order->getShippingAddress()->getData('prefix');
328
+ $row['shipping_firstname'] = $order->getShippingAddress()->getData('firstname');
329
+ $row['shipping_middlename'] = $order->getShippingAddress()->getData('middlename');
330
+ $row['shipping_lastname'] = $order->getShippingAddress()->getData('lastname');
331
+ $row['shipping_suffix'] = $order->getShippingAddress()->getData('suffix');
332
+ $row['shipping_street_full'] = $order->getShippingAddress()->getStreet(1);
333
+ $row['shipping_street_2'] = $order->getShippingAddress()->getStreet(2);
334
+ $row['shipping_city'] = $order->getShippingAddress()->getData('city');
335
+ $row['shipping_region'] = $order->getShippingAddress()->getData('region');
336
+ $row['shipping_country'] = $order->getShippingAddress()->getData('country_id');
337
+ $row['shipping_postcode'] = $order->getShippingAddress()->getData('postcode');
338
+ $row['shipping_telephone'] = $order->getShippingAddress()->getData('telephone');
339
+ $row['shipping_company'] = $order->getShippingAddress()->getData('company');
340
+ $row['shipping_fax'] = $order->getShippingAddress()->getData('fax');
341
+ } else {
342
+ $row['shipping_prefix'] = $order->getData('prefix');
343
+ $row['shipping_firstname'] = $order->getData('firstname');
344
+ $row['shipping_middlename'] = $order->getData('middlename');
345
+ $row['shipping_lastname'] = $order->getData('lastname');
346
+ $row['shipping_suffix'] = $order->getData('suffix');
347
+ $row['shipping_street_full'] = $order->getStreet(1);
348
+ $row['shipping_street_2'] = $order->getStreet(2);
349
+ $row['shipping_city'] = $order->getData('city');
350
+ $row['shipping_region'] = $order->getData('region');
351
+ $row['shipping_country'] = $order->getData('country_id');
352
+ $row['shipping_postcode'] = $order->getData('postcode');
353
+ $row['shipping_telephone'] = $order->getData('telephone');
354
+ $row['shipping_company'] = $order->getData('company');
355
+ $row['shipping_fax'] = $order->getData('fax');
356
+ }
357
+ $row['email'] = $order->getCustomerEmail();
358
+ $row['customers_id'] = "0";
359
+
360
+ } else {
361
+ $customer = $this->getCustomerModel()
362
+ ->setData(array())
363
+ ->load($customerId);
364
+ /* @var $customer Mage_Customer_Model_Customer */
365
+
366
+ $position = Mage::helper('catalog')->__('Line %d, Email: %s', ($i+1), $customer->getEmail());
367
+ $this->setPosition($position);
368
+
369
+ foreach ($customer->getData() as $field => $value) {
370
+ //echo "FIELDS: " . $field;
371
+ if ($field == 'website_id') {
372
+ $website = $this->getWebsiteById($value);
373
+ if ($website === false) {
374
+ $website = $this->getWebsiteById(0);
375
+ }
376
+ $row['website'] = $website->getCode();
377
+ #$row['website'] = $storefromorder->getCode();
378
+ continue;
379
+ }
380
+ if (in_array($field, $systemFields) || is_object($value)) {
381
+ continue;
382
+ }
383
+
384
+ $attribute = $this->getAttribute($field);
385
+ if (!$attribute) {
386
+ continue;
387
+ }
388
+
389
+ if ($attribute->usesSource()) {
390
+
391
+ $option = $attribute->getSource()->getOptionText($value);
392
+ if ($value && empty($option)) {
393
+ $message = Mage::helper('catalog')->__("Invalid option id specified for %s (%s), skipping the record", $field, $value);
394
+ $this->addException($message, Mage_Dataflow_Model_Convert_Exception::ERROR);
395
+ continue;
396
+ }
397
+ if (is_array($option)) {
398
+ $value = join(self::MULTI_DELIMITER, $option);
399
+ } else {
400
+ $value = $option;
401
+ }
402
+ unset($option);
403
+ }
404
+ elseif (is_array($value)) {
405
+ continue;
406
+ }
407
+ $row[$field] = $value;
408
+ $row['email'] = $order->getCustomerEmail();
409
+ }
410
+ $row['password'] = "changeme";
411
+
412
+ $defaultBillingId = $customer->getDefaultBilling();
413
+ $defaultShippingId = $customer->getDefaultShipping();
414
+
415
+ $customerAddress = $this->getCustomerAddressModel();
416
+
417
+ if (!$defaultBillingId) {
418
+ foreach ($this->getFields() as $code=>$node) {
419
+ if ($node->is('billing')) {
420
+ $row['billing_'.$code] = null;
421
+ }
422
+ }
423
+ }
424
+ else {
425
+ $customerAddress->load($defaultBillingId);
426
+
427
+ foreach ($this->getFields() as $code=>$node) {
428
+ if ($node->is('billing')) {
429
+ if($code == "street_full") {
430
+ $row['billing_street_full'] = $customerAddress->getDataUsingMethod("street_1");
431
+ $row['billing_street_2'] = $customerAddress->getDataUsingMethod("street_2");
432
+ } else {
433
+ $row['billing_'.$code] = $customerAddress->getDataUsingMethod($code);
434
+ }
435
+ }
436
+ }
437
+ }
438
+
439
+ if (!$defaultShippingId) {
440
+ foreach ($this->getFields() as $code=>$node) {
441
+ if ($node->is('shipping')) {
442
+ $row['shipping_'.$code] = null;
443
+ }
444
+ }
445
+ }
446
+ else {
447
+ if ($defaultShippingId != $defaultBillingId) {
448
+ $customerAddress->load($defaultShippingId);
449
+ }
450
+ foreach ($this->getFields() as $code=>$node) {
451
+ if ($node->is('shipping')) {
452
+ if($code == "street_full") {
453
+ $row['shipping_street_full'] = $customerAddress->getDataUsingMethod("street_1");
454
+ $row['shipping_street_2'] = $customerAddress->getDataUsingMethod("street_2");
455
+ } else {
456
+ $row['shipping_'.$code] = $customerAddress->getDataUsingMethod($code);
457
+ }
458
+ }
459
+ }
460
+ }
461
+
462
+ } //if guest end if statement
463
+
464
+ $customerId = $order->getData('customer_id');
465
+ $customer = $this->getCustomerModel()
466
+ ->setData(array())
467
+ ->load($customerId);
468
+ //print($customer);
469
+ $store = $this->getStoreById($customer->getStoreId());
470
+ if ($store === false) {
471
+ $store = $this->getStoreById(0);
472
+ }
473
+ $row['created_in'] = $store->getCode();
474
+
475
+ $newsletter = $this->getNewsletterModel()
476
+ ->loadByCustomer($customer);
477
+ $row['is_subscribed'] = ($newsletter->getId()
478
+ && $newsletter->getSubscriberStatus() == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED)
479
+ ? 1 : 0;
480
+ /* ADDITIONAL ORDER DETAILS TO EXPORT */
481
+ #print_r($order);
482
+ $row['customers_id'] = $customerId;
483
+ $row['order_id'] = $order->getData('increment_id');
484
+ $row['created_at'] = $order->getData('created_at');
485
+ $row['updated_at'] = $order->getData('updated_at');
486
+ $row['tax_amount'] = $order->getData('tax_amount');
487
+ $row['shipping_method'] = $order->getData('shipping_method');
488
+ $row['shipping_amount'] = $order->getData('shipping_amount');
489
+ $row['discount_amount'] = $order->getData('discount_amount');
490
+ $row['subtotal'] = $order->getData('subtotal');
491
+ $row['grand_total'] = $order->getData('grand_total');
492
+ $row['total_paid'] = $order->getData('total_paid');
493
+ $row['total_refunded'] = $order->getData('total_refunded');
494
+ $row['total_qty_ordered'] = $order->getData('total_qty_ordered');
495
+ $row['total_canceled'] = $order->getData('total_canceled');
496
+ $row['total_invoiced'] = $order->getData('total_invoiced');
497
+ $row['total_online_refunded'] = $order->getData('total_online_refunded');
498
+ $row['total_offline_refunded'] = $order->getData('total_offline_refunded');
499
+ $row['base_tax_amount'] = $order->getData('base_tax_amount');
500
+ $row['base_shipping_amount'] = $order->getData('base_shipping_amount');
501
+ $row['base_discount_amount'] = $order->getData('base_discount_amount');
502
+ $row['base_subtotal'] = $order->getData('base_subtotal');
503
+ $row['base_grand_total'] = $order->getData('base_grand_total');
504
+ $row['base_total_paid'] = $order->getData('base_total_paid');
505
+ $row['base_total_refunded'] = $order->getData('base_total_refunded');
506
+ $row['base_total_qty_ordered'] = $order->getData('base_total_qty_ordered');
507
+ $row['base_total_canceled'] = $order->getData('base_total_canceled');
508
+ $row['base_total_invoiced'] = $order->getData('base_total_invoiced');
509
+ $row['base_total_online_refunded'] = $order->getData('base_total_online_refunded');
510
+ $row['base_total_offline_refunded'] = $order->getData('base_total_offline_refunded');
511
+ $row['subtotal_refunded'] = $order->getData('subtotal_refunded');
512
+ $row['subtotal_canceled'] = $order->getData('subtotal_canceled');
513
+ $row['discount_refunded'] = $order->getData('discount_refunded');
514
+ $row['discount_invoiced'] = $order->getData('discount_invoiced');
515
+ $row['tax_refunded'] = $order->getData('tax_refunded');
516
+ $row['tax_canceled'] = $order->getData('tax_canceled');
517
+ $row['shipping_refunded'] = $order->getData('shipping_refunded');
518
+ $row['shipping_canceled'] = $order->getData('shipping_canceled');
519
+ $row['base_subtotal_refunded'] = $order->getData('base_subtotal_refunded');
520
+ $row['base_subtotal_canceled'] = $order->getData('base_subtotal_canceled');
521
+ $row['base_discount_refunded'] = $order->getData('base_discount_refunded');
522
+ $row['base_discount_canceled'] = $order->getData('base_discount_canceled');
523
+ $row['base_discount_invoiced'] = $order->getData('base_discount_invoiced');
524
+ $row['base_tax_refunded'] = $order->getData('base_tax_refunded');
525
+ $row['base_tax_canceled'] = $order->getData('base_tax_canceled');
526
+ $row['base_shipping_refunded'] = $order->getData('base_shipping_refunded');
527
+ $row['base_shipping_canceled'] = $order->getData('base_shipping_canceled');
528
+ $row['subtotal_invoiced'] = $order->getData('subtotal_invoiced');
529
+ $row['tax_invoiced'] = $order->getData('tax_invoiced');
530
+ $row['shipping_invoiced'] = $order->getData('shipping_invoiced');
531
+ $row['base_subtotal_invoiced'] = $order->getData('base_subtotal_invoiced');
532
+ $row['base_tax_invoiced'] = $order->getData('base_tax_invoiced');
533
+ $row['base_shipping_invoiced'] = $order->getData('base_shipping_invoiced');
534
+ $row['shipping_tax_amount'] = $order->getData('shipping_tax_amount');
535
+ $row['base_shipping_tax_amount'] = $order->getData('base_shipping_tax_amount');
536
+ $row['shipping_tax_refunded'] = $order->getData('shipping_tax_refunded');
537
+ $row['base_shipping_tax_refunded'] = $order->getData('base_shipping_tax_refunded');
538
+
539
+ if($order->getStoreId() !="") {
540
+ #$row['store_id'] = $this->getStoreId();
541
+ $row['store_id'] = $order->getStoreId();
542
+ } else {
543
+ $row['store_id'] = $this->getVar('store');
544
+ }
545
+
546
+ #if(method_exists($order->getPayment(), 'getMethod')) {
547
+ $row['payment_method'] = $order->getPayment()->getMethod();
548
+ #} else {
549
+ #$row['payment_method'] = "";
550
+ #}
551
+ $items = $order->getAllItems();
552
+ $itemscount = 1;
553
+ $finalproductsorder = "";
554
+ $finalvaluesfromoptions="";
555
+ $nonconfigurablesku="";
556
+ $theseproductsarebundlesimples="";
557
+ foreach ($items as $itemId => $item)
558
+ {
559
+ /*
560
+ $row['product_name_'.$itemscount.''] = $item->getName();
561
+ $row['product_price_'.$itemscount.''] = $item->getPrice();
562
+ $row['product_sku_'.$itemscount.''] = $item->getSku();
563
+ $row['product_id_'.$itemscount.''] = $item->getProductId();
564
+ $row['product_qty_'.$itemscount.''] = $item->getQtyToInvoice();
565
+ #$row['product_qty_'.$itemscount.''] = $item->getQtyOrdered();
566
+ //echo "TEST: " . $item->getData('product_options');
567
+ $itemscount++;
568
+ */
569
+ #echo "SKU: " . $item->getSku();
570
+ #echo "TYPE: " . $item->getProductType();
571
+
572
+ $productoptionsfromconfigurables = unserialize($item->getData('product_options'));
573
+
574
+ if(isset($productoptionsfromconfigurables['attributes_info'])) {
575
+ foreach ($productoptionsfromconfigurables['attributes_info'] as $configurablesitemId => $configurablesitem)
576
+ {
577
+ #print_r($configurablesitem);
578
+ $finalvaluesfromoptions .= $configurablesitem['value'] . ":";
579
+ }
580
+ }
581
+ if ($item->getProductType() == "configurable") {
582
+ #print_r($item->getData('product_id'));
583
+ #$productconfigItem = Mage::getModel('catalog/product')->load($item->getData('product_id'));
584
+ #$configskuforexport = $productconfigItem->getSku();
585
+ $configskuforexport = $item->getSku();
586
+ $configskuforexport1 = $item->getSku(). "config"; //for when oddly simple and config skus match
587
+ #echo "CONFIG SKU: " . $configskuforexport . "<br/>";
588
+ $nonconfigurablesku = $item->getProductOptionByCode('simple_sku');
589
+ }
590
+ if ($item->getProductType() == "bundle") {
591
+
592
+ #print_r($item->getData());
593
+ $finalbundleoptions = "";
594
+ $theseproductsarebundlesimples = false;
595
+ #$productbundleItem = Mage::getModel('catalog/product')->load($item->getData('product_id'));
596
+ #$bundleskuforexport = $productbundleItem->getSku();
597
+ $bundleskuforexport = $item->getSku();
598
+ #echo "BUNDLE SKU: " . $bundleskuforexport . "<br/>";
599
+ #echo "BUNDLE SIMPLE SKU: " . $item->getSku();
600
+ $bundle_simple_skus = explode('-',$item->getSku());
601
+ foreach ($bundle_simple_skus as $bundle_single_sku_data) {
602
+ if($bundleskuforexport != $bundle_single_sku_data && $nonconfigurablesku != $bundle_single_sku_data) {
603
+ #echo "T: " . $bundle_single_sku_data . "~" .$item->getQtyOrdered(). "^";
604
+ $finalbundleoptions .= $bundle_single_sku_data . "~" .$item->getQtyOrdered(). "^";
605
+ $theseproductsarebundlesimples = true;
606
+ }
607
+ }
608
+ $final_bundle_simple_skus = substr_replace($finalbundleoptions,"",-1);
609
+
610
+ $productoptionsfrombundles = unserialize($item->getData('product_options'));
611
+ #print_r($productoptionsfrombundles['info_buyRequest']);
612
+
613
+ if(isset($productoptionsfrombundles['info_buyRequest']['bundle_option'])) {
614
+ foreach ($productoptionsfrombundles['info_buyRequest'] as $bundleitemId => $bundleitem)
615
+ {
616
+ #echo "T: " . $bundleitemId . "<br/>";
617
+ #echo "T2: " . $bundleitem . "<br/>";
618
+ #print_r($bundleitem);
619
+ }
620
+ }
621
+ }
622
+ //for when simple and config oddly match
623
+ if($finalvaluesfromoptions !="" && $item->getProductType() == "configurable" && $nonconfigurablesku != $configskuforexport1) {
624
+ #if($finalvaluesfromoptions !="" && $item->getProductType() == "configurable" && $nonconfigurablesku != $configskuforexport) {
625
+ $okcleanedfinalvalues = substr_replace($finalvaluesfromoptions,"",-1);
626
+
627
+ if($this->getVar('export_product_pricing') == "true") {
628
+ $finalproductsorder .= $configskuforexport . ":" . $item->getQtyOrdered() . ":configurable:" . $okcleanedfinalvalues . "^" . $item->getPrice() . "^" . $item->getName() . "|";
629
+ } else {
630
+ $finalproductsorder .= $configskuforexport . ":" . $item->getQtyOrdered() . ":configurable:" . $okcleanedfinalvalues . "|";
631
+ }
632
+
633
+ } else if($item->getProductType() == "bundle") {
634
+ if($this->getVar('export_product_pricing') == "true") {
635
+ $finalproductsorder .= $bundleskuforexport . ":" . $item->getQtyOrdered() . ":bundle:" . $final_bundle_simple_skus;
636
+ } else {
637
+ $finalproductsorder .= $bundleskuforexport . ":" . $item->getQtyOrdered() . ":bundle:" . $final_bundle_simple_skus;
638
+ }
639
+ } else if($nonconfigurablesku != $item->getSku() && $theseproductsarebundlesimples != true) {
640
+
641
+ #$arrayofsimpleproductcustomoptios = $item->getProductOptions();
642
+ $currentoptionscount=0;
643
+ #$productsimplecustomItem = Mage::getModel('catalog/product')->load($item->getData('product_id'));
644
+ #if($productsimplecustomItem['has_options']) {
645
+ $itemsOptions = $item->getProductOptions();
646
+ #print_r($itemsOptions);
647
+ if(is_array($itemsOptions) && !empty($itemsOptions['options'])) {
648
+ #if($productsimplecustomItem->getTypeInstance(true)->hasOptions($productsimplecustomItem)) {
649
+ $finalsimpleoptionsexport = "";
650
+ foreach ($item->getProductOptions() as $option)
651
+ {
652
+ #print_r($option);
653
+ #echo "SKU: " . $item->getSku() . " ID: " . $order->getData('increment_id') . "<br/>";
654
+ if (isset($option[$currentoptionscount]['label']) && isset($option[$currentoptionscount]['value'])) {
655
+ $itemsoptionscount=1;
656
+ foreach ($option as $optionchoices) {
657
+ if (isset($optionchoices['label'])) {
658
+ //echo $optionchoices['label'];
659
+ $finalsimpleoptionsexport .= $optionchoices['value'] .":";
660
+ $itemsoptionscount++;
661
+ }
662
+ }
663
+ $currentoptionscount++;
664
+
665
+ if($this->getVar('export_product_pricing') == "true") {
666
+ $finalproductsorder .= $item->getSku() . ":" . $item->getQtyOrdered() . ":simple:" . substr_replace($finalsimpleoptionsexport,"",-1) . "^" . $item->getPrice() . "^" . $item->getName() . "|";
667
+ } else {
668
+ $finalproductsorder .= $item->getSku() . ":" . $item->getQtyOrdered() . ":simple:" . substr_replace($finalsimpleoptionsexport,"",-1) . "|";
669
+ }
670
+ }
671
+ }
672
+ } else {
673
+
674
+ if($this->getVar('export_product_pricing') == "true") {
675
+ $finalproductsorder .= $item->getSku() . ":" . $item->getQtyOrdered() . ":" . $item->getPrice() . ":" . $item->getName() . "|";
676
+ } else {
677
+ $finalproductsorder .= $item->getSku() . ":" . $item->getQtyOrdered() . "|";
678
+ }
679
+ }
680
+ }
681
+
682
+ #$finalproductsorder .= $item->getSku() .":" . $item->getQtyOrdered() . "|";
683
+ }
684
+ $row['products_ordered'] = substr_replace($finalproductsorder,"",-1);
685
+
686
+ //get product options
687
+ /*
688
+ print_r($item);
689
+ foreach ($item->getProductOptions() as $option)
690
+ {
691
+ //print_r($option);
692
+ if (isset($option[$currentoptionscount]['label']) && isset($option[$currentoptionscount]['value'])) {
693
+ $itemsoptionscount=1;
694
+ foreach ($option as $optionchoices) {
695
+ if (isset($optionchoices['label'])) {
696
+ //echo $optionchoices['label'];
697
+ $row['product_options_'.$itemsoptionscount.''] = $optionchoices['label'];
698
+ $row['product_options_'.$itemsoptionscount.''] .= " (".$optionchoices['value'].")";
699
+ $itemsoptionscount++;
700
+ }
701
+ }
702
+ $currentoptionscount++;
703
+ }
704
+ }
705
+ */
706
+ $row['order_status'] = $order->getStatus();
707
+
708
+ $batchExport = $this->getBatchExportModel()
709
+ ->setId(null)
710
+ ->setBatchId($this->getBatchModel()->getId())
711
+ ->setBatchData($row)
712
+ ->setStatus(1)
713
+ ->save();
714
+ $overallcount+=1;
715
+ } #ends check on count of orders being exported
716
+ }
717
+
718
+ return $this;
719
+ }
720
+
721
+ public function getExternalAttributes()
722
+ {
723
+ $internal = array(
724
+ 'store_id',
725
+ 'entity_id',
726
+ 'website_id',
727
+ 'group_id',
728
+ 'created_in',
729
+ 'default_billing',
730
+ 'default_shipping',
731
+ 'country_id'
732
+ );
733
+
734
+ $entityTypeId = Mage::getSingleton('eav/config')->getEntityType('customer')->getId();
735
+ $customerAttributes = Mage::getResourceModel('eav/entity_attribute_collection')
736
+ ->setEntityTypeFilter($entityTypeId)
737
+ ->load()->getIterator();
738
+
739
+ $entityTypeId = Mage::getSingleton('eav/config')->getEntityType('customer_address')->getId();
740
+ $addressAttributes = Mage::getResourceModel('eav/entity_attribute_collection')
741
+ ->setEntityTypeFilter($entityTypeId)
742
+ ->load()->getIterator();
743
+
744
+ $attributes = array(
745
+ 'website' => 'website',
746
+ 'email' => 'email',
747
+ 'group' => 'group',
748
+ 'create_in' => 'create_in',
749
+ 'is_subscribed' => 'is_subscribed'
750
+ );
751
+
752
+ foreach ($customerAttributes as $attr) {
753
+ $code = $attr->getAttributeCode();
754
+ if (in_array($code, $internal) || $attr->getFrontendInput()=='hidden') {
755
+ continue;
756
+ }
757
+ $attributes[$code] = $code;
758
+ }
759
+ $attributes['password_hash'] = 'password_hash';
760
+
761
+ foreach ($addressAttributes as $attr) {
762
+ $code = $attr->getAttributeCode();
763
+ if (in_array($code, $internal) || $attr->getFrontendInput()=='hidden') {
764
+ continue;
765
+ }
766
+ $attributes['billing_'.$code] = 'billing_'.$code;
767
+ }
768
+ $attributes['billing_country'] = 'billing_country';
769
+
770
+ foreach ($addressAttributes as $attr) {
771
+ $code = $attr->getAttributeCode();
772
+ if (in_array($code, $internal) || $attr->getFrontendInput()=='hidden') {
773
+ continue;
774
+ }
775
+ $attributes['shipping_'.$code] = 'shipping_'.$code;
776
+ }
777
+ $attributes['shipping_country'] = 'shipping_country';
778
+
779
+ return $attributes;
780
+ }
781
+
782
+
783
+
784
+ /**
785
+ * @deprecated not used anymore
786
+ */
787
+ public function parse()
788
+ {
789
+ $data = $this->getData();
790
+
791
+ $entityTypeId = Mage::getSingleton('eav/config')->getEntityType('customer')->getId();
792
+ $result = array();
793
+ foreach ($data as $i=>$row) {
794
+ $this->setPosition('Line: '.($i+1));
795
+ try {
796
+
797
+ // validate SKU
798
+ if (empty($row['email'])) {
799
+ $this->addException(Mage::helper('customer')->__('Missing email, skipping the record'), Varien_Convert_Exception::ERROR);
800
+ continue;
801
+ }
802
+ $this->setPosition('Line: '.($i+1).', email: '.$row['email']);
803
+
804
+ // try to get entity_id by sku if not set
805
+ /*
806
+ if (empty($row['entity_id'])) {
807
+ $row['entity_id'] = $this->getResource()->getProductIdBySku($row['email']);
808
+ }
809
+ */
810
+
811
+ // if attribute_set not set use default
812
+ if (empty($row['attribute_set'])) {
813
+ $row['attribute_set'] = 'Default';
814
+ }
815
+
816
+ // get attribute_set_id, if not throw error
817
+ $row['attribute_set_id'] = $this->getAttributeSetId($entityTypeId, $row['attribute_set']);
818
+ if (!$row['attribute_set_id']) {
819
+ $this->addException(Mage::helper('customer')->__("Invalid attribute set specified, skipping the record"), Varien_Convert_Exception::ERROR);
820
+ continue;
821
+ }
822
+
823
+ if (empty($row['group'])) {
824
+ $row['group'] = 'General';
825
+ }
826
+
827
+ if (empty($row['firstname'])) {
828
+ $this->addException(Mage::helper('customer')->__('Missing firstname, skipping the record'), Varien_Convert_Exception::ERROR);
829
+ continue;
830
+ }
831
+ //$this->setPosition('Line: '.($i+1).', Firstname: '.$row['firstname']);
832
+
833
+ if (empty($row['lastname'])) {
834
+ $this->addException(Mage::helper('customer')->__('Missing lastname, skipping the record'), Varien_Convert_Exception::ERROR);
835
+ continue;
836
+ }
837
+ //$this->setPosition('Line: '.($i+1).', Lastname: '.$row['lastname']);
838
+
839
+ /*
840
+ // get product type_id, if not throw error
841
+ $row['type_id'] = $this->getProductTypeId($row['type']);
842
+ if (!$row['type_id']) {
843
+ $this->addException(Mage::helper('catalog')->__("Invalid product type specified, skipping the record"), Varien_Convert_Exception::ERROR);
844
+ continue;
845
+ }
846
+ */
847
+
848
+ // get store ids
849
+ $storeIds = $this->getStoreIds(isset($row['store']) ? $row['store'] : $this->getVar('store'));
850
+ if (!$storeIds) {
851
+ $this->addException(Mage::helper('customer')->__("Invalid store specified, skipping the record"), Varien_Convert_Exception::ERROR);
852
+ continue;
853
+ }
854
+
855
+ // import data
856
+ $rowError = false;
857
+ foreach ($storeIds as $storeId) {
858
+ $collection = $this->getCollection($storeId);
859
+ //print_r($collection);
860
+ $entity = $collection->getEntity();
861
+
862
+ $model = Mage::getModel('customer/customer');
863
+ $model->setStoreId($storeId);
864
+ if (!empty($row['entity_id'])) {
865
+ $model->load($row['entity_id']);
866
+ }
867
+ foreach ($row as $field=>$value) {
868
+ $attribute = $entity->getAttribute($field);
869
+ if (!$attribute) {
870
+ continue;
871
+ #$this->addException(Mage::helper('catalog')->__("Unknown attribute: %s", $field), Varien_Convert_Exception::ERROR);
872
+
873
+ }
874
+
875
+ if ($attribute->usesSource()) {
876
+ $source = $attribute->getSource();
877
+ $optionId = $this->getSourceOptionId($source, $value);
878
+ if (is_null($optionId)) {
879
+ $rowError = true;
880
+ $this->addException(Mage::helper('customer')->__("Invalid attribute option specified for attribute %s (%s), skipping the record", $field, $value), Varien_Convert_Exception::ERROR);
881
+ continue;
882
+ }
883
+ $value = $optionId;
884
+ }
885
+ $model->setData($field, $value);
886
+
887
+ }//foreach ($row as $field=>$value)
888
+
889
+
890
+ $billingAddress = $model->getPrimaryBillingAddress();
891
+ $customer = Mage::getModel('customer/customer')->load($model->getId());
892
+
893
+
894
+ if (!$billingAddress instanceof Mage_Customer_Model_Address) {
895
+ $billingAddress = new Mage_Customer_Model_Address();
896
+ if ($customer->getId() && $customer->getDefaultBilling()) {
897
+ $billingAddress->setId($customer->getDefaultBilling());
898
+ }
899
+ }
900
+
901
+ $regions = Mage::getResourceModel('directory/region_collection')->addRegionNameFilter($row['billing_region'])->load();
902
+ if ($regions) foreach($regions as $region) {
903
+ $regionId = $region->getId();
904
+ }
905
+
906
+ $billingAddress->setFirstname($row['firstname']);
907
+ $billingAddress->setLastname($row['lastname']);
908
+ $billingAddress->setCity($row['billing_city']);
909
+ $billingAddress->setRegion($row['billing_region']);
910
+ $billingAddress->setRegionId($regionId);
911
+ $billingAddress->setCountryId($row['billing_country']);
912
+ $billingAddress->setPostcode($row['billing_postcode']);
913
+ $billingAddress->setStreet(array($row['billing_street1'],$row['billing_street2']));
914
+ if (!empty($row['billing_telephone'])) {
915
+ $billingAddress->setTelephone($row['billing_telephone']);
916
+ }
917
+
918
+ if (!$model->getDefaultBilling()) {
919
+ $billingAddress->setCustomerId($model->getId());
920
+ $billingAddress->setIsDefaultBilling(true);
921
+ $billingAddress->save();
922
+ $model->setDefaultBilling($billingAddress->getId());
923
+ $model->addAddress($billingAddress);
924
+ if ($customer->getDefaultBilling()) {
925
+ $model->setDefaultBilling($customer->getDefaultBilling());
926
+ } else {
927
+ $shippingAddress->save();
928
+ $model->setDefaultShipping($billingAddress->getId());
929
+ $model->addAddress($billingAddress);
930
+
931
+ }
932
+ }
933
+
934
+ $shippingAddress = $model->getPrimaryShippingAddress();
935
+ if (!$shippingAddress instanceof Mage_Customer_Model_Address) {
936
+ $shippingAddress = new Mage_Customer_Model_Address();
937
+ if ($customer->getId() && $customer->getDefaultShipping()) {
938
+ $shippingAddress->setId($customer->getDefaultShipping());
939
+ }
940
+ }
941
+
942
+ $regions = Mage::getResourceModel('directory/region_collection')->addRegionNameFilter($row['shipping_region'])->load();
943
+ if ($regions) foreach($regions as $region) {
944
+ $regionId = $region->getId();
945
+ }
946
+
947
+ $shippingAddress->setFirstname($row['firstname']);
948
+ $shippingAddress->setLastname($row['lastname']);
949
+ $shippingAddress->setCity($row['shipping_city']);
950
+ $shippingAddress->setRegion($row['shipping_region']);
951
+ $shippingAddress->setRegionId($regionId);
952
+ $shippingAddress->setCountryId($row['shipping_country']);
953
+ $shippingAddress->setPostcode($row['shipping_postcode']);
954
+ $shippingAddress->setStreet(array($row['shipping_street1'], $row['shipping_street2']));
955
+ $shippingAddress->setCustomerId($model->getId());
956
+ if (!empty($row['shipping_telephone'])) {
957
+ $shippingAddress->setTelephone($row['shipping_telephone']);
958
+ }
959
+
960
+ if (!$model->getDefaultShipping()) {
961
+ if ($customer->getDefaultShipping()) {
962
+ $model->setDefaultShipping($customer->getDefaultShipping());
963
+ } else {
964
+ $shippingAddress->save();
965
+ $model->setDefaultShipping($shippingAddress->getId());
966
+ $model->addAddress($shippingAddress);
967
+
968
+ }
969
+ $shippingAddress->setIsDefaultShipping(true);
970
+ }
971
+
972
+ if (!$rowError) {
973
+ $collection->addItem($model);
974
+ }
975
+
976
+ } //foreach ($storeIds as $storeId)
977
+
978
+ } catch (Exception $e) {
979
+ if (!$e instanceof Mage_Dataflow_Model_Convert_Exception) {
980
+ $this->addException(Mage::helper('customer')->__("Error during retrieval of option value: %s", $e->getMessage()), Mage_Dataflow_Model_Convert_Exception::FATAL);
981
+ }
982
+ }
983
+ }
984
+ $this->setData($this->_collections);
985
+ return $this;
986
+ }
987
+ }
app/code/local/Indianic/Reviewexport/Model/Convert/Parser/Reviewexport.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Indianic_Reviewexport_Model_Convert_Parser_Reviewexport extends Mage_Eav_Model_Convert_Parser_Abstract
4
+ {
5
+ const MULTI_DELIMITER = ' , ';
6
+
7
+ public function unparse()
8
+ {
9
+ $reviews = Mage::getModel('review/review')->getResourceCollection()
10
+ ->setDateOrder()
11
+ ->addRateVotes()
12
+ ->load();
13
+ $csv_fields = array();
14
+
15
+ $i = 1;
16
+
17
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
18
+ foreach($reviews as $review)
19
+ {
20
+ $sku = $write->query('select sku from `catalog_product_entity` where entity_id = "'.$review->getEntity_pk_value().'" ');
21
+ $sku = $sku->fetch();
22
+
23
+ if($sku){
24
+ $ratingCollection = Mage::getModel('rating/rating_option_vote')
25
+ ->getResourceCollection()
26
+ ->setReviewFilter($review->getId());
27
+ $value = "";
28
+ foreach($ratingCollection as $rating)
29
+ {
30
+ $value = $rating->getValue();
31
+ }
32
+ $csv_fields['created_at'] = $review->getCreated_at();
33
+ $csv_fields['Sku'] = $sku['sku'];
34
+ $csv_fields['status_id'] = $review->getStatus_id();
35
+ $csv_fields['title'] = $review->getTitle();
36
+ $csv_fields['detail'] = $review->getDetail();
37
+ $csv_fields['nickname'] = $review->getNickname();
38
+ $csv_fields['customer_id'] = $review->getCustomer_id();
39
+ $csv_fields['option_id'] = $value;
40
+ $i++;
41
+ }
42
+ $batchExport = $this->getBatchExportModel()
43
+ ->setId(null)
44
+ ->setBatchId($this->getBatchModel()->getId())
45
+ ->setBatchData($csv_fields)
46
+ ->setStatus(1)
47
+ ->save();
48
+ }
49
+ return $this;
50
+ }
51
+ public function parse()
52
+ {
53
+
54
+ }
55
+ }
app/code/local/Indianic/Reviewexport/Model/Reviewexport.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Indianic_Reviewexport_Model_Review extends Mage_Core_Model_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('reviewexport/reviewexport');
9
+ }
10
+ }
app/code/local/Indianic/Reviewexport/etc/config.xml ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @category Indianic
5
+ * @package Indianic_Review
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+ -->
9
+ <config>
10
+ <modules>
11
+ <Indianic_Reviewexport>
12
+ <version>0.1.0</version>
13
+ </Indianic_Reviewexport>
14
+ </modules>
15
+
16
+
17
+ <global>
18
+ <models>
19
+ <reviewexport>
20
+ <class>Indianic_Reviewexport_Model</class>
21
+ <resourceModel>reviewexport_mysql4</resourceModel>
22
+ </reviewexport>
23
+
24
+ </models>
25
+ </global>
26
+ </config>
app/etc/modules/Indianic_Review.xml ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @category Indianic
5
+ * @package Indianic_Review
6
+ * @author ModuleCreator
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+ -->
10
+ <config>
11
+ <modules>
12
+ <Indianic_Reviewexport>
13
+ <active>true</active>
14
+ <codePool>local</codePool>
15
+ </Indianic_Reviewexport>
16
+ </modules>
17
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Indianic_Reviewimportexport</name>
4
+ <version>1.0.0.1</version>
5
+ <stability>stable</stability>
6
+ <license>OSL v3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Import/export customer review </summary>
10
+ <description>Import/export customer review from one magento set up to another</description>
11
+ <notes>Stable version</notes>
12
+ <authors><author><name>Mufaddal kapadiya</name><user>muffadal</user><email>muffadal.kapadiya@indianic.com</email></author></authors>
13
+ <date>2013-04-17</date>
14
+ <time>12:14:31</time>
15
+ <contents><target name="magelocal"><dir name="Indianic"><dir name="Reviewexport"><dir name="Model"><dir name="Convert"><dir name="Adapter"><file name="Reviewimport.php" hash="e06823ef9175149d606a63a2d7846cec"/></dir><dir name="Parser"><file name="Exportorders.php" hash="e7654c1b1c9f122ad2411533288ee3e9"/><file name="Reviewexport.php" hash="8dbfc2aed9e2eb75e1eec7083af4ce20"/></dir></dir><file name="Reviewexport.php" hash="ef06553339bdd5c61640916e67bd7d9b"/></dir><dir name="etc"><file name="config.xml" hash="491eddd18e320b9fb6773b0ba8c753b9"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Indianic_Review.xml" hash="9bc68c0dd9d6127a23cdd29ec9b6a650"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php><package><name>Mage_core_modules</name><channel>community</channel><min>1.6.0.0</min><max>1.7</max></package><extension><name>gd</name><min>2.0.28</min><max>3.0</max></extension></required></dependencies>
18
+ </package>