Version Notes
- Improvement of category tree import
- Improvement to speed of import
- Added possibility to run import by Cron
- Added new field delivery_eta
Download this release
Release Info
Developer | IceShop |
Extension | ice_import |
Version | 1.1.0 |
Comparing to | |
See all releases |
Code changes from version 1.0.0 to 1.1.0
app/code/community/Capacitywebsolutions/Importproduct/Model/Convert/Adapter/Product.php
CHANGED
@@ -1,25 +1,166 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* Import Multiple Images during Product Import
|
4 |
-
* Copyright
|
5 |
* http://www.capacitywebsolutions.com
|
6 |
*/
|
7 |
|
|
|
8 |
class Capacitywebsolutions_Importproduct_Model_Convert_Adapter_Product extends Mage_Catalog_Model_Convert_Adapter_Product
|
9 |
{
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
->reset();
|
24 |
|
25 |
if (empty($importData['store'])) {
|
@@ -35,7 +176,7 @@ class Capacitywebsolutions_Importproduct_Model_Convert_Adapter_Product extends M
|
|
35 |
}
|
36 |
|
37 |
if ($store === false) {
|
38 |
-
$message = Mage::helper('catalog')->__('Skip import row, store "%s"
|
39 |
Mage::throwException($message);
|
40 |
}
|
41 |
|
@@ -124,8 +265,16 @@ class Capacitywebsolutions_Importproduct_Model_Convert_Adapter_Product extends M
|
|
124 |
if (!empty($importData['unspsc'])) {
|
125 |
$unspsc = $importData['unspsc'];
|
126 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
|
128 |
-
$categoryIds = $this->_addCategories($importData['categories'], $
|
129 |
if ($categoryIds) {
|
130 |
|
131 |
// check, that's product exist
|
@@ -186,7 +335,7 @@ class Capacitywebsolutions_Importproduct_Model_Convert_Adapter_Product extends M
|
|
186 |
}
|
187 |
$attribute = $this->getAttribute($field);
|
188 |
if (!$attribute) {
|
189 |
-
|
190 |
if(strpos($field,':')!==FALSE && strlen($value)) {
|
191 |
$values=explode('|',$value);
|
192 |
if(count($values)>0) {
|
@@ -381,151 +530,308 @@ class Capacitywebsolutions_Importproduct_Model_Convert_Adapter_Product extends M
|
|
381 |
}
|
382 |
}
|
383 |
return true;
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
|
|
398 |
|
399 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
400 |
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
406 |
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
435 |
}
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
$cat->unsNamePath();
|
441 |
}
|
442 |
-
$
|
|
|
|
|
|
|
|
|
|
|
443 |
}
|
444 |
-
|
445 |
-
|
446 |
-
$catIds = array();
|
447 |
-
foreach (explode(',', $categories) as $categoryPathStr) {
|
448 |
-
$categoryPathStr = preg_replace('#\s*/\s*#', '/', trim($categoryPathStr));
|
449 |
-
if (!empty($cache[$categoryPathStr])) {
|
450 |
-
$catIds[] = $cache[$categoryPathStr]->getId();
|
451 |
-
if (!$multylang) {
|
452 |
-
continue;
|
453 |
-
}
|
454 |
-
}
|
455 |
-
$path = $rootPath;
|
456 |
-
$namePath = '';
|
457 |
-
|
458 |
-
if ($multyLang) {
|
459 |
-
$shadowPath = '';
|
460 |
-
}
|
461 |
-
|
462 |
-
$shadowCategory = explode('/', $leader_categories);
|
463 |
-
$shadowIterator = 0;
|
464 |
-
|
465 |
-
$catNamesArr = explode('/', $categoryPathStr);
|
466 |
-
|
467 |
-
$categoriesCounter = count($catNamesArr);
|
468 |
-
|
469 |
-
foreach ($catNamesArr as $catName) {
|
470 |
-
$namePath .= (empty($namePath) ? '' : '/').strtolower($catName);
|
471 |
-
|
472 |
-
if ($multyLang) {
|
473 |
-
// update existing category, set new name to NL store.
|
474 |
-
$shadowPath .= (empty($shadowPath) ? '' : '/').strtolower($shadowCategory[$shadowIterator]);
|
475 |
-
$catId = $cache[$shadowPath]->getId();
|
476 |
-
$cat = Mage::getModel('catalog/category');
|
477 |
-
$cat->setStoreId($store->getId());
|
478 |
-
$cat->load($catId);
|
479 |
-
$cat->setData('name', $catName);
|
480 |
-
$cat->save();
|
481 |
-
$cache[$shadowPath] = $cat;
|
482 |
-
|
483 |
-
} else {
|
484 |
-
if (empty($cache[$namePath])) {
|
485 |
-
$cat = Mage::getModel('catalog/category');
|
486 |
-
$cat = Mage::getModel('catalog/category')
|
487 |
-
->setStoreId($shadowStore->getId())
|
488 |
-
->setPath($path)
|
489 |
-
->setName($catName)
|
490 |
-
->setIsActive($categoryActive);
|
491 |
-
|
492 |
-
if ($categoriesCounter -1 == $shadowIterator) {
|
493 |
-
if (!empty($unspsc)) {
|
494 |
-
$catAttrib = $cat->getAttributes();
|
495 |
-
if ($catAttrib['unspsc']) {
|
496 |
-
$cat->setData('unspsc', $unspsc);
|
497 |
-
}
|
498 |
-
}
|
499 |
-
}
|
500 |
-
|
501 |
-
$cat->save();
|
502 |
-
$cache[$namePath] = $cat;
|
503 |
-
} else {
|
504 |
-
if ($categoriesCounter -1 == $shadowIterator) {
|
505 |
-
if (!empty($unspsc)) {
|
506 |
-
$catAttrib = $cache[$namePath]->getAttributes();
|
507 |
-
if ($catAttrib['unspsc']) {
|
508 |
-
$cache[$namePath]->setIsActive($categoryActive)
|
509 |
-
->setData('unspsc', $unspsc)
|
510 |
-
->save();
|
511 |
-
}
|
512 |
-
}
|
513 |
-
}
|
514 |
-
}
|
515 |
|
516 |
-
|
517 |
-
|
|
|
518 |
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
|
524 |
-
|
525 |
-
|
526 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
527 |
}
|
528 |
-
|
529 |
-
|
530 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
531 |
}
|
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 saveRow(array $importData) {
|
16 |
+
|
17 |
+
if (!empty($importData['mpn']) && !empty($importData['brand_name']) && !empty($importData['categories'])) {
|
18 |
+
// custom logic
|
19 |
+
$this->_connRes = Mage::getSingleton('core/resource')->getConnection('core_write');
|
20 |
+
|
21 |
+
$tablePrefix = (array)Mage::getConfig()->getTablePrefix();
|
22 |
+
if (!empty($tablePrefix)) {
|
23 |
+
$this->_tablePrefix = $tablePrefix[0];
|
24 |
+
}
|
25 |
+
|
26 |
+
$this->_coreSaveRow($importData);
|
27 |
+
//$this->_capacitySaveRow($importData);
|
28 |
+
} else {
|
29 |
+
// old logic
|
30 |
+
$this->_capacitySaveRow($importData);
|
31 |
+
}
|
32 |
+
}
|
33 |
+
|
34 |
+
protected function _coreSaveRow(array $importData){
|
35 |
+
if (empty($importData['store'])) {
|
36 |
+
if (!is_null($this->getBatchParams('store'))) {
|
37 |
+
$store = $this->getStoreById($this->getBatchParams('store'));
|
38 |
+
} else {
|
39 |
+
$message = Mage::helper('catalog')->__('Skip import row, required field "%s" not defined', 'store');
|
40 |
+
Mage::throwException($message);
|
41 |
+
}
|
42 |
+
}else {
|
43 |
+
$store = $this->getStoreByCode($importData['store']);
|
44 |
+
}
|
45 |
+
|
46 |
+
if ($store === false) {
|
47 |
+
$message = Mage::helper('catalog')->__('Skip import row, store "%s" not exists', $importData['store']);
|
48 |
+
Mage::throwException($message);
|
49 |
+
}
|
50 |
+
|
51 |
+
$storeId = $store->getId();
|
52 |
+
|
53 |
+
$websiteId = false;
|
54 |
+
if (!empty($importData['websites'])) {
|
55 |
+
$website = Mage::app()->getWebsite(trim($importData['websites']));
|
56 |
+
$websiteId = $website->getId();
|
57 |
+
} else {
|
58 |
+
$message = Mage::helper('catalog')->__('Skip import row, required field "%s" not defined', 'website');
|
59 |
+
Mage::throwException($message);
|
60 |
+
}
|
61 |
+
|
62 |
+
if (empty($importData['sku'])) {
|
63 |
+
$message = Mage::helper('catalog')->__('Skip import row, required field "%s" not defined', 'sku');
|
64 |
+
Mage::throwException($message);
|
65 |
+
}
|
66 |
+
|
67 |
+
// attributes set up
|
68 |
+
$this->_connRes->query("
|
69 |
+
SELECT @product_entity_type_id := entity_type_id FROM " . $this->_tablePrefix . "eav_entity_type WHERE entity_type_code = 'catalog_product';
|
70 |
+
SELECT @category_entity_type_id := entity_type_id FROM " . $this->_tablePrefix . "eav_entity_type WHERE entity_type_code = 'catalog_category';
|
71 |
+
SELECT @attribute_set_id := entity_type_id FROM " . $this->_tablePrefix . "eav_entity_type WHERE entity_type_code = 'catalog_product';
|
72 |
+
SELECT @attribute_set_id := `attribute_set_id` FROM eav_attribute_set
|
73 |
+
WHERE attribute_set_name = 'Default' AND entity_type_id =
|
74 |
+
(SELECT entity_type_id FROM eav_entity_type WHERE entity_type_code = 'catalog_product');
|
75 |
+
|
76 |
+
SELECT @name_id := `attribute_id` FROM `" . $this->_tablePrefix . "eav_attribute` WHERE `attribute_code` = 'name' AND entity_type_id = @product_entity_type_id;
|
77 |
+
SELECT @mpn_id := `attribute_id` FROM `" . $this->_tablePrefix . "eav_attribute` WHERE `attribute_code` = 'mpn' AND entity_type_id = @product_entity_type_id;
|
78 |
+
SELECT @brand_id := `attribute_id` FROM `" . $this->_tablePrefix . "eav_attribute` WHERE `attribute_code` = 'brand_name' AND entity_type_id = @product_entity_type_id;
|
79 |
+
SELECT @desc_id := `attribute_id` FROM `" . $this->_tablePrefix . "eav_attribute` WHERE `attribute_code` = 'description' AND entity_type_id = @product_entity_type_id;
|
80 |
+
SELECT @sh_desc_id := `attribute_id` FROM `" . $this->_tablePrefix . "eav_attribute` WHERE `attribute_code` = 'short_description' AND entity_type_id = @product_entity_type_id;
|
81 |
+
SELECT @sku_id := `attribute_id` FROM `" . $this->_tablePrefix . "eav_attribute` WHERE `attribute_code` = 'sku' AND entity_type_id = @product_entity_type_id;
|
82 |
+
SELECT @weight_id := `attribute_id` FROM `" . $this->_tablePrefix . "eav_attribute` WHERE `attribute_code` = 'weight' AND entity_type_id = @product_entity_type_id;
|
83 |
+
SELECT @status_id := `attribute_id` FROM `" . $this->_tablePrefix . "eav_attribute` WHERE `attribute_code` = 'status' AND entity_type_id = @product_entity_type_id;
|
84 |
+
SELECT @url_key_id := `attribute_id` FROM `" . $this->_tablePrefix . "eav_attribute` WHERE `attribute_code` = 'url_key' AND entity_type_id = @product_entity_type_id;
|
85 |
+
SELECT @visibility_id := `attribute_id` FROM `" . $this->_tablePrefix . "eav_attribute` WHERE `attribute_code` = 'visibility' AND entity_type_id = @product_entity_type_id;
|
86 |
+
SELECT @price_id := `attribute_id` FROM `" . $this->_tablePrefix . "eav_attribute` WHERE `attribute_code` = 'price' AND entity_type_id = @product_entity_type_id;
|
87 |
+
SELECT @stock_id := `stock_id` FROM `" . $this->_tablePrefix . "cataloginventory_stock` where stock_name = 'Default';
|
88 |
+
SELECT @delivery_id := `attribute_id` FROM `" . $this->_tablePrefix . "eav_attribute` WHERE `attribute_code` = 'delivery_eta' AND entity_type_id = @product_entity_type_id;
|
89 |
+
|
90 |
+
SELECT @unspcs_id := `attribute_id` FROM `" . $this->_tablePrefix . "eav_attribute` WHERE `attribute_code` = 'unspsc' AND entity_type_id = @category_entity_type_id;
|
91 |
+
SELECT @category_name_id := `attribute_id` FROM `" . $this->_tablePrefix . "eav_attribute` WHERE `attribute_code` = 'name' AND entity_type_id = @category_entity_type_id;
|
92 |
+
SELECT @category_active_id := `attribute_id` FROM `" . $this->_tablePrefix . "eav_attribute` WHERE `attribute_code` = 'is_active' AND entity_type_id = @category_entity_type_id;
|
93 |
+
SELECT @include_nav_bar_id := `attribute_id` FROM `" . $this->_tablePrefix . "eav_attribute` WHERE `attribute_code` = 'include_in_menu' AND entity_type_id = @category_entity_type_id;
|
94 |
+
");
|
95 |
+
|
96 |
+
$prodIdFetch = $this->_connRes->fetchRow('SELECT entity_id FROM catalog_product_entity WHERE sku = :sku limit 1' , array(':sku' => $importData['sku']));
|
97 |
+
$productId = $prodIdFetch['entity_id'];
|
98 |
+
|
99 |
+
if (!empty($productId)) {
|
100 |
+
// check import type (Import only price & qty or all product info)
|
101 |
+
if('import_price_stock' == Mage::getStoreConfig('importprod_root/importprod/import_only_prices_stock',
|
102 |
+
$storeId)) {
|
103 |
+
$this->_corePriceStock($websiteId, $productId, $importData['price'], $importData['qty']);
|
104 |
+
return true;
|
105 |
+
}
|
106 |
+
} else {
|
107 |
+
$productId = false;
|
108 |
+
}
|
109 |
+
|
110 |
+
// get category id
|
111 |
+
if (isset($importData['categories'])) {
|
112 |
+
$categoriesToActiveConf = Mage::getStoreConfig('importprod_root/importprod/category_active',
|
113 |
+
$storeId);
|
114 |
+
|
115 |
+
if (!empty($importData['leader_categories'])) {
|
116 |
+
$leader_categories = $importData['leader_categories'];
|
117 |
+
$leader_store = $this->getStoreByCode($importData['leader_store']);
|
118 |
+
} else {
|
119 |
+
$leader_categories = '';
|
120 |
+
$leader_store = '';
|
121 |
+
}
|
122 |
+
|
123 |
+
$unspsc = '';
|
124 |
+
if (!empty($importData['unspsc'])) {
|
125 |
+
$unspsc = $importData['unspsc'];
|
126 |
+
}
|
127 |
+
|
128 |
+
$unspscPath = '';
|
129 |
+
if (!empty($importData['unspsc_path'])) {
|
130 |
+
$unspscPath = $importData['unspsc_path'];
|
131 |
+
} else {
|
132 |
+
$message = Mage::helper('catalog')->__('Skip import. Category UNSPSC not defined in store');
|
133 |
+
Mage::throwException($message);
|
134 |
+
}
|
135 |
+
$categoryId = $this->_addCategories($importData['categories'], $storeId, $importData['leader_store'], $unspsc, $unspscPath, $categoriesToActiveConf);
|
136 |
+
}
|
137 |
+
|
138 |
+
// agregate product data
|
139 |
+
$productData = array();
|
140 |
+
$productData['websiteId'] = $websiteId;
|
141 |
+
$productData['storeId'] = $storeId;
|
142 |
+
$productData['name'] = $importData['name'];
|
143 |
+
$productData['sku'] = $importData['sku'];
|
144 |
+
$productData['mpn'] = $importData['mpn'];
|
145 |
+
$productData['brand_name'] = $importData['brand_name'];
|
146 |
+
$productData['short_description'] = $importData['short_description'];
|
147 |
+
$productData['description'] = $importData['description'];
|
148 |
+
$productData['store'] = $importData['store'];
|
149 |
+
$productData['price'] = $importData['price'];
|
150 |
+
$productData['qty'] = $importData['qty'];
|
151 |
+
$productData['weight'] = $importData['weight'];
|
152 |
+
$productData['status'] = $importData['status'];
|
153 |
+
$productData['visibility'] = $importData['visibility'];
|
154 |
+
$productData['is_in_stock'] = $importData['is_in_stock'];
|
155 |
+
$productData['delivery_eta'] = $importData['delivery_eta'];
|
156 |
+
$productData['productId'] = $productId;
|
157 |
+
$productData['categoryId'] = $categoryId;
|
158 |
+
|
159 |
+
return (bool)$this->_coreSave($productData);
|
160 |
+
}
|
161 |
+
|
162 |
+
protected function _capacitySaveRow(array $importData){
|
163 |
+
$product = $this->getProductModel()
|
164 |
->reset();
|
165 |
|
166 |
if (empty($importData['store'])) {
|
176 |
}
|
177 |
|
178 |
if ($store === false) {
|
179 |
+
$message = Mage::helper('catalog')->__('Skip import row, store "%s" not exists', $importData['store']);
|
180 |
Mage::throwException($message);
|
181 |
}
|
182 |
|
265 |
if (!empty($importData['unspsc'])) {
|
266 |
$unspsc = $importData['unspsc'];
|
267 |
}
|
268 |
+
|
269 |
+
$unspscPath = '';
|
270 |
+
if (!empty($importData['unspsc_path'])) {
|
271 |
+
$unspscPath = $importData['unspsc_path'];
|
272 |
+
} else {
|
273 |
+
$message = Mage::helper('catalog')->__('Skip import. Category UNSPSC not defined in store');
|
274 |
+
Mage::throwException($message);
|
275 |
+
}
|
276 |
|
277 |
+
$categoryIds = $this->_addCategories($importData['categories'], $store, $leader_store, $unspsc, $unspscPath, $categoriesToActiveConf);
|
278 |
if ($categoryIds) {
|
279 |
|
280 |
// check, that's product exist
|
335 |
}
|
336 |
$attribute = $this->getAttribute($field);
|
337 |
if (!$attribute) {
|
338 |
+
|
339 |
if(strpos($field,':')!==FALSE && strlen($value)) {
|
340 |
$values=explode('|',$value);
|
341 |
if(count($values)>0) {
|
530 |
}
|
531 |
}
|
532 |
return true;
|
533 |
+
}
|
534 |
+
|
535 |
+
protected function _coreSave(array $productData) {
|
536 |
+
$preUrl = explode(' ', strtolower($productData['name']));
|
537 |
+
$url = implode('_', $preUrl) . '_' . $productData['store'];
|
538 |
+
|
539 |
+
if ($productData['productId'] === false) {
|
540 |
+
// add product to store
|
541 |
+
$coreSaveProduct = "INSERT INTO `" . $this->_tablePrefix . "catalog_product_entity` (`entity_type_id`, `attribute_set_id`, `type_id`, `sku`) VALUES
|
542 |
+
(@product_entity_type_id, @attribute_set_id, 'simple', :sku)
|
543 |
+
ON DUPLICATE KEY UPDATE
|
544 |
+
`entity_type_id` = @product_entity_type_id,
|
545 |
+
`attribute_set_id` = @attribute_set_id,
|
546 |
+
`type_id` = 'simple',
|
547 |
+
`sku` = :sku;
|
548 |
|
549 |
+
SELECT @product_id := LAST_INSERT_ID();
|
550 |
+
";
|
551 |
+
|
552 |
+
$this->_connRes->query($coreSaveProduct, array(':sku' => $productData['sku']));
|
553 |
+
// get product ID
|
554 |
+
$prodFetch = $this->_connRes->fetchRow('SELECT @product_id AS prod_id');
|
555 |
+
$productId = $prodFetch['prod_id'];
|
556 |
+
} else {
|
557 |
+
$productId = (int)$productData['productId'];
|
558 |
+
$coreSaveSQL .= "SELECT @product_id := " . $productId . "; ";
|
559 |
+
}
|
560 |
+
// eav varchar
|
561 |
+
$coreSaveSQL .= "
|
562 |
+
INSERT INTO `" . $this->_tablePrefix . "catalog_product_entity_varchar` (`entity_type_id`, `attribute_id`, `store_id`, `entity_id`, `value`) VALUES
|
563 |
+
(@product_entity_type_id, @name_id, 0, @product_id, :name),
|
564 |
+
(@product_entity_type_id, @mpn_id, 0, @product_id, :mpn),
|
565 |
+
(@product_entity_type_id, @brand_id, 0, @product_id, :brand_name),
|
566 |
+
(@product_entity_type_id, @url_key_id, 0, @product_id, :url),
|
567 |
+
(@product_entity_type_id, @delivery_id, 0, @product_id, :delivery_eta),
|
568 |
+
(@product_entity_type_id, @name_id, :store_id, @product_id, :name),
|
569 |
+
(@product_entity_type_id, @mpn_id, :store_id, @product_id, :mpn),
|
570 |
+
(@product_entity_type_id, @brand_id, :store_id, @product_id, :brand_name),
|
571 |
+
(@product_entity_type_id, @url_key_id, :store_id, @product_id, :url),
|
572 |
+
(@product_entity_type_id, @delivery_id, :store_id, @product_id, :delivery_eta)
|
573 |
+
ON DUPLICATE KEY UPDATE
|
574 |
+
`entity_type_id` = VALUES (`entity_type_id`),
|
575 |
+
`attribute_id` = VALUES (`attribute_id`),
|
576 |
+
`store_id` = VALUES (`store_id`),
|
577 |
+
`entity_id` = VALUES (`entity_id`),
|
578 |
+
`value` = VALUES (`value`);
|
579 |
+
";
|
580 |
|
581 |
+
// eav text
|
582 |
+
$coreSaveSQL .= "
|
583 |
+
INSERT INTO `" . $this->_tablePrefix . "catalog_product_entity_text` (`entity_type_id`, `attribute_id`, `store_id`, `entity_id`, `value`) VALUES
|
584 |
+
(@product_entity_type_id, @desc_id, 0, @product_id, :description),
|
585 |
+
(@product_entity_type_id, @sh_desc_id, 0, @product_id, :short_description),
|
586 |
+
(@product_entity_type_id, @desc_id, :store_id, @product_id, :description),
|
587 |
+
(@product_entity_type_id, @sh_desc_id, :store_id, @product_id, :short_description)
|
588 |
+
ON DUPLICATE KEY UPDATE
|
589 |
+
`entity_type_id` = VALUES(`entity_type_id`),
|
590 |
+
`attribute_id` = VALUES(`attribute_id`),
|
591 |
+
`store_id` = VALUES(`store_id`),
|
592 |
+
`entity_id` = VALUES(`entity_id`),
|
593 |
+
`value` = VALUES(`value`);
|
594 |
+
";
|
595 |
+
|
596 |
+
// eav decimal
|
597 |
+
$coreSaveSQL .= "
|
598 |
+
INSERT INTO `" . $this->_tablePrefix . "catalog_product_entity_decimal` (`entity_type_id`,`attribute_id`,`store_id`, `entity_id`, `value`) VALUES
|
599 |
+
(@product_entity_type_id, @weight_id, 0, @product_id, :weight)
|
600 |
+
ON DUPLICATE KEY UPDATE
|
601 |
+
`entity_type_id` = @product_entity_type_id,
|
602 |
+
`attribute_id` = @weight_id,
|
603 |
+
`store_id` = 0,
|
604 |
+
`entity_id` = @product_id,
|
605 |
+
`value` = :weight;
|
606 |
+
";
|
607 |
+
|
608 |
+
// eav int
|
609 |
+
$coreSaveSQL .= "
|
610 |
+
INSERT INTO `" . $this->_tablePrefix . "catalog_product_entity_int` (`entity_type_id`, `attribute_id`, `store_id`, `entity_id`, `value`) VALUES
|
611 |
+
(@product_entity_type_id, @status_id, 0, @product_id, :status),
|
612 |
+
(@product_entity_type_id, @visibility_id, 0, @product_id, :visibility),
|
613 |
+
(@product_entity_type_id, @status_id, :store_id, @product_id, :status),
|
614 |
+
(@product_entity_type_id, @visibility_id, :store_id, @product_id, :visibility)
|
615 |
+
ON DUPLICATE KEY UPDATE
|
616 |
+
`entity_type_id` = VALUES(`entity_type_id`),
|
617 |
+
`attribute_id` = VALUES(`attribute_id`),
|
618 |
+
`store_id` = VALUES(`store_id`),
|
619 |
+
`entity_id` = VALUES(`entity_id`),
|
620 |
+
`value` = VALUES(`value`);
|
621 |
+
";
|
622 |
+
|
623 |
+
// categories
|
624 |
+
$categoryId = $productData['categoryId'];
|
625 |
+
$coreSaveSQL .= "
|
626 |
+
INSERT INTO `" . $this->_tablePrefix . "catalog_category_product` (`category_id`, `product_id`, `position`) VALUES
|
627 |
+
(" . (int)$categoryId . ", @product_id, 1);";
|
628 |
+
|
629 |
+
if ($productData['status'] == 'Enabled') {
|
630 |
+
$productData['status'] = 1;
|
631 |
+
} else {
|
632 |
+
$productData['status'] = 0;
|
633 |
+
}
|
634 |
+
|
635 |
+
if ($productData['visibility'] == 'Catalog, Search') {
|
636 |
+
$productData['visibility'] = 4;
|
637 |
+
} else {
|
638 |
+
$productData['visibility'] = 1;
|
639 |
+
}
|
640 |
+
|
641 |
+
try{
|
642 |
+
$this->_connRes->query($coreSaveSQL, array(
|
643 |
+
':store_id' => $productData['storeId'],
|
644 |
+
':sku' => $productData['sku'],
|
645 |
+
':name' => $productData['name'],
|
646 |
+
':mpn' => $productData['mpn'],
|
647 |
+
':brand_name' => $productData['brand_name'],
|
648 |
+
':description' => $productData['description'],
|
649 |
+
':short_description' => $productData['short_description'],
|
650 |
+
':weight' => $productData['weight'],
|
651 |
+
':status' => $productData['status'],
|
652 |
+
':visibility' => $productData['visibility'],
|
653 |
+
':url' => $url,
|
654 |
+
':delivery_eta' => $productData['delivery_eta']
|
655 |
+
));
|
656 |
+
|
657 |
+
} catch (Exception $e) {
|
658 |
+
echo $e->getMessage();
|
659 |
+
}
|
660 |
+
|
661 |
+
$this->_corePriceStock($productData['websiteId'], $productId, $productData['price'], $productData['qty']);
|
662 |
+
|
663 |
+
}
|
664 |
+
|
665 |
+
protected function _corePriceStock($website = false, $productId =false, $price =false, $qty =false) {
|
666 |
+
|
667 |
+
$stockSaveSQL = "
|
668 |
+
INSERT INTO `" . $this->_tablePrefix . "cataloginventory_stock_item` (`product_id`, `stock_id`, `qty`, `is_in_stock`) VALUES
|
669 |
+
(:product_id, (SELECT stock_id FROM `cataloginventory_stock` where stock_name = 'Default'), :qty,1)
|
670 |
+
ON DUPLICATE KEY UPDATE
|
671 |
+
`product_id` = :product_id,
|
672 |
+
`stock_id` = (SELECT stock_id FROM `cataloginventory_stock` where stock_name = 'Default'),
|
673 |
+
`qty` = :qty,
|
674 |
+
`is_in_stock` = 1;
|
675 |
|
676 |
+
INSERT INTO `" . $this->_tablePrefix . "cataloginventory_stock_status` (`product_id`, `website_id`, `stock_id`, `qty`, `stock_status`) VALUES
|
677 |
+
(:product_id, :webisteId, @stock_id, :qty, 1)
|
678 |
+
ON DUPLICATE KEY UPDATE
|
679 |
+
`product_id` = :product_id,
|
680 |
+
`website_id` = :webisteId,
|
681 |
+
`stock_id` = @stock_id,
|
682 |
+
`qty` = :qty,
|
683 |
+
`stock_status` = 1;
|
684 |
+
|
685 |
+
INSERT INTO `" . $this->_tablePrefix . "catalog_product_website` (`product_id`, `website_id`) VALUES
|
686 |
+
(:product_id, :webisteId)
|
687 |
+
ON DUPLICATE KEY UPDATE
|
688 |
+
`product_id` = :product_id,
|
689 |
+
`website_id` = :webisteId;
|
690 |
+
|
691 |
+
INSERT INTO `" . $this->_tablePrefix . "catalog_product_entity_decimal` (`entity_type_id`,`attribute_id`,`store_id`, `entity_id`, `value`) VALUES
|
692 |
+
(@product_entity_type_id, @price_id, 0, :product_id, :price)
|
693 |
+
ON DUPLICATE KEY UPDATE
|
694 |
+
`entity_type_id` = @product_entity_type_id,
|
695 |
+
`attribute_id` = @price_id,
|
696 |
+
`store_id` = 0,
|
697 |
+
`entity_id` = :product_id,
|
698 |
+
`value` = :price;
|
699 |
+
";
|
700 |
+
|
701 |
+
$this->_connRes->query($stockSaveSQL, array(
|
702 |
+
':webisteId' => ($website) ? $website : 0,
|
703 |
+
':product_id' => $productId,
|
704 |
+
':price' => $price,
|
705 |
+
':qty' => $qty
|
706 |
+
));
|
707 |
+
}
|
708 |
+
|
709 |
+
protected function _addCategories($categories, $storeId, $leader_store, $unspsc, $unspscPath, $categoryActive = 1) {
|
710 |
+
// check if product exists
|
711 |
+
$categoryId = $this->_getCategoryIdByUnspsc($unspsc);
|
712 |
+
if (!empty($categoryId)) {
|
713 |
+
if ( 1 == $categoryActive) {
|
714 |
+
$unspscArray = explode('/', $unspscPath);
|
715 |
+
if ($unspscArray) {
|
716 |
+
$activeSetter = "INSERT INTO `" . $this->_tablePrefix . "catalog_category_entity_int` (`entity_type_id`, `attribute_id`, `store_id`, `entity_id`, `value`) VALUES ";
|
717 |
}
|
718 |
+
foreach($unspscArray as $cat_unspsc) {
|
719 |
+
$categoryParrentId = $this->_getCategoryIdByUnspsc($cat_unspsc);
|
720 |
+
$activeSetter .= "(@category_entity_type_id, @category_active_id, :store_id, " . $categoryParrentId . ", 1),
|
721 |
+
(@category_entity_type_id, @category_active_id, 0, " . $categoryParrentId . ", 1), ";
|
|
|
722 |
}
|
723 |
+
$activeSetter = substr($activeSetter, 0, -2);
|
724 |
+
$activeSetter .= "
|
725 |
+
ON DUPLICATE KEY UPDATE
|
726 |
+
`value` = 1
|
727 |
+
";
|
728 |
+
$this->_connRes->query($activeSetter, array(':store_id' => $storeId));
|
729 |
}
|
730 |
+
return $categoryId;
|
731 |
+
} else {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
732 |
|
733 |
+
// merge unspcs to current name in unspcs & name path's
|
734 |
+
$nameArray = explode('/', $categories);
|
735 |
+
$unspscArray = explode('/', $unspscPath);
|
736 |
|
737 |
+
if (count($nameArray) != count($unspscArray)) {
|
738 |
+
$message = Mage::helper('catalog')->__('Skip import row, categories data is invaled');
|
739 |
+
Mage::throwException($message);
|
740 |
+
}
|
741 |
|
742 |
+
$categoryMergedArray = array(
|
743 |
+
array(
|
744 |
+
'unspsc' => 'default_root',
|
745 |
+
'name' => 'Default category'
|
746 |
+
)
|
747 |
+
);
|
748 |
+
|
749 |
+
for($i = 0; $i < count($unspscArray); $i++) {
|
750 |
+
$categoryMergedArray[] = array('name' =>$nameArray[$i],
|
751 |
+
'unspsc' =>$unspscArray[$i]);
|
752 |
}
|
753 |
+
|
754 |
+
// get max created parrent category
|
755 |
+
$categoryCreateArray = array();
|
756 |
+
for ($i = count($categoryMergedArray) -1; $i >= 0; $i--) {
|
757 |
+
$category = $categoryMergedArray[$i];
|
758 |
+
$checkCategoryId = $this->_getCategoryIdByUnspsc($category['unspsc']);
|
759 |
+
if ($checkCategoryId != null) {
|
760 |
+
$categoryId = $this->_buildCategoryTree($checkCategoryId, $storeId, $categoryCreateArray, $categoryActive);
|
761 |
+
break;
|
762 |
+
} else {
|
763 |
+
$categoryCreateArray[] = $category;
|
764 |
+
}
|
765 |
+
}
|
766 |
+
return $categoryId;
|
767 |
+
}
|
768 |
+
}
|
769 |
+
|
770 |
+
protected function _getCategoryIdByUnspsc($unspcs) {
|
771 |
+
if ($unspcs == 'default_root') {
|
772 |
+
return Mage::app()->getStore(1)->getRootCategoryId();
|
773 |
+
} else {
|
774 |
+
$categoryId = $this->_connRes->fetchRow("SELECT entity_id FROM `" . $this->_tablePrefix . "catalog_category_entity_varchar` WHERE
|
775 |
+
`value` = :unspsc AND attribute_id = @unspcs_id", array(':unspsc' => $unspcs));
|
776 |
+
return ($categoryId['entity_id']) ? $categoryId['entity_id'] : null;
|
777 |
+
}
|
778 |
+
}
|
779 |
+
|
780 |
+
protected function _buildCategoryTree($parrentCategoryId, $storeId, $pathArray, $categoryActive = 0) {
|
781 |
+
for ($i = count($pathArray) -1; $i >= 0; $i--) {
|
782 |
+
$category = $pathArray[$i];
|
783 |
+
$parrentCategoryId = $this->_createCategory($parrentCategoryId, $category['unspsc'], $storeId, $category['name'], $categoryActive);
|
784 |
+
}
|
785 |
+
|
786 |
+
return $parrentCategoryId;
|
787 |
+
}
|
788 |
+
|
789 |
+
protected function _createCategory($parrentId, $unspsc, $storeId, $name, $categoryActive = 0) {
|
790 |
+
|
791 |
+
$addCategory = "
|
792 |
+
SELECT @tPath := `path`, @tLevel := `level` FROM `" . $this->_tablePrefix . "catalog_category_entity` WHERE `entity_id` = :parrent_id;
|
793 |
+
SET @tLevel = @tLevel +1;
|
794 |
+
|
795 |
+
SET @path := CONCAT(@tPath, '/',(SELECT MAX(entity_id) FROM `catalog_category_entity`) +1 );
|
796 |
+
|
797 |
+
INSERT INTO `" . $this->_tablePrefix . "catalog_category_entity` (`entity_type_id`, `attribute_set_id`,
|
798 |
+
`parent_id`, `created_at`,
|
799 |
+
`path`, `position`,
|
800 |
+
`level`, `children_count`)
|
801 |
+
VALUES
|
802 |
+
(@category_entity_type_id, 0, :parrent_id, NOW(), @path, 1, @tLevel, 0);
|
803 |
+
|
804 |
+
SELECT @catId := LAST_INSERT_ID();
|
805 |
+
|
806 |
+
UPDATE `" . $this->_tablePrefix . "catalog_category_entity` SET children_count = children_count +1 WHERE entity_id = :parrent_id;
|
807 |
+
|
808 |
+
INSERT IGNORE INTO `" . $this->_tablePrefix . "catalog_category_entity_int` (`entity_type_id`, `attribute_id`,
|
809 |
+
`store_id`, `entity_id`, `value`)
|
810 |
+
VALUES
|
811 |
+
(@category_entity_type_id, @category_active_id, 0, @catId, :category_active),
|
812 |
+
(@category_entity_type_id, @category_active_id, :store, @catId, :category_active),
|
813 |
+
(@category_entity_type_id, @include_nav_bar_id, 0, @catId, 1),
|
814 |
+
(@category_entity_type_id, @include_nav_bar_id, :store, @catId, 1);
|
815 |
+
|
816 |
+
|
817 |
+
INSERT IGNORE INTO `" . $this->_tablePrefix . "catalog_category_entity_varchar` (`entity_type_id`, `attribute_id`,
|
818 |
+
`store_id`, `entity_id`, `value`)
|
819 |
+
VALUES
|
820 |
+
(@category_entity_type_id, @category_name_id, 0, @catId, :category_name),
|
821 |
+
(@category_entity_type_id, @category_name_id, :store, @catId, :category_name),
|
822 |
+
(@category_entity_type_id, @unspcs_id, 0, @catId, :unspsc_val),
|
823 |
+
(@category_entity_type_id, @unspcs_id, :store, @catId, :unspsc_val);
|
824 |
+
";
|
825 |
+
|
826 |
+
$this->_connRes->query($addCategory, array(
|
827 |
+
':store' => $storeId,
|
828 |
+
':parrent_id' => $parrentId,
|
829 |
+
':category_name' => $name,
|
830 |
+
':unspsc_val' => $unspsc,
|
831 |
+
':category_active' => (int)$categoryActive
|
832 |
+
));
|
833 |
+
|
834 |
+
$categoryIdFetch = $this->_connRes->fetchRow('SELECT @catId AS category_id');
|
835 |
+
return $categoryIdFetch['category_id'];
|
836 |
+
}
|
837 |
}
|
package.xml
CHANGED
@@ -1,18 +1,21 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>ice_import</name>
|
4 |
-
<version>1.
|
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 & products</summary>
|
10 |
<description>This extension can use to import products with categories, multiple images and custom options from CSV file.</description>
|
11 |
-
<notes
|
|
|
|
|
|
|
12 |
<authors><author><name>Iceshop</name><user>Iceshop</user><email>support@iceshop.nl</email></author></authors>
|
13 |
-
<date>2012-
|
14 |
-
<time>
|
15 |
-
<contents><target name="magecommunity"><dir name="Capacitywebsolutions"><dir name="Importproduct"><dir name="etc"><file name="config.xml" hash="287d723649aea3da75aa67f5b70fa632"/><file name="system.xml" hash="7a810bc95f4565c6bb09b8634e27109a"/></dir><dir name="Model"><dir name="Convert"><dir name="Adapter"><file name="Product.php" hash="
|
16 |
<compatible/>
|
17 |
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
18 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>ice_import</name>
|
4 |
+
<version>1.1.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 & products</summary>
|
10 |
<description>This extension can use to import products with categories, multiple images and custom options from CSV file.</description>
|
11 |
+
<notes>- Improvement of category tree import
|
12 |
+
- Improvement to speed of import
|
13 |
+
- Added possibility to run import by Cron
|
14 |
+
- Added new field delivery_eta</notes>
|
15 |
<authors><author><name>Iceshop</name><user>Iceshop</user><email>support@iceshop.nl</email></author></authors>
|
16 |
+
<date>2012-09-03</date>
|
17 |
+
<time>10:33:38</time>
|
18 |
+
<contents><target name="magecommunity"><dir name="Capacitywebsolutions"><dir name="Importproduct"><dir name="etc"><file name="config.xml" hash="287d723649aea3da75aa67f5b70fa632"/><file name="system.xml" hash="7a810bc95f4565c6bb09b8634e27109a"/></dir><dir name="Model"><dir name="Convert"><dir name="Adapter"><file name="Product.php" hash="02edef81c4ac6446d60e953e077fb54e"/></dir></dir><dir name="System"><dir name="Config"><file name="Categoryactivity.php" hash="b6765ac67a3dfda7c7fdafb09b0a9374"/><file name="Imageimport.php" hash="6d46e8ff52f3006a4461c0f0d479a190"/><file name="Lockproddetails.php" hash="32a823c0c914348585702536732fed3e"/></dir></dir><file name="Observer.php" hash="8ea437e36f8755a8578f31a8d0141f5a"/></dir><dir name="sql"><dir name="importproduct_setup"><file name="mysql4-install-0.1.0.php" hash="d20ba6989d47a7e3bb896f4e82172303"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Capacitywebsolutions_Importproduct.xml" hash="02cb79dd6ed129ce3aa5305e1bfb4bbf"/></dir></target></contents>
|
19 |
<compatible/>
|
20 |
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
21 |
</package>
|