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
+