ice_import - Version 1.5.0

Version Notes

- Added Magento V1.8 Compatibility
- Added batch of settings for information to be imported (desription, name, stock, price and etc)
- Speed improvements
- Fixed issues with TimeOut
- Changed namespaces

Download this release

Release Info

Developer IceShop
Extension ice_import
Version 1.5.0
Comparing to
See all releases


Code changes from version 1.4.0 to 1.5.0

Files changed (36) hide show
  1. app/code/community/Capacitywebsolutions/Importproduct/Model/Convert/Adapter/Product.php +0 -907
  2. app/code/community/Capacitywebsolutions/Importproduct/Model/Observer.php +0 -203
  3. app/code/community/Capacitywebsolutions/Importproduct/Model/System/Config/Categoryactivity.php +0 -13
  4. app/code/community/Capacitywebsolutions/Importproduct/Model/System/Config/Defaulttax.php +0 -19
  5. app/code/community/Capacitywebsolutions/Importproduct/Model/System/Config/Imageimport.php +0 -14
  6. app/code/community/Capacitywebsolutions/Importproduct/Model/System/Config/Lockproddetails.php +0 -15
  7. app/code/community/Capacitywebsolutions/Importproduct/etc/config.xml +0 -90
  8. app/code/community/Capacitywebsolutions/Importproduct/etc/system.xml +0 -63
  9. app/code/community/Capacitywebsolutions/Importproduct/sql/importproduct_setup/mysql4-install-0.1.0.php +0 -61
  10. app/code/community/Iceshop/Iceimport/Model/Convert/Adapter/Product.php +933 -0
  11. app/code/community/Iceshop/Iceimport/Model/Dataflow/Batch/Import.php +52 -0
  12. app/code/community/Iceshop/Iceimport/Model/Dataflow/Convert/Parser/Csv.php +141 -0
  13. app/code/community/Iceshop/Iceimport/Model/Observer.php +225 -0
  14. app/code/community/Iceshop/Iceimport/Model/System/Config/Categoryactivity.php +15 -0
  15. app/code/community/Iceshop/Iceimport/Model/System/Config/Defaulttax.php +20 -0
  16. app/code/community/Iceshop/Iceimport/Model/System/Config/Imageimport.php +15 -0
  17. app/code/community/Iceshop/Iceimport/Model/System/Config/Importdeliveryeta.php +15 -0
  18. app/code/community/Iceshop/Iceimport/Model/System/Config/Importprices.php +15 -0
  19. app/code/community/Iceshop/Iceimport/Model/System/Config/Importproductbrand.php +15 -0
  20. app/code/community/Iceshop/Iceimport/Model/System/Config/Importproductdescription.php +15 -0
  21. app/code/community/Iceshop/Iceimport/Model/System/Config/Importproductean.php +15 -0
  22. app/code/community/Iceshop/Iceimport/Model/System/Config/Importproductmpn.php +15 -0
  23. app/code/community/Iceshop/Iceimport/Model/System/Config/Importproductname.php +15 -0
  24. app/code/community/Iceshop/Iceimport/Model/System/Config/Importproductshdescription.php +15 -0
  25. app/code/community/Iceshop/Iceimport/Model/System/Config/Importproductshsudescription.php +15 -0
  26. app/code/community/Iceshop/Iceimport/Model/System/Config/Importproductsudescription.php +15 -0
  27. app/code/community/Iceshop/Iceimport/Model/System/Config/Importstock.php +15 -0
  28. app/code/community/Iceshop/Iceimport/Model/System/Config/Lockproddetails.php +15 -0
  29. app/code/community/Iceshop/Iceimport/etc/config.xml +103 -0
  30. app/code/community/Iceshop/Iceimport/etc/system.xml +153 -0
  31. app/code/community/Iceshop/Iceimport/sql/iceimport_setup/mysql4-install-1.5.0.php +65 -0
  32. app/code/community/Iceshop/Iceimport/sql/iceimport_setup/mysql4-upgrade-0.1.0-1.5.0.php +63 -0
  33. app/code/community/Iceshop/Iceimport/sql/iceimport_setup/mysql4-upgrade-1.4.0-1.5.0.php +65 -0
  34. app/code/community/Iceshop/Iceimport/sql/iceimport_setup/uninstall-old-version.php +48 -0
  35. app/etc/modules/{Capacitywebsolutions_Importproduct.xml → Iceshop_Iceimport.xml} +2 -2
  36. package.xml +10 -12
app/code/community/Capacitywebsolutions/Importproduct/Model/Convert/Adapter/Product.php DELETED
@@ -1,907 +0,0 @@
1
- <?php
2
- /**
3
- * Import Multiple Images during Product Import
4
- * Copyright ? 2010 Web Design by Capacity Web Solutions Pvt. Ltd. All Rights Reserved.
5
- * http://www.capacitywebsolutions.com
6
- */
7
-
8
-
9
- class Capacitywebsolutions_Importproduct_Model_Convert_Adapter_Product extends Mage_Catalog_Model_Convert_Adapter_Product
10
- {
11
- protected $_categoryCache = array();
12
- protected $_connRes = null;
13
- protected $_tablePrefix = '';
14
-
15
- public function __construct(){
16
-
17
- $this->_connRes = Mage::getSingleton('core/resource')->getConnection('core_write');
18
- $tablePrefix = (array)Mage::getConfig()->getTablePrefix();
19
- if (!empty($tablePrefix)) {
20
- $this->_tablePrefix = $tablePrefix[0];
21
- }
22
-
23
- }
24
-
25
- public function saveRow(array $importData) {
26
-
27
- // separate import data to eav & static
28
- $sortedProductData = $this->_mapAttributes($importData);
29
- $productData = $sortedProductData['productData'];
30
- $iceimportAttributes = $sortedProductData['iceimportAttributes'];
31
- $failedAttributes = $sortedProductData['failedAttributes'];
32
-
33
- //Init session values to count total products and determine the last call of saveRow method
34
- $session = Mage::getSingleton("core/session");
35
- $import_total = $session->getData("import_total");
36
- $counter = $session->getData("counter");
37
-
38
- if (!isset($counter)) {
39
- $session->setData("counter",1);
40
- $counter = $session->getData("counter");
41
- }
42
-
43
- if (!isset($import_total)) {
44
- $batchId = Mage::getSingleton('core/app')->getRequest()->getPost('batch_id', 0);
45
- $batchModel = Mage::getModel('dataflow/batch')->load($batchId);
46
- $batchImportModel = $batchModel->getBatchImportModel();
47
- $importIds = $batchImportModel->getIdCollection();
48
- $import_total = count($importIds);
49
- $session->setData("import_total",(int)$import_total);
50
- } else if(isset($counter) && isset($import_total)) {
51
- if($counter < $import_total) {
52
- $session->setData("counter",(int)++$counter);
53
- }
54
- }
55
-
56
- // mark product ice_import generic
57
- $productData['varchar']['is_iceimport'] =1;
58
-
59
- // set website id
60
- if (empty($iceimportAttributes['websites'])) {
61
- $message = Mage::helper('catalog')->__('Skip import row, required field "%s" not defined', 'website');
62
- Mage::throwException($message);
63
- }
64
- $website = Mage::app()->getWebsite(trim($iceimportAttributes['websites']));
65
- $websiteId = $website->getId();
66
-
67
- // set store id
68
- if (empty($iceimportAttributes['store'])) {
69
- if (!is_null($this->getBatchParams('store'))) {
70
- $store = $this->getStoreById($this->getBatchParams('store'));
71
- } else {
72
- $message = Mage::helper('catalog')->__('Skip import row, required field "%s" not defined', 'store');
73
- Mage::throwException($message);
74
- }
75
- }
76
- $store = $this->getStoreByCode($iceimportAttributes['store']);
77
- if ($store === false) {
78
- $message = Mage::helper('catalog')->__('Skip import row, store "%s" not exists', $iceimportAttributes['store']);
79
- Mage::throwException($message);
80
- }
81
- $storeId = $store->getId();
82
-
83
- // set type
84
- if (empty($iceimportAttributes['type'])) {
85
- $message = Mage::helper('catalog')->__('Skip import row, required field "%s" not defined', 'type');
86
- Mage::throwException($message);
87
- }
88
- $productType = $iceimportAttributes['type'];
89
-
90
- // set attribute set
91
- if (empty($iceimportAttributes['attribute_set'])) {
92
- $message = Mage::helper('catalog')->__('Skip import row, required field "%s" not defined', 'attribute_set');
93
- Mage::throwException($message);
94
- }
95
- $attribute_set = $iceimportAttributes['attribute_set'];
96
-
97
- // set sku
98
- if (empty($iceimportAttributes['sku'])) {
99
- $message = Mage::helper('catalog')->__('Skip import row, required field "%s" not defined', 'sku');
100
- Mage::throwException($message);
101
- }
102
- $sku = $iceimportAttributes['sku'];
103
-
104
- // set category, unspsc, unspsc path
105
- if (empty($iceimportAttributes['categories'])) {
106
- $message = Mage::helper('catalog')->__('Skip import row, required field "%s" not defined', 'categories');
107
- Mage::throwException($message);
108
- }
109
- $category = $iceimportAttributes['categories'];
110
- if (empty($iceimportAttributes['unspsc'])) {
111
- $message = Mage::helper('catalog')->__('Skip import. Category UNSPSC not defined in store');
112
- Mage::throwException($message);
113
- }
114
- $unspsc = $iceimportAttributes['unspsc'];
115
- if (empty($iceimportAttributes['unspsc_path'])) {
116
- $message = Mage::helper('catalog')->__('Skip import. Category UNSPSC path not defined in store');
117
- Mage::throwException($message);
118
- }
119
- $unspscPath = $iceimportAttributes['unspsc_path'];
120
-
121
- // set in / out of stock
122
- $isInStock = 0;
123
- if (!empty($iceimportAttributes['is_in_stock'])) {
124
- $isInStock = $iceimportAttributes['is_in_stock'];
125
- }
126
-
127
- // set qty
128
- $qty = 0;
129
- if (!empty($iceimportAttributes['qty'])) {
130
- $qty = $iceimportAttributes['qty'];
131
- }
132
-
133
- // set price
134
- $price = 0.00;
135
- if (!empty($iceimportAttributes['price'])) {
136
- $price = $iceimportAttributes['price'];
137
- }
138
-
139
- // set status value
140
- $statusValue = (!empty($iceimportAttributes['status']) && $iceimportAttributes['status'] == 'Enabled') ? 1 : 0;
141
- $productData['int']['status'] = $statusValue;
142
-
143
- // set visibility value
144
- $visibilityValue = 1;
145
- if (!empty($iceimportAttributes['visibility'])) {
146
- switch ($iceimportAttributes['visibility']) {
147
- case 'Not Visible Individually':
148
- $visibilityValue = 1;
149
- break;
150
- case 'Catalog':
151
- $visibilityValue = 2;
152
- break;
153
- case 'Search':
154
- $visibilityValue = 3;
155
- break;
156
- case 'Catalog, Search':
157
- $visibilityValue = 4;
158
- break;
159
- }
160
- }
161
- $productData['int']['visibility'] = $visibilityValue;
162
-
163
- // set product image
164
- $productImage = '';
165
- if (!empty($iceimportAttributes['image'])) {
166
- $productImage = $iceimportAttributes['image'];
167
- }
168
-
169
- // init general attributes query
170
- $initAttributes = "
171
- SELECT @product_entity_type_id := `entity_type_id` FROM `" . $this->_tablePrefix . "eav_entity_type` WHERE
172
- entity_type_code = 'catalog_product';
173
- SELECT @category_entity_type_id := `entity_type_id` FROM `" . $this->_tablePrefix . "eav_entity_type` WHERE
174
- entity_type_code = 'catalog_category';
175
- SELECT @attribute_set_id := `entity_type_id` FROM `" . $this->_tablePrefix . "eav_entity_type` WHERE
176
- entity_type_code = 'catalog_product';
177
- SELECT @stock_id := `stock_id` FROM `" . $this->_tablePrefix . "cataloginventory_stock` WHERE
178
- stock_name = 'Default';
179
- SELECT @attribute_set_id := `attribute_set_id` FROM `" . $this->_tablePrefix . "eav_attribute_set`
180
- WHERE attribute_set_name = :attribute_set AND entity_type_id =
181
- @product_entity_type_id;
182
-
183
- SELECT @price_id := `attribute_id` FROM `" . $this->_tablePrefix . "eav_attribute` WHERE
184
- `attribute_code` = 'price' AND entity_type_id = @product_entity_type_id;
185
-
186
- SELECT @unspcs_id := `attribute_id` FROM `" . $this->_tablePrefix . "eav_attribute` WHERE
187
- `attribute_code` = 'unspsc' AND entity_type_id = @category_entity_type_id;
188
- SELECT @category_name_id := `attribute_id` FROM `" . $this->_tablePrefix . "eav_attribute` WHERE
189
- `attribute_code` = 'name' AND entity_type_id = @category_entity_type_id;
190
- SELECT @category_active_id := `attribute_id` FROM `" . $this->_tablePrefix . "eav_attribute` WHERE
191
- `attribute_code` = 'is_active' AND entity_type_id = @category_entity_type_id;
192
- SELECT @include_nav_bar_id := `attribute_id` FROM `" . $this->_tablePrefix . "eav_attribute` WHERE
193
- `attribute_code` = 'include_in_menu' AND entity_type_id = @category_entity_type_id;
194
- SELECT @category_is_anchor_id := `attribute_id` FROM `" . $this->_tablePrefix . "eav_attribute` WHERE
195
- `attribute_code` = 'is_anchor' AND entity_type_id = @category_entity_type_id;
196
- ";
197
-
198
-
199
- $this->_connRes->query($initAttributes, array(':attribute_set' => $iceimportAttributes['attribute_set']));
200
-
201
- $prodIdFetch = $this->_connRes->fetchRow("SELECT entity_id FROM `" . $this->_tablePrefix . "catalog_product_entity` WHERE sku = :sku limit 1" , array(
202
- ':sku' => $sku
203
- ));
204
- $productId = $prodIdFetch['entity_id'];
205
-
206
- if (!empty($productId)) {
207
- // check import type (Import only price & qty or all product info)
208
- if('import_price_stock' == Mage::getStoreConfig('importprod_root/importprod/import_only_prices_stock',
209
- $storeId)) {
210
- $this->_corePriceStock($websiteId, $productId, $price, $qty, $sku, $isInStock);
211
- $query = $this->_connRes->query('INSERT INTO iceimport_imported_product_ids (product_id, product_sku) VALUES (:prod_id, :sku)',array(':prod_id' => $productId,':sku' => $sku));
212
- return true;
213
- }
214
- } else {
215
- $productId = null;
216
- }
217
- $defaulttaxConf = (int)Mage::getStoreConfig('importprod_root/importprod/default_tax',$storeId);
218
-
219
- if( !empty($defaulttaxConf) ) {
220
- $productData['int']['tax_class_id'] = $defaulttaxConf;
221
- }
222
- // get category id
223
- $categoriesToActiveConf = Mage::getStoreConfig('importprod_root/importprod/category_active',
224
- $storeId);
225
- $categoryIds = $this->_addCategories($category, $storeId, $unspsc, $unspscPath, $categoriesToActiveConf);
226
-
227
- // get url key
228
- $url = '';
229
- if (!empty($productData['varchar']['name'])) {
230
- $preUrl = explode(' ', strtolower($productData['varchar']['name']));
231
- $url = implode('-', $preUrl) . '-' . $iceimportAttributes['store'];
232
- }
233
- $productData['varchar']['url_key'] = $url;
234
-
235
- // if new product then ovewrride product id from null to id
236
- $productId = $this->_coreSave($productData, $productId, $storeId, $sku, $categoryIds);
237
-
238
- // add product image to queue
239
- if (Mage::getStoreConfig('importprod_root/importprod/import_images')) {
240
- $this->_addImageToQueue($productId, $productImage);
241
- }
242
-
243
- // add price & stock
244
- $this->_corePriceStock($websiteId, $productId, $price, $qty, $sku, $isInStock);
245
-
246
- $query = $this->_connRes->query('INSERT INTO iceimport_imported_product_ids (product_id, product_sku) VALUES (:prod_id, :sku)',array(':prod_id' => $productId,':sku' => $sku));
247
-
248
- // Check if this is last imported product
249
- // Do category sort and set categories without products to inactive
250
- if (isset($counter) && isset($import_total) && ($counter==$import_total)) {
251
- $catCollection = Mage::getModel('catalog/category')
252
- ->getCollection()
253
- ->addAttributeToSort('name', 'ASC');
254
- $position = 1;
255
-
256
- foreach ($catCollection as $category) {
257
-
258
- $query = $this->_connRes->query("UPDATE `". $this->_tablePrefix . "catalog_category_entity` SET position = :position WHERE entity_id = :cat_id ", array(
259
- ':position'=>$position,
260
- ':cat_id'=> $category->getId()
261
- ));
262
-
263
- $query = "SELECT COUNT(*) FROM `" . $this->_tablePrefix . "catalog_category_product` WHERE category_id = :cat_id ";
264
- $cat_products = $this->_connRes->fetchRow($query,array(
265
- ':cat_id'=> $category->getId()
266
- ));
267
-
268
- if ($cat_products['COUNT(*)'] == 0) {
269
- $query = "SELECT `entity_id` FROM `" . $this->_tablePrefix . "catalog_category_entity` WHERE parent_id = :cat_id";
270
- $child_cat = $this->_connRes->fetchAll($query,array(
271
- ':cat_id'=> $category->getId()
272
- ));
273
-
274
- if (isset($child_cat) && count($child_cat) > 0) {
275
- //Count child categories products and set them to inactive if they have no
276
- $this->CountChildProd($child_cat);
277
- } else {
278
- $this->_connRes->query("UPDATE `" . $this->_tablePrefix . "catalog_category_entity_int`
279
- SET `value` = 0 WHERE `attribute_id` = @category_active_id AND entity_id = :cat_id",array(
280
- ':cat_id'=> $category->getId()
281
- ));
282
- }
283
- }
284
- $position++;
285
- }
286
-
287
- $session->unsetData('import_total');
288
- $session->unsetData('counter');
289
- }
290
-
291
- return true;
292
- }
293
-
294
- protected function _coreSave(array $entityData, $productId = null, $storeId = 0, $sku, $categoryIds) {
295
- if ($productId === null) {
296
- // add product to store
297
- $coreSaveProduct = "INSERT INTO `" . $this->_tablePrefix . "catalog_product_entity` (`entity_type_id`, `attribute_set_id`, `type_id`, `sku`, `created_at`) VALUES
298
- (@product_entity_type_id, @attribute_set_id, 'simple', :sku, NOW());
299
- SELECT @product_id := LAST_INSERT_ID();
300
- ";
301
- $this->_connRes->query($coreSaveProduct, array(':sku' => $sku));
302
- // get product ID
303
- $prodFetch = $this->_connRes->fetchRow('SELECT @product_id AS prod_id');
304
- $productId = $prodFetch['prod_id'];
305
- } else {
306
- $coreSaveSQL .= "SELECT @product_id := " . (int)$productId . "; ";
307
- }
308
-
309
- $bindArray[':store_id'] = $storeId;
310
- foreach ($entityData as $type => $typeAttributes) {
311
- if ($type != 'spec') {
312
- $tailCoreSaveSQL = '';
313
- $attributesInit = '';
314
- if (!empty($typeAttributes)) {
315
- $tailCoreSaveSQL .= "
316
- INSERT INTO `" . $this->_tablePrefix . "catalog_product_entity_" . $type . "` (`entity_type_id`, `attribute_id`, `store_id`, `entity_id`, `value`) VALUES ";
317
- foreach ($typeAttributes as $attribute => $value) {
318
- $attributesInit .= "
319
- SELECT @" . $attribute . "_id := `attribute_id` FROM `" . $this->_tablePrefix . "eav_attribute` WHERE
320
- `attribute_code` = '" . $attribute . "' AND entity_type_id = @product_entity_type_id;
321
- ";
322
- $tailCoreSaveSQL .= "
323
- (@product_entity_type_id, @" . $attribute . "_id, 0, @product_id, :" . $attribute . " ),
324
- (@product_entity_type_id, @" . $attribute . "_id, :store_id, @product_id, :" . $attribute . " ), ";
325
- $bindArray[':' . $attribute] = $value;
326
- }
327
- $tailCoreSaveSQL = substr($tailCoreSaveSQL, 0, -2);
328
- $tailCoreSaveSQL .= "
329
- ON DUPLICATE KEY UPDATE
330
- `value` = VALUES (`value`);
331
- ";
332
- }
333
- $coreSaveSQL .= $attributesInit . $tailCoreSaveSQL;
334
- } else {
335
- foreach ($typeAttributes as $attribute => $attributeData) {
336
- $prod_id_field = $attributeData['prod_id_field'];
337
- $table = $attributeData['table'];
338
- $field = $attributeData['field'];
339
- $value = $attributeData['value'];
340
- if (!empty($table) && !empty($field)) {
341
- $coreSaveSQL .= "
342
- UPDATE `" . $this->_tablePrefix . $table . "` SET `" . $field . "` = :" . $attribute . " WHERE `" . $prod_id_field . "` = @product_id;
343
- ";
344
- $bindArray[':' . $attribute] = $value;
345
- }
346
- }
347
- }
348
- }
349
-
350
-
351
- // categories
352
- $coreSaveSQL .= "INSERT INTO `" . $this->_tablePrefix . "catalog_category_product` (`category_id`, `product_id`, `position`) VALUES ";
353
- $counter = 1;
354
- $categoryIds[] = Mage::app()->getStore(1)->getRootCategoryId();
355
- foreach ($categoryIds as $categoryId) {
356
- if ($counter < count($categoryIds)) {
357
- $coreSaveSQL .= " (" . (int)$categoryId . ", @product_id, 1) , ";
358
- } else if ($counter == count($categoryIds)) {
359
- $coreSaveSQL .= " (" . (int)$categoryId . ", @product_id, 1) ON DUPLICATE KEY UPDATE `position` = 1 ";
360
- }
361
- $counter++;
362
- }
363
- try{
364
- $query = $this->_connRes->query($coreSaveSQL, $bindArray);
365
-
366
- /*$newCategories = $categoryIds;
367
- $newCategories[] = Mage::app()->getStore(1)->getRootCategoryId();
368
- $product = Mage::getModel('catalog/product')->load($productId);
369
- $product->setCategoryIds(
370
- array_merge($product->getCategoryIds(), $newCategories)
371
- );
372
- echo ' 367 ';
373
- $product->save();*/
374
- } catch(Exception $e) {
375
- echo $e->getMessage();
376
- }
377
- return $productId;
378
- }
379
-
380
- protected function _corePriceStock($website =0, $productId =false, $price =0.00, $qty =0.00, $sku =false, $isInStock =0) {
381
-
382
- if (!$productId) {
383
- $message = Mage::helper('catalog')->__('Skip import row, product_id for product "%s" not defined ', $sku);
384
- Mage::throwException($message);
385
- }
386
-
387
- $stockSaveSQL = "
388
- INSERT INTO `" . $this->_tablePrefix . "cataloginventory_stock_item` (`product_id`, `stock_id`, `qty`, `is_in_stock`) VALUES
389
- (:product_id, @stock_id, :qty,1)
390
- ON DUPLICATE KEY UPDATE
391
- `product_id` = :product_id,
392
- `stock_id` = @stock_id,
393
- `qty` = :qty,
394
- `is_in_stock` = :is_in_stock;
395
-
396
- INSERT INTO `" . $this->_tablePrefix . "cataloginventory_stock_status` (`product_id`, `website_id`, `stock_id`, `qty`, `stock_status`) VALUES
397
- (:product_id, :webisteId, @stock_id, :qty, 1)
398
- ON DUPLICATE KEY UPDATE
399
- `product_id` = :product_id,
400
- `website_id` = :webisteId,
401
- `stock_id` = @stock_id,
402
- `qty` = :qty,
403
- `stock_status` = :is_in_stock;
404
-
405
- INSERT INTO `" . $this->_tablePrefix . "catalog_product_website` (`product_id`, `website_id`) VALUES
406
- (:product_id, :webisteId)
407
- ON DUPLICATE KEY UPDATE
408
- `product_id` = :product_id,
409
- `website_id` = :webisteId;
410
-
411
- INSERT INTO `" . $this->_tablePrefix . "catalog_product_entity_decimal` (`entity_type_id`,`attribute_id`,`store_id`, `entity_id`, `value`) VALUES
412
- (@product_entity_type_id, @price_id, 0, :product_id, :price)
413
- ON DUPLICATE KEY UPDATE
414
- `entity_type_id` = @product_entity_type_id,
415
- `attribute_id` = @price_id,
416
- `store_id` = 0,
417
- `entity_id` = :product_id,
418
- `value` = :price;
419
- ";
420
-
421
- $this->_connRes->query($stockSaveSQL, array(
422
- ':webisteId' => $website,
423
- ':product_id' => $productId,
424
- ':price' => $price,
425
- ':qty' => $qty,
426
- ':is_in_stock' => $isInStock
427
- ));
428
-
429
- }
430
-
431
- protected function _addImageToQueue ($productId =false, $productImageUrl) {
432
- $productImageUrl = trim($productImageUrl);
433
- if ($productId && !empty($productImageUrl)) {
434
- // add image if not exists to queue
435
- $this->_connRes->query(" INSERT IGNORE INTO `" . $this->_tablePrefix . "capacity_product_image_queue` (`entity_id`, `image_url` ) VALUES
436
- (:product_id, :image_url)
437
- ", array(':product_id' => $productId,
438
- ':image_url' => $productImageUrl));
439
- }
440
- }
441
-
442
- public function getImageQueue(){
443
- return $this->_connRes->fetchAll("SELECT `queue_id`, `entity_id`, `image_url` FROM `" . $this->_tablePrefix . "capacity_product_image_queue`
444
- WHERE `is_downloaded` = 0
445
- ");
446
- }
447
-
448
- public function setImageAsDownloaded($queueId =false){
449
- if ($queueId) {
450
- $this->_connRes->query("UPDATE `" . $this->_tablePrefix . "capacity_product_image_queue` SET is_downloaded = 1
451
- WHERE queue_id = :queue_id", array(':queue_id' => $queueId));
452
- }
453
- }
454
-
455
- protected function _addCategories($categories, $storeId, $unspsc, $unspscPath, $categoryActive = 1) {
456
-
457
- // check if product exists
458
- $categoryId = $this->_getCategoryIdByUnspsc($unspsc);
459
- $categoryIds = array();
460
-
461
- if (!empty($categoryId)) {
462
- // merge categories by unspsc
463
- $categoryMergedArray = $this->_categoryMapper($categories, $unspscPath);
464
- foreach ($categoryMergedArray as $category) {
465
- $categoryName = $category['name'];
466
- $categoryUnspsc = $category['unspsc'];
467
- $categoryTreeId = $this->_getCategoryIdByUnspsc($categoryUnspsc);
468
- // check category name to current store
469
- $categoryBindArray = array(
470
- ':store_id' => $storeId,
471
- ':category_id' => $categoryTreeId
472
- );
473
- $nameCheckerFetch = $this->_connRes->fetchRow("SELECT value_id FROM `" . $this->_tablePrefix . "catalog_category_entity_varchar` WHERE
474
- store_id = :store_id AND entity_id = :category_id AND attribute_id = @category_name_id
475
- ", $categoryBindArray);
476
- $nameChecker = $nameCheckerFetch['value_id'];
477
- if (!$nameChecker) {
478
- // add category name to current store
479
- $categoryBindArray[':category_name'] = $categoryName;
480
- if (!empty($categoryBindArray[':category_id'])){
481
- $this->_connRes->query("
482
- INSERT INTO `" . $this->_tablePrefix . "catalog_category_entity_varchar` (`entity_type_id`, `attribute_id`, `store_id`, `entity_id`, `value`) VALUES
483
- (@category_entity_type_id, @category_name_id, :store_id, :category_id, :category_name)
484
- ", $categoryBindArray);
485
- }
486
- }
487
- }
488
- if (1 == $categoryActive) {
489
- // get current path of category
490
- $categoryPath = $this->_connRes->fetchRow("SELECT path FROM `" . $this->_tablePrefix . "catalog_category_entity` WHERE entity_id = :entity_id",
491
- array(':entity_id' => $categoryId));
492
- $categoryPathArray = explode('/', $categoryPath['path']);
493
- if ($categoryPathArray) {
494
- $activeSetter = "INSERT INTO `" . $this->_tablePrefix . "catalog_category_entity_int` (`entity_type_id`, `attribute_id`, `store_id`, `entity_id`, `value`) VALUES ";
495
- }
496
-
497
- $falseCounter = 0;
498
- foreach($categoryPathArray as $categoryId) {
499
- $category = Mage::getModel('catalog/category')->load($categoryId);
500
- $cid = $category->getId();
501
- if (!empty($cid)) {
502
- if (!empty($categoryId)) {
503
- $categoryIds[] = (int)$categoryId;
504
- $activeSetter .= "(@category_entity_type_id, @category_active_id, :store_id, " . $categoryId . ", 1),
505
- (@category_entity_type_id, @category_active_id, 0, " . $categoryId . ", 1), ";
506
- } else {
507
- $falseCounter++;
508
- }
509
- } else {
510
- $falseCounter++;
511
- }
512
- }
513
- $activeSetter = substr($activeSetter, 0, -2);
514
- $activeSetter .= "
515
- ON DUPLICATE KEY UPDATE
516
- `value` = 1
517
- ";
518
- if ($falseCounter < count($categoryPathArray)) {
519
- $this->_connRes->query($activeSetter, array(':store_id' => $storeId));
520
- }
521
- }
522
- return $categoryIds;
523
- } else {
524
-
525
- // merge unspcs to current name in unspcs & name path's
526
- $categoryMergedArray = $this->_categoryMapper($categories, $unspscPath);
527
- // get max created parrent category
528
- $categoryCreateArray = array();
529
- for ($i = count($categoryMergedArray) -1; $i >= 0; $i--) {
530
- $category = $categoryMergedArray[$i];
531
- $checkCategoryId = $this->_getCategoryIdByUnspsc($category['unspsc']);
532
- if ($checkCategoryId != null) {
533
- $categoryId = $this->_buildCategoryTree($checkCategoryId, $storeId, $categoryCreateArray, $categoryActive);
534
- $categoryIds[] = (int)$categoryId;
535
- break;
536
- } else {
537
- $categoryCreateArray[] = $category;
538
- }
539
- }
540
- return $categoryIds;
541
- }
542
- }
543
-
544
- protected function _categoryMapper($categoryPath, $unspscPath) {
545
- $nameArray = explode('/', $categoryPath);
546
- $unspscArray = explode('/', $unspscPath);
547
-
548
- if (count($nameArray) != count($unspscArray)) {
549
- $message = Mage::helper('catalog')->__('Skip import row, @categories data is invaled');
550
- Mage::throwException($message);
551
- }
552
-
553
- $categoryMergedArray = array(
554
- array(
555
- 'unspsc' => 'default_root',
556
- 'name' => 'Default category'
557
- )
558
- );
559
-
560
- for($i = 0; $i < count($unspscArray); $i++) {
561
- $categoryMergedArray[] = array('name' =>$nameArray[$i],
562
- 'unspsc' =>$unspscArray[$i]);
563
- }
564
-
565
- return $categoryMergedArray;
566
- }
567
-
568
- protected function _getCategoryIdByUnspsc($unspcs) {
569
- if ($unspcs == 'default_root') {
570
- return Mage::app()->getStore(1)->getRootCategoryId();
571
- } else {
572
- $categoryId = $this->_connRes->fetchRow("SELECT entity_id FROM `" . $this->_tablePrefix . "catalog_category_entity_varchar` WHERE
573
- `value` = :unspsc AND attribute_id = @unspcs_id", array(':unspsc' => $unspcs));
574
- return ($categoryId['entity_id']) ? $categoryId['entity_id'] : null;
575
- }
576
- }
577
-
578
- protected function _buildCategoryTree($parrentCategoryId, $storeId, $pathArray, $categoryActive = 0) {
579
- for ($i = count($pathArray) -1; $i >= 0; $i--) {
580
- $category = $pathArray[$i];
581
- $parrentCategoryId = $this->_createCategory($parrentCategoryId, $category['unspsc'], $storeId, $category['name'], $categoryActive);
582
- }
583
-
584
- return $parrentCategoryId;
585
- }
586
-
587
- protected function _createCategory($parrentId, $unspsc, $storeId, $name, $categoryActive = 0) {
588
-
589
- $addCategory = "
590
- SELECT @tPath := `path`, @tLevel := `level` FROM `" . $this->_tablePrefix . "catalog_category_entity` WHERE `entity_id` = :parrent_id;
591
- SET @tLevel = @tLevel +1;
592
-
593
- SET @path := CONCAT(@tPath, '/',(SELECT MAX(entity_id) FROM `" . $this->_tablePrefix . "catalog_category_entity`) +1 );
594
-
595
- INSERT INTO `" . $this->_tablePrefix . "catalog_category_entity` (`entity_type_id`, `attribute_set_id`,
596
- `parent_id`, `created_at`,
597
- `path`, `position`,
598
- `level`, `children_count`)
599
- VALUES
600
- (@category_entity_type_id, 0, :parrent_id, NOW(), @path, 1, @tLevel, 0);
601
-
602
- SELECT @catId := LAST_INSERT_ID();
603
-
604
- UPDATE `" . $this->_tablePrefix . "catalog_category_entity` SET children_count = children_count +1 WHERE entity_id = :parrent_id;
605
-
606
- INSERT IGNORE INTO `" . $this->_tablePrefix . "catalog_category_entity_int` (`entity_type_id`, `attribute_id`,
607
- `store_id`, `entity_id`, `value`)
608
- VALUES
609
- (@category_entity_type_id, @category_active_id, 0, @catId, :category_active),
610
- (@category_entity_type_id, @category_active_id, :store, @catId, :category_active),
611
- (@category_entity_type_id, @category_is_anchor_id, 0, @catId, 1),
612
- (@category_entity_type_id, @category_is_anchor_id, :store, @catId, 1),
613
- (@category_entity_type_id, @include_nav_bar_id, 0, @catId, 1),
614
- (@category_entity_type_id, @include_nav_bar_id, :store, @catId, 1);
615
-
616
- INSERT IGNORE INTO `" . $this->_tablePrefix . "catalog_category_entity_varchar` (`entity_type_id`, `attribute_id`,
617
- `store_id`, `entity_id`, `value`)
618
- VALUES
619
- (@category_entity_type_id, @category_name_id, 0, @catId, :category_name),
620
- (@category_entity_type_id, @category_name_id, :store, @catId, :category_name),
621
- (@category_entity_type_id, @unspcs_id, 0, @catId, :unspsc_val),
622
- (@category_entity_type_id, @unspcs_id, :store, @catId, :unspsc_val);
623
- ";
624
-
625
- $this->_connRes->query($addCategory, array(
626
- ':store' => $storeId,
627
- ':parrent_id' => $parrentId,
628
- ':category_name' => $name,
629
- ':unspsc_val' => $unspsc,
630
- ':category_active' => (int)$categoryActive
631
- ));
632
-
633
- $categoryIdFetch = $this->_connRes->fetchRow('SELECT @catId AS category_id');
634
-
635
- return $categoryIdFetch['category_id'];
636
- }
637
-
638
- protected function _mapAttributes(array $importData) {
639
-
640
- // map iceimport attributes, skip some attributes
641
- $iceAttributes = array();
642
- foreach ($importData as $attribute => $value) {
643
- // map iceimport attributes
644
- if ($attribute == 'type' ||
645
- $attribute == 'sku' ||
646
- $attribute == 'attribute_set' ||
647
- $attribute == 'categories' ||
648
- $attribute == 'unspsc' ||
649
- $attribute == 'price' ||
650
- $attribute == 'qty' ||
651
- $attribute == 'status' ||
652
- $attribute == 'visibility' ||
653
- $attribute == 'store' ||
654
- $attribute == 'websites' ||
655
- $attribute == 'is_in_stock' ||
656
- $attribute == 'image' ||
657
- $attribute == 'unspsc_path') {
658
-
659
- $iceAttributes[$attribute] = $value;
660
- unset($importData[$attribute]);
661
-
662
- }
663
- // skip some attributes
664
- if ($attribute == 'supplier_product_code' ||
665
- $attribute == 'supplier' ||
666
- $attribute == 'leader_categories' ||
667
- $attribute == 'leader_store' ||
668
- $attribute == 'sprice' ||
669
- $attribute == 'euprice' ||
670
- $attribute == 'icecat_product_id' ||
671
- $attribute == 'icecat_category_id' ||
672
- $attribute == 'icecat_vendor_id' ||
673
- $attribute == 'icecat_quality' ||
674
- $attribute == 'icecat_url' ||
675
- $attribute == 'icecat_thumbnail_img' ||
676
- $attribute == 'icecat_low_res_img' ||
677
- $attribute == 'icecat_high_res_img' ||
678
- $attribute == 'tax1' ||
679
- $attribute == 'tax2' ||
680
- $attribute == 'tax3' ||
681
- $attribute == 'tax4' ||
682
- $attribute == 'min_quantity' ||
683
- $attribute == 'loms' ||
684
- $attribute == 'image_label' ||
685
- $attribute == 'links_title' ||
686
- $attribute == 'small_image_label' ||
687
- $attribute == 'tax_rate' ||
688
- $attribute == 'gallery' ||
689
- $attribute == 'weight_type' ||
690
- $attribute == 'sku_type' ||
691
- $attribute == 'manage_stock' ||
692
- $attribute == 'minimal_price' ||
693
- $attribute == 'required_options' ||
694
- $attribute == 'samples_title' ||
695
- $attribute == 'shipment_type' ||
696
- $attribute == 'url_path' ||
697
- $attribute == 'recurring_profile' ||
698
- $attribute == 'product_keys') {
699
-
700
- unset($importData[$attribute]);
701
-
702
- }
703
-
704
- }
705
-
706
- // map default attributes
707
- $productData = array();
708
- foreach($this->_getDefaultAttributesList() as $backendType => $attributesList) {
709
- if ($backendType != 'spec') {
710
- foreach($attributesList as $attribute) {
711
- if (isset($importData[$attribute])) {
712
- $productData[$backendType][$attribute] = $importData[$attribute];
713
- unset($importData[$attribute]);
714
- }
715
- }
716
- } else {
717
- foreach($attributesList as $attributeCode => $attributeSpecs) {
718
- if (isset($importData[$attributeCode])) {
719
- $attributeSpecs['value'] = $importData[$attributeCode];
720
- $productData[$backendType][$attributeCode] = $attributeSpecs;
721
- unset($importData[$attributeCode]);
722
- }
723
- }
724
- }
725
- }
726
-
727
- // map custom attributes
728
- if (!empty($importData)) {
729
- foreach ($importData as $attributeCode => $value) {
730
- $backendTypeFetch = $this->_connRes->fetchRow("SELECT backend_type FROM `" . $this->_tablePrefix . "eav_attribute` WHERE `attribute_code` = :code", array(':code' => $attributeCode));
731
- $backendType = $backendTypeFetch['backend_type'];
732
- if ($backendType != 'static' && !empty($backendType)) {
733
- $productData[$backendType][$attributeCode] = $value;
734
- unset($importData[$attributeCode]);
735
- }
736
- }
737
- }
738
-
739
- $failedAttributes = array();
740
- if (count($importData) > 0) {
741
- $failedAttributes = array_keys($importData);
742
- }
743
-
744
- return array(
745
- 'iceimportAttributes' => $iceAttributes,
746
- 'productData' => $productData,
747
- 'failedAttributes' => $failedAttributes
748
- );
749
-
750
- }
751
-
752
- protected function _getDefaultAttributesList () {
753
- return array(
754
- 'varchar' => array(
755
- 'gift_message_available',
756
- 'custom_design',
757
- 'msrp_display_actual_price_type',
758
- 'msrp_enabled',
759
- 'options_container',
760
- 'page_layout',
761
- 'mpn',
762
- 'brand_name',
763
- 'name',
764
- 'url_key',
765
- 'meta_description',
766
- 'meta_title'
767
- ),
768
- 'int' => array(
769
- 'enable_googlecheckout',
770
- 'is_recurring',
771
- 'links_purchased_separately',
772
- 'links_exist',
773
- 'status',
774
- 'visibility',
775
- 'tax_class_id',
776
- 'color',
777
- 'price_view',
778
- 'manufacturer'
779
- ),
780
- 'text' => array(
781
- 'recurring_profile',
782
- 'description',
783
- 'custom_layout_update',
784
- 'meta_keyword',
785
- 'short_description'
786
- ),
787
- 'decimal' => array(
788
- 'cost',
789
- 'group_price',
790
- 'weight',
791
- 'special_price',
792
- 'msrp'
793
- ),
794
- 'datetime' => array(
795
- 'custom_design_from',
796
- 'custom_design_to',
797
- 'news_from_date',
798
- 'news_to_date',
799
- 'special_from_date',
800
- 'special_to_date'
801
- ),
802
- 'spec' => array(
803
- 'is_qty_decimal' => array(
804
- 'prod_id_field' => 'product_id',
805
- 'table' => 'cataloginventory_stock_item',
806
- 'field' => 'is_qty_decimal'
807
- ),
808
- 'use_config_min_qty' => array(
809
- 'prod_id_field' => 'product_id',
810
- 'table' => 'cataloginventory_stock_item',
811
- 'field' => 'use_config_min_qty'
812
- ),
813
- 'use_config_min_sale_qty' => array(
814
- 'prod_id_field' => 'product_id',
815
- 'table' => 'cataloginventory_stock_item',
816
- 'field' => 'use_config_min_sale_qty'
817
- ),
818
- 'use_config_max_sale_qty' => array(
819
- 'prod_id_field' => 'product_id',
820
- 'table' => 'cataloginventory_stock_item',
821
- 'field' => 'use_config_max_sale_qty'
822
- ),
823
- 'use_config_manage_stock' => array(
824
- 'prod_id_field' => 'product_id',
825
- 'table' => 'cataloginventory_stock_item',
826
- 'field' => 'use_config_manage_stock'
827
- ),
828
- 'is_decimal_divided' => array(
829
- 'prod_id_field' => 'product_id',
830
- 'table' => 'cataloginventory_stock_item',
831
- 'field' => 'is_decimal_divided'
832
- ),
833
- 'use_config_backorders' => array(
834
- 'prod_id_field' => 'product_id',
835
- 'table' => 'cataloginventory_stock_item',
836
- 'field' => 'use_config_backorders'
837
- ),
838
- 'use_config_notify_stock_qty' => array(
839
- 'prod_id_field' => 'product_id',
840
- 'table' => 'cataloginventory_stock_item',
841
- 'field' => 'use_config_notify_stock_qty'
842
- ),
843
- 'max_sale_qty' => array(
844
- 'prod_id_field' => 'product_id',
845
- 'table' => 'cataloginventory_stock_item',
846
- 'field' => 'max_sale_qty'
847
- ),
848
- 'min_sale_qty' => array(
849
- 'prod_id_field' => 'product_id',
850
- 'table' => 'cataloginventory_stock_item',
851
- 'field' => 'min_sale_qty'
852
- ),
853
- 'notify_stock_qty' => array(
854
- 'prod_id_field' => 'product_id',
855
- 'table' => 'cataloginventory_stock_item',
856
- 'field' => 'notify_stock_qty'
857
- ),
858
- 'backorders' => array(
859
- 'prod_id_field' => 'product_id',
860
- 'table' => 'cataloginventory_stock_item',
861
- 'field' => 'backorders'
862
- ),
863
- 'created_at' => array(
864
- 'prod_id_field' => 'entity_id',
865
- 'table' => 'catalog_product_entity',
866
- 'field' => 'created_at'
867
- ),
868
- 'min_qty' => array(
869
- 'prod_id_field' => 'product_id',
870
- 'table' => 'cataloginventory_stock_item',
871
- 'field' => 'min_qty'
872
- ),
873
- 'updated_at' => array(
874
- 'prod_id_field' => 'entity_id',
875
- 'table' => 'catalog_product_entity',
876
- 'field' => 'updated_at'
877
- )
878
- )
879
- );
880
- }
881
-
882
- // Count child categories products and set them inactive if they have no products
883
- public function CountChildProd($child_cat) {
884
- foreach ($child_cat as $cat) {
885
- $query = "SELECT `entity_id` FROM `" . $this->_tablePrefix . "catalog_category_entity` WHERE parent_id = :cat_id";
886
- $child_cat = $this->_connRes->fetchAll($query,array(
887
- ':cat_id'=> $cat['entity_id']
888
- ));
889
-
890
- $query = "SELECT COUNT(*) FROM `" . $this->_tablePrefix . "catalog_category_product` WHERE category_id = :cat_id ";
891
- $cat_products = $this->_connRes->fetchRow($query,array(
892
- ':cat_id'=> $cat['entity_id']
893
- ));
894
-
895
- if ($cat_products['COUNT(*)'] == 0 && empty($child_cat)) {
896
- $this->_connRes->query("UPDATE `" . $this->_tablePrefix . "catalog_category_entity_int`
897
- SET `value` = 0 WHERE `attribute_id` = @category_active_id AND entity_id = :cat_id",array(
898
- ':cat_id'=> $cat['entity_id']
899
- ));
900
- } else if (!empty($child_cat)) {
901
- $this->CountChildProd($child_cat);
902
- }
903
- }
904
- }
905
-
906
- }
907
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Capacitywebsolutions/Importproduct/Model/Observer.php DELETED
@@ -1,203 +0,0 @@
1
- <?php
2
- class Capacitywebsolutions_Importproduct_Model_Observer
3
- {
4
-
5
- protected function _construct() {
6
- $this->_init('importproduct/observer');
7
- }
8
-
9
-
10
- /**
11
- * load
12
- * @access publc
13
- */
14
- public function load() {
15
-
16
- $profileId = 3;
17
- $logFileName= 'test.log';
18
- $recordCount = 0;
19
-
20
- Mage::log("Import Started",null,$logFileName);
21
-
22
- $profile = Mage::getModel('dataflow/profile');
23
-
24
- $userModel = Mage::getModel('admin/user');
25
- $userModel->setUserId(0);
26
- Mage::getSingleton('admin/session')->setUser($userModel);
27
-
28
- if ($profileId) {
29
- $profile->load($profileId);
30
- if (!$profile->getId()) {
31
- Mage::getSingleton('adminhtml/session')->addError('The profile that you are trying to save no longer exists');
32
- }
33
- }
34
-
35
- $profile->run();
36
-
37
- $batchModel = Mage::getSingleton('dataflow/batch');
38
-
39
- if ($batchModel->getId()) {
40
- if ($batchModel->getAdapter()) {
41
- $batchId = $batchModel->getId();
42
- $batchImportModel = $batchModel->getBatchImportModel();
43
- $importIds = $batchImportModel->getIdCollection();
44
-
45
- $batchModel = Mage::getModel('dataflow/batch')->load($batchId);
46
-
47
- $adapter = Mage::getModel($batchModel->getAdapter());
48
-
49
- foreach ($importIds as $importId) {
50
-
51
- $recordCount++;
52
- try{
53
- $batchImportModel->load($importId);
54
- if (!$batchImportModel->getId()) {
55
- $errors[] = Mage::helper('dataflow')->__('Skip undefined row');
56
- continue;
57
- }
58
-
59
- $importData = $batchImportModel->getBatchData();
60
-
61
- try {
62
- $adapter->saveRow($importData);
63
- } catch (Exception $e) {
64
- Mage::log($e->getMessage(),null,$logFileName);
65
- continue;
66
- }
67
-
68
- }catch (Exeption $ex) {
69
- Mage::log('Record# ' . $recordCount . ' - SKU = ' . $importData['sku']. ' - Error - ' . $ex->getMessage(),null,$logFileName);
70
- }
71
-
72
- }
73
-
74
- // delete old products
75
- $db_res = Mage::getSingleton('core/resource')->getConnection('core_write');
76
- $tablePrefix = '';
77
- $tPrefix = (array)Mage::getConfig()->getTablePrefix();
78
- if (!empty($tPrefix)) {
79
- $tablePrefix = $tPrefix[0];
80
- }
81
-
82
- try{
83
- $db_res->query("SELECT @is_iceimport_id := `attribute_id` FROM " . $tablePrefix . "eav_attribute WHERE attribute_code = 'is_iceimport'");
84
- $db_res->query("DELETE cpe FROM " . $tablePrefix . "catalog_product_entity AS cpe
85
- JOIN " . $tablePrefix . "catalog_product_entity_varchar AS cpev ON cpe.entity_id = cpev.entity_id AND cpev.value = 1 AND cpev.attribute_id = @is_iceimport_id
86
- LEFT JOIN iceimport_imported_product_ids AS iip ON cpe.entity_id = iip.product_id
87
- WHERE iip.product_id IS NULL");
88
- $db_res->query('DELETE FROM iceimport_imported_product_ids');
89
-
90
- } catch (Exception $e) {
91
- throw new Exception($e->getMessage());
92
- }
93
-
94
-
95
- // download & set product images
96
- $queueList = $adapter->getImageQueue();
97
- if (count($queueList) > 0) {
98
- $mediaDir = Mage::getBaseDir('media');
99
- foreach ($queueList as $queue) {
100
- $queueId = $queue['queue_id'];
101
- $productId = $queue['entity_id'];
102
- $imageUrl = $queue['image_url'];
103
-
104
- $preImageName = explode('/', $imageUrl);
105
- $imageName = array_pop($preImageName);
106
- if (file_exists($mediaDir . DS . $imageName)) {
107
- $imageName = rand() .'_'. time() . $imageName;
108
- }
109
-
110
- if(file_put_contents($mediaDir . DS . $imageName, file_get_contents($imageUrl))) {
111
- $product = Mage::getModel('catalog/product')->load($productId);
112
- $product->addImageToMediaGallery($mediaDir . DS . $imageName,
113
- array('image', 'small_image', 'thumbnail'),
114
- true, true
115
- );
116
- $product->save();
117
- $adapter->setImageAsDownloaded($queueId);
118
- echo $product->getCategory() . '<br>';
119
- unset($product);
120
- } else {
121
- Mage::log('Unable download file to ' . $productId, $logFileName);
122
- continue;
123
- }
124
- }
125
- }
126
- // sort category in abc
127
-
128
- $catCollection = Mage::getModel('catalog/category')
129
- ->getCollection()
130
- ->addAttributeToSort('name', 'ASC');
131
- $position =1;
132
- foreach($catCollection as $category) {
133
- $catSource = Mage::getModel('catalog/category')->load($category->getId());
134
- $catSource->setData('position', $position);
135
- $catSource->save();
136
- $query = "SELECT COUNT(*) FROM `" . $this->_tablePrefix . "catalog_category_product` WHERE category_id = :cat_id ";
137
- $cat_products = $db_res->fetchRow($query,array(
138
- ':cat_id'=> $category->getId()
139
- ));
140
-
141
- if ($cat_products['COUNT(*)'] == 0) {
142
- $query = "SELECT `entity_id` FROM `" . $this->_tablePrefix . "catalog_category_entity` WHERE parent_id = :cat_id";
143
- $child_cat = $db_res->fetchAll($query,array(
144
- ':cat_id'=> $category->getId()
145
- ));
146
- $cat_prod = 0;
147
-
148
- if (isset($child_cat) && count($child_cat) > 0) {
149
-
150
- foreach ($child_cat as $cat) {
151
- $query = "SELECT COUNT(*) FROM `" . $this->_tablePrefix . "catalog_category_product` WHERE category_id = :cat_id ";
152
- $cat_products = $db_res->fetchRow($query,array(
153
- ':cat_id'=> $cat['entity_id']
154
- ));
155
-
156
- if ($cat_products['COUNT(*)'] != 0) {
157
- $cat_prod = 1;
158
- }
159
-
160
- }
161
-
162
- if ($cat_prod == 0) {
163
- $db_res->query("UPDATE `" . $this->_tablePrefix . "catalog_category_entity_int`
164
- SET `value` = 0 WHERE `attribute_id` = @category_active_id AND entity_id = :cat_id",array(
165
- ':cat_id'=> $category->getId()
166
- ));
167
- }
168
- } else {
169
- $db_res->query("UPDATE `" . $this->_tablePrefix . "catalog_category_entity_int`
170
- SET `value` = 0 WHERE `attribute_id` = @category_active_id AND entity_id = :cat_id",array(
171
- ':cat_id'=> $category->getId()
172
- ));
173
- }
174
- }
175
- $position++;
176
- }
177
-
178
-
179
- $processes = Mage::getSingleton('index/indexer')->getProcessesCollection();
180
- $processes->walk('reindexAll');
181
-
182
- foreach ($profile->getExceptions() as $e) {
183
- Mage::log($e->getMessage(),null,$logFileName);
184
- }
185
-
186
- }
187
- }
188
-
189
- unset($db_res);
190
- echo 'Import Completed';
191
- Mage::log("Import Completed",null,$logFileName);
192
-
193
- try {
194
- $import = Mage::getModel('importexport/import');
195
- } catch (Exeptint $e) {
196
- Mage::log($e->getMessage(), null, $logFileName);
197
- }
198
-
199
- // get prouct download queue
200
- }
201
-
202
- }
203
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Capacitywebsolutions/Importproduct/Model/System/Config/Categoryactivity.php DELETED
@@ -1,13 +0,0 @@
1
- <?php
2
-
3
- class Capacitywebsolutions_Importproduct_Model_System_Config_Categoryactivity
4
- {
5
- public function toOptionArray(){
6
- $paramsArray = array(
7
- 1 => 'Yes',
8
- 0 => 'No'
9
- );
10
- return $paramsArray;
11
- }
12
- }
13
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Capacitywebsolutions/Importproduct/Model/System/Config/Defaulttax.php DELETED
@@ -1,19 +0,0 @@
1
- <?php
2
-
3
- class Capacitywebsolutions_Importproduct_Model_System_Config_Defaulttax
4
- {
5
- public function toOptionArray()
6
- {
7
- $collection = Mage::getModel('tax/class')->getCollection();
8
- $paramsArray = array();
9
- $paramsArray['0'] = 'None';
10
-
11
- foreach ($collection as $product) {
12
- $tax = $product->getData();
13
- $paramsArray[$tax['class_id']] = $tax['class_name'];
14
- }
15
-
16
- return $paramsArray;
17
- }
18
- }
19
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Capacitywebsolutions/Importproduct/Model/System/Config/Imageimport.php DELETED
@@ -1,14 +0,0 @@
1
- <?php
2
-
3
- class Capacitywebsolutions_Importproduct_Model_System_Config_Imageimport
4
- {
5
- public function toOptionArray()
6
- {
7
- $paramsArray = array(
8
- '1' => 'Yes',
9
- '0' => 'No'
10
- );
11
- return $paramsArray;
12
- }
13
- }
14
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Capacitywebsolutions/Importproduct/Model/System/Config/Lockproddetails.php DELETED
@@ -1,15 +0,0 @@
1
- <?php
2
-
3
- class Capacitywebsolutions_Importproduct_Model_System_Config_Lockproddetails
4
- {
5
- public function toOptionArray()
6
- {
7
- $paramsArray = array(
8
- 'import_price_stock' => 'Yes',
9
- 'import_info' => 'No'
10
- );
11
- return $paramsArray;
12
- }
13
- }
14
-
15
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Capacitywebsolutions/Importproduct/etc/config.xml DELETED
@@ -1,90 +0,0 @@
1
- <?xml version="1.0"?>
2
- <config>
3
- <modules>
4
- <Capacitywebsolutions_Importproduct>
5
- <version>1.4.0</version>
6
- </Capacitywebsolutions_Importproduct>
7
- </modules>
8
- <global>
9
- <events>
10
- <controller_action_predispatch_adminhtml_profile_batchfinish>
11
- <observers>
12
- <Capacitywebsolutions_Importproduct>
13
- <class>Capacitywebsolutions_Importproduct/Observer</class>
14
- <method>sortCategory</method>
15
- </Capacitywebsolutions_Importproduct>
16
- </observers>
17
- </controller_action_predispatch_adminhtml_profile_batchfinish>
18
- <controller_action_postdispatch_adminhtml_profile_batchFinish>
19
- <observers>
20
- <Capacitywebsolutions_Importproduct>
21
- <class>Capacitywebsolutions_Importproduct/Observer</class>
22
- <method>sortCategory</method>
23
- </Capacitywebsolutions_Importproduct>
24
- </observers>
25
- </controller_action_postdispatch_adminhtml_profile_batchFinish>
26
- </events>
27
- <models>
28
- <catalog>
29
- <rewrite>
30
- <!-- Override Mage_Catalog_Model_Convert_Adapter_Product -->
31
- <convert_adapter_product>Capacitywebsolutions_Importproduct_Model_Convert_Adapter_Product</convert_adapter_product>
32
- </rewrite>
33
- </catalog>
34
- <importproduct>
35
- <class>Capacitywebsolutions_Importproduct_Model</class>
36
- </importproduct>
37
- </models>
38
- <resources>
39
- <importproduct_setup>
40
- <setup>
41
- <module>Capacitywebsolutions_Importproduct</module>
42
- <class>Mage_Catalog_Model_Resource_Eav_Mysql4_Setup</class>
43
- </setup>
44
- <connection>
45
- <use>core_setup</use>
46
- </connection>
47
- </importproduct_setup>
48
- <importproduct_setup_write>
49
- <connection>
50
- <use>core_write</use>
51
- </connection>
52
- </importproduct_setup_write>
53
- <importproduct_setup_read>
54
- <connection>
55
- <use>core_read</use>
56
- </connection>
57
- </importproduct_setup_read>
58
- </resources>
59
- </global>
60
-
61
- <adminhtml>
62
- <acl>
63
- <resources>
64
- <admin>
65
- <children>
66
- <system>
67
- <children>
68
- <config>
69
- <children>
70
- <importprod_root>
71
- <title>IceImport module</title>
72
- </importprod_root>
73
- </children>
74
- </config>
75
- </children>
76
- </system>
77
- </children>
78
- </admin>
79
- </resources>
80
- </acl>
81
- </adminhtml>
82
- <crontab>
83
- <jobs>
84
- <importproduct>
85
- <schedule><cron_expr>* * * * *</cron_expr></schedule>
86
- <run><model>importproduct/observer::load</model></run>
87
- </importproduct>
88
- </jobs>
89
- </crontab>
90
- </config>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Capacitywebsolutions/Importproduct/etc/system.xml DELETED
@@ -1,63 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <config>
3
- <sections>
4
- <importprod_root translate="label" module="catalog">
5
- <class>separator-top</class>
6
- <label>IceImport</label>
7
- <tab>catalog</tab>
8
- <frontend_type>text</frontend_type>
9
- <sort_order>300</sort_order>
10
- <show_in_default>1</show_in_default>
11
- <show_in_website>1</show_in_website>
12
- <show_in_store>1</show_in_store>
13
- <groups>
14
- <importprod translate="label">
15
- <label>IceImport Settings</label>
16
- <frontend_type>text</frontend_type>
17
- <sort_order>50</sort_order>
18
- <show_in_default>1</show_in_default>
19
- <show_in_website>1</show_in_website>
20
- <show_in_store>1</show_in_store>
21
- <fields>
22
- <category_active translate="label">
23
- <label>Set to active imported categories</label>
24
- <frontend_type>select</frontend_type>
25
- <source_model>importproduct/system_config_categoryactivity</source_model>
26
- <sort_order>10</sort_order>
27
- <show_in_default>1</show_in_default>
28
- <show_in_website>1</show_in_website>
29
- <show_in_store>1</show_in_store>
30
- </category_active>
31
- <import_only_prices_stock translate="label">
32
- <label>Import only prices and stock</label>
33
- <frontend_type>select</frontend_type>
34
- <source_model>importproduct/system_config_lockproddetails</source_model>
35
- <sort_order>20</sort_order>
36
- <show_in_default>1</show_in_default>
37
- <show_in_website>1</show_in_website>
38
- <show_in_store>1</show_in_store>
39
- </import_only_prices_stock>
40
- <import_images translate="label">
41
- <label>Import product images (via Cron)</label>
42
- <frontend_type>select</frontend_type>
43
- <source_model>importproduct/system_config_imageimport</source_model>
44
- <sort_order>30</sort_order>
45
- <show_in_default>1</show_in_default>
46
- <show_in_website>1</show_in_website>
47
- <show_in_store>1</show_in_store>
48
- </import_images>
49
- <default_tax translate="label">
50
- <label>Default tax for product</label>
51
- <frontend_type>select</frontend_type>
52
- <source_model>importproduct/system_config_defaulttax</source_model>
53
- <sort_order>40</sort_order>
54
- <show_in_default>1</show_in_default>
55
- <show_in_website>1</show_in_website>
56
- <show_in_store>1</show_in_store>
57
- </default_tax>
58
- </fields>
59
- </importprod>
60
- </groups>
61
- </importprod_root>
62
- </sections>
63
- </config>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Capacitywebsolutions/Importproduct/sql/importproduct_setup/mysql4-install-0.1.0.php DELETED
@@ -1,61 +0,0 @@
1
- <?php
2
-
3
- $installer = $this;
4
- $installer->startSetup();
5
-
6
- $entityTypeId = $installer->getEntityTypeId('catalog_category');
7
- $attributeSetId = $installer->getDefaultAttributeSetId($entityTypeId);
8
- $attributeGroupId = $installer->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
9
-
10
- $installer->addAttribute('catalog_category', 'unspsc', array(
11
- 'type' => 'varchar',
12
- 'label' => 'unspsc',
13
- 'input' => 'text',
14
- 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
15
- 'visible' => true,
16
- 'required' => false,
17
- 'user_defined' => false,
18
- 'default' => 0
19
- ));
20
-
21
- $installer->addAttributeToGroup(
22
- $entityTypeId,
23
- $attributeSetId,
24
- $attributeGroupId,
25
- 'unspsc',
26
- '11'
27
- );
28
-
29
- $attributeId = $installer->getAttributeId($entityTypeId, 'unspsc');
30
-
31
- $installer->run("
32
-
33
- DROP TABLE IF EXISTS `iceimport_imported_product_ids`;
34
- DROP TABLE IF EXISTS `{$installer->getTable('capacity_product_image_queue')}`;
35
-
36
- INSERT IGNORE INTO `{$installer->getTable('catalog_category_entity_varchar')}`
37
- (`entity_type_id`, `attribute_id`, `entity_id`, `value`)
38
- SELECT '{$entityTypeId}', '{$attributeId}', `entity_id`, '1'
39
- FROM `{$installer->getTable('catalog_category_entity')}`;
40
-
41
- CREATE TABLE IF NOT EXISTS `{$installer->getTable('capacity_product_image_queue')}`
42
- (
43
- `queue_id` INT(10) NOT NULL AUTO_INCREMENT,
44
- `entity_id` INT(10) UNSIGNED NOT NULL,
45
- `image_url` VARCHAR(255) NOT NULL,
46
- `is_downloaded` TINYINT NOT NULL DEFAULT 0,
47
- PRIMARY KEY(`queue_id`),
48
- UNIQUE KEY (`entity_id`, `image_url`),
49
- CONSTRAINT `FK_CAP_PRD_IMG_QUEUE_ENTT_ID_CAT_PRD_ENTT_ENTT_ID` FOREIGN KEY (`entity_id`) REFERENCES `{$installer->getTable('catalog_product_entity')}` (`entity_id`) ON DELETE CASCADE
50
- )ENGINE=InnoDB CHARSET=utf8 COMMENT='Table to manage product image import';
51
-
52
- CREATE TABLE IF NOT EXISTS `iceimport_imported_product_ids` (
53
- `product_id` int(11) NOT NULL,
54
- `product_sku` varchar(255) DEFAULT NULL,
55
- KEY `pi_idx` (`product_id`)
56
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8
57
- ");
58
-
59
- $installer->endSetup();
60
-
61
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Iceshop/Iceimport/Model/Convert/Adapter/Product.php ADDED
@@ -0,0 +1,933 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Import Product with additional attributes
4
+ *
5
+ *
6
+ */
7
+
8
+
9
+ class Iceshop_Iceimport_Model_Convert_Adapter_Product extends Mage_Catalog_Model_Convert_Adapter_Product
10
+ {
11
+ protected $_categoryCache = array();
12
+ protected $_connRes = null;
13
+ protected $_tablePrefix = '';
14
+
15
+ public function __construct()
16
+ {
17
+
18
+ $this->_connRes = Mage::getSingleton('core/resource')->getConnection('core_write');
19
+ $tablePrefix = (array)Mage::getConfig()->getTablePrefix();
20
+ if (!empty($tablePrefix)) {
21
+ $this->_tablePrefix = $tablePrefix[0];
22
+ }
23
+
24
+ }
25
+
26
+ public function saveRow(array $importData)
27
+ {
28
+ // separate import data to eav & static
29
+ $sortedProductData = $this->_mapAttributes($importData);
30
+ $productData = $sortedProductData['productData'];
31
+ $iceimportAttributes = $sortedProductData['iceimportAttributes'];
32
+ $failedAttributes = $sortedProductData['failedAttributes'];
33
+
34
+ //Init session values to count total products and determine the last call of saveRow method
35
+ $session = Mage::getSingleton("core/session");
36
+ $import_total = $session->getData("import_total");
37
+ $counter = $session->getData("counter");
38
+
39
+ if (!isset($counter)) {
40
+ $session->setData("counter", 1);
41
+ $counter = $session->getData("counter");
42
+ }
43
+
44
+ if (!isset($import_total)) {
45
+ $batchId = Mage::getSingleton('core/app')->getRequest()->getPost('batch_id', 0);
46
+ $batchModel = Mage::getModel('dataflow/batch')->load($batchId);
47
+ $batchImportModel = $batchModel->getBatchImportModel();
48
+ $importIds = $batchImportModel->getIdCollection();
49
+ $import_total = count($importIds);
50
+ $session->setData("imqport_total", (int)$import_total);
51
+ } else if (isset($counter) && isset($import_total)) {
52
+ if ($counter < $import_total) {
53
+ $session->setData("counter", (int)++$counter);
54
+ }
55
+ }
56
+
57
+ // mark product ice_import generic
58
+ $productData['varchar']['is_iceimport'] = 1;
59
+ // set website id
60
+ if (empty($iceimportAttributes['websites'])) {
61
+ $message = Mage::helper('catalog')->__('Skip import row, required field "%s" not defined', 'website');
62
+ Mage::throwException($message);
63
+ }
64
+ $website = Mage::app()->getWebsite(trim($iceimportAttributes['websites']));
65
+ $websiteId = $website->getId();
66
+
67
+ // set store id
68
+ if (empty($iceimportAttributes['store'])) {
69
+ if (!is_null($this->getBatchParams('store'))) {
70
+ $store = $this->getStoreById($this->getBatchParams('store'));
71
+ } else {
72
+ $message = Mage::helper('catalog')->__('Skip import row, required field "%s" not defined', 'store');
73
+ Mage::throwException($message);
74
+ }
75
+ }
76
+ $store = $this->getStoreByCode($iceimportAttributes['store']);
77
+ if ($store === false) {
78
+ $message = Mage::helper('catalog')->__('Skip import row, store "%s" not exists', $iceimportAttributes['store']);
79
+ Mage::throwException($message);
80
+ }
81
+ $storeId = $store->getId();
82
+
83
+ // set type
84
+ if (empty($iceimportAttributes['type'])) {
85
+ $message = Mage::helper('catalog')->__('Skip import row, required field "%s" not defined', 'type');
86
+ Mage::throwException($message);
87
+ }
88
+ $productType = $iceimportAttributes['type'];
89
+
90
+ // set attribute set
91
+ if (empty($iceimportAttributes['attribute_set'])) {
92
+ $message = Mage::helper('catalog')->__('Skip import row, required field "%s" not defined', 'attribute_set');
93
+ Mage::throwException($message);
94
+ }
95
+ $attribute_set = $iceimportAttributes['attribute_set'];
96
+
97
+ // set sku
98
+ if (empty($iceimportAttributes['sku'])) {
99
+ $message = Mage::helper('catalog')->__('Skip import row, required field "%s" not defined', 'sku');
100
+ Mage::throwException($message);
101
+ }
102
+ $sku = $iceimportAttributes['sku'];
103
+
104
+ // set category, unspsc, unspsc path
105
+ if (empty($iceimportAttributes['categories'])) {
106
+ $message = Mage::helper('catalog')->__('Skip import row, required field "%s" not defined', 'categories');
107
+ Mage::throwException($message);
108
+ }
109
+ $category = $iceimportAttributes['categories'];
110
+ if (empty($iceimportAttributes['unspsc'])) {
111
+ $message = Mage::helper('catalog')->__('Skip import. Category UNSPSC not defined in store');
112
+ Mage::throwException($message);
113
+ }
114
+ $unspsc = $iceimportAttributes['unspsc'];
115
+ if (empty($iceimportAttributes['unspsc_path'])) {
116
+ $message = Mage::helper('catalog')->__('Skip import. Category UNSPSC path not defined in store');
117
+ Mage::throwException($message);
118
+ }
119
+ $unspscPath = $iceimportAttributes['unspsc_path'];
120
+
121
+ // set in / out of stock
122
+ $isInStock = 0;
123
+ if (!empty($iceimportAttributes['is_in_stock'])) {
124
+ $isInStock = $iceimportAttributes['is_in_stock'];
125
+ }
126
+
127
+ // set qty
128
+ $qty = 0;
129
+ if (!empty($iceimportAttributes['qty'])) {
130
+ $qty = $iceimportAttributes['qty'];
131
+ }
132
+
133
+ // set price
134
+ $price = 0.00;
135
+ if (!empty($iceimportAttributes['price'])) {
136
+ $price = $iceimportAttributes['price'];
137
+ }
138
+
139
+ // set status value
140
+ $statusValue = (!empty($iceimportAttributes['status']) && $iceimportAttributes['status'] == 'Enabled') ? 1 : 0;
141
+ $productData['int']['status'] = $statusValue;
142
+
143
+ // set visibility value
144
+ $visibilityValue = 1;
145
+ if (!empty($iceimportAttributes['visibility'])) {
146
+ switch ($iceimportAttributes['visibility']) {
147
+ case 'Not Visible Individually':
148
+ $visibilityValue = 1;
149
+ break;
150
+ case 'Catalog':
151
+ $visibilityValue = 2;
152
+ break;
153
+ case 'Search':
154
+ $visibilityValue = 3;
155
+ break;
156
+ case 'Catalog, Search':
157
+ $visibilityValue = 4;
158
+ break;
159
+ }
160
+ }
161
+ $productData['int']['visibility'] = $visibilityValue;
162
+
163
+ // set product image
164
+ $productImage = '';
165
+ if (!empty($iceimportAttributes['image'])) {
166
+ $productImage = $iceimportAttributes['image'];
167
+ }
168
+
169
+ // init general attributes query
170
+ $initAttributes = "
171
+ SELECT @product_entity_type_id := `entity_type_id` FROM `" . $this->_tablePrefix . "eav_entity_type` WHERE
172
+ entity_type_code = 'catalog_product';
173
+ SELECT @category_entity_type_id := `entity_type_id` FROM `" . $this->_tablePrefix . "eav_entity_type` WHERE
174
+ entity_type_code = 'catalog_category';
175
+ SELECT @attribute_set_id := `entity_type_id` FROM `" . $this->_tablePrefix . "eav_entity_type` WHERE
176
+ entity_type_code = 'catalog_product';
177
+ SELECT @stock_id := `stock_id` FROM `" . $this->_tablePrefix . "cataloginventory_stock` WHERE
178
+ stock_name = 'Default';
179
+ SELECT @attribute_set_id := `attribute_set_id` FROM `" . $this->_tablePrefix . "eav_attribute_set`
180
+ WHERE attribute_set_name = :attribute_set AND entity_type_id =
181
+ @product_entity_type_id;
182
+
183
+ SELECT @price_id := `attribute_id` FROM `" . $this->_tablePrefix . "eav_attribute` WHERE
184
+ `attribute_code` = 'price' AND entity_type_id = @product_entity_type_id;
185
+
186
+ SELECT @unspcs_id := `attribute_id` FROM `" . $this->_tablePrefix . "eav_attribute` WHERE
187
+ `attribute_code` = 'unspsc' AND entity_type_id = @category_entity_type_id;
188
+ SELECT @category_name_id := `attribute_id` FROM `" . $this->_tablePrefix . "eav_attribute` WHERE
189
+ `attribute_code` = 'name' AND entity_type_id = @category_entity_type_id;
190
+ SELECT @category_active_id := `attribute_id` FROM `" . $this->_tablePrefix . "eav_attribute` WHERE
191
+ `attribute_code` = 'is_active' AND entity_type_id = @category_entity_type_id;
192
+ SELECT @include_nav_bar_id := `attribute_id` FROM `" . $this->_tablePrefix . "eav_attribute` WHERE
193
+ `attribute_code` = 'include_in_menu' AND entity_type_id = @category_entity_type_id;
194
+ SELECT @category_is_anchor_id := `attribute_id` FROM `" . $this->_tablePrefix . "eav_attribute` WHERE
195
+ `attribute_code` = 'is_anchor' AND entity_type_id = @category_entity_type_id;
196
+ ";
197
+
198
+
199
+ $this->_connRes->query($initAttributes, array(':attribute_set' => $iceimportAttributes['attribute_set']));
200
+
201
+ $defaulttaxConf = (int)Mage::getStoreConfig('importprod_root/importprod/default_tax', $storeId);
202
+
203
+ $productData['int']['tax_class_id'] = $defaulttaxConf;
204
+
205
+ // get category id
206
+ $categoriesToActiveConf = Mage::getStoreConfig('importprod_root/importprod/category_active', $storeId);
207
+ $categoryIds = $this->_addCategories($category, $storeId, $unspsc, $unspscPath, $categoriesToActiveConf);
208
+
209
+ // get url key
210
+ $url = '';
211
+ if (!empty($productData['varchar']['name'])) {
212
+ $preUrl = explode(' ', strtolower($productData['varchar']['name']));
213
+ $url = implode('-', $preUrl) . '-' . $iceimportAttributes['store'];
214
+ }
215
+ $productData['varchar']['url_key'] = $url;
216
+
217
+ $prodIdFetch = $this->_connRes->fetchRow("SELECT entity_id FROM `" . $this->_tablePrefix . "catalog_product_entity` WHERE sku = :sku limit 1", array(
218
+ ':sku' => $sku
219
+ ));
220
+ $productId = $prodIdFetch['entity_id'];
221
+ if (!empty($productId)) {
222
+ // check import type (Import only price & qty or all product info)
223
+ $stockConf = (int)Mage::getStoreConfig('importprod_root/importprod/import_stock', $storeId);
224
+ $priceConf = (int)Mage::getStoreConfig('importprod_root/importprod/import_prices', $storeId);
225
+ $productId = $this->_coreSave($productData, $productId, $storeId, $sku, $categoryIds);
226
+ $this->_corePriceStock($websiteId, $productId, $price, $qty, $sku, $isInStock, $stockConf, $priceConf);
227
+ $this->_connRes->query('INSERT INTO iceshop_iceimport_imported_product_ids (product_id, product_sku) VALUES (:prod_id, :sku) ON DUPLICATE KEY UPDATE product_sku = :sku', array(':prod_id' => $productId, ':sku' => $sku));
228
+ } else {
229
+ $productId = $this->_coreSave($productData, $productId, $storeId, $sku, $categoryIds);
230
+ // add price & stock
231
+ $this->_corePriceStock($websiteId, $productId, $price, $qty, $sku, $isInStock);
232
+ $this->_connRes->query('INSERT INTO iceshop_iceimport_imported_product_ids (product_id, product_sku) VALUES (:prod_id, :sku) ON DUPLICATE KEY UPDATE product_sku = :sku', array(':prod_id' => $productId, ':sku' => $sku));
233
+ }
234
+
235
+ // add product image to queue
236
+ if (Mage::getStoreConfig('importprod_root/importprod/import_images')) {
237
+ $this->_addImageToQueue($productId, $productImage);
238
+ }
239
+
240
+ // Check if this is last imported product
241
+ // Do category sort and set categories without products to inactive
242
+ if (isset($counter) && isset($import_total) && ($counter == $import_total)) {
243
+ $catCollection = Mage::getModel('catalog/category')
244
+ ->getCollection()
245
+ ->addAttributeToSort('name', 'ASC');
246
+ $position = 1;
247
+
248
+ foreach ($catCollection as $category) {
249
+
250
+ $query = $this->_connRes->query("UPDATE `" . $this->_tablePrefix . "catalog_category_entity` SET position = :position WHERE entity_id = :cat_id ", array(
251
+ ':position' => $position,
252
+ ':cat_id' => $category->getId()
253
+ ));
254
+
255
+ $query = "SELECT COUNT(*) FROM `" . $this->_tablePrefix . "catalog_category_product` WHERE category_id = :cat_id ";
256
+ $cat_products = $this->_connRes->fetchRow($query, array(
257
+ ':cat_id' => $category->getId()
258
+ ));
259
+
260
+ if ($cat_products['COUNT(*)'] == 0) {
261
+ $query = "SELECT `entity_id` FROM `" . $this->_tablePrefix . "catalog_category_entity` WHERE parent_id = :cat_id";
262
+ $child_cat = $this->_connRes->fetchAll($query, array(
263
+ ':cat_id' => $category->getId()
264
+ ));
265
+
266
+ if (isset($child_cat) && count($child_cat) > 0) {
267
+ //Count child categories products and set them to inactive if they have no
268
+ $this->CountChildProd($child_cat);
269
+ } else {
270
+ $this->_connRes->query("UPDATE `" . $this->_tablePrefix . "catalog_category_entity_int`
271
+ SET `value` = 0 WHERE `attribute_id` = @category_active_id AND entity_id = :cat_id", array(
272
+ ':cat_id' => $category->getId()
273
+ ));
274
+ }
275
+ }
276
+ $position++;
277
+ }
278
+
279
+ $session->unsetData('import_total');
280
+ $session->unsetData('counter');
281
+ }
282
+
283
+ return true;
284
+ }
285
+
286
+ protected function _coreSave(array $entityData, $productId = null, $storeId = 0, $sku, $categoryIds)
287
+ {
288
+ if ($productId === null) {
289
+ // add product to store
290
+ $coreSaveProduct = "INSERT INTO `" . $this->_tablePrefix . "catalog_product_entity` (`entity_type_id`, `attribute_set_id`, `type_id`, `sku`, `created_at`) VALUES
291
+ (@product_entity_type_id, @attribute_set_id, 'simple', :sku, NOW());
292
+ SELECT @product_id := LAST_INSERT_ID();
293
+ ";
294
+ $this->_connRes->query($coreSaveProduct, array(':sku' => $sku));
295
+ // get product ID
296
+ $prodFetch = $this->_connRes->fetchRow('SELECT @product_id AS prod_id');
297
+ $productId = $prodFetch['prod_id'];
298
+
299
+ } else {
300
+ $coreSaveSQL .= "SELECT @product_id := " . (int)$productId . "; ";
301
+ $producteanConf = (int)Mage::getStoreConfig('importprod_root/importprod/import_product_ean', $storeId);
302
+ $productmpnConf = (int)Mage::getStoreConfig('importprod_root/importprod/import_product_mpn', $storeId);
303
+ $productnameConf = (int)Mage::getStoreConfig('importprod_root/importprod/import_product_name', $storeId);
304
+ $productshdescriptionConf = (int)Mage::getStoreConfig('importprod_root/importprod/import_product_short_description', $storeId);
305
+ $productdescriptionConf = (int)Mage::getStoreConfig('importprod_root/importprod/import_product_description', $storeId);
306
+ $productshsudescriptionConf = (int)Mage::getStoreConfig('importprod_root/importprod/import_product_short_summary_description', $storeId);
307
+ $productsudescriptionConf = (int)Mage::getStoreConfig('importprod_root/importprod/import_product_summary_description', $storeId);
308
+ $productbrandConf = (int)Mage::getStoreConfig('importprod_root/importprod/import_product_brand', $storeId);
309
+ $deliveryetaConf = (int)Mage::getStoreConfig('importprod_root/importprod/import_delivery_eta', $storeId);
310
+ foreach ($entityData as $type => $typeAttributes) {
311
+ foreach ($typeAttributes as $attribute => $value) {
312
+ if ((($attribute == 'mpn' && $productmpnConf == 0) || ($attribute == 'brand_name' && $productbrandConf == 0) || ($attribute == 'ean' && $producteanConf == 0) || ($attribute == 'name' && $productnameConf == 0) || ($attribute == 'short_description' && $productshdescriptionConf == 0) || ($attribute == 'description' && $productdescriptionConf == 0) || ($attribute == 'short_summary_description' && $productshsudescriptionConf == 0) || ($attribute == 'long_summary_description' && $productsudescriptionConf == 0) || ($attribute == 'delivery_eta' && $deliveryetaConf == 0))) {
313
+ unset($entityData[$type][$attribute]);
314
+ }
315
+ }
316
+ }
317
+ }
318
+ $bindArray[':store_id'] = $storeId;
319
+
320
+ foreach ($entityData as $type => $typeAttributes) {
321
+
322
+ if ($type != 'spec') {
323
+ $tailCoreSaveSQL = '';
324
+ $attributesInit = '';
325
+
326
+ if (!empty($typeAttributes)) {
327
+ $tailCoreSaveSQL .= "
328
+ INSERT INTO `" . $this->_tablePrefix . "catalog_product_entity_" . $type . "` (`entity_type_id`, `attribute_id`, `store_id`, `entity_id`, `value`) VALUES ";
329
+ foreach ($typeAttributes as $attribute => $value) {
330
+
331
+ $attributesInit .= "
332
+ SELECT @" . $attribute . "_id := `attribute_id` FROM `" . $this->_tablePrefix . "eav_attribute` WHERE
333
+ `attribute_code` = '" . $attribute . "' AND entity_type_id = @product_entity_type_id;
334
+ ";
335
+
336
+ $tailCoreSaveSQL .= "
337
+ (@product_entity_type_id, @" . $attribute . "_id, 0, @product_id, :" . $attribute . " ),
338
+ (@product_entity_type_id, @" . $attribute . "_id, :store_id, @product_id, :" . $attribute . " ), ";
339
+ $bindArray[':' . $attribute] = $value;
340
+
341
+ }
342
+ $tailCoreSaveSQL = substr($tailCoreSaveSQL, 0, -2);
343
+ $tailCoreSaveSQL .= "
344
+ ON DUPLICATE KEY UPDATE
345
+ `value` = VALUES (`value`);
346
+ ";
347
+ }
348
+ $coreSaveSQL .= $attributesInit . $tailCoreSaveSQL;
349
+ } else {
350
+ foreach ($typeAttributes as $attribute => $attributeData) {
351
+ $prod_id_field = $attributeData['prod_id_field'];
352
+ $table = $attributeData['table'];
353
+ $field = $attributeData['field'];
354
+ $value = $attributeData['value'];
355
+ if (!empty($table) && !empty($field)) {
356
+ $coreSaveSQL .= "
357
+ UPDATE `" . $this->_tablePrefix . $table . "` SET `" . $field . "` = :" . $attribute . " WHERE `" . $prod_id_field . "` = @product_id;
358
+ ";
359
+ $bindArray[':' . $attribute] = $value;
360
+ }
361
+ }
362
+ }
363
+ }
364
+ // categories
365
+ $coreSaveSQL .= "INSERT INTO `" . $this->_tablePrefix . "catalog_category_product` (`category_id`, `product_id`, `position`) VALUES ";
366
+ $counter = 1;
367
+ $categoryIds[] = Mage::app()->getStore(1)->getRootCategoryId();
368
+ foreach ($categoryIds as $categoryId) {
369
+ if ($counter < count($categoryIds)) {
370
+ $coreSaveSQL .= " (" . (int)$categoryId . ", @product_id, 1) , ";
371
+ } else if ($counter == count($categoryIds)) {
372
+ $coreSaveSQL .= " (" . (int)$categoryId . ", @product_id, 1) ON DUPLICATE KEY UPDATE `position` = 1 ";
373
+ }
374
+ $counter++;
375
+ }
376
+ try {
377
+ $bindArray[':' . $attribute] = $value;
378
+
379
+ $query = $this->_connRes->query($coreSaveSQL, $bindArray);
380
+
381
+ } catch (Exception $e) {
382
+ echo $e->getMessage();
383
+ }
384
+ return $productId;
385
+ }
386
+
387
+ protected function _corePriceStock($website = 0, $productId = false, $price = 0.00, $qty = 0.00, $sku = false, $isInStock = 0, $stockConf = 1, $priceConf = 1)
388
+ {
389
+
390
+ if (!$productId) {
391
+ $message = Mage::helper('catalog')->__('Skip import row, product_id for product "%s" not defined ', $sku);
392
+ Mage::throwException($message);
393
+ }
394
+ if ($stockConf == 1) {
395
+ $stockSaveSQL = "
396
+ INSERT INTO `" . $this->_tablePrefix . "cataloginventory_stock_item` (`product_id`, `stock_id`, `qty`, `is_in_stock`) VALUES
397
+ (:product_id, @stock_id, :qty,1)
398
+ ON DUPLICATE KEY UPDATE
399
+ `product_id` = :product_id,
400
+ `stock_id` = @stock_id,
401
+ `qty` = :qty,
402
+ `is_in_stock` = :is_in_stock;
403
+
404
+ INSERT INTO `" . $this->_tablePrefix . "cataloginventory_stock_status` (`product_id`, `website_id`, `stock_id`, `qty`, `stock_status`) VALUES
405
+ (:product_id, :webisteId, @stock_id, :qty, 1)
406
+ ON DUPLICATE KEY UPDATE
407
+ `product_id` = :product_id,
408
+ `website_id` = :webisteId,
409
+ `stock_id` = @stock_id,
410
+ `qty` = :qty,
411
+ `stock_status` = :is_in_stock;";
412
+ }
413
+ if ($priceConf == 1) {
414
+ $stockSaveSQL .= "
415
+ INSERT INTO `" . $this->_tablePrefix . "catalog_product_website` (`product_id`, `website_id`) VALUES
416
+ (:product_id, :webisteId)
417
+ ON DUPLICATE KEY UPDATE
418
+ `product_id` = :product_id,
419
+ `website_id` = :webisteId;
420
+
421
+ INSERT INTO `" . $this->_tablePrefix . "catalog_product_entity_decimal` (`entity_type_id`,`attribute_id`,`store_id`, `entity_id`, `value`) VALUES
422
+ (@product_entity_type_id, @price_id, 0, :product_id, :price)
423
+ ON DUPLICATE KEY UPDATE
424
+ `entity_type_id` = @product_entity_type_id,
425
+ `attribute_id` = @price_id,
426
+ `store_id` = 0,
427
+ `entity_id` = :product_id,
428
+ `value` = :price;
429
+ ";
430
+ }
431
+ if ($priceConf == 1 || $stockConf == 1) {
432
+ $this->_connRes->query($stockSaveSQL, array(
433
+ ':webisteId' => $website,
434
+ ':product_id' => $productId,
435
+ ':price' => $price,
436
+ ':qty' => $qty,
437
+ ':is_in_stock' => $isInStock
438
+ ));
439
+ }
440
+ }
441
+
442
+ protected function _addImageToQueue($productId = false, $productImageUrl)
443
+ {
444
+ $productImageUrl = trim($productImageUrl);
445
+ if ($productId && !empty($productImageUrl)) {
446
+ // add image if not exists to queue
447
+ $this->_connRes->query(" INSERT IGNORE INTO `" . $this->_tablePrefix . "iceshop_iceimport_image_queue` (`entity_id`, `image_url` ) VALUES
448
+ (:product_id, :image_url)
449
+ ", array(':product_id' => $productId,
450
+ ':image_url' => $productImageUrl));
451
+ }
452
+ }
453
+
454
+ public function getImageQueue()
455
+ {
456
+ return $this->_connRes->fetchAll("SELECT `queue_id`, `entity_id`, `image_url` FROM `" . $this->_tablePrefix . "iceshop_iceimport_image_queue`
457
+ WHERE `is_downloaded` = 0
458
+ ");
459
+ }
460
+
461
+ public function setImageAsDownloaded($queueId = false)
462
+ {
463
+ if ($queueId) {
464
+ $this->_connRes->query("UPDATE `" . $this->_tablePrefix . "iceshop_iceimport_image_queue` SET is_downloaded = 1
465
+ WHERE queue_id = :queue_id", array(':queue_id' => $queueId));
466
+ }
467
+ }
468
+
469
+ protected function _addCategories($categories, $storeId, $unspsc, $unspscPath, $categoryActive = 1)
470
+ {
471
+
472
+ // check if product exists
473
+ $categoryId = $this->_getCategoryIdByUnspsc($unspsc);
474
+ $categoryIds = array();
475
+ if (!empty($categoryId)) {
476
+ // merge categories by unspsc
477
+ $categoryMergedArray = $this->_categoryMapper($categories, $unspscPath);
478
+ foreach ($categoryMergedArray as $category) {
479
+ $categoryName = $category['name'];
480
+ $categoryUnspsc = $category['unspsc'];
481
+ $categoryTreeId = $this->_getCategoryIdByUnspsc($categoryUnspsc);
482
+ // check category name to current store
483
+ $categoryBindArray = array(
484
+ ':store_id' => $storeId,
485
+ ':category_id' => $categoryTreeId
486
+ );
487
+ $nameCheckerFetch = $this->_connRes->fetchRow("SELECT value_id FROM `" . $this->_tablePrefix . "catalog_category_entity_varchar` WHERE
488
+ store_id = :store_id AND entity_id = :category_id AND attribute_id = @category_name_id
489
+ ", $categoryBindArray);
490
+ $nameChecker = $nameCheckerFetch['value_id'];
491
+ if (!$nameChecker) {
492
+ // add category name to current store
493
+ $categoryBindArray[':category_name'] = $categoryName;
494
+ if (!empty($categoryBindArray[':category_id'])) {
495
+ $this->_connRes->query("
496
+ INSERT INTO `" . $this->_tablePrefix . "catalog_category_entity_varchar` (`entity_type_id`, `attribute_id`, `store_id`, `entity_id`, `value`) VALUES
497
+ (@category_entity_type_id, @category_name_id, :store_id, :category_id, :category_name)
498
+ ", $categoryBindArray);
499
+ }
500
+ }
501
+ }
502
+ //
503
+
504
+ // get current path of category
505
+ $categoryPath = $this->_connRes->fetchRow("SELECT path FROM `" . $this->_tablePrefix . "catalog_category_entity` WHERE entity_id = :entity_id",
506
+ array(':entity_id' => $categoryId));
507
+ $categoryPathArray = explode('/', $categoryPath['path']);
508
+ if ($categoryPathArray) {
509
+ $activeSetter = "INSERT INTO `" . $this->_tablePrefix . "catalog_category_entity_int` (`entity_type_id`, `attribute_id`, `store_id`, `entity_id`, `value`) VALUES ";
510
+ }
511
+
512
+ $falseCounter = 0;
513
+ foreach ($categoryPathArray as $categoryId) {
514
+ $category = Mage::getModel('catalog/category')->load($categoryId);
515
+ $cid = $category->getId();
516
+ if (!empty($cid)) {
517
+ if (!empty($categoryId)) {
518
+ $categoryIds[] = (int)$categoryId;
519
+ $activeSetter .= "(@category_entity_type_id, @category_active_id, :store_id, " . $categoryId . ", 1),
520
+ (@category_entity_type_id, @category_active_id, 0, " . $categoryId . ", 1), ";
521
+ } else {
522
+ $falseCounter++;
523
+ }
524
+ } else {
525
+ $falseCounter++;
526
+ }
527
+ }
528
+ $activeSetter = substr($activeSetter, 0, -2);
529
+ $activeSetter .= "
530
+ ON DUPLICATE KEY UPDATE
531
+ `value` = 1
532
+ ";
533
+ if (1 == $categoryActive) {
534
+ if ($falseCounter < count($categoryPathArray)) {
535
+ $this->_connRes->query($activeSetter, array(':store_id' => $storeId));
536
+ }
537
+ }
538
+ return $categoryIds;
539
+ } else {
540
+
541
+ // merge unspcs to current name in unspcs & name path's
542
+ $categoryMergedArray = $this->_categoryMapper($categories, $unspscPath);
543
+ // get max created parrent category
544
+ $categoryCreateArray = array();
545
+ for ($i = count($categoryMergedArray) - 1; $i >= 0; $i--) {
546
+ $category = $categoryMergedArray[$i];
547
+ $checkCategoryId = $this->_getCategoryIdByUnspsc($category['unspsc']);
548
+ if ($checkCategoryId != null) {
549
+ $categoryId = $this->_buildCategoryTree($checkCategoryId, $storeId, $categoryCreateArray, $categoryActive);
550
+ $categoryIds[] = (int)$categoryId;
551
+ break;
552
+ } else {
553
+ $categoryCreateArray[] = $category;
554
+ }
555
+ }
556
+ return $categoryIds;
557
+ }
558
+ }
559
+
560
+ protected function _categoryMapper($categoryPath, $unspscPath)
561
+ {
562
+ $nameArray = explode('/', $categoryPath);
563
+ $unspscArray = explode('/', $unspscPath);
564
+
565
+ if (count($nameArray) != count($unspscArray)) {
566
+ $message = Mage::helper('catalog')->__('Skip import row, @categories data is invaled');
567
+ Mage::throwException($message);
568
+ }
569
+
570
+ $categoryMergedArray = array(
571
+ array(
572
+ 'unspsc' => 'default_root',
573
+ 'name' => 'Default category'
574
+ )
575
+ );
576
+
577
+ for ($i = 0; $i < count($unspscArray); $i++) {
578
+ $categoryMergedArray[] = array('name' => $nameArray[$i],
579
+ 'unspsc' => $unspscArray[$i]);
580
+ }
581
+
582
+ return $categoryMergedArray;
583
+ }
584
+
585
+ protected function _getCategoryIdByUnspsc($unspcs)
586
+ {
587
+ if ($unspcs == 'default_root') {
588
+ return Mage::app()->getStore(1)->getRootCategoryId();
589
+ } else {
590
+ $categoryId = $this->_connRes->fetchRow("SELECT entity_id FROM `" . $this->_tablePrefix . "catalog_category_entity_varchar` WHERE
591
+ `value` = :unspsc AND attribute_id = @unspcs_id", array(':unspsc' => $unspcs));
592
+ return ($categoryId['entity_id']) ? $categoryId['entity_id'] : null;
593
+ }
594
+ }
595
+
596
+ protected function _buildCategoryTree($parrentCategoryId, $storeId, $pathArray, $categoryActive = 0)
597
+ {
598
+ for ($i = count($pathArray) - 1; $i >= 0; $i--) {
599
+ $category = $pathArray[$i];
600
+ $parrentCategoryId = $this->_createCategory($parrentCategoryId, $category['unspsc'], $storeId, $category['name'], $categoryActive);
601
+ }
602
+
603
+ return $parrentCategoryId;
604
+ }
605
+
606
+ protected function _createCategory($parrentId, $unspsc, $storeId, $name, $categoryActive = 0)
607
+ {
608
+
609
+ $addCategory = "
610
+ SELECT @tPath := `path`, @tLevel := `level` FROM `" . $this->_tablePrefix . "catalog_category_entity` WHERE `entity_id` = :parrent_id;
611
+ SET @tLevel = @tLevel +1;
612
+
613
+ SET @path := CONCAT(@tPath, '/',(SELECT MAX(entity_id) FROM `" . $this->_tablePrefix . "catalog_category_entity`) +1 );
614
+
615
+ INSERT INTO `" . $this->_tablePrefix . "catalog_category_entity` (`entity_type_id`, `attribute_set_id`,
616
+ `parent_id`, `created_at`,
617
+ `path`, `position`,
618
+ `level`, `children_count`)
619
+ VALUES
620
+ (@category_entity_type_id, 0, :parrent_id, NOW(), @path, 1, @tLevel, 0);
621
+
622
+ SELECT @catId := LAST_INSERT_ID();
623
+
624
+ UPDATE `" . $this->_tablePrefix . "catalog_category_entity` SET `path` = CONCAT(@tPath, '/', @catId) WHERE entity_id = LAST_INSERT_ID();
625
+
626
+ UPDATE `" . $this->_tablePrefix . "catalog_category_entity` SET children_count = children_count +1 WHERE entity_id = :parrent_id;
627
+
628
+ INSERT IGNORE INTO `" . $this->_tablePrefix . "catalog_category_entity_int` (`entity_type_id`, `attribute_id`,
629
+ `store_id`, `entity_id`, `value`)
630
+ VALUES
631
+ (@category_entity_type_id, @category_active_id, 0, @catId, :category_active),
632
+ (@category_entity_type_id, @category_active_id, :store, @catId, :category_active),
633
+ (@category_entity_type_id, @category_is_anchor_id, 0, @catId, 1),
634
+ (@category_entity_type_id, @category_is_anchor_id, :store, @catId, 1),
635
+ (@category_entity_type_id, @include_nav_bar_id, 0, @catId, 1),
636
+ (@category_entity_type_id, @include_nav_bar_id, :store, @catId, 1);
637
+
638
+ INSERT IGNORE INTO `" . $this->_tablePrefix . "catalog_category_entity_varchar` (`entity_type_id`, `attribute_id`,
639
+ `store_id`, `entity_id`, `value`)
640
+ VALUES
641
+ (@category_entity_type_id, @category_name_id, 0, @catId, :category_name),
642
+ (@category_entity_type_id, @category_name_id, :store, @catId, :category_name),
643
+ (@category_entity_type_id, @unspcs_id, 0, @catId, :unspsc_val),
644
+ (@category_entity_type_id, @unspcs_id, :store, @catId, :unspsc_val);
645
+ ";
646
+
647
+ $this->_connRes->query($addCategory, array(
648
+ ':store' => $storeId,
649
+ ':parrent_id' => $parrentId,
650
+ ':category_name' => $name,
651
+ ':unspsc_val' => $unspsc,
652
+ ':category_active' => (int)$categoryActive
653
+ ));
654
+
655
+ $categoryIdFetch = $this->_connRes->fetchRow('SELECT @catId AS category_id');
656
+
657
+ return $categoryIdFetch['category_id'];
658
+ }
659
+
660
+ protected function _mapAttributes(array $importData)
661
+ {
662
+
663
+ // map iceimport attributes, skip some attributes
664
+ $iceAttributes = array();
665
+ foreach ($importData as $attribute => $value) {
666
+ // map iceimport attributes
667
+ if ($attribute == 'type' ||
668
+ $attribute == 'sku' ||
669
+ $attribute == 'attribute_set' ||
670
+ $attribute == 'categories' ||
671
+ $attribute == 'unspsc' ||
672
+ $attribute == 'price' ||
673
+ $attribute == 'qty' ||
674
+ $attribute == 'status' ||
675
+ $attribute == 'visibility' ||
676
+ $attribute == 'store' ||
677
+ $attribute == 'websites' ||
678
+ $attribute == 'is_in_stock' ||
679
+ $attribute == 'image' ||
680
+ $attribute == 'unspsc_path'
681
+ ) {
682
+
683
+ $iceAttributes[$attribute] = $value;
684
+ unset($importData[$attribute]);
685
+
686
+ }
687
+ // skip some attributes
688
+ if ($attribute == 'supplier_product_code' ||
689
+ $attribute == 'supplier' ||
690
+ $attribute == 'leader_categories' ||
691
+ $attribute == 'leader_store' ||
692
+ $attribute == 'sprice' ||
693
+ $attribute == 'euprice' ||
694
+ $attribute == 'icecat_product_id' ||
695
+ $attribute == 'icecat_category_id' ||
696
+ $attribute == 'icecat_vendor_id' ||
697
+ $attribute == 'icecat_quality' ||
698
+ $attribute == 'icecat_url' ||
699
+ $attribute == 'icecat_thumbnail_img' ||
700
+ $attribute == 'icecat_low_res_img' ||
701
+ $attribute == 'icecat_high_res_img' ||
702
+ $attribute == 'tax1' ||
703
+ $attribute == 'tax2' ||
704
+ $attribute == 'tax3' ||
705
+ $attribute == 'tax4' ||
706
+ $attribute == 'min_quantity' ||
707
+ $attribute == 'loms' ||
708
+ $attribute == 'image_label' ||
709
+ $attribute == 'links_title' ||
710
+ $attribute == 'small_image_label' ||
711
+ $attribute == 'tax_rate' ||
712
+ $attribute == 'gallery' ||
713
+ $attribute == 'weight_type' ||
714
+ $attribute == 'sku_type' ||
715
+ $attribute == 'manage_stock' ||
716
+ $attribute == 'minimal_price' ||
717
+ $attribute == 'required_options' ||
718
+ $attribute == 'samples_title' ||
719
+ $attribute == 'shipment_type' ||
720
+ $attribute == 'url_path' ||
721
+ $attribute == 'recurring_profile' ||
722
+ $attribute == 'product_keys'
723
+ ) {
724
+
725
+ unset($importData[$attribute]);
726
+
727
+ }
728
+
729
+ }
730
+
731
+ // map default attributes
732
+ $productData = array();
733
+ foreach ($this->_getDefaultAttributesList() as $backendType => $attributesList) {
734
+ if ($backendType != 'spec') {
735
+ foreach ($attributesList as $attribute) {
736
+ if (isset($importData[$attribute]) && $importData[$attribute] != '') {
737
+ $productData[$backendType][$attribute] = $importData[$attribute];
738
+ unset($importData[$attribute]);
739
+ }
740
+ }
741
+ } else {
742
+ foreach ($attributesList as $attributeCode => $attributeSpecs) {
743
+ if (isset($importData[$attributeCode]) && $importData[$attributeCode] != false) {
744
+ $attributeSpecs['value'] = $importData[$attributeCode];
745
+ $productData[$backendType][$attributeCode] = $attributeSpecs;
746
+ unset($importData[$attributeCode]);
747
+ }
748
+ }
749
+ }
750
+ }
751
+
752
+ // map custom attributes
753
+ if (!empty($importData)) {
754
+ foreach ($importData as $attributeCode => $value) {
755
+ $backendTypeFetch = $this->_connRes->fetchRow("SELECT backend_type FROM `" . $this->_tablePrefix . "eav_attribute` WHERE `attribute_code` = :code", array(':code' => $attributeCode));
756
+ $backendType = $backendTypeFetch['backend_type'];
757
+ if ($backendType != 'static' && !empty($backendType) && $value != '') {
758
+ $productData[$backendType][$attributeCode] = $value;
759
+ unset($importData[$attributeCode]);
760
+ }
761
+ }
762
+ }
763
+
764
+ $failedAttributes = array();
765
+ if (count($importData) > 0) {
766
+ $failedAttributes = array_keys($importData);
767
+ }
768
+
769
+ return array(
770
+ 'iceimportAttributes' => $iceAttributes,
771
+ 'productData' => $productData,
772
+ 'failedAttributes' => $failedAttributes
773
+ );
774
+
775
+ }
776
+
777
+ protected function _getDefaultAttributesList()
778
+ {
779
+ return array(
780
+ 'varchar' => array(
781
+ 'gift_message_available',
782
+ 'custom_design',
783
+ 'msrp_display_actual_price_type',
784
+ 'msrp_enabled',
785
+ 'options_container',
786
+ 'page_layout',
787
+ 'mpn',
788
+ 'brand_name',
789
+ 'name',
790
+ 'url_key',
791
+ 'meta_description',
792
+ 'meta_title'
793
+ ),
794
+ 'int' => array(
795
+ 'enable_googlecheckout',
796
+ 'is_recurring',
797
+ 'links_purchased_separately',
798
+ 'links_exist',
799
+ 'status',
800
+ 'visibility',
801
+ 'tax_class_id',
802
+ 'color',
803
+ 'price_view',
804
+ 'manufacturer'
805
+ ),
806
+ 'text' => array(
807
+ 'recurring_profile',
808
+ 'description',
809
+ 'custom_layout_update',
810
+ 'meta_keyword',
811
+ 'short_description'
812
+ ),
813
+ 'decimal' => array(
814
+ 'cost',
815
+ 'group_price',
816
+ 'weight',
817
+ 'special_price',
818
+ 'msrp'
819
+ ),
820
+ 'datetime' => array(
821
+ 'custom_design_from',
822
+ 'custom_design_to',
823
+ 'news_from_date',
824
+ 'news_to_date',
825
+ 'special_from_date',
826
+ 'special_to_date'
827
+ ),
828
+ 'spec' => array(
829
+ 'is_qty_decimal' => array(
830
+ 'prod_id_field' => 'product_id',
831
+ 'table' => 'cataloginventory_stock_item',
832
+ 'field' => 'is_qty_decimal'
833
+ ),
834
+ 'use_config_min_qty' => array(
835
+ 'prod_id_field' => 'product_id',
836
+ 'table' => 'cataloginventory_stock_item',
837
+ 'field' => 'use_config_min_qty'
838
+ ),
839
+ 'use_config_min_sale_qty' => array(
840
+ 'prod_id_field' => 'product_id',
841
+ 'table' => 'cataloginventory_stock_item',
842
+ 'field' => 'use_config_min_sale_qty'
843
+ ),
844
+ 'use_config_max_sale_qty' => array(
845
+ 'prod_id_field' => 'product_id',
846
+ 'table' => 'cataloginventory_stock_item',
847
+ 'field' => 'use_config_max_sale_qty'
848
+ ),
849
+ 'use_config_manage_stock' => array(
850
+ 'prod_id_field' => 'product_id',
851
+ 'table' => 'cataloginventory_stock_item',
852
+ 'field' => 'use_config_manage_stock'
853
+ ),
854
+ 'is_decimal_divided' => array(
855
+ 'prod_id_field' => 'product_id',
856
+ 'table' => 'cataloginventory_stock_item',
857
+ 'field' => 'is_decimal_divided'
858
+ ),
859
+ 'use_config_backorders' => array(
860
+ 'prod_id_field' => 'product_id',
861
+ 'table' => 'cataloginventory_stock_item',
862
+ 'field' => 'use_config_backorders'
863
+ ),
864
+ 'use_config_notify_stock_qty' => array(
865
+ 'prod_id_field' => 'product_id',
866
+ 'table' => 'cataloginventory_stock_item',
867
+ 'field' => 'use_config_notify_stock_qty'
868
+ ),
869
+ 'max_sale_qty' => array(
870
+ 'prod_id_field' => 'product_id',
871
+ 'table' => 'cataloginventory_stock_item',
872
+ 'field' => 'max_sale_qty'
873
+ ),
874
+ 'min_sale_qty' => array(
875
+ 'prod_id_field' => 'product_id',
876
+ 'table' => 'cataloginventory_stock_item',
877
+ 'field' => 'min_sale_qty'
878
+ ),
879
+ 'notify_stock_qty' => array(
880
+ 'prod_id_field' => 'product_id',
881
+ 'table' => 'cataloginventory_stock_item',
882
+ 'field' => 'notify_stock_qty'
883
+ ),
884
+ 'backorders' => array(
885
+ 'prod_id_field' => 'product_id',
886
+ 'table' => 'cataloginventory_stock_item',
887
+ 'field' => 'backorders'
888
+ ),
889
+ 'created_at' => array(
890
+ 'prod_id_field' => 'entity_id',
891
+ 'table' => 'catalog_product_entity',
892
+ 'field' => 'created_at'
893
+ ),
894
+ 'min_qty' => array(
895
+ 'prod_id_field' => 'product_id',
896
+ 'table' => 'cataloginventory_stock_item',
897
+ 'field' => 'min_qty'
898
+ ),
899
+ 'updated_at' => array(
900
+ 'prod_id_field' => 'entity_id',
901
+ 'table' => 'catalog_product_entity',
902
+ 'field' => 'updated_at'
903
+ )
904
+ )
905
+ );
906
+ }
907
+
908
+ // Count child categories products and set them inactive if they have no products
909
+ public function CountChildProd($child_cat)
910
+ {
911
+ foreach ($child_cat as $cat) {
912
+ $query = "SELECT `entity_id` FROM `" . $this->_tablePrefix . "catalog_category_entity` WHERE parent_id = :cat_id";
913
+ $child_cat = $this->_connRes->fetchAll($query, array(
914
+ ':cat_id' => $cat['entity_id']
915
+ ));
916
+
917
+ $query = "SELECT COUNT(*) FROM `" . $this->_tablePrefix . "catalog_category_product` WHERE category_id = :cat_id ";
918
+ $cat_products = $this->_connRes->fetchRow($query, array(
919
+ ':cat_id' => $cat['entity_id']
920
+ ));
921
+
922
+ if ($cat_products['COUNT(*)'] == 0 && empty($child_cat)) {
923
+ $this->_connRes->query("UPDATE `" . $this->_tablePrefix . "catalog_category_entity_int`
924
+ SET `value` = 0 WHERE `attribute_id` = @category_active_id AND entity_id = :cat_id", array(
925
+ ':cat_id' => $cat['entity_id']
926
+ ));
927
+ } else if (!empty($child_cat)) {
928
+ $this->CountChildProd($child_cat);
929
+ }
930
+ }
931
+ }
932
+
933
+ }
app/code/community/Iceshop/Iceimport/Model/Dataflow/Batch/Import.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Dataflow Batch import model
4
+ *
5
+ * @method Mage_Dataflow_Model_Resource_Batch_Import _getResource()
6
+ * @method Mage_Dataflow_Model_Resource_Batch_Import getResource()
7
+ * @method int getBatchId()
8
+ * @method Mage_Dataflow_Model_Batch_Import setBatchId(int $value)
9
+ * @method int getStatus()
10
+ * @method Mage_Dataflow_Model_Batch_Import setStatus(int $value)
11
+ *
12
+ * @category Mage
13
+ * @package Mage_Dataflow
14
+ * @author Magento Core Team <core@magentocommerce.com>
15
+ */
16
+ class Iceshop_Iceimport_Model_Dataflow_Batch_Import extends Mage_Dataflow_Model_Batch_Import
17
+ {
18
+ protected $_connRes = null;
19
+
20
+ protected function _construct()
21
+ {
22
+ $this->_connRes = Mage::getSingleton('core/resource')->getConnection('core_write');
23
+ $this->_init('dataflow/batch_import');
24
+
25
+ }
26
+
27
+ public function setBatchData($data)
28
+ {
29
+
30
+ if ('"libiconv"' == ICONV_IMPL) {
31
+ foreach ($data as $item){
32
+ foreach ($item as &$value) {
33
+ $value = iconv('utf-8', 'utf-8//IGNORE', $value);
34
+ }
35
+ }
36
+ }
37
+
38
+ $batch_import = Mage::getSingleton('core/resource')->getTableName('dataflow/batch_import');
39
+ $insert_query = "INSERT INTO ".$batch_import." (`batch_id`, `batch_data`, `status`) VALUES ";
40
+ foreach ($data as $item){
41
+ if(!empty($item)){
42
+ $insert_query .= "(".$this->getBatchId().", '".addslashes(serialize($item))."', 1), ";
43
+ }
44
+ }
45
+ $insert_query = substr($insert_query, 0, -2);
46
+
47
+ $this->_connRes->query($insert_query);
48
+
49
+ return $this;
50
+ }
51
+
52
+ }
app/code/community/Iceshop/Iceimport/Model/Dataflow/Convert/Parser/Csv.php ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Convert csv parser
4
+ *
5
+ * @category Mage
6
+ * @package Mage_Dataflow
7
+ * @author Magento Core Team <core@magentocommerce.com>
8
+ */
9
+ class Iceshop_Iceimport_Model_Dataflow_Convert_Parser_Csv extends Mage_Dataflow_Model_Convert_Parser_Csv
10
+ {
11
+ protected $_fields;
12
+
13
+ protected $_mapfields = array();
14
+
15
+ public function parse()
16
+ {
17
+ $entityTypeId = Mage::getModel('eav/entity')
18
+ ->setType('catalog_product')
19
+ ->getTypeId();
20
+ $attributeSetCollection = Mage::getModel('eav/entity_attribute_set')
21
+ ->getCollection()
22
+ ->setEntityTypeFilter($entityTypeId);
23
+ $default_attr_set = $attributeSetCollection->getData();
24
+ $attributes = Mage::getModel('catalog/product_attribute_api')->items($default_attr_set[0]['attribute_set_id'] );
25
+ $req_attributes = array('brand_name', 'ean', 'mpn', 'delivery_eta', 'is_iceimport');
26
+ $not_found_attr = array();
27
+ foreach($req_attributes as $req_attribute){
28
+ foreach($attributes as $_attribute){
29
+ if($_attribute['code'] == $req_attribute){
30
+ unset($not_found_attr[$req_attribute]);
31
+ break;
32
+ }else{
33
+ $not_found_attr[$req_attribute] = $req_attribute;
34
+ }
35
+ }
36
+ }
37
+ if(!empty($not_found_attr)){
38
+ echo '
39
+ <li style="background-color:#FDD" id="error-0">
40
+ <img id="error-0_img" src="' . Mage::getBaseUrl('web') . '/skin/adminhtml/default/default/images/error_msg_icon.gif" class="v-middle" style="margin-right:5px">
41
+ <span id="error-0_status" class="text">Not found attributes: ' . implode(", ", $not_found_attr) . ' please check you defaul attribute set.</span>
42
+ </li>';
43
+ exit;
44
+ }
45
+
46
+ // fixed for multibyte characters
47
+ setlocale(LC_ALL, Mage::app()->getLocale()->getLocaleCode().'.UTF-8');
48
+
49
+ $fDel = $this->getVar('delimiter', ',');
50
+ $fEnc = $this->getVar('enclose', '"');
51
+ if ($fDel == '\t') {
52
+ $fDel = "\t";
53
+ }
54
+
55
+ $adapterName = $this->getVar('adapter', null);
56
+ $adapterMethod = $this->getVar('method', 'saveRow');
57
+
58
+ if (!$adapterName || !$adapterMethod) {
59
+ $message = Mage::helper('dataflow')->__('Please declare "adapter" and "method" nodes first.');
60
+ $this->addException($message, Mage_Dataflow_Model_Convert_Exception::FATAL);
61
+ return $this;
62
+ }
63
+
64
+ try {
65
+ $adapter = Mage::getModel($adapterName);
66
+ }
67
+ catch (Exception $e) {
68
+ $message = Mage::helper('dataflow')->__('Declared adapter %s was not found.', $adapterName);
69
+ $this->addException($message, Mage_Dataflow_Model_Convert_Exception::FATAL);
70
+ return $this;
71
+ }
72
+
73
+ if (!is_callable(array($adapter, $adapterMethod))) {
74
+ $message = Mage::helper('dataflow')->__('Method "%s" not defined in adapter %s.', $adapterMethod, $adapterName);
75
+ $this->addException($message, Mage_Dataflow_Model_Convert_Exception::FATAL);
76
+ return $this;
77
+ }
78
+
79
+ $batchModel = $this->getBatchModel();
80
+ $batchIoAdapter = $this->getBatchModel()->getIoAdapter();
81
+
82
+ if (Mage::app()->getRequest()->getParam('files')) {
83
+ $file = Mage::app()->getConfig()->getTempVarDir().'/import/'
84
+ . urldecode(Mage::app()->getRequest()->getParam('files'));
85
+ $this->_copy($file);
86
+ }
87
+
88
+ $batchIoAdapter->open(false);
89
+
90
+ $isFieldNames = $this->getVar('fieldnames', '') == 'true' ? true : false;
91
+ if (!$isFieldNames && is_array($this->getVar('map'))) {
92
+ $fieldNames = $this->getVar('map');
93
+ }
94
+ else {
95
+ $fieldNames = array();
96
+ foreach ($batchIoAdapter->read(true, $fDel, $fEnc) as $v) {
97
+ $fieldNames[$v] = $v;
98
+ }
99
+ }
100
+ $countRows = 0;
101
+ $currentRow = 0;
102
+ $maxRows = 400;
103
+ $itemData = array();
104
+ while (($csvData = $batchIoAdapter->read(true, $fDel, $fEnc)) !== false) {
105
+ if (count($csvData) == 1 && $csvData[0] === null) {
106
+ continue;
107
+ }
108
+ $countRows ++; $i = 0;
109
+ foreach ($fieldNames as $field) {
110
+ $itemData[$currentRow][$field] = isset($csvData[$i]) ? $csvData[$i] : null;
111
+ $i ++;
112
+ }
113
+
114
+ if($currentRow == $maxRows){
115
+ $currentRow = 0;
116
+ $batchImportModel = $this->getBatchImportModel()
117
+ ->setBatchId($this->getBatchModel()->getId())
118
+ ->setBatchData($itemData)->setStatus(1);
119
+ $itemData = array();
120
+ }
121
+ $currentRow++;
122
+
123
+ }
124
+ if($currentRow < $maxRows && $currentRow != 0){
125
+ $batchImportModel = $this->getBatchImportModel()
126
+ ->setBatchId($this->getBatchModel()->getId())
127
+ ->setBatchData($itemData)->setStatus(1);
128
+ }
129
+
130
+ $this->addException(Mage::helper('dataflow')->__('Found %d rows.', $countRows));
131
+ $this->addException(Mage::helper('dataflow')->__('Starting %s :: %s', $adapterName, $adapterMethod));
132
+
133
+ $batchModel->setParams($this->getVars())
134
+ ->setAdapter($adapterName)
135
+ ->save();
136
+
137
+
138
+ return $this;
139
+ }
140
+
141
+ }
app/code/community/Iceshop/Iceimport/Model/Observer.php ADDED
@@ -0,0 +1,225 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Iceshop_Iceimport_Model_Observer
3
+ {
4
+ /**
5
+ * Our process ID.
6
+ */
7
+ private $process_id = 'iceshop_iceimport';
8
+ private $indexProcess;
9
+
10
+ protected function _construct()
11
+ {
12
+ $this->_init('iceimport/observer');
13
+ }
14
+
15
+
16
+ /**
17
+ * load
18
+ * @access publc
19
+ */
20
+ public function load()
21
+ {
22
+
23
+ $profileId = 3;
24
+ $logFileName = 'test.log';
25
+ $recordCount = 0;
26
+ $this->indexProcess = new Mage_Index_Model_Process();
27
+ $this->indexProcess->setId($this->process_id);
28
+
29
+ if ($this->indexProcess->isLocked()) {
30
+ echo 'Error! Another iceimport module cron process is running!';
31
+ die();
32
+ }
33
+
34
+ $this->indexProcess->lockAndBlock();
35
+
36
+ Mage::log("Import Started", null, $logFileName);
37
+
38
+ $profile = Mage::getModel('dataflow/profile');
39
+
40
+ $userModel = Mage::getModel('admin/user');
41
+ $userModel->setUserId(0);
42
+ Mage::getSingleton('admin/session')->setUser($userModel);
43
+
44
+ if ($profileId) {
45
+ $profile->load($profileId);
46
+ if (!$profile->getId()) {
47
+ Mage::getSingleton('adminhtml/session')->addError('The profile that you are trying to save no longer exists');
48
+ }
49
+ }
50
+
51
+ $profile->run();
52
+
53
+ $batchModel = Mage::getSingleton('dataflow/batch');
54
+
55
+ if ($batchModel->getId()) {
56
+ if ($batchModel->getAdapter()) {
57
+ $batchId = $batchModel->getId();
58
+ $batchImportModel = $batchModel->getBatchImportModel();
59
+ $importIds = $batchImportModel->getIdCollection();
60
+
61
+ $batchModel = Mage::getModel('dataflow/batch')->load($batchId);
62
+
63
+ $adapter = Mage::getModel($batchModel->getAdapter());
64
+ // delete previous products id
65
+ $db_res = Mage::getSingleton('core/resource')->getConnection('core_write');
66
+ $tablePrefix = '';
67
+ $tPrefix = (array)Mage::getConfig()->getTablePrefix();
68
+ if (!empty($tPrefix)) {
69
+ $tablePrefix = $tPrefix[0];
70
+ }
71
+
72
+ try {
73
+ $db_res->query('DELETE FROM ' . $tablePrefix . 'iceshop_iceimport_imported_product_ids');
74
+ } catch (Exception $e) {
75
+ throw new Exception($e->getMessage());
76
+ }
77
+ foreach ($importIds as $importId) {
78
+
79
+ $recordCount++;
80
+ try {
81
+ $batchImportModel->load($importId);
82
+ if (!$batchImportModel->getId()) {
83
+ $errors[] = Mage::helper('dataflow')->__('Skip undefined row');
84
+ continue;
85
+ }
86
+
87
+ $importData = $batchImportModel->getBatchData();
88
+
89
+ try {
90
+ $adapter->saveRow($importData);
91
+ } catch (Exception $e) {
92
+ Mage::log($e->getMessage(), null, $logFileName);
93
+ continue;
94
+ }
95
+
96
+ } catch (Exeption $ex) {
97
+ Mage::log('Record# ' . $recordCount . ' - SKU = ' . $importData['sku'] . ' - Error - ' . $ex->getMessage(), null, $logFileName);
98
+ }
99
+
100
+ }
101
+
102
+ // delete old products
103
+ try {
104
+ $db_res->query("SELECT @is_iceimport_id := `attribute_id` FROM " . $tablePrefix . "eav_attribute WHERE attribute_code = 'is_iceimport'");
105
+ $db_res->query("DELETE cpe FROM " . $tablePrefix . "catalog_product_entity AS cpe
106
+ JOIN " . $tablePrefix . "catalog_product_entity_varchar AS cpev ON cpe.entity_id = cpev.entity_id AND cpev.value = 1 AND cpev.attribute_id = @is_iceimport_id
107
+ LEFT JOIN " . $tablePrefix . "iceshop_iceimport_imported_product_ids AS iip ON cpe.entity_id = iip.product_id
108
+ WHERE iip.product_id IS NULL");
109
+
110
+ } catch (Exception $e) {
111
+ throw new Exception($e->getMessage());
112
+ }
113
+
114
+
115
+ // download & set product images
116
+ $queueList = $adapter->getImageQueue();
117
+ if (count($queueList) > 0) {
118
+ $mediaDir = Mage::getBaseDir('media');
119
+ foreach ($queueList as $queue) {
120
+ $queueId = $queue['queue_id'];
121
+ $productId = $queue['entity_id'];
122
+ $imageUrl = $queue['image_url'];
123
+
124
+ $preImageName = explode('/', $imageUrl);
125
+ $imageName = array_pop($preImageName);
126
+ if (file_exists($mediaDir . DS . $imageName)) {
127
+ $imageName = rand() . '_' . time() . $imageName;
128
+ }
129
+
130
+ if (file_put_contents($mediaDir . DS . $imageName, file_get_contents($imageUrl))) {
131
+ $product = Mage::getModel('catalog/product')->load($productId);
132
+ $product->addImageToMediaGallery($mediaDir . DS . $imageName,
133
+ array('image', 'small_image', 'thumbnail'),
134
+ true, true
135
+ );
136
+ $product->save();
137
+ $adapter->setImageAsDownloaded($queueId);
138
+ echo $product->getCategory() . '<br>';
139
+ unset($product);
140
+ } else {
141
+ Mage::log('Unable download file to ' . $productId, $logFileName);
142
+ continue;
143
+ }
144
+ }
145
+ }
146
+ // sort category in abc
147
+
148
+ $catCollection = Mage::getModel('catalog/category')
149
+ ->getCollection()
150
+ ->addAttributeToSort('name', 'ASC');
151
+ $position = 1;
152
+ foreach ($catCollection as $category) {
153
+ $catSource = Mage::getModel('catalog/category')->load($category->getId());
154
+ $catSource->setData('position', $position);
155
+ $catSource->save();
156
+ $query = "SELECT COUNT(*) FROM `" . $tablePrefix . "catalog_category_product` WHERE category_id = :cat_id ";
157
+ $cat_products = $db_res->fetchRow($query, array(
158
+ ':cat_id' => $category->getId()
159
+ ));
160
+
161
+ if ($cat_products['COUNT(*)'] == 0) {
162
+ $query = "SELECT `entity_id` FROM `" . $tablePrefix . "catalog_category_entity` WHERE parent_id = :cat_id";
163
+ $child_cat = $db_res->fetchAll($query, array(
164
+ ':cat_id' => $category->getId()
165
+ ));
166
+ $cat_prod = 0;
167
+
168
+ if (isset($child_cat) && count($child_cat) > 0) {
169
+
170
+ foreach ($child_cat as $cat) {
171
+ $query = "SELECT COUNT(*) FROM `" . $tablePrefix . "catalog_category_product` WHERE category_id = :cat_id ";
172
+ $cat_products = $db_res->fetchRow($query, array(
173
+ ':cat_id' => $cat['entity_id']
174
+ ));
175
+
176
+ if ($cat_products['COUNT(*)'] != 0) {
177
+ $cat_prod = 1;
178
+ }
179
+
180
+ }
181
+
182
+ if ($cat_prod == 0) {
183
+ $db_res->query("UPDATE `" . $tablePrefix . "catalog_category_entity_int`
184
+ SET `value` = 0 WHERE `attribute_id` = @category_active_id AND entity_id = :cat_id", array(
185
+ ':cat_id' => $category->getId()
186
+ ));
187
+ }
188
+ } else {
189
+ $db_res->query("UPDATE `" . $tablePrefix . "catalog_category_entity_int`
190
+ SET `value` = 0 WHERE `attribute_id` = @category_active_id AND entity_id = :cat_id", array(
191
+ ':cat_id' => $category->getId()
192
+ ));
193
+ }
194
+ }
195
+ $position++;
196
+ }
197
+
198
+
199
+ $processes = Mage::getSingleton('index/indexer')->getProcessesCollection();
200
+ $processes->walk('reindexAll');
201
+
202
+ foreach ($profile->getExceptions() as $e) {
203
+ Mage::log($e->getMessage(), null, $logFileName);
204
+ }
205
+
206
+ }
207
+ }
208
+
209
+ unset($db_res);
210
+ echo 'Import Completed';
211
+ $this->indexProcess->unlock();
212
+ Mage::log("Import Completed", null, $logFileName);
213
+
214
+ try {
215
+ $import = Mage::getModel('importexport/import');
216
+ } catch (Exeptint $e) {
217
+ Mage::log($e->getMessage(), null, $logFileName);
218
+ }
219
+
220
+ // get prouct download queue
221
+ }
222
+
223
+ }
224
+
225
+ ?>
app/code/community/Iceshop/Iceimport/Model/System/Config/Categoryactivity.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Iceshop_Iceimport_Model_System_Config_Categoryactivity
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ $paramsArray = array(
8
+ 1 => 'Yes',
9
+ 0 => 'No'
10
+ );
11
+ return $paramsArray;
12
+ }
13
+ }
14
+
15
+ ?>
app/code/community/Iceshop/Iceimport/Model/System/Config/Defaulttax.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Iceshop_Iceimport_Model_System_Config_Defaulttax
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ $collection = Mage::getModel('tax/class')->getCollection();
8
+ $paramsArray = array();
9
+ $paramsArray['0'] = 'None';
10
+
11
+ foreach ($collection as $product) {
12
+ $tax = $product->getData();
13
+ $paramsArray[$tax['class_id']] = $tax['class_name'];
14
+ }
15
+
16
+ return $paramsArray;
17
+ }
18
+ }
19
+
20
+ ?>
app/code/community/Iceshop/Iceimport/Model/System/Config/Imageimport.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Iceshop_Iceimport_Model_System_Config_Imageimport
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ $paramsArray = array(
8
+ '1' => 'Yes',
9
+ '0' => 'No'
10
+ );
11
+ return $paramsArray;
12
+ }
13
+ }
14
+
15
+ ?>
app/code/community/Iceshop/Iceimport/Model/System/Config/Importdeliveryeta.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Iceshop_Iceimport_Model_System_Config_Importdeliveryeta
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ $paramsArray = array(
8
+ '1' => 'Yes',
9
+ '0' => 'No'
10
+ );
11
+ return $paramsArray;
12
+ }
13
+ }
14
+
15
+ ?>
app/code/community/Iceshop/Iceimport/Model/System/Config/Importprices.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Iceshop_Iceimport_Model_System_Config_Importprices
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ $paramsArray = array(
8
+ '1' => 'Yes',
9
+ '0' => 'No'
10
+ );
11
+ return $paramsArray;
12
+ }
13
+ }
14
+
15
+ ?>
app/code/community/Iceshop/Iceimport/Model/System/Config/Importproductbrand.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Iceshop_Iceimport_Model_System_Config_Importproductbrand
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ $paramsArray = array(
8
+ '1' => 'Yes',
9
+ '0' => 'No'
10
+ );
11
+ return $paramsArray;
12
+ }
13
+ }
14
+
15
+ ?>
app/code/community/Iceshop/Iceimport/Model/System/Config/Importproductdescription.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Iceshop_Iceimport_Model_System_Config_Importproductdescription
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ $paramsArray = array(
8
+ '1' => 'Yes',
9
+ '0' => 'No'
10
+ );
11
+ return $paramsArray;
12
+ }
13
+ }
14
+
15
+ ?>
app/code/community/Iceshop/Iceimport/Model/System/Config/Importproductean.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Iceshop_Iceimport_Model_System_Config_Importproductean
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ $paramsArray = array(
8
+ '1' => 'Yes',
9
+ '0' => 'No'
10
+ );
11
+ return $paramsArray;
12
+ }
13
+ }
14
+
15
+ ?>
app/code/community/Iceshop/Iceimport/Model/System/Config/Importproductmpn.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Iceshop_Iceimport_Model_System_Config_Importproductmpn
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ $paramsArray = array(
8
+ '1' => 'Yes',
9
+ '0' => 'No'
10
+ );
11
+ return $paramsArray;
12
+ }
13
+ }
14
+
15
+ ?>
app/code/community/Iceshop/Iceimport/Model/System/Config/Importproductname.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Iceshop_Iceimport_Model_System_Config_Importproductname
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ $paramsArray = array(
8
+ '1' => 'Yes',
9
+ '0' => 'No'
10
+ );
11
+ return $paramsArray;
12
+ }
13
+ }
14
+
15
+ ?>
app/code/community/Iceshop/Iceimport/Model/System/Config/Importproductshdescription.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Iceshop_Iceimport_Model_System_Config_Importproductshdescription
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ $paramsArray = array(
8
+ '1' => 'Yes',
9
+ '0' => 'No'
10
+ );
11
+ return $paramsArray;
12
+ }
13
+ }
14
+
15
+ ?>
app/code/community/Iceshop/Iceimport/Model/System/Config/Importproductshsudescription.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Iceshop_Iceimport_Model_System_Config_Importproductshsudescription
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ $paramsArray = array(
8
+ '1' => 'Yes',
9
+ '0' => 'No'
10
+ );
11
+ return $paramsArray;
12
+ }
13
+ }
14
+
15
+ ?>
app/code/community/Iceshop/Iceimport/Model/System/Config/Importproductsudescription.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Iceshop_Iceimport_Model_System_Config_Importproductsudescription
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ $paramsArray = array(
8
+ '1' => 'Yes',
9
+ '0' => 'No'
10
+ );
11
+ return $paramsArray;
12
+ }
13
+ }
14
+
15
+ ?>
app/code/community/Iceshop/Iceimport/Model/System/Config/Importstock.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Iceshop_Iceimport_Model_System_Config_Importstock
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ $paramsArray = array(
8
+ '1' => 'Yes',
9
+ '0' => 'No'
10
+ );
11
+ return $paramsArray;
12
+ }
13
+ }
14
+
15
+ ?>
app/code/community/Iceshop/Iceimport/Model/System/Config/Lockproddetails.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Iceshop_Iceimport_Model_System_Config_Lockproddetails
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ $paramsArray = array(
8
+ 'import_price_stock' => 'Yes',
9
+ 'import_info' => 'No'
10
+ );
11
+ return $paramsArray;
12
+ }
13
+ }
14
+
15
+ ?>
app/code/community/Iceshop/Iceimport/etc/config.xml ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Iceshop_Iceimport>
5
+ <version>1.5.0</version>
6
+ </Iceshop_Iceimport>
7
+ </modules>
8
+ <global>
9
+ <events>
10
+ <controller_action_predispatch_adminhtml_profile_batchfinish>
11
+ <observers>
12
+ <Iceshop_Iceimport>
13
+ <class>Iceshop_Iceimport/Observer</class>
14
+ <method>sortCategory</method>
15
+ </Iceshop_Iceimport>
16
+ </observers>
17
+ </controller_action_predispatch_adminhtml_profile_batchfinish>
18
+ <controller_action_postdispatch_adminhtml_profile_batchFinish>
19
+ <observers>
20
+ <Iceshop_Iceimport>
21
+ <class>Iceshop_Iceimport/Observer</class>
22
+ <method>sortCategory</method>
23
+ </Iceshop_Iceimport>
24
+ </observers>
25
+ </controller_action_postdispatch_adminhtml_profile_batchFinish>
26
+ </events>
27
+ <models>
28
+ <catalog>
29
+ <rewrite>
30
+ <!-- Override Mage_Catalog_Model_Convert_Adapter_Product -->
31
+ <convert_adapter_product>Iceshop_Iceimport_Model_Convert_Adapter_Product</convert_adapter_product>
32
+ </rewrite>
33
+ </catalog>
34
+ <dataflow>
35
+ <rewrite>
36
+ <!-- Override Mage_Catalog_Model_Convert_Adapter_Product -->
37
+ <batch_import>Iceshop_Iceimport_Model_Dataflow_Batch_Import</batch_import>
38
+ </rewrite>
39
+ <rewrite>
40
+ <!-- Override Mage_Catalog_Model_Convert_Adapter_Product -->
41
+ <convert_parser_csv>Iceshop_Iceimport_Model_Dataflow_Convert_Parser_Csv</convert_parser_csv>
42
+ </rewrite>
43
+ </dataflow>
44
+ <iceimport>
45
+ <class>Iceshop_Iceimport_Model</class>
46
+ </iceimport>
47
+ </models>
48
+ <resources>
49
+ <iceimport_setup>
50
+ <setup>
51
+ <module>Iceshop_Iceimport</module>
52
+ <class>Mage_Catalog_Model_Resource_Eav_Mysql4_Setup</class>
53
+ </setup>
54
+ <connection>
55
+ <use>core_setup</use>
56
+ </connection>
57
+ </iceimport_setup>
58
+ <iceimport_setup_write>
59
+ <connection>
60
+ <use>core_write</use>
61
+ </connection>
62
+ </iceimport_setup_write>
63
+ <iceimport_setup_read>
64
+ <connection>
65
+ <use>core_read</use>
66
+ </connection>
67
+ </iceimport_setup_read>
68
+ </resources>
69
+ </global>
70
+ <adminhtml>
71
+ <acl>
72
+ <resources>
73
+ <admin>
74
+ <children>
75
+ <system>
76
+ <children>
77
+ <config>
78
+ <children>
79
+ <importprod_root>
80
+ <title>IceImport module</title>
81
+ </importprod_root>
82
+ </children>
83
+ </config>
84
+ </children>
85
+ </system>
86
+ </children>
87
+ </admin>
88
+ </resources>
89
+ </acl>
90
+ </adminhtml>
91
+ <crontab>
92
+ <jobs>
93
+ <iceimport>
94
+ <schedule>
95
+ <cron_expr>0 0 * * 0</cron_expr>
96
+ </schedule>
97
+ <run>
98
+ <model>iceimport/observer::load</model>
99
+ </run>
100
+ </iceimport>
101
+ </jobs>
102
+ </crontab>
103
+ </config>
app/code/community/Iceshop/Iceimport/etc/system.xml ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <sections>
4
+ <importprod_root translate="label" module="catalog">
5
+ <class>separator-top</class>
6
+ <label>IceImport</label>
7
+ <tab>catalog</tab>
8
+ <frontend_type>text</frontend_type>
9
+ <sort_order>300</sort_order>
10
+ <show_in_default>1</show_in_default>
11
+ <show_in_website>1</show_in_website>
12
+ <show_in_store>1</show_in_store>
13
+ <groups>
14
+ <importprod translate="label">
15
+ <label>IceImport Settings</label>
16
+ <frontend_type>text</frontend_type>
17
+ <sort_order>50</sort_order>
18
+ <show_in_default>1</show_in_default>
19
+ <show_in_website>1</show_in_website>
20
+ <show_in_store>1</show_in_store>
21
+ <fields>
22
+ <category_active translate="label">
23
+ <label>Set to active imported categories</label>
24
+ <frontend_type>select</frontend_type>
25
+ <source_model>iceimport/system_config_categoryactivity</source_model>
26
+ <sort_order>10</sort_order>
27
+ <show_in_default>1</show_in_default>
28
+ <show_in_website>1</show_in_website>
29
+ <show_in_store>1</show_in_store>
30
+ </category_active>
31
+ <import_product_ean translate="label">
32
+ <label>Import product EAN</label>
33
+ <frontend_type>select</frontend_type>
34
+ <source_model>iceimport/system_config_importproductean</source_model>
35
+ <sort_order>12</sort_order>
36
+ <show_in_default>1</show_in_default>
37
+ <show_in_website>1</show_in_website>
38
+ <show_in_store>1</show_in_store>
39
+ </import_product_ean>
40
+ <import_product_mpn translate="label">
41
+ <label>Import product MPN</label>
42
+ <frontend_type>select</frontend_type>
43
+ <source_model>iceimport/system_config_importproductmpn</source_model>
44
+ <sort_order>13</sort_order>
45
+ <show_in_default>1</show_in_default>
46
+ <show_in_website>1</show_in_website>
47
+ <show_in_store>1</show_in_store>
48
+ </import_product_mpn>
49
+ <import_product_brand translate="label">
50
+ <label>Import product brand</label>
51
+ <frontend_type>select</frontend_type>
52
+ <source_model>iceimport/system_config_importproductbrand</source_model>
53
+ <sort_order>14</sort_order>
54
+ <show_in_default>1</show_in_default>
55
+ <show_in_website>1</show_in_website>
56
+ <show_in_store>1</show_in_store>
57
+ </import_product_brand>
58
+ <import_product_name translate="label">
59
+ <label>Import product name</label>
60
+ <frontend_type>select</frontend_type>
61
+ <source_model>iceimport/system_config_importproductname</source_model>
62
+ <sort_order>15</sort_order>
63
+ <show_in_default>1</show_in_default>
64
+ <show_in_website>1</show_in_website>
65
+ <show_in_store>1</show_in_store>
66
+ </import_product_name>
67
+ <import_product_short_description translate="label">
68
+ <label>Import product short description</label>
69
+ <frontend_type>select</frontend_type>
70
+ <source_model>iceimport/system_config_importproductshdescription</source_model>
71
+ <sort_order>16</sort_order>
72
+ <show_in_default>1</show_in_default>
73
+ <show_in_website>1</show_in_website>
74
+ <show_in_store>1</show_in_store>
75
+ </import_product_short_description>
76
+ <import_product_description translate="label">
77
+ <label>Import product description</label>
78
+ <frontend_type>select</frontend_type>
79
+ <source_model>iceimport/system_config_importproductdescription</source_model>
80
+ <sort_order>17</sort_order>
81
+ <show_in_default>1</show_in_default>
82
+ <show_in_website>1</show_in_website>
83
+ <show_in_store>1</show_in_store>
84
+ </import_product_description>
85
+ <import_product_short_summary_description translate="label">
86
+ <label>Import product short summary description</label>
87
+ <frontend_type>select</frontend_type>
88
+ <source_model>iceimport/system_config_importproductshsudescription</source_model>
89
+ <sort_order>18</sort_order>
90
+ <show_in_default>1</show_in_default>
91
+ <show_in_website>1</show_in_website>
92
+ <show_in_store>1</show_in_store>
93
+ </import_product_short_summary_description>
94
+ <import_product_summary_description translate="label">
95
+ <label>Import product summary description</label>
96
+ <frontend_type>select</frontend_type>
97
+ <source_model>iceimport/system_config_importproductsudescription</source_model>
98
+ <sort_order>19</sort_order>
99
+ <show_in_default>1</show_in_default>
100
+ <show_in_website>1</show_in_website>
101
+ <show_in_store>1</show_in_store>
102
+ </import_product_summary_description>
103
+ <import_prices translate="label">
104
+ <label>Import prices</label>
105
+ <frontend_type>select</frontend_type>
106
+ <source_model>iceimport/system_config_importprices</source_model>
107
+ <sort_order>20</sort_order>
108
+ <show_in_default>1</show_in_default>
109
+ <show_in_website>1</show_in_website>
110
+ <show_in_store>1</show_in_store>
111
+ </import_prices>
112
+ <import_stock translate="label">
113
+ <label>Import stock</label>
114
+ <frontend_type>select</frontend_type>
115
+ <source_model>iceimport/system_config_importstock</source_model>
116
+ <sort_order>21</sort_order>
117
+ <show_in_default>1</show_in_default>
118
+ <show_in_website>1</show_in_website>
119
+ <show_in_store>1</show_in_store>
120
+ </import_stock>
121
+ <import_delivery_eta translate="label">
122
+ <label>Import delivery eta</label>
123
+ <frontend_type>select</frontend_type>
124
+ <source_model>iceimport/system_config_importdeliveryeta</source_model>
125
+ <sort_order>22</sort_order>
126
+ <show_in_default>1</show_in_default>
127
+ <show_in_website>1</show_in_website>
128
+ <show_in_store>1</show_in_store>
129
+ </import_delivery_eta>
130
+ <import_images translate="label">
131
+ <label>Import product images (via Cron)</label>
132
+ <frontend_type>select</frontend_type>
133
+ <source_model>iceimport/system_config_imageimport</source_model>
134
+ <sort_order>30</sort_order>
135
+ <show_in_default>1</show_in_default>
136
+ <show_in_website>1</show_in_website>
137
+ <show_in_store>1</show_in_store>
138
+ </import_images>
139
+ <default_tax translate="label">
140
+ <label>Default tax for product</label>
141
+ <frontend_type>select</frontend_type>
142
+ <source_model>iceimport/system_config_defaulttax</source_model>
143
+ <sort_order>40</sort_order>
144
+ <show_in_default>1</show_in_default>
145
+ <show_in_website>1</show_in_website>
146
+ <show_in_store>1</show_in_store>
147
+ </default_tax>
148
+ </fields>
149
+ </importprod>
150
+ </groups>
151
+ </importprod_root>
152
+ </sections>
153
+ </config>
app/code/community/Iceshop/Iceimport/sql/iceimport_setup/mysql4-install-1.5.0.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ include_once 'uninstall-old-version.php';
3
+ $unistaller_old_version = new Uninstall_Capacitywebsolutions_Importproduct();
4
+ $unistaller_old_version->uninstall();
5
+ $installer = $this;
6
+ $installer->startSetup();
7
+
8
+ $entityTypeId = $installer->getEntityTypeId('catalog_category');
9
+ $attributeSetId = $installer->getDefaultAttributeSetId($entityTypeId);
10
+ $attributeGroupId = $installer->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
11
+
12
+ $installer->addAttribute('catalog_category', 'unspsc', array(
13
+ 'type' => 'varchar',
14
+ 'label' => 'unspsc',
15
+ 'input' => 'text',
16
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
17
+ 'visible' => true,
18
+ 'required' => false,
19
+ 'user_defined' => false,
20
+ 'default' => 0
21
+ ));
22
+
23
+ $installer->addAttributeToGroup(
24
+ $entityTypeId,
25
+ $attributeSetId,
26
+ $attributeGroupId,
27
+ 'unspsc',
28
+ '11'
29
+ );
30
+
31
+ $attributeId = $installer->getAttributeId($entityTypeId, 'unspsc');
32
+
33
+ $installer->run("
34
+
35
+ DROP TABLE IF EXISTS `{$installer->getTable('iceimport_imported_product_ids')}`;
36
+ DROP TABLE IF EXISTS `{$installer->getTable('capacity_product_image_queue')}`;
37
+ DROP TABLE IF EXISTS `{$installer->getTable('iceshop_iceimport_imported_product_ids')}`;
38
+ DROP TABLE IF EXISTS `{$installer->getTable('iceshop_iceimport_image_queue')}`;
39
+
40
+ INSERT IGNORE INTO `{$installer->getTable('catalog_category_entity_varchar')}`
41
+ (`entity_type_id`, `attribute_id`, `entity_id`, `value`)
42
+ SELECT '{$entityTypeId}', '{$attributeId}', `entity_id`, '1'
43
+ FROM `{$installer->getTable('catalog_category_entity')}`;
44
+
45
+ CREATE TABLE IF NOT EXISTS `{$installer->getTable('iceshop_iceimport_image_queue')}`
46
+ (
47
+ `queue_id` INT(10) NOT NULL AUTO_INCREMENT,
48
+ `entity_id` INT(10) UNSIGNED NOT NULL,
49
+ `image_url` VARCHAR(255) NOT NULL,
50
+ `is_downloaded` TINYINT NOT NULL DEFAULT 0,
51
+ PRIMARY KEY(`queue_id`),
52
+ UNIQUE KEY (`entity_id`, `image_url`),
53
+ CONSTRAINT `FK_CAP_PRD_IMG_QUEUE_ENTT_ID_CAT_PRD_ENTT_ENTT_ID` FOREIGN KEY (`entity_id`) REFERENCES `{$installer->getTable('catalog_product_entity')}` (`entity_id`) ON DELETE CASCADE
54
+ )ENGINE=InnoDB CHARSET=utf8 COMMENT='Table to manage product image import';
55
+
56
+ CREATE TABLE IF NOT EXISTS `{$installer->getTable('iceshop_iceimport_imported_product_ids')}` (
57
+ `product_id` int(11) NOT NULL,
58
+ `product_sku` varchar(255) DEFAULT NULL,
59
+ KEY `pi_idx` (`product_id`)
60
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8
61
+ ");
62
+
63
+ $installer->endSetup();
64
+
65
+ ?>
app/code/community/Iceshop/Iceimport/sql/iceimport_setup/mysql4-upgrade-0.1.0-1.5.0.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ include_once 'uninstall-old-version.php';
3
+ $unistaller_old_version = new Uninstall_Capacitywebsolutions_Importproduct();
4
+ $unistaller_old_version->uninstall();
5
+ $installer = $this;
6
+ $installer->startSetup();
7
+
8
+ $entityTypeId = $installer->getEntityTypeId('catalog_category');
9
+ $attributeSetId = $installer->getDefaultAttributeSetId($entityTypeId);
10
+ $attributeGroupId = $installer->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
11
+
12
+ $installer->addAttribute('catalog_category', 'unspsc', array(
13
+ 'type' => 'varchar',
14
+ 'label' => 'unspsc',
15
+ 'input' => 'text',
16
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
17
+ 'visible' => true,
18
+ 'required' => false,
19
+ 'user_defined' => false,
20
+ 'default' => 0
21
+ ));
22
+
23
+ $installer->addAttributeToGroup(
24
+ $entityTypeId,
25
+ $attributeSetId,
26
+ $attributeGroupId,
27
+ 'unspsc',
28
+ '11'
29
+ );
30
+
31
+ $attributeId = $installer->getAttributeId($entityTypeId, 'unspsc');
32
+
33
+ $installer->run("
34
+
35
+ DROP TABLE IF EXISTS `{$installer->getTable('iceimport_imported_product_ids')}`;
36
+ DROP TABLE IF EXISTS `{$installer->getTable('capacity_product_image_queue')}`;
37
+ DROP TABLE IF EXISTS `{$installer->getTable('iceshop_iceimport_imported_product_ids')}`;
38
+ DROP TABLE IF EXISTS `{$installer->getTable('iceshop_iceimport_image_queue')}`;
39
+
40
+ INSERT IGNORE INTO `{$installer->getTable('catalog_category_entity_varchar')}`
41
+ (`entity_type_id`, `attribute_id`, `entity_id`, `value`)
42
+ SELECT '{$entityTypeId}', '{$attributeId}', `entity_id`, '1'
43
+ FROM `{$installer->getTable('catalog_category_entity')}`;
44
+
45
+ CREATE TABLE IF NOT EXISTS `{$installer->getTable('iceshop_iceimport_image_queue')}`
46
+ (
47
+ `queue_id` INT(10) NOT NULL AUTO_INCREMENT,
48
+ `entity_id` INT(10) UNSIGNED NOT NULL,
49
+ `image_url` VARCHAR(255) NOT NULL,
50
+ `is_downloaded` TINYINT NOT NULL DEFAULT 0,
51
+ PRIMARY KEY(`queue_id`),
52
+ UNIQUE KEY (`entity_id`, `image_url`),
53
+ CONSTRAINT `FK_CAP_PRD_IMG_QUEUE_ENTT_ID_CAT_PRD_ENTT_ENTT_ID` FOREIGN KEY (`entity_id`) REFERENCES `{$installer->getTable('catalog_product_entity')}` (`entity_id`) ON DELETE CASCADE
54
+ )ENGINE=InnoDB CHARSET=utf8 COMMENT='Table to manage product image import';
55
+
56
+ CREATE TABLE IF NOT EXISTS `{$installer->getTable('iceshop_iceimport_imported_product_ids')}` (
57
+ `product_id` int(11) NOT NULL,
58
+ `product_sku` varchar(255) DEFAULT NULL,
59
+ KEY `pi_idx` (`product_id`)
60
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8
61
+ ");
62
+
63
+ $installer->endSetup();
app/code/community/Iceshop/Iceimport/sql/iceimport_setup/mysql4-upgrade-1.4.0-1.5.0.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ include_once 'uninstall-old-version.php';
3
+ $unistaller_old_version = new Uninstall_Capacitywebsolutions_Importproduct();
4
+ $unistaller_old_version->uninstall();
5
+ $installer = $this;
6
+ $installer->startSetup();
7
+
8
+ $entityTypeId = $installer->getEntityTypeId('catalog_category');
9
+ $attributeSetId = $installer->getDefaultAttributeSetId($entityTypeId);
10
+ $attributeGroupId = $installer->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
11
+
12
+ $installer->addAttribute('catalog_category', 'unspsc', array(
13
+ 'type' => 'varchar',
14
+ 'label' => 'unspsc',
15
+ 'input' => 'text',
16
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
17
+ 'visible' => true,
18
+ 'required' => false,
19
+ 'user_defined' => false,
20
+ 'default' => 0
21
+ ));
22
+
23
+ $installer->addAttributeToGroup(
24
+ $entityTypeId,
25
+ $attributeSetId,
26
+ $attributeGroupId,
27
+ 'unspsc',
28
+ '11'
29
+ );
30
+
31
+ $attributeId = $installer->getAttributeId($entityTypeId, 'unspsc');
32
+
33
+ $installer->run("
34
+
35
+ DROP TABLE IF EXISTS `{$installer->getTable('iceimport_imported_product_ids')}`;
36
+ DROP TABLE IF EXISTS `{$installer->getTable('capacity_product_image_queue')}`;
37
+ DROP TABLE IF EXISTS `{$installer->getTable('iceshop_iceimport_imported_product_ids')}`;
38
+ DROP TABLE IF EXISTS `{$installer->getTable('iceshop_iceimport_image_queue')}`;
39
+
40
+ INSERT IGNORE INTO `{$installer->getTable('catalog_category_entity_varchar')}`
41
+ (`entity_type_id`, `attribute_id`, `entity_id`, `value`)
42
+ SELECT '{$entityTypeId}', '{$attributeId}', `entity_id`, '1'
43
+ FROM `{$installer->getTable('catalog_category_entity')}`;
44
+
45
+ CREATE TABLE IF NOT EXISTS `{$installer->getTable('iceshop_iceimport_image_queue')}`
46
+ (
47
+ `queue_id` INT(10) NOT NULL AUTO_INCREMENT,
48
+ `entity_id` INT(10) UNSIGNED NOT NULL,
49
+ `image_url` VARCHAR(255) NOT NULL,
50
+ `is_downloaded` TINYINT NOT NULL DEFAULT 0,
51
+ PRIMARY KEY(`queue_id`),
52
+ UNIQUE KEY (`entity_id`, `image_url`),
53
+ CONSTRAINT `FK_CAP_PRD_IMG_QUEUE_ENTT_ID_CAT_PRD_ENTT_ENTT_ID` FOREIGN KEY (`entity_id`) REFERENCES `{$installer->getTable('catalog_product_entity')}` (`entity_id`) ON DELETE CASCADE
54
+ )ENGINE=InnoDB CHARSET=utf8 COMMENT='Table to manage product image import';
55
+
56
+ CREATE TABLE IF NOT EXISTS `{$installer->getTable('iceshop_iceimport_imported_product_ids')}` (
57
+ `product_id` int(11) NOT NULL,
58
+ `product_sku` varchar(255) DEFAULT NULL,
59
+ KEY `pi_idx` (`product_id`)
60
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8
61
+ ");
62
+
63
+ $installer->endSetup();
64
+
65
+ ?>
app/code/community/Iceshop/Iceimport/sql/iceimport_setup/uninstall-old-version.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Uninstall_Capacitywebsolutions_Importproduct
3
+ {
4
+ /**
5
+ * Delete Iceimport extension with old namespace
6
+ */
7
+ public function uninstall()
8
+ {
9
+ $code_dir = Mage::getBaseDir('app') . '/code/community/Capacitywebsolutions/Importproduct';
10
+ $etc_capacitywebsolutions_xml = Mage::getBaseDir('app') . '/etc/modules/Capacitywebsolutions_Importproduct.xml';
11
+
12
+ $this->remove_dir($code_dir);
13
+ $this->remove_file($etc_capacitywebsolutions_xml);
14
+ }
15
+
16
+ public function remove_dir($path)
17
+ {
18
+ if (file_exists($path) && is_dir($path)) {
19
+ $dirHandle = opendir($path);
20
+ while (false !== ($file = readdir($dirHandle))) {
21
+ if ($file != '.' && $file != '..') {
22
+ $tmpPath = $path . '/' . $file;
23
+ chmod($tmpPath, 0777);
24
+
25
+ if (is_dir($tmpPath)) {
26
+ $this->remove_dir($tmpPath);
27
+ } else {
28
+ if (file_exists($tmpPath)) {
29
+ unlink($tmpPath);
30
+ }
31
+ }
32
+ }
33
+ }
34
+ closedir($dirHandle);
35
+
36
+ if (file_exists($path)) {
37
+ rmdir($path);
38
+ }
39
+ }
40
+ }
41
+
42
+ public function remove_file($path)
43
+ {
44
+ if (file_exists($path)) {
45
+ unlink($path);
46
+ }
47
+ }
48
+ }
app/etc/modules/{Capacitywebsolutions_Importproduct.xml → Iceshop_Iceimport.xml} RENAMED
@@ -1,9 +1,9 @@
1
  <?xml version="1.0"?>
2
  <config>
3
  <modules>
4
- <Capacitywebsolutions_Importproduct>
5
  <active>true</active>
6
  <codePool>community</codePool>
7
- </Capacitywebsolutions_Importproduct>
8
  </modules>
9
  </config>
1
  <?xml version="1.0"?>
2
  <config>
3
  <modules>
4
+ <Iceshop_Iceimport>
5
  <active>true</active>
6
  <codePool>community</codePool>
7
+ </Iceshop_Iceimport>
8
  </modules>
9
  </config>
package.xml CHANGED
@@ -1,24 +1,22 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>ice_import</name>
4
- <version>1.4.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v.3</license>
7
  <channel>community</channel>
8
  <extends/>
9
- <summary>Import categories &amp; products</summary>
10
  <description>This extension can use to import products with categories, multiple images and custom options from CSV file.</description>
11
- <notes>- Add default tax attribute.&#xD; - Add support multisites stores category mapping.&#xD;
12
- - Removed skipped field warnings&#xD;
13
- - Fix some bugs...etc.&#xD;
14
- - Delete old not relevant products&#xD;
15
- - Set is anchor category property to yes&#xD;
16
- - Sort imported categories by name&#xD;
17
- - Added method to set categories, subcategories without products to inactive&#xD; -Added imported products to all categories listed in import file for product including Default webshop's category </notes>
18
  <authors><author><name>Iceshop</name><user>Iceshop</user><email>support@iceshop.nl</email></author></authors>
19
- <date>2013-08-23</date>
20
- <time>12:07:42</time>
21
- <contents><target name="magecommunity"><dir name="Capacitywebsolutions"><dir name="Importproduct"><dir name="etc"><file name="config.xml" hash="c59424e1f6806af1c50f322a84c262a9"/><file name="system.xml" hash="0f76e79143ac01dc948a1c4c5315c072"/></dir><dir name="Model"><dir name="Convert"><dir name="Adapter"><file name="Product.php" hash="b14683db8316b3bfa88a663abc42e7df"/></dir></dir><dir name="System"><dir name="Config"><file name="Categoryactivity.php" hash="2ddc7588dd1d038661f0017c8ff397a6"/><file name="Imageimport.php" hash="8b29e7bbf67d82a06f04ad9a63df26a0"/><file name="Lockproddetails.php" hash="32a823c0c914348585702536732fed3e"/><file name="Defaulttax.php" hash="32a823c0c914348585702536732fed3e"/></dir></dir><file name="Observer.php" hash="cf7944e708df4fca8fbb218f8828b305"/></dir><dir name="sql"><dir name="importproduct_setup"><file name="mysql4-install-0.1.0.php" hash="61102e9caee6f92ebba4230d391b922d"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Capacitywebsolutions_Importproduct.xml" hash="02cb79dd6ed129ce3aa5305e1bfb4bbf"/></dir></target></contents>
22
  <compatible/>
23
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
24
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>ice_import</name>
4
+ <version>1.5.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v.3</license>
7
  <channel>community</channel>
8
  <extends/>
9
+ <summary>Import categories &amp;amp; products</summary>
10
  <description>This extension can use to import products with categories, multiple images and custom options from CSV file.</description>
11
+ <notes>- Added Magento V1.8 Compatibility&#xD;
12
+ - Added batch of settings for information to be imported (desription, name, stock, price and etc)&#xD;
13
+ - Speed improvements&#xD;
14
+ - Fixed issues with TimeOut&#xD;
15
+ - Changed namespaces</notes>
 
 
16
  <authors><author><name>Iceshop</name><user>Iceshop</user><email>support@iceshop.nl</email></author></authors>
17
+ <date>2013-11-13</date>
18
+ <time>19:52:32</time>
19
+ <contents><target name="magecommunity"><dir name="Iceshop"><dir name="Iceimport"><dir name="Model"><dir name="Convert"><dir name="Adapter"><file name="Product.php" hash="04350eb3276aa632cd70c98b8c44b2d5"/></dir></dir><dir name="Dataflow"><dir name="Batch"><file name="Import.php" hash="90a3fdd194991e4b1a0c1e6dd2ba3db1"/></dir><dir name="Convert"><dir name="Parser"><file name="Csv.php" hash="9f1dbe6d5117d92a19038cc1d64bd162"/></dir></dir></dir><file name="Observer.php" hash="b392ef90dec09ff51e3a0984f3523677"/><dir name="System"><dir name="Config"><file name="Categoryactivity.php" hash="c60f739b06f29e47f3098bf91bc0b8fd"/><file name="Defaulttax.php" hash="d5d3b7b5862ef1264ee4b960e8dbb627"/><file name="Imageimport.php" hash="d4f67a21d5b8731716c6246a30f7a01f"/><file name="Importdeliveryeta.php" hash="0807017f687f4adeb76129dcb7f5358c"/><file name="Importprices.php" hash="1367181841e8c93f67160dbc497fa658"/><file name="Importproductbrand.php" hash="5b210f5ae30bcd69c8215f0db15f873f"/><file name="Importproductdescription.php" hash="47e0df7a29e9eb9b35e6b9b85a94d757"/><file name="Importproductean.php" hash="4e5ba806f6c31705df6797e9703a714c"/><file name="Importproductmpn.php" hash="9dc525200e8782f9161e59ea20d97517"/><file name="Importproductname.php" hash="c9a6c970105bf3ce9a368351fa27d2d6"/><file name="Importproductshdescription.php" hash="86b361fe2a483757cbd3c37a7cd556bb"/><file name="Importproductshsudescription.php" hash="c0b75d1b619f39db30d4529cc2981652"/><file name="Importproductsudescription.php" hash="8b21d2e05ac3e8f47a6eda5380fb0f49"/><file name="Importstock.php" hash="dcd5838f2b8d21f374b621bc440d9a7c"/><file name="Lockproddetails.php" hash="66107a746bb9a50c8d74e3f27bdaaedf"/></dir></dir></dir><dir name="etc"><file name="config.xml" hash="5faff23af0e722d7e92af56b5eff63d4"/><file name="system.xml" hash="e76ed11ef4b797c0cf3d8553e1409e8d"/></dir><dir name="sql"><dir name="iceimport_setup"><file name="mysql4-install-1.5.0.php" hash="c90722a11b7de7d23d92f12bd37d3706"/><file name="mysql4-upgrade-0.1.0-1.5.0.php" hash="26cded28767c71f2d4945e9866b7feb0"/><file name="mysql4-upgrade-1.4.0-1.5.0.php" hash="07b4b6f1e01d253db017038bd1985170"/><file name="uninstall-old-version.php" hash="291f724845f8e62d51ccdf61baf81b37"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Iceshop_Iceimport.xml" hash="c22b6e566abee45bbb2102b3239cd6a2"/></dir></target></contents>
20
  <compatible/>
21
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
22
  </package>