ice_import - Version 1.8.0

Version Notes

- Updated logic of importing of products and categories
- Speed improvement
- Reduced memory usage

Download this release

Release Info

Developer IceShop
Extension ice_import
Version 1.8.0
Comparing to
See all releases


Code changes from version 1.7.23 to 1.8.0

Files changed (22) hide show
  1. app/code/community/ICEshop/Iceimport/Block/Adminhtml/Dashboard.php +0 -8
  2. app/code/community/ICEshop/Iceimport/Model/Convert/Adapter/Iceimport.php +1259 -0
  3. app/code/community/ICEshop/Iceimport/Model/Convert/Adapter/Product.php +0 -1868
  4. app/code/community/ICEshop/Iceimport/Model/Dataflow/Batch/Import.php +0 -1
  5. app/code/community/ICEshop/Iceimport/Model/Observer.php +62 -46
  6. app/code/community/ICEshop/Iceimport/Model/System/Config/Category.php +33 -0
  7. app/code/community/ICEshop/Iceimport/controllers/Adminhtml/IceimportController.php +0 -9
  8. app/code/community/ICEshop/Iceimport/controllers/Adminhtml/System/Convert/GuiController.php +40 -15
  9. app/code/community/ICEshop/Iceimport/etc/config.xml +4 -9
  10. app/code/community/ICEshop/Iceimport/etc/system.xml +28 -20
  11. app/code/community/ICEshop/Iceimport/include.php +11 -0
  12. app/code/community/ICEshop/Iceimport/sql/iceimport_setup/{mysql4-install-1.7.22.php → mysql4-install-1.8.0.php} +0 -0
  13. app/code/community/ICEshop/Iceimport/sql/iceimport_setup/{mysql4-upgrade-1.7.15-1.7.22.php → mysql4-upgrade-1.7.15-1.8.0.php} +0 -0
  14. app/code/community/ICEshop/Iceimport/sql/iceimport_setup/{mysql4-upgrade-1.7.16-1.7.22.php → mysql4-upgrade-1.7.16-1.8.0.php} +0 -0
  15. app/code/community/ICEshop/Iceimport/sql/iceimport_setup/{mysql4-upgrade-1.7.17-1.7.22.php → mysql4-upgrade-1.7.17-1.8.0.php} +0 -0
  16. app/code/community/ICEshop/Iceimport/sql/iceimport_setup/{mysql4-upgrade-1.7.18-1.7.22.php → mysql4-upgrade-1.7.18-1.8.0.php} +0 -0
  17. app/code/community/ICEshop/Iceimport/sql/iceimport_setup/{mysql4-upgrade-1.7.19-1.7.22.php → mysql4-upgrade-1.7.19-1.8.0.php} +0 -0
  18. app/code/community/ICEshop/Iceimport/sql/iceimport_setup/{mysql4-upgrade-1.7.20-1.7.22.php → mysql4-upgrade-1.7.20-1.8.0.php} +0 -0
  19. app/code/community/ICEshop/Iceimport/sql/iceimport_setup/{mysql4-upgrade-1.7.21-1.7.22.php → mysql4-upgrade-1.7.21-1.8.0.php} +0 -0
  20. app/code/community/ICEshop/Iceimport/sql/iceimport_setup/mysql4-upgrade-1.7.22-1.8.0.php +7 -0
  21. app/code/community/ICEshop/Iceimport/sql/iceimport_setup/{mysql4-upgrade-1.7.8-1.7.22.php → mysql4-upgrade-1.7.8-1.8.0.php} +0 -0
  22. package.xml +8 -15
app/code/community/ICEshop/Iceimport/Block/Adminhtml/Dashboard.php CHANGED
@@ -21,19 +21,11 @@ class ICEshop_Iceimport_Block_Adminhtml_Dashboard extends Mage_Adminhtml_Block_T
21
  $last_imported_products_count = $db->getLogEntryByKey('iceimport_count_imported_products');
22
  $import_filename = $db->getLogEntryByKey('import_filename');
23
  $productivity = $checker->getModulePerformance($last_imported_products_count, $last_started_by_cron, $last_finished_by_cron);
24
- $currently_imported_products = $db->getRowsCount($db->_prefix . "iceshop_iceimport_imported_product_ids");
25
  $data_flows = $db->getRowCountByField($db->getTableName('dataflow_batch_import'), 'batch_id', false, ' ORDER BY 1 DESC LIMIT 50');
26
 
27
  $last_run = $db->readQuery("SELECT `performed_at` FROM {$table_name} WHERE `profile_id` = 3 ORDER BY `performed_at` DESC LIMIT 1");
28
  $last_deleted_products_count = $db->getLogEntryByKey('iceimport_count_delete_product');
29
 
30
- if (!empty($currently_imported_products) && ($import_status_cron['log_value'] == 'Running' || $import_status_cron['log_value'] == 'Failed')) {
31
- $additional = array(
32
- 'label' => $helper->__("Currently products imported"),
33
- 'value' => $currently_imported_products . ' from ' . $data_flows[0]['row_count']
34
- );
35
- }
36
-
37
  //packing response
38
  $response = array(
39
  array(
21
  $last_imported_products_count = $db->getLogEntryByKey('iceimport_count_imported_products');
22
  $import_filename = $db->getLogEntryByKey('import_filename');
23
  $productivity = $checker->getModulePerformance($last_imported_products_count, $last_started_by_cron, $last_finished_by_cron);
 
24
  $data_flows = $db->getRowCountByField($db->getTableName('dataflow_batch_import'), 'batch_id', false, ' ORDER BY 1 DESC LIMIT 50');
25
 
26
  $last_run = $db->readQuery("SELECT `performed_at` FROM {$table_name} WHERE `profile_id` = 3 ORDER BY `performed_at` DESC LIMIT 1");
27
  $last_deleted_products_count = $db->getLogEntryByKey('iceimport_count_delete_product');
28
 
 
 
 
 
 
 
 
29
  //packing response
30
  $response = array(
31
  array(
app/code/community/ICEshop/Iceimport/Model/Convert/Adapter/Iceimport.php ADDED
@@ -0,0 +1,1259 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Iceimport
4
+ {
5
+
6
+ public $arFields = false;
7
+
8
+ public $db_magento = null;
9
+
10
+ public $db_config = [];
11
+
12
+ public $tablePrefix = false;
13
+
14
+ public $arrayForPostfixes = [];
15
+
16
+ public $stores = [];
17
+
18
+ public $count_all_products = 0;
19
+
20
+ public $batch = 100000;
21
+
22
+ public $end = 0;
23
+
24
+ public $filenameCats = 'file.csv';
25
+
26
+ public $filenameValues = 'category_to_product.csv';
27
+
28
+ public $tempFeed = 'tempFeed.csv';
29
+
30
+ public $tempAttr = 'attr.csv';
31
+
32
+ public function __construct ()
33
+ {
34
+
35
+ $config = Mage::getConfig()->getResourceConnectionConfig("default_setup");
36
+
37
+ $dbinfo = ["host" => $config->host,
38
+ "user" => $config->username,
39
+ "pass" => $config->password,
40
+ "dbname" => $config->dbname
41
+ ];
42
+
43
+ $hostname = $dbinfo["host"];
44
+ $user = $dbinfo["user"];
45
+ $password = $dbinfo["pass"];
46
+ $dbname = $dbinfo["dbname"];
47
+
48
+ $this->db_config = [
49
+ 'host' => $hostname,
50
+ 'username' => $user,
51
+ 'password' => $password,
52
+ 'dbname' => $dbname,
53
+ 'driver_options' => [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8', PDO::MYSQL_ATTR_LOCAL_INFILE => true]
54
+ ];
55
+
56
+ $this->db_magento = Zend_Db::factory('Pdo_Mysql', $this->db_config);
57
+
58
+ $tablePrefix = (array)Mage::getConfig()->getTablePrefix();
59
+
60
+ if (!empty($tablePrefix)) {
61
+ $this->tablePrefix = $tablePrefix[0];
62
+ }
63
+
64
+ if (!empty(Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/batch_size'))) {
65
+ $this->batch = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/batch_size');
66
+ }
67
+ }
68
+
69
+ public function makeFileFromArrayForManualLaunching ($importProduct)
70
+ {
71
+
72
+ $fp = fopen($this->tempFeed, 'w+');
73
+
74
+ fputcsv($fp, array_keys($importProduct[0]), "\t");
75
+
76
+ foreach ($importProduct as $fields) {
77
+ fputcsv($fp, $fields, "\t");
78
+ }
79
+
80
+ fclose($fp);
81
+ }
82
+
83
+ public function getGuiData ()
84
+ {
85
+
86
+ $profileId = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/iceimport_profile');
87
+
88
+ if (!$profileId) {
89
+ $profileId = 3;
90
+ }
91
+
92
+ $select_gui_data = $this->db_magento->query("SELECT gui_data FROM `{$this->tablePrefix}dataflow_profile` WHERE profile_id = $profileId;");
93
+ $gui_data = $select_gui_data->fetch()['gui_data'];
94
+ $gui_data = unserialize($gui_data);
95
+ return $gui_data;
96
+ }
97
+
98
+ public function getFileByFTP ()
99
+ {
100
+
101
+ $gui_data = $this->getGuiData();
102
+ $file_name = $gui_data['file']['filename'];
103
+ $url = $gui_data['file']['host'];
104
+ $login = $gui_data['file']['user'];
105
+ $password = $gui_data['file']['password'];
106
+ $file_mode = $gui_data['file']['file_mode'];
107
+ $passive_mode = $gui_data['file']['passive'];
108
+ $path = $gui_data['file']['path'];
109
+ $tmp_file = sys_get_temp_dir() . DS . time() . '_' . $file_name;
110
+
111
+ if (file_exists($tmp_file)) {
112
+ unlink($tmp_file);
113
+ }
114
+
115
+ $conn_id = ftp_connect($url);
116
+
117
+ if (empty($conn_id)) {
118
+ throw new \Exception('Cannot connect by ftp for shop');
119
+ }
120
+
121
+ $login_result = ftp_login($conn_id, $login, $password);
122
+
123
+ if (empty($login_result)) {
124
+ ftp_close($conn_id);
125
+ throw new \Exception('Cannot login on ftp server for shop');
126
+ }
127
+ //set passive mode
128
+ if ($passive_mode == 1) {
129
+ ftp_pasv($conn_id, true);
130
+ }
131
+
132
+ $size = ftp_size($conn_id, $path . $file_name);
133
+ if ($size > 0) {
134
+
135
+ $res = ftp_get($conn_id, $tmp_file, $path . $file_name, $file_mode);
136
+
137
+ if (empty($res)) {
138
+ ftp_close($conn_id);
139
+ throw new \Exception('Cannot get file from ftp server for shop');
140
+ }
141
+ } else {
142
+ throw new \Exception('File on FTP not exists or empty');
143
+ }
144
+
145
+ ftp_close($conn_id);
146
+
147
+ return $tmp_file;
148
+ }
149
+
150
+ public function getDelimiterFromProfile ()
151
+ {
152
+
153
+ $gui_data = $this->getGuiData();
154
+ $delimiter = $gui_data['parse']['delimiter'];
155
+
156
+ if ($delimiter == '\t') {
157
+ $delimiter = "\t";
158
+ }
159
+
160
+ return $delimiter;
161
+
162
+ }
163
+
164
+ public function sendToDb ($importProduct = [])
165
+ {
166
+
167
+ $db_helper = Mage::helper('iceimport/db');
168
+
169
+ $gui_data = $this->getGuiData();
170
+ $if_ftp = $gui_data['file']['type'];
171
+ $delimiter = $this->getDelimiterFromProfile();
172
+ $file_name = $gui_data['file']['filename'];
173
+
174
+ $db_helper->insertLogEntry('import_filename', $file_name, 'info');
175
+
176
+ if (!defined('MAGENTO_ROOT')) {
177
+ define('MAGENTO_ROOT', getcwd());
178
+ }
179
+
180
+ $filepath = MAGENTO_ROOT.DS.$gui_data['file']['path'].DS.$file_name;
181
+
182
+ if (!empty($importProduct)) {
183
+
184
+ $this->makeFileFromArrayForManualLaunching($importProduct);
185
+ $filepath = $this->tempFeed;
186
+ }
187
+
188
+ if ($if_ftp == 'ftp') {
189
+ $filepath = $this->getFileByFTP();
190
+ }
191
+
192
+ $fieldsForCreatingTable = '`id` INT(10) NOT NULL PRIMARY KEY AUTO_INCREMENT, ';
193
+
194
+ $fieldsAr = fgetcsv(fopen($filepath, "r"));
195
+
196
+ if (!$fieldsAr) {
197
+ $this->db_magento->query("INSERT INTO `{$this->tablePrefix}iceshop_extensions_logs` (`log_key`, `log_value`, `log_type`, `timecol`) VALUES ('errorFile', 'Can not find file', 'stat', NOW());");
198
+ echo "Can not find file. \n";
199
+ exit;
200
+ }
201
+
202
+ $fields = str_replace($delimiter, ',', $fieldsAr[0]);
203
+
204
+ $arrayForTable = explode(',', $fields);
205
+
206
+ foreach ($arrayForTable as $key => $field) {
207
+
208
+ if ($field == "") {
209
+ $this->db_magento->query("INSERT INTO `{$this->tablePrefix}iceshop_extensions_logs` (`log_key`, `log_value`, `log_type`, `timecol`) VALUES ('errorColumn', 'Empty column name', 'stat', NOW());");
210
+ echo "Empty column name. \n";
211
+ exit;
212
+ }
213
+ if (stristr($field, '_id') || stristr($field, 'quantity') || stristr($field, 'is_in_stock') || stristr($field, 'central_stock')) {
214
+ $fieldsForCreatingTable .= "`$field` INT(10) DEFAULT NULL, ";
215
+ $this->arrayForPostfixes['int'][] = $field;
216
+ }
217
+
218
+ elseif ($field == 'sku') {
219
+ $fieldsForCreatingTable .= "`$field` VARCHAR(64) NOT NULL, ";
220
+ }
221
+
222
+ elseif (stristr($field, 'price') || stristr($field, 'weight') || stristr($field, 'cost') || $field == 'qty') {
223
+ $fieldsForCreatingTable .= "`$field` DECIMAL(12,4) DEFAULT NULL, ";
224
+ $this->arrayForPostfixes['decimal'][] = $field;
225
+ }
226
+
227
+ elseif ((stristr($field, 'description') && !stristr($field, 'short_') && !stristr($field, 'long_')) || stristr($field, 'categories') || stristr($field, '_tree')) {
228
+ $fieldsForCreatingTable .= "`$field` TEXT DEFAULT NULL, ";
229
+ $this->arrayForPostfixes['text'][] = $field;
230
+ }
231
+
232
+ elseif (stristr($field, 'tax')) {
233
+ $fieldsForCreatingTable .= "`$field` DECIMAL(12,4) DEFAULT NULL, ";
234
+ $this->arrayForPostfixes['taxes'][] = $field;
235
+ }
236
+
237
+ else {
238
+ $fieldsForCreatingTable .= "`$field` VARCHAR(128) DEFAULT NULL, ";
239
+ $this->arrayForPostfixes['varchar'][] = $field;
240
+ }
241
+
242
+ if ($field == 'visibility' || $field == 'status') {
243
+ $this->arrayForPostfixes['int'][] = $field;
244
+ }
245
+ }
246
+
247
+ $fieldsForCreatingTable .= '`entity_id` int(10) DEFAULT NULL,`attribute_set_id` smallint(5) DEFAULT NULL, `entity_type_id` smallint(5) DEFAULT NULL, `tax_class_id` int(10) DEFAULT NULL, `is_iceimport` VARCHAR(64) DEFAULT 1, `url_key` VARCHAR(255) DEFAULT NULL,
248
+ `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP';
249
+
250
+ $this->arrayForPostfixes['int'][] = 'tax_class_id';
251
+ $this->arrayForPostfixes['varchar'][] = 'is_iceimport';
252
+ $this->arrayForPostfixes['varchar'][] = 'url_key';
253
+
254
+ $this->db_magento->query("DROP TABLE IF EXISTS {$this->tablePrefix}import_feed;");
255
+ $this->db_magento->query("CREATE TABLE IF NOT EXISTS {$this->tablePrefix}import_feed($fieldsForCreatingTable) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8");
256
+ $this->db_magento->query("LOAD DATA LOCAL INFILE '{$filepath}' IGNORE INTO TABLE {$this->tablePrefix}import_feed FIELDS TERMINATED BY '$delimiter' ENCLOSED BY '' LINES TERMINATED BY '\n' IGNORE 1 LINES ($fields);");
257
+ }
258
+
259
+ public function getDefaultStoreId ()
260
+ {
261
+
262
+ $website_code = Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/websites');
263
+
264
+ $select_website_id = $this->db_magento->query("SELECT website_id FROM `{$this->tablePrefix}core_website` WHERE `code` = '$website_code';");
265
+ $website_id = $select_website_id->fetch()['website_id'];
266
+
267
+ $select_default_store_id = $this->db_magento->query("SELECT default_store_id FROM `{$this->tablePrefix}core_store_group` WHERE website_id = $website_id;");
268
+ $default_store_id = $select_default_store_id->fetch()['default_store_id'];
269
+
270
+ return $default_store_id;
271
+ }
272
+
273
+ public function updateFeedTable ($importProduct = [])
274
+ {
275
+
276
+ $this->sendToDb($importProduct);
277
+
278
+ $defaulttaxConf = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/default_tax');
279
+
280
+ $select_product_entity_type_id = $this->db_magento->query("SELECT entity_type_id FROM `{$this->tablePrefix}eav_entity_type` WHERE entity_type_code = 'catalog_product';");
281
+ $product_entity_type_id = $select_product_entity_type_id->fetch()['entity_type_id'];
282
+ $select_attribute_set_id = $this->db_magento->query("SELECT `default_attribute_set_id` FROM `{$this->tablePrefix}eav_entity_type` WHERE entity_type_code = 'catalog_product';");
283
+ $attribute_set_id = $select_attribute_set_id->fetch()['default_attribute_set_id'];
284
+ $this->db_magento->query("UPDATE `{$this->tablePrefix}import_feed` SET `entity_type_id` = $product_entity_type_id;");
285
+ $this->db_magento->query("UPDATE `{$this->tablePrefix}import_feed` SET `attribute_set_id` = $attribute_set_id;");
286
+ $this->db_magento->query("DELETE FROM `{$this->tablePrefix}import_feed` WHERE sku = '';");
287
+
288
+ foreach ($this->arrayForPostfixes['varchar'] as $i) {
289
+
290
+ $this->db_magento->query("UPDATE `{$this->tablePrefix}import_feed` SET $i = TRIM(BOTH '\"' FROM $i);");
291
+ }
292
+
293
+ $update_visibility = "UPDATE `{$this->tablePrefix}import_feed` SET `visibility` = CASE WHEN visibility = 'Not Visible Individually' THEN ". Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE. " WHEN visibility = 'Catalog' THEN ". Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG. " WHEN visibility = 'Search' THEN ". Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_SEARCH. " WHEN visibility = 'Catalog, Search' THEN ". Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH. " ELSE visibility END;";
294
+ $this->db_magento->query($update_visibility);
295
+
296
+ $update_status = "UPDATE `{$this->tablePrefix}import_feed` SET `status` = CASE WHEN status = 'Enabled' THEN ". Mage_Catalog_Model_Product_Status::STATUS_ENABLED ." ELSE ". Mage_Catalog_Model_Product_Status::STATUS_DISABLED ." END;";
297
+ $this->db_magento->query($update_status);
298
+
299
+ $this->db_magento->query("UPDATE `{$this->tablePrefix}import_feed` SET `tax_class_id` = $defaulttaxConf;");
300
+ $this->db_magento->query("UPDATE `{$this->tablePrefix}import_feed` SET `url_key` = LOWER(REPLACE(REPLACE(REPLACE(REPLACE(name, ' ', '-'), '/', '-'), '*', ''), ',', ''));");
301
+
302
+ // Update stores
303
+
304
+ $default_store_id = $this->getDefaultStoreId();
305
+ $stores_array = $this->db_magento->fetchAll("SELECT `store_id`, `code` FROM {$this->tablePrefix}core_store WHERE store_id <> 0;");
306
+ $this->stores = $stores_array;
307
+ $query_for_store_update = "UPDATE `{$this->tablePrefix}import_feed` SET `store` = CASE WHEN store = 'default' THEN $default_store_id ";
308
+
309
+ foreach ($stores_array as $store) {
310
+
311
+ $store_code = $store['code'];
312
+ $store_id = $store['store_id'];
313
+ $query_for_store_update .= "WHEN store = '$store_code' THEN $store_id ";
314
+ }
315
+
316
+ $query_for_store_update .= 'ELSE store END;';
317
+
318
+ $this->db_magento->query($query_for_store_update);
319
+ }
320
+
321
+ public function getUnspscToCatId ()
322
+ {
323
+
324
+ $select_category_entity_type = $this->db_magento->query("SELECT entity_type_id FROM `{$this->tablePrefix}eav_entity_type` WHERE entity_type_code = 'catalog_category';");
325
+ $category_entity_type = $select_category_entity_type->fetch()['entity_type_id'];
326
+ $select_unspsc_id = $this->db_magento->query("SELECT attribute_id FROM `{$this->tablePrefix}eav_attribute` WHERE attribute_code = 'unspsc' AND entity_type_id = $category_entity_type;");
327
+ $unspsc_id = $select_unspsc_id->fetch()['attribute_id'];
328
+ $select_unspsc_to_id = $this->db_magento->query("SELECT `entity_id`, `value` FROM `{$this->tablePrefix}catalog_category_entity_varchar` WHERE attribute_id = $unspsc_id AND store_id = 0;");
329
+
330
+ return $select_unspsc_to_id->fetchAll(PDO::FETCH_KEY_PAIR);
331
+ }
332
+
333
+ public function addCatIdToArray ($offset)
334
+ {
335
+
336
+ $unspscToCatId = $this->getUnspscToCatId();
337
+ $unspscToProdId = $this->db_magento->fetchAll("SELECT `unspsc`, `entity_id` FROM `{$this->tablePrefix}import_feed` GROUP BY `entity_id` LIMIT $offset, $this->batch;");
338
+
339
+ $resultArray = [];
340
+ foreach ($unspscToProdId as $key => &$value) {
341
+
342
+ foreach ($unspscToCatId as $k => $item) {
343
+
344
+ if ($value['unspsc'] == $item) {
345
+ $resultArray[$key]['unspsc'] = $k;
346
+ $resultArray[$key]['entity_id'] = $value['entity_id'];
347
+ }
348
+ }
349
+ }
350
+
351
+ return $resultArray;
352
+ }
353
+
354
+ public function makeTempFileForCatalogCategoryProductInsert ($offset)
355
+ {
356
+
357
+ $this->deleteTempFileForCatalogCategoryProductInsert();
358
+
359
+ $arValues = $this->addCatIdToArray($offset);
360
+ $columns = ['category_id', 'product_id'];
361
+ $fp = fopen($this->filenameValues, 'w+');
362
+
363
+ fputcsv($fp, array_unique($columns), "\t");
364
+
365
+ foreach ($arValues as $fields) {
366
+ fputcsv($fp, $fields, "\t");
367
+ }
368
+
369
+ fclose($fp);
370
+
371
+ // delete categories for set new
372
+
373
+ $final = array_map(function ($elements) {
374
+ return $elements['entity_id'];
375
+ }, $arValues);
376
+
377
+ if (!empty($final)) {
378
+ $this->db_magento->query("DELETE FROM {$this->tablePrefix}catalog_category_product WHERE product_id IN (" . implode(',', $final) . ");");
379
+ }
380
+ }
381
+
382
+ public function loadDataToCatalogCategoryProduct()
383
+ {
384
+
385
+ $continue = true;
386
+ $counter = 0;
387
+
388
+ while ($continue) {
389
+
390
+ $offset = $counter * $this->batch;
391
+
392
+ $this->makeTempFileForCatalogCategoryProductInsert($offset);
393
+
394
+ $this->db_magento->query("LOAD DATA LOCAL INFILE '{$this->filenameValues}' IGNORE INTO TABLE {$this->tablePrefix}catalog_category_product FIELDS TERMINATED BY '\t' ENCLOSED BY '' LINES TERMINATED BY '\n' IGNORE 1 LINES (category_id, product_id);");
395
+ $this->db_magento->query("UPDATE {$this->tablePrefix}catalog_category_product SET position = 1;");
396
+
397
+ if ($counter == $this->end) {
398
+
399
+ $continue = false;
400
+ }
401
+
402
+ $counter++;
403
+ }
404
+ }
405
+
406
+ public function getCategoriesEntityId ()
407
+ {
408
+
409
+ $select_data = $this->db_magento->query("SELECT `entity_id`, `path` FROM `{$this->tablePrefix}catalog_category_entity` WHERE entity_id <> 1 AND entity_id <> 2 ORDER BY entity_id;");
410
+ return $select_data->fetchAll(PDO::FETCH_KEY_PAIR);
411
+ }
412
+
413
+ public function prepareArrayForInsertCategories ()
414
+ {
415
+
416
+ $select_max_qty_of_slashes = $this->db_magento->query("select MAX(LENGTH(`categories`) - LENGTH(REPLACE(`categories`, '/', ''))) as `max_qty_of_slashes` from `{$this->tablePrefix}import_feed`;");
417
+ $max_qty_of_slashes = $select_max_qty_of_slashes->fetch()['max_qty_of_slashes'] + 1;
418
+
419
+ $selectCategories = "";
420
+
421
+ for ($i = 1; $i <= $max_qty_of_slashes; $i++) {
422
+ if ($i == 1) {
423
+ $selectCategories .= "select SUBSTRING_INDEX(categories,'/', $i) category, SUBSTRING_INDEX(unspsc_path,'/', $i) as unspsc_c, unspsc_path, categories path, store
424
+ from {$this->tablePrefix}import_feed
425
+ group by store, unspsc_c union ";
426
+ } else {
427
+ $selectCategories .= "select (SUBSTRING_INDEX(SUBSTRING_INDEX(categories,'/', $i),'/',-1)) category, (SUBSTRING_INDEX(SUBSTRING_INDEX(unspsc_path,'/', $i),'/',-1)) as unspsc_c, unspsc_path, categories path, store
428
+ from {$this->tablePrefix}import_feed
429
+ group by store, unspsc_c union ";
430
+ }
431
+ }
432
+
433
+ $selectCategories = rtrim($selectCategories, 'union ');
434
+ $selectCategories .= " order by unspsc_c;";
435
+
436
+ $categories = $this->db_magento->fetchAll($selectCategories);
437
+
438
+ $unique_categories = [];
439
+
440
+ foreach ($categories as $key => $category) {
441
+
442
+ $path = explode('/', $category['unspsc_path']);
443
+ $category['unspsc_path_c'] = '';
444
+
445
+ foreach ($path as $k => $cat) {
446
+ if ($cat == $category['unspsc_c']) {
447
+ $category['level'] = $k + 2;
448
+ break;
449
+ }
450
+ }
451
+
452
+ $unsps_s = $category['store'].$category['unspsc_c'];
453
+
454
+ if (!array_key_exists($unsps_s, $unique_categories)) {
455
+ $unique_categories[$unsps_s] = $category;
456
+ }
457
+ }
458
+
459
+ foreach ($unique_categories as $key => &$category) {
460
+
461
+ $path = explode('/', $unique_categories[$key]['unspsc_path']);
462
+
463
+ foreach ($path as $cat) {
464
+ foreach ($unique_categories as $k => $item) {
465
+ if ($cat == $item['unspsc_c']) {
466
+ $category['unspsc_path_c'] .= $item['unspsc_c'].'/';
467
+ break;
468
+ }
469
+ }
470
+ if ($cat == $category['unspsc_c']) {
471
+ break;
472
+ }
473
+ }
474
+
475
+ $category['unspsc_path_c'] = rtrim($category['unspsc_path_c'], '/');
476
+ }
477
+
478
+ return $unique_categories;
479
+ }
480
+
481
+ public function makeTempFileForCategories ()
482
+ {
483
+
484
+ $this->deleteTempFileForCategories();
485
+ $arCats = $this->prepareArrayForInsertCategories();
486
+ $columns = [];
487
+
488
+ foreach ($arCats as &$value) {
489
+ foreach ($value as $key => $item) {
490
+ if ($key == 'path') {
491
+ unset($value[$key]);
492
+ }
493
+ else {
494
+ $columns[] = $key;
495
+ }
496
+ }
497
+ }
498
+
499
+ $fp = fopen($this->filenameCats, 'w+');
500
+
501
+ fputcsv($fp, array_unique($columns), "\t");
502
+
503
+ foreach ($arCats as $fields) {
504
+ fputcsv($fp, $fields, "\t");
505
+ }
506
+
507
+ fclose($fp);
508
+
509
+ }
510
+
511
+ public function processTemFileForAttributes ($attributes)
512
+ {
513
+
514
+ $delimiter = $this->getDelimiterFromProfile();
515
+
516
+ $this->deleteTemFileForAttributes();
517
+
518
+ $fp = fopen($this->tempAttr, 'w+');
519
+
520
+ foreach ($attributes as $fields) {
521
+ fputcsv($fp, $fields, $delimiter);
522
+ $fields['store'] = 0;
523
+ fputcsv($fp, $fields, $delimiter);
524
+ }
525
+
526
+ fclose($fp);
527
+ }
528
+
529
+ public function insertIdsInCatalogCategoryEntity ()
530
+ {
531
+
532
+ $now = date("Y-m-d H:i:s");
533
+
534
+ $select_attribute_set_id = $this->db_magento->query("SELECT `default_attribute_set_id` FROM `{$this->tablePrefix}eav_entity_type` WHERE entity_type_code = 'catalog_category';");
535
+ $attribute_set_id = $select_attribute_set_id->fetch()['default_attribute_set_id'];
536
+
537
+ $select_category_entity_type = $this->db_magento->query("SELECT entity_type_id FROM `{$this->tablePrefix}eav_entity_type` WHERE entity_type_code = 'catalog_category';");
538
+ $category_entity_type = $select_category_entity_type->fetch()['entity_type_id'];
539
+
540
+ $select_unspsc_id = $this->db_magento->query("SELECT attribute_id FROM `{$this->tablePrefix}eav_attribute` WHERE attribute_code = 'unspsc' AND entity_type_id = $category_entity_type;");
541
+ $unspsc_id = $select_unspsc_id->fetch()['attribute_id'];
542
+ $this->db_magento->query("INSERT INTO {$this->tablePrefix}catalog_category_entity (`entity_type_id`, `attribute_set_id`, `path`, `level`, `created_at`, `updated_at`) SELECT $category_entity_type, $attribute_set_id, tc.unspsc_path_c, tc.level, '$now', '$now' FROM {$this->tablePrefix}temp_cats tc WHERE unspsc_c NOT IN (SELECT value FROM {$this->tablePrefix}catalog_category_entity_varchar WHERE attribute_id = $unspsc_id) GROUP BY tc.unspsc_path_c;");
543
+ }
544
+
545
+ public function updateCategoryPath ()
546
+ {
547
+
548
+ $unspsc_ids = $this->db_magento->fetchAll("SELECT id, unspsc_c, unspsc_path_c FROM `{$this->tablePrefix}temp_cats`;");
549
+
550
+ $select_root_category_id = $this->db_magento->query("SELECT entity_id FROM `{$this->tablePrefix}catalog_category_entity` WHERE level = 0;");
551
+ $root_category_id = $select_root_category_id->fetch()['entity_id'];
552
+
553
+ if (!$root_category_id) {
554
+ $this->db_magento->query("INSERT INTO `{$this->tablePrefix}iceshop_extensions_logs` (`log_key`, `log_value`, `log_type`, `timecol`) VALUES ('errorRootCategory', 'There is no root category in shop.', 'stat', NOW());");
555
+ echo "There is no root category in your shop. \n";
556
+ exit;
557
+ }
558
+
559
+ $default_category_from_config = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/default_category');
560
+
561
+ if (!$default_category_from_config) {
562
+ $this->db_magento->query("INSERT INTO `{$this->tablePrefix}iceshop_extensions_logs` (`log_key`, `log_value`, `log_type`, `timecol`) VALUES ('errorDefaultCategory', 'There is no default category in shop.', 'stat', NOW());");
563
+ echo "There is no default category in your shop. \n";
564
+ exit;
565
+ }
566
+
567
+ foreach ($unspsc_ids as $k => &$unspsc_id) {
568
+
569
+ $unspsc_id['cat_path'] = $root_category_id.'/'.$default_category_from_config.'/';
570
+ $paths = explode('/', $unspsc_id['unspsc_path_c']);
571
+
572
+ foreach ($paths as $path) {
573
+ foreach ($unspsc_ids as $key => $item) {
574
+ if ($path == $item['unspsc_c']) {
575
+ $unspsc_id['cat_path'] .= $item['id'].'/';
576
+ break;
577
+ }
578
+ }
579
+
580
+ if ($path == $unspsc_ids[$k]['unspsc_c']) {
581
+ break;
582
+ }
583
+ }
584
+
585
+ $unspsc_id['cat_path'] = rtrim($unspsc_id['cat_path'], '/');
586
+ $parent = explode('/', $unspsc_id['cat_path']);
587
+ $unspsc_id['parent_id'] = $parent[count($parent) - 2];
588
+ }
589
+
590
+ $query_for_update_path = "UPDATE `{$this->tablePrefix}catalog_category_entity` SET `path` = CASE ";
591
+
592
+ foreach ($unspsc_ids as $k => $v) {
593
+
594
+ $id = $v['id'];
595
+ $path = $v['cat_path'];
596
+ $query_for_update_path .= "WHEN entity_id = '$id' THEN '$path' ";
597
+ }
598
+
599
+ $query_for_update_path .= 'ELSE path END;';
600
+
601
+ $this->db_magento->query($query_for_update_path);
602
+
603
+ $query_for_update_parent_id = "UPDATE `{$this->tablePrefix}catalog_category_entity` SET `parent_id` = CASE ";
604
+
605
+ foreach ($unspsc_ids as $key => $unspsc_id) {
606
+ $id = $unspsc_id['id'];
607
+ $parent_id = $unspsc_id['parent_id'];
608
+ $query_for_update_parent_id .= "WHEN entity_id = '$id' THEN '$parent_id' ";
609
+ }
610
+
611
+ $query_for_update_parent_id .= 'ELSE parent_id END;';
612
+ $this->db_magento->query($query_for_update_parent_id);
613
+ }
614
+
615
+ public function makeTempTableForCategories ()
616
+ {
617
+
618
+ $fieldsForCreatingTable = '`row_id` INT(10) NOT NULL PRIMARY KEY AUTO_INCREMENT, ';
619
+
620
+ $fieldsAr = fgetcsv(fopen($this->filenameCats, "r"));
621
+ $fields = str_replace("\t", ',', $fieldsAr[0]);
622
+ $arrayForTable = explode(',', $fields);
623
+
624
+ foreach ($arrayForTable as $key => $field) {
625
+
626
+ if ($field == 'level' || $field == 'parent_id') {
627
+ $fieldsForCreatingTable .= "`$field` INT(10) DEFAULT NULL, ";
628
+ }
629
+ else {
630
+ $fieldsForCreatingTable .= "`$field` VARCHAR(128) DEFAULT NULL, ";
631
+ }
632
+ }
633
+
634
+ $fieldsForCreatingTable = rtrim($fieldsForCreatingTable, ', ');
635
+
636
+ $this->db_magento->query("DROP TABLE IF EXISTS {$this->tablePrefix}temp_cats;");
637
+ $this->db_magento->query("CREATE TABLE IF NOT EXISTS {$this->tablePrefix}temp_cats($fieldsForCreatingTable, id INT(10) DEFAULT NULL, `url_key` VARCHAR(255) DEFAULT NULL) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8");
638
+
639
+ $this->db_magento->query("LOAD DATA LOCAL INFILE '{$this->filenameCats}' IGNORE INTO TABLE {$this->tablePrefix}temp_cats FIELDS TERMINATED BY '\t' ENCLOSED BY '' LINES TERMINATED BY '\n' IGNORE 1 LINES ($fields);");
640
+
641
+ }
642
+
643
+ public function countAllProducts ()
644
+ {
645
+
646
+ $select_count_all_products = $this->db_magento->query("SELECT COUNT(DISTINCT sku) as count_all_prods FROM {$this->tablePrefix}import_feed;");
647
+ $this->count_all_products = $select_count_all_products->fetch()['count_all_prods'];
648
+ }
649
+
650
+ public function importProduct ($importProduct = [])
651
+ {
652
+
653
+ $this->updateFeedTable($importProduct);
654
+
655
+ $this->countAllProducts();
656
+ $this->end = ceil($this->count_all_products / $this->batch);
657
+
658
+ $websites = Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/websites');
659
+ $website = Mage::app()->getWebsite(trim($websites));
660
+ $websiteId = $website->getId();
661
+
662
+ $countryCode = Mage::getStoreConfig('general/country/default');
663
+
664
+ // new products
665
+ $newProducts = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/import_new_products');
666
+
667
+ // product attributes
668
+ $producteanConf = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/import_product_ean');
669
+ $productmpnConf = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/import_product_mpn');
670
+ $productbrandConf = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/import_product_brand_name');
671
+ $productnameConf = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/import_product_name');
672
+ $productshdescriptionConf = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/import_product_short_description');
673
+ $productdescriptionConf = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/import_product_description');
674
+ $deliveryetaConf = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/import_product_delivery_eta');
675
+ $updateStatusFromCsvConf = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/update_status_from_csv');
676
+ $updateVisibilityFromCsvConf = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/update_visibility_from_csv');
677
+ $updateUrlKeyFromCsvConf = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/update_url_key_from_csv');
678
+
679
+ // Images
680
+ $addImages = Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/import_images');
681
+
682
+ // p&a
683
+ $productpricesConf = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/import_prices');
684
+ $productstockConf = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/import_stock');
685
+ $updateIsInStockFromCsvConf = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/update_is_in_stock_from_csv');
686
+
687
+ // categories
688
+ $categoriesConf = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/update_categories_from_csv');
689
+ $categoriesToActiveConf = Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/category_active');
690
+
691
+ // mapping
692
+ $config_mpn = Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/attribute_mapping_mpn');
693
+ $config_brand = Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/attribute_mapping_brand_name');
694
+ $config_gtin = Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/attribute_mapping_ean');
695
+ $config_delivery_eta = Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/attribute_mapping_delivery_eta');
696
+
697
+ // sorting
698
+ $default_store_id = $this->getDefaultStoreId();
699
+
700
+ // importing products
701
+ if (!$newProducts) {
702
+ $this->db_magento->query("DELETE FROM `{$this->tablePrefix}import_feed` WHERE sku NOT IN (SELECT sku FROM `{$this->tablePrefix}catalog_product_entity`);");
703
+ }
704
+
705
+ //check for empty main table
706
+ $main_table_query = $this->db_magento->query("SELECT COUNT(*) as cnt_rows FROM `{$this->tablePrefix}import_feed` WHERE 1;");
707
+ $main_table_check = $main_table_query->fetch()['cnt_rows'];
708
+
709
+ if (!empty($main_table_check)) {
710
+
711
+ $this->db_magento->query("UPDATE `{$this->tablePrefix}catalog_product_entity` cpe JOIN {$this->tablePrefix}import_feed impf ON cpe.sku = impf.sku SET cpe.`sku` = impf.sku, cpe.`entity_type_id` = impf.entity_type_id, cpe.`attribute_set_id` = impf.attribute_set_id, cpe.`type_id` = 'simple', cpe.`updated_at` = impf.updated_at;");
712
+
713
+ $this->db_magento->query("INSERT INTO `{$this->tablePrefix}catalog_product_entity` (`sku`, `entity_type_id`, `attribute_set_id`, `type_id`, `created_at`, `updated_at`) SELECT impf.sku, impf.entity_type_id, impf.attribute_set_id, 'simple', impf.created_at, impf.updated_at
714
+ FROM {$this->tablePrefix}import_feed impf WHERE sku NOT IN (SELECT sku FROM {$this->tablePrefix}catalog_product_entity WHERE sku IS NOT NULL) GROUP BY impf.sku;");
715
+
716
+ $this->db_magento->query("UPDATE `{$this->tablePrefix}import_feed` impf JOIN `{$this->tablePrefix}catalog_product_entity` cpe ON impf.sku = cpe.sku SET impf.entity_id = cpe.entity_id;");
717
+ $this->db_magento->query("INSERT INTO `{$this->tablePrefix}iceshop_iceimport_imported_product_ids` (`product_id`, `product_sku`) SELECT impf.entity_id, impf.sku FROM `{$this->tablePrefix}import_feed` impf ON DUPLICATE KEY UPDATE product_sku = impf.sku;");
718
+
719
+ $this->db_magento->query("INSERT INTO `{$this->tablePrefix}catalog_product_website` (`product_id`, `website_id`) SELECT impf.entity_id, $websiteId FROM {$this->tablePrefix}import_feed impf ON DUPLICATE KEY UPDATE product_id = impf.entity_id, website_id = $websiteId;");
720
+
721
+ $select_product_entity_type_id = $this->db_magento->query("SELECT entity_type_id FROM `{$this->tablePrefix}eav_entity_type` WHERE entity_type_code = 'catalog_product';");
722
+ $product_entity_type_id = $select_product_entity_type_id->fetch()['entity_type_id'];
723
+
724
+ if (!$config_mpn || !$config_brand || !$config_gtin || !$config_delivery_eta) {
725
+ $this->db_magento->query("INSERT INTO `{$this->tablePrefix}iceshop_extensions_logs` (`log_key`, `log_value`, `log_type`, `timecol`) VALUES ('errorMapping', 'Mapings are incorrect.', 'stat', NOW());");
726
+ echo "Mapings are incorrect. \n";
727
+ exit;
728
+ }
729
+
730
+ if ($addImages) {
731
+ $this->db_magento->query("INSERT IGNORE INTO `{$this->tablePrefix}iceshop_iceimport_image_queue` (`entity_id`, `image_url`) SELECT impf.entity_id, impf.image FROM `{$this->tablePrefix}import_feed` impf ;");
732
+ }
733
+
734
+ foreach ($this->arrayForPostfixes as $key => $value) {
735
+ if ($key != 'taxes') {
736
+
737
+ foreach ($value as $k => $attr) {
738
+ $front_input = false;
739
+ if ($attr == 'mpn' && !$productmpnConf ||
740
+ $attr == 'ean' && !$producteanConf ||
741
+ $attr == 'brand_name' && !$productbrandConf ||
742
+ $attr == 'delivery_eta' && !$deliveryetaConf ||
743
+ $attr == 'description' && !$productdescriptionConf ||
744
+ $attr == 'short_description' && !$productshdescriptionConf ||
745
+ $attr == 'visibility' && !$updateVisibilityFromCsvConf ||
746
+ $attr == 'url_key' && !$updateUrlKeyFromCsvConf ||
747
+ $attr == 'name' && !$productnameConf ||
748
+ $attr == 'price' && !$productpricesConf ||
749
+ $attr == 'status' && !$updateStatusFromCsvConf
750
+ ) {
751
+ continue;
752
+ }
753
+
754
+ $attr_for_select = $attr;
755
+
756
+ switch ($attr_for_select) {
757
+ case 'mpn':
758
+ $attr_for_select = $config_mpn;
759
+ break;
760
+ case 'delivery_eta':
761
+ $attr_for_select = $config_delivery_eta;
762
+ break;
763
+ case 'brand_name':
764
+ $attr_for_select = $config_brand;
765
+ break;
766
+ case 'ean':
767
+ $attr_for_select = $config_gtin;
768
+ break;
769
+ }
770
+
771
+ $select_attribute_id = $this->db_magento->query("SELECT `attribute_id`, `frontend_input`, `source_model` FROM `{$this->tablePrefix}eav_attribute` WHERE attribute_code = '$attr_for_select' AND entity_type_id = $product_entity_type_id;");
772
+ $tmp_attribute = $select_attribute_id->fetch();
773
+ $attribute_id = (isset($tmp_attribute['attribute_id'])) ? $tmp_attribute['attribute_id'] : null;
774
+ $frontend_input = (isset($tmp_attribute['frontend_input'])) ? $tmp_attribute['frontend_input'] : null;
775
+ $source_model = (isset($tmp_attribute['source_model'])) ? $tmp_attribute['source_model'] : null;
776
+
777
+ if ($attribute_id) {
778
+
779
+ if ($frontend_input == 'select' && ($source_model == 'eav/entity_attribute_source_table' || empty($source_model))) {
780
+ $front_input = true;
781
+
782
+ $brands_in_store = [];
783
+ $elements = [];
784
+ $brands_in_store = $this->db_magento->fetchAll("SELECT DISTINCT `{$attr}` FROM {$this->tablePrefix}import_feed WHERE `{$attr}` NOT IN (SELECT `value` FROM {$this->tablePrefix}eav_attribute_option_value eavov LEFT JOIN {$this->tablePrefix}eav_attribute_option eavo ON eavov.option_id = eavo.option_id WHERE eavo.attribute_id = '{$attribute_id}') AND `{$attr}` <> '';");
785
+
786
+ if (!empty($brands_in_store)) {
787
+ $final = array_map(function ($elements) use ($attr) {
788
+ return $elements[$attr];
789
+ }, $brands_in_store);
790
+
791
+ $attribute_model = Mage::getModel('eav/entity_attribute');
792
+ $attribute_options_model = Mage::getModel('eav/entity_attribute_source_table');
793
+
794
+ $attribute_code = $attribute_model->getIdByCode('catalog_product', $attr_for_select);
795
+ $attribute = $attribute_model->load($attribute_code);
796
+
797
+ $attribute_options_model->setAttribute($attribute);
798
+ $attribute_options_model->getAllOptions(false);
799
+
800
+ foreach ($final as $brand_item) {
801
+ $value = [];
802
+ $value['option'] = [$brand_item];
803
+ $result = ['value' => $value];
804
+ $attribute->setData('option', $result);
805
+ $attribute->save();
806
+ }
807
+ }
808
+ }
809
+
810
+ $post_fix = $key;
811
+
812
+ $continue = true;
813
+ $counter = 0;
814
+
815
+ if ($front_input) {
816
+ $this->db_magento->query("UPDATE {$this->tablePrefix}import_feed impf LEFT JOIN (SELECT eavov.`option_id` as option_id, eavov.`value` FROM {$this->tablePrefix}eav_attribute_option_value eavov LEFT JOIN {$this->tablePrefix}eav_attribute_option eavo ON eavov.option_id = eavo.option_id WHERE eavo.attribute_id = '{$attribute_id}') tmptable ON tmptable.value = impf.{$attr} SET impf.{$attr} = tmptable.option_id WHERE tmptable.option_id IS NOT NULL;");
817
+ }
818
+
819
+ while ($continue) {
820
+
821
+ $offset = $counter * $this->batch;
822
+
823
+ if ($front_input) {
824
+ $post_fix = 'int';
825
+ $select_attributes = $this->db_magento->query("SELECT impf.entity_type_id, $attribute_id, impf.store, impf.entity_id, $attr FROM {$this->tablePrefix}import_feed impf LIMIT $offset, $this->batch;");
826
+
827
+ } else {
828
+ $select_attributes = $this->db_magento->query("SELECT impf.entity_type_id, $attribute_id, impf.store, impf.entity_id, $attr FROM {$this->tablePrefix}import_feed impf LIMIT $offset, $this->batch;");
829
+ }
830
+
831
+ $attributes = $select_attributes->fetchAll();
832
+ $this->processTemFileForAttributes($attributes);
833
+
834
+ $delimiter = $this->getDelimiterFromProfile();
835
+ $filepath = $this->tempAttr;
836
+
837
+ $this->db_magento->query("LOAD DATA LOCAL INFILE '{$filepath}' IGNORE INTO TABLE {$this->tablePrefix}catalog_product_entity_{$post_fix} FIELDS TERMINATED BY '$delimiter' ENCLOSED BY '' LINES TERMINATED BY '\n' (entity_type_id, attribute_id, store_id, entity_id, value);");
838
+
839
+ if ($counter == $this->end) {
840
+
841
+ $continue = false;
842
+ }
843
+
844
+ $counter++;
845
+ }
846
+
847
+ $this->db_magento->query("UPDATE {$this->tablePrefix}catalog_product_entity_{$post_fix} cpek JOIN {$this->tablePrefix}import_feed impf ON impf.entity_id = cpek.entity_id SET cpek.value = impf.$attr WHERE cpek.attribute_id = $attribute_id AND cpek.value <> impf.$attr AND cpek.store_id = impf.store AND cpek.entity_type_id = impf.entity_type_id;");
848
+ $this->db_magento->query("UPDATE {$this->tablePrefix}catalog_product_entity_{$post_fix} cpek JOIN {$this->tablePrefix}import_feed impf ON impf.entity_id = cpek.entity_id SET cpek.value = impf.$attr WHERE cpek.attribute_id = $attribute_id AND cpek.value <> impf.$attr AND cpek.store_id = 0 AND cpek.entity_type_id = impf.entity_type_id;");
849
+
850
+ }
851
+ }
852
+ }
853
+ }
854
+
855
+ $this->deleteTemFileForAttributes();
856
+
857
+ if (array_key_exists('taxes', $this->arrayForPostfixes)) {
858
+
859
+ foreach ($this->arrayForPostfixes['taxes'] as $tax) {
860
+
861
+ $select_tax_id = $this->db_magento->query("SELECT `attribute_id` FROM `{$this->tablePrefix}eav_attribute` WHERE attribute_code = '$tax' AND entity_type_id = $product_entity_type_id;");
862
+ $tax_id = $select_tax_id->fetch()['attribute_id'];
863
+
864
+ if ($tax_id) {
865
+ $this->db_magento->query("DELETE FROM `{$this->tablePrefix}weee_tax` WHERE attribute_id = '$tax_id';");
866
+ $this->db_magento->query("INSERT INTO {$this->tablePrefix}weee_tax (website_id, entity_id, country, value, state, attribute_id, entity_type_id) SELECT 0, entity_id, '$countryCode', $tax, '*', $tax_id, $product_entity_type_id FROM {$this->tablePrefix}import_feed;");
867
+ }
868
+ }
869
+ }
870
+
871
+ $stock_name = Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/stock_inventory');
872
+ $select_stock_id = $this->db_magento->query("SELECT stock_id FROM `{$this->tablePrefix}cataloginventory_stock` WHERE stock_name = '$stock_name';");
873
+ $stock_id = $select_stock_id->fetch()['stock_id'];
874
+
875
+ if ($productstockConf) {
876
+ $this->db_magento->query("UPDATE {$this->tablePrefix}import_feed SET qty = 0 WHERE qty IS NULL;");
877
+ $this->db_magento->query("INSERT INTO {$this->tablePrefix}cataloginventory_stock_item (`product_id`, `stock_id`, `qty`, `is_in_stock`) SELECT impf.entity_id, $stock_id, impf.qty, impf.is_in_stock FROM {$this->tablePrefix}import_feed impf
878
+ ON DUPLICATE KEY UPDATE product_id = impf.entity_id, stock_id = $stock_id, qty = impf.qty;");
879
+ }
880
+
881
+ if ($updateIsInStockFromCsvConf) {
882
+ $this->db_magento->query("INSERT INTO {$this->tablePrefix}cataloginventory_stock_status (`product_id`, `website_id`, `stock_id`, `qty`, `stock_status`) SELECT impf.entity_id, $websiteId, $stock_id, impf.qty, impf.is_in_stock FROM {$this->tablePrefix}import_feed impf
883
+ ON DUPLICATE KEY UPDATE product_id = impf.entity_id, stock_id = $stock_id, website_id = $websiteId, qty = impf.qty;");
884
+ }
885
+
886
+ // Creating temp file for categories
887
+ $this->makeTempFileForCategories();
888
+
889
+ // Creating temp table
890
+ $this->makeTempTableForCategories();
891
+
892
+ // catalog_category_entity
893
+ $select_category_entity_type = $this->db_magento->query("SELECT entity_type_id FROM `{$this->tablePrefix}eav_entity_type` WHERE entity_type_code = 'catalog_category';");
894
+ $category_entity_type = $select_category_entity_type->fetch()['entity_type_id'];
895
+
896
+ $select_unspsc_id = $this->db_magento->query("SELECT attribute_id FROM `{$this->tablePrefix}eav_attribute` WHERE attribute_code = 'unspsc' AND entity_type_id = $category_entity_type;");
897
+ $unspsc_id = $select_unspsc_id->fetch()['attribute_id'];
898
+
899
+ $select_name_id = $this->db_magento->query("SELECT attribute_id FROM `{$this->tablePrefix}eav_attribute` WHERE attribute_code = 'name' AND entity_type_id = $category_entity_type;");
900
+ $name_id = $select_name_id->fetch()['attribute_id'];
901
+
902
+ $select_url_key_id = $this->db_magento->query("SELECT attribute_id FROM `{$this->tablePrefix}eav_attribute` WHERE attribute_code = 'url_key' AND entity_type_id = $category_entity_type;");
903
+ $url_key_id = $select_url_key_id->fetch()['attribute_id'];
904
+
905
+ $this->db_magento->query("UPDATE `{$this->tablePrefix}temp_cats` tc JOIN `{$this->tablePrefix}catalog_category_entity_varchar` ccev ON ccev.value = tc.unspsc_c SET tc.id = ccev.entity_id WHERE attribute_id = $unspsc_id AND tc.id IS NULL;");
906
+ $this->db_magento->query("UPDATE `{$this->tablePrefix}temp_cats` SET `category` = TRIM(BOTH '\"' FROM `category`);");
907
+ $this->db_magento->query("UPDATE `{$this->tablePrefix}temp_cats` SET `url_key` = LOWER(REPLACE(REPLACE(REPLACE(category, '&', '-'), '/', '-'), ' ', ''));");
908
+
909
+ $this->insertIdsInCatalogCategoryEntity();
910
+ $this->db_magento->query("UPDATE `{$this->tablePrefix}temp_cats` tc JOIN `{$this->tablePrefix}catalog_category_entity` cce ON cce.path = tc.unspsc_path_c SET tc.id = cce.entity_id;");
911
+
912
+ $this->updateCategoryPath();
913
+
914
+ if ($categoriesConf) {
915
+ // catalog_category_entity_varchar
916
+ $array_for_varchar = ['unspsc_c' => $unspsc_id, 'category' => $name_id, 'url_key' => $url_key_id];
917
+ foreach ($array_for_varchar as $attr_varchar => $attr_varchar_id) {
918
+
919
+ $this->db_magento->query("INSERT INTO {$this->tablePrefix}catalog_category_entity_varchar (`entity_type_id`, `attribute_id`, `store_id`, `entity_id`, `value`) SELECT $category_entity_type, $attr_varchar_id , tc.store, tc.id, tc.$attr_varchar FROM {$this->tablePrefix}temp_cats tc WHERE tc.id <> 0 ON DUPLICATE KEY UPDATE `value` = tc.$attr_varchar;");
920
+ $this->db_magento->query("INSERT INTO {$this->tablePrefix}catalog_category_entity_varchar (`entity_type_id`, `attribute_id`, `store_id`, `entity_id`, `value`) SELECT $category_entity_type, $attr_varchar_id , 0, tc.id, tc.$attr_varchar FROM {$this->tablePrefix}temp_cats tc WHERE store = '$default_store_id' AND tc.id <> 0 ON DUPLICATE KEY UPDATE `value` = tc.$attr_varchar;");
921
+ }
922
+
923
+ // catalog_category_entity_int
924
+ $array_for_int = ['is_active' => $categoriesToActiveConf, 'is_anchor' => 1, 'include_in_menu' => 1];
925
+
926
+ foreach ($array_for_int as $attr_int => $int) {
927
+
928
+ $select_attribute_int = $this->db_magento->query("SELECT attribute_id FROM `{$this->tablePrefix}eav_attribute` WHERE attribute_code = '$attr_int' AND entity_type_id = $category_entity_type;");
929
+ $attribute_int = $select_attribute_int->fetch()['attribute_id'];
930
+
931
+ $this->db_magento->query("INSERT INTO {$this->tablePrefix}catalog_category_entity_int (`entity_type_id`, `attribute_id`, `store_id`, `entity_id`, `value`) SELECT $category_entity_type, $attribute_int , tc.store, tc.id, $int FROM {$this->tablePrefix}temp_cats tc WHERE tc.id <> 0 ON DUPLICATE KEY UPDATE `value` = $int;");
932
+ $this->db_magento->query("INSERT INTO {$this->tablePrefix}catalog_category_entity_int (`entity_type_id`, `attribute_id`, `store_id`, `entity_id`, `value`) SELECT $category_entity_type, $attribute_int , 0, tc.id, $int FROM {$this->tablePrefix}temp_cats tc WHERE store = '$default_store_id' AND tc.id <> 0 ON DUPLICATE KEY UPDATE `value` = $int;");
933
+ }
934
+ }
935
+
936
+ // loading data to catalog_category_product;
937
+ $this->loadDataToCatalogCategoryProduct();
938
+ }
939
+
940
+ // Deleting temp files
941
+ $this->deleteTempFileForCategories();
942
+ $this->deleteTempFileForCatalogCategoryProductInsert();
943
+
944
+ // Deleting temp tables
945
+ $this->deleteTempTableCats();
946
+ $this->deleteTempTableProds();
947
+
948
+ if (!empty($importProduct)) {
949
+ $this->deleteFileFromArrayForManualLaunching();
950
+ }
951
+
952
+ $this->checkAndSetIceField();
953
+ }
954
+
955
+ public function runCategoriesSorting ()
956
+ {
957
+
958
+ $select_number_of_iteration = $this->db_magento->query("SELECT MAX(level) as max FROM `{$this->tablePrefix}catalog_category_entity`;");
959
+ $number_of_iteration = $select_number_of_iteration->fetch()['max'] - 1;
960
+
961
+ $position = 1;
962
+
963
+ if ($number_of_iteration > 0) {
964
+
965
+ for ($i = 1; $i <= $number_of_iteration; $i++) {
966
+
967
+ $query_select_entity_id = "SELECT cce.entity_id FROM `{$this->tablePrefix}catalog_category_entity` cce LEFT JOIN `{$this->tablePrefix}catalog_category_product` ccp ON cce.entity_id = ccp.category_id WHERE ccp.category_id IS NULL AND SUBSTRING_INDEX(cce.path,'/',-1) = cce.entity_id;";
968
+ $empty_categories = $this->db_magento->fetchAll($query_select_entity_id);
969
+
970
+ $final_array = array_map(function ($element) {
971
+ return $element['entity_id'];
972
+ }, $empty_categories);
973
+
974
+ $catCollection = Mage::getModel('catalog/category')
975
+ ->getCollection()
976
+ ->addAttributeToSort('name', 'ASC');
977
+
978
+ $select_category_entity_type = $this->db_magento->query("SELECT entity_type_id FROM `{$this->tablePrefix}eav_entity_type` WHERE entity_type_code = 'catalog_category';");
979
+ $category_entity_type = $select_category_entity_type->fetch()['entity_type_id'];
980
+ $select_attribute_is_active_id = $this->db_magento->query("SELECT attribute_id FROM `{$this->tablePrefix}eav_attribute` WHERE attribute_code = 'is_active' AND entity_type_id = $category_entity_type;");
981
+ $attribute_is_active_id = $select_attribute_is_active_id->fetch()['attribute_id'];
982
+ $update_hide_category = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/update_hide_category');
983
+
984
+ $array_for_updating_is_active = [];
985
+
986
+ foreach ($catCollection as $key => $category) {
987
+
988
+ $query = "UPDATE `{$this->tablePrefix}catalog_category_entity` SET position = :position WHERE entity_id = :cat_id ";
989
+ $this->db_magento->query($query, array(
990
+ ':position' => $position++,
991
+ ':cat_id' => $category->getId()
992
+ ));
993
+
994
+ if ($update_hide_category) {
995
+
996
+ if (in_array($category->getId(), $final_array)){
997
+ $count = count($category->getChildrenCategories());
998
+
999
+ if ($count == 0){
1000
+ $array_for_updating_is_active[] = $category->getId();
1001
+ }
1002
+ }
1003
+ }
1004
+ }
1005
+
1006
+ $ids_for_update_is_active = implode(',', $array_for_updating_is_active);
1007
+
1008
+ if (!empty($ids_for_update_is_active)) {
1009
+ $this->db_magento->query("UPDATE `{$this->tablePrefix}catalog_category_entity_int` SET `value` = 0 WHERE `attribute_id` = $attribute_is_active_id AND `entity_id` IN ($ids_for_update_is_active);");
1010
+ }
1011
+ }
1012
+ }
1013
+ }
1014
+
1015
+ public function deleteOldProducts($DB_logger)
1016
+ {
1017
+
1018
+ try {
1019
+
1020
+ $this->db_magento->query("SELECT @is_iceimport_id := `attribute_id`
1021
+ FROM {$this->tablePrefix}eav_attribute
1022
+ WHERE attribute_code = 'is_iceimport'");
1023
+
1024
+ $count_prod = $this->db_magento->fetchRow("SELECT count(t2.entity_id) AS count_prod FROM (SELECT cpe.entity_id
1025
+ FROM {$this->tablePrefix}catalog_product_entity AS cpe
1026
+ JOIN {$this->tablePrefix}catalog_product_entity_varchar AS cpev
1027
+ ON cpe.entity_id = cpev.entity_id
1028
+ AND cpev.value = 1
1029
+ AND cpev.attribute_id = @is_iceimport_id
1030
+ GROUP BY cpe.entity_id) t2");
1031
+
1032
+ $count_prod = $count_prod['count_prod'];
1033
+
1034
+ if ($count_prod > 0) {
1035
+ //iceimport products exists, amount > 0
1036
+
1037
+ $count_del_prod = $this->db_magento->fetchRow("SELECT count(t1.entity_id) AS count__del_prod FROM (SELECT cpe.entity_id
1038
+ FROM {$this->tablePrefix}catalog_product_entity AS cpe
1039
+ JOIN {$this->tablePrefix}catalog_product_entity_varchar AS cpev
1040
+ ON cpe.entity_id = cpev.entity_id
1041
+ AND cpev.value = 1
1042
+ AND cpev.attribute_id = @is_iceimport_id
1043
+ LEFT JOIN {$this->tablePrefix}iceshop_iceimport_imported_product_ids AS iip
1044
+ ON cpe.entity_id = iip.product_id
1045
+ WHERE iip.product_id IS NULL GROUP BY cpe.entity_id) t1; ");
1046
+
1047
+ if(!empty($count_del_prod['count__del_prod'])){
1048
+ $count_del_prod = $count_del_prod['count__del_prod'];
1049
+ } else {
1050
+ $count_del_prod = 0;
1051
+ }
1052
+
1053
+ if ($count_del_prod > 0) {
1054
+ //iceimport products to delete exists, amount > 0
1055
+ $delete_old_products_tolerance = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/delete_old_products_tolerance');
1056
+
1057
+ if (round(($count_del_prod / $count_prod * 100), 0) <= $delete_old_products_tolerance) {
1058
+
1059
+ //iceimport products to delete franction is less than allowed tolerance, deletion approved
1060
+ $this->db_magento->query("DELETE cpe
1061
+ FROM {$this->tablePrefix}catalog_product_entity AS cpe
1062
+ JOIN {$this->tablePrefix}catalog_product_entity_varchar AS cpev
1063
+ ON cpe.entity_id = cpev.entity_id
1064
+ AND cpev.value = 1
1065
+ AND cpev.attribute_id = @is_iceimport_id
1066
+ LEFT JOIN {$this->tablePrefix}iceshop_iceimport_imported_product_ids AS iip
1067
+ ON cpe.entity_id = iip.product_id
1068
+ WHERE iip.product_id IS NULL");
1069
+
1070
+ $this->db_magento->query("TRUNCATE TABLE {$this->tablePrefix}iceshop_iceimport_imported_product_ids");
1071
+ } else {
1072
+ $error_message = 'Attempt to delete more old products than allowed in Iceimport configuration. Interruption of the process.';
1073
+ $DB_logger->insertLogEntry('error_try_delete_product', $error_message);
1074
+ $error_message2 = 'Old product percentage: ' . round(($count_del_prod / $count_prod * 100), 2) . '%';
1075
+ $DB_logger->insertLogEntry('error_try_delete_product_percentage', $error_message2);
1076
+
1077
+ //flag to warning notice
1078
+ $DB_logger->insertLogEntry('try_delete_product_percentage_warning_flag', 'SHOW');
1079
+ $DB_logger->insertLogEntry('iceimport_count_delete_product', $count_del_prod);
1080
+ print $error_message;
1081
+ print $error_message2;
1082
+ exit;
1083
+ }
1084
+ }
1085
+ $DB_logger->insertLogEntry('iceimport_count_delete_product', $count_del_prod);
1086
+ }
1087
+ } catch (Exception $e) {
1088
+ throw new Exception($e->getMessage());
1089
+ }
1090
+ }
1091
+
1092
+ public function processImageQueue($logFileName)
1093
+ {
1094
+
1095
+ $queueList = $this->db_magento->fetchAll("SELECT `queue_id`, `entity_id`, `image_url` FROM `{$this->tablePrefix}iceshop_iceimport_image_queue` WHERE `is_downloaded` = 0");
1096
+ if (count($queueList) > 0) {
1097
+ $mediaDir = Mage::getBaseDir('media');
1098
+ foreach ($queueList as $queue) {
1099
+
1100
+ $queueId = $queue['queue_id'];
1101
+ $productId = $queue['entity_id'];
1102
+ $imageUrl = $queue['image_url'];
1103
+
1104
+ try {
1105
+ $preImageName = explode('/', $imageUrl);
1106
+ $imageName = array_pop($preImageName);
1107
+ if (file_exists($mediaDir . DS . $imageName)) {
1108
+ $imageName = rand() . '_' . time() . $imageName;
1109
+ }
1110
+
1111
+ if (file_put_contents($mediaDir . DS . $imageName, file_get_contents($imageUrl))) {
1112
+ $product = Mage::getModel('catalog/product')->load($productId);
1113
+ $product->addImageToMediaGallery($mediaDir . DS . $imageName,
1114
+ ['image', 'small_image', 'thumbnail'],
1115
+ true, true
1116
+ );
1117
+ $product->save();
1118
+ $this->setImageAsDownloaded($queueId);
1119
+ unset($product);
1120
+ } else {
1121
+ $this->setImageAsDownloadedError($queueId);
1122
+ Mage::log('Unable download file to ' . $productId, $logFileName);
1123
+ continue;
1124
+ }
1125
+ } catch(Exception $e) {
1126
+ $this->db_magento->query("UPDATE `{$this->tablePrefix}iceshop_iceimport_image_queue` SET `is_downloaded` = 2 WHERE `queue_id` = '$queueId';");
1127
+ }
1128
+ }
1129
+ }
1130
+ }
1131
+
1132
+ public function setImageAsDownloaded($queueId = false)
1133
+ {
1134
+
1135
+ if ($queueId) {
1136
+ $this->db_magento->query(
1137
+ "UPDATE `{$this->tablePrefix}iceshop_iceimport_image_queue`
1138
+ SET is_downloaded = 1
1139
+ WHERE queue_id = :queue_id",
1140
+ array(':queue_id' => $queueId)
1141
+ );
1142
+ }
1143
+ }
1144
+
1145
+ public function setImageAsDownloadedError($queueId = false)
1146
+ {
1147
+
1148
+ if ($queueId) {
1149
+ $this->db_magento->query(
1150
+ "UPDATE `{$this->tablePrefix}iceshop_iceimport_image_queue`
1151
+ SET is_downloaded = 2
1152
+ WHERE queue_id = :queue_id",
1153
+ array(':queue_id' => $queueId)
1154
+ );
1155
+ }
1156
+ }
1157
+
1158
+ public function checkAndSetIceField()
1159
+ {
1160
+
1161
+ $attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'active_ice')->getData();
1162
+ if (isset($attribute['attribute_id'])) {
1163
+
1164
+ $sql = "DROP PROCEDURE IF EXISTS FIELD_EXISTS;";
1165
+ $this->db_magento->query($sql);
1166
+
1167
+ $sql = "CREATE PROCEDURE FIELD_EXISTS(
1168
+ OUT _exists BOOLEAN, -- return value
1169
+ IN tableName CHAR(255) CHARACTER SET 'utf8', -- name of table to look for
1170
+ IN columnName CHAR(255) CHARACTER SET 'utf8', -- name of column to look for
1171
+ IN dbName CHAR(255) CHARACTER SET 'utf8' -- optional specific db
1172
+ ) BEGIN
1173
+ -- try to lookup db if none provided
1174
+ SET @_dbName := IF(dbName IS NULL, database(), dbName);
1175
+
1176
+ IF CHAR_LENGTH(@_dbName) = 0
1177
+ THEN -- no specific or current db to check against
1178
+ SELECT
1179
+ FALSE
1180
+ INTO _exists;
1181
+ ELSE -- we have a db to work with
1182
+ SELECT
1183
+ IF(count(*) > 0, TRUE, FALSE)
1184
+ INTO _exists
1185
+ FROM information_schema.COLUMNS c
1186
+ WHERE
1187
+ c.TABLE_SCHEMA = @_dbName
1188
+ AND c.TABLE_NAME = tableName
1189
+ AND c.COLUMN_NAME = columnName;
1190
+ END IF;
1191
+ END;";
1192
+ $this->db_magento->query($sql);
1193
+
1194
+ $sql = "CALL FIELD_EXISTS(@_exists, '{$this->tablePrefix}catalog_product_entity', 'active_ice', NULL);";
1195
+ $this->db_magento->query($sql);
1196
+
1197
+ $sql = "SELECT @_exists;";
1198
+ $res = $this->db_magento->fetchCol($sql);
1199
+ if (array_shift($res)) {
1200
+ $options = Mage::getModel('eav/config')->getAttribute('catalog_product', 'active_ice')->getSource()->getAllOptions();
1201
+ $optionId = false;
1202
+ foreach ($options as $option) {
1203
+ if ($option['label'] == 'Yes') {
1204
+ $optionId = $option['value'];
1205
+ break;
1206
+ }
1207
+ }
1208
+ if ($optionId) {
1209
+ $sql = "UPDATE `{$this->tablePrefix}catalog_product_entity` SET `active_ice` = '{$optionId}' WHERE `active_ice` IS NULL;";
1210
+ $this->db_magento->query($sql);
1211
+ }
1212
+ }
1213
+ }
1214
+ }
1215
+
1216
+ public function deleteTempTableProds ()
1217
+ {
1218
+
1219
+ $this->db_magento->query("DROP TABLE IF EXISTS {$this->tablePrefix}import_feed;");
1220
+ }
1221
+
1222
+ public function deleteTempTableCats ()
1223
+ {
1224
+
1225
+ $this->db_magento->query("DROP TABLE IF EXISTS {$this->tablePrefix}temp_cats;");
1226
+ }
1227
+
1228
+ public function deleteTempFileForCategories ()
1229
+ {
1230
+
1231
+ if (file_exists($this->filenameCats)) {
1232
+ unlink($this->filenameCats);
1233
+ }
1234
+ }
1235
+
1236
+ public function deleteTempFileForCatalogCategoryProductInsert ()
1237
+ {
1238
+
1239
+ if (file_exists($this->filenameValues)) {
1240
+ unlink($this->filenameValues);
1241
+ }
1242
+ }
1243
+
1244
+ public function deleteFileFromArrayForManualLaunching ()
1245
+ {
1246
+
1247
+ if (file_exists($this->tempFeed)) {
1248
+ unlink($this->tempFeed);
1249
+ }
1250
+ }
1251
+
1252
+ public function deleteTemFileForAttributes ()
1253
+ {
1254
+
1255
+ if (file_exists($this->tempAttr)) {
1256
+ unlink($this->tempAttr);
1257
+ }
1258
+ }
1259
+ }
app/code/community/ICEshop/Iceimport/Model/Convert/Adapter/Product.php DELETED
@@ -1,1868 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Import Product with additional attributes
5
- *
6
- *
7
- */
8
- class ICEshop_Iceimport_Model_Convert_Adapter_Product extends Mage_Catalog_Model_Convert_Adapter_Product
9
- {
10
- /**
11
- * @var array
12
- */
13
- protected $_categoryCache = array();
14
-
15
- /**
16
- * @var null
17
- */
18
- protected $_connRes = null;
19
-
20
- /**
21
- * @var string
22
- */
23
- protected $_tablePrefix = '';
24
- protected $_counter = 0;
25
-
26
- /**
27
- * @var
28
- */
29
- protected $_refreshSettings;
30
-
31
- /**
32
- * Import process ID
33
- *
34
- * @var int
35
- */
36
- protected $process_id = 'iceshop_iceimport';
37
-
38
- /**
39
- * Init class
40
- */
41
- public function __construct()
42
- {
43
-
44
- $this->_connRes = Mage::getSingleton('core/resource')->getConnection('core_write');
45
- $tablePrefix = (array)Mage::getConfig()->getTablePrefix();
46
- if (!empty($tablePrefix)) {
47
- $this->_tablePrefix = $tablePrefix[0];
48
- }
49
-
50
- }
51
-
52
- /**
53
- * @param $storeId
54
- */
55
-
56
- private function _initRefreshSettings($storeId)
57
- {
58
- $this->_refreshSettings = new Varien_Object();
59
- $this->_refreshSettings->setData('categories', (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/update_categories_from_csv', $storeId));
60
- $this->_refreshSettings->setData('status', (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/update_status_from_csv', $storeId));
61
- $this->_refreshSettings->setData('visibility', (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/update_visibility_from_csv', $storeId));
62
- $this->_refreshSettings->setData('is_in_stock', (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/update_is_in_stock_from_csv', $storeId));
63
- $this->_refreshSettings->setData('update_hide_category', (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/update_hide_category', $storeId));
64
- $this->_refreshSettings->setData('url_key', (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/update_url_key_from_csv', $storeId));
65
- $this->_refreshSettings->setData('import_new_products', (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/import_new_products', $storeId));
66
- }
67
-
68
- /**
69
- * @param $key
70
- * @return mixed
71
- */
72
- private function _getRefreshSetting($key)
73
- {
74
- $key = Mage::helper('iceimport')->toCamelCase($key, true);
75
- return $this->_refreshSettings->{'get' . $key}();
76
- }
77
-
78
- /**
79
- * @param array $importData
80
- * @return bool
81
- * @throws Mage_Core_Exception
82
- */
83
- public function saveRow(array $importData, $manually = false)
84
- {
85
-
86
- $DB_helper = Mage::helper('iceimport/db');
87
-
88
- $DB_logger = Mage::helper('iceimport/db');
89
-
90
- $transactions_enabled = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/transactions_enabled');
91
-
92
- if (empty($importData[0]['batchId'])) {
93
- $batchId = Mage::getSingleton('core/app')->getRequest()->getPost('batch_id', 0);
94
- } else {
95
- $batchId = (int)$importData[0]['batchId'];
96
- }
97
-
98
- // set store id
99
-
100
- if (empty($importData[0]['store'])) {
101
- if (!is_null($this->getBatchParams('store'))) {
102
- $store = $this->getStoreById($this->getBatchParams('store'));
103
- } else {
104
- $message = Mage::helper('catalog')->__('Skip import, required field "%s" not defined', 'store');
105
- Mage::throwException($message);
106
- }
107
- }
108
-
109
- if (empty($importData[0]['attribute_set'])) {
110
- $message = Mage::helper('catalog')->__('Skip import, required field "%s" not defined', 'attribute_set');
111
- Mage::throwException($message);
112
- }
113
-
114
- if (empty($store)) {
115
- $store = Mage::app()->getStore(trim($importData[0]['store']));
116
- }
117
-
118
- if ($store === false) {
119
- $message = Mage::helper('catalog')->__('Skip import, store "%s" not exists', $importData[0]['store']);
120
- Mage::throwException($message);
121
- }
122
-
123
- $storeId = $store->getId();
124
-
125
- $stock_name = Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/stock_inventory');
126
-
127
- $defaulttaxConf = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/default_tax', $storeId);
128
-
129
- $stockConf = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/import_stock', $storeId);
130
- $priceConf = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/import_prices', $storeId);
131
-
132
- $categoriesToActiveConf = Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/category_active', $storeId);
133
-
134
- $batch_size = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/iceimport_batch_size', $storeId);
135
-
136
- $addImages = Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/import_images');
137
-
138
- //init refresh settings values
139
- $this->_initRefreshSettings($storeId);
140
-
141
- if ($transactions_enabled != 0 && !$manually) {
142
- $this->_connRes->beginTransaction();
143
- }
144
-
145
- foreach($importData as $key => $importDatum) {
146
-
147
- $sortedProductData = $this->_mapAttributes($importDatum);
148
-
149
- $productData = $sortedProductData['productData'];
150
- $iceimportAttributes = $sortedProductData['iceimportAttributes'];
151
-
152
-
153
- $DB_helper->deleteLogEntry('try_delete_product_percentage_warning_flag');
154
- if ($batchId != $DB_helper->getConfigData($this->process_id . '_flag')) {
155
- //set flag, first iteration
156
- $DB_helper->unsetConfigData("import_total");
157
- $DB_helper->unsetConfigData("counter");
158
- $DB_helper->unsetConfigData("skipped_counter");
159
- $DB_helper->setConfigData($this->process_id . '_flag', $batchId);
160
- }
161
-
162
- $import_total = $DB_helper->getConfigData("import_total");
163
- $counter = $DB_helper->getConfigData("counter");
164
- $skipped_counter = $DB_helper->getConfigData("skipped_counter");
165
-
166
- if (empty($import_total)) {
167
- $batchModel = Mage::getModel('dataflow/batch')->load($batchId);
168
- $batchImportModel = $batchModel->getBatchImportModel();
169
- $importIds = $batchImportModel->getIdCollection();
170
- $import_total = count($importIds);
171
- $DB_helper->setConfigData("import_total", (int)$import_total);
172
- }
173
- if (empty($counter)) {
174
- $DB_helper->setConfigData("counter", 1);
175
- $counter = $DB_helper->getConfigData("counter");
176
- }
177
- if (empty($skipped_counter)) {
178
- $DB_helper->setConfigData("skipped_counter", 0);
179
- $skipped_counter = $DB_helper->getConfigData("skipped_counter");
180
- }
181
-
182
- // mark product ice_import generic
183
- $productData['varchar']['is_iceimport'] = 1;
184
-
185
- // set sku
186
- if (empty($iceimportAttributes['sku'])) {
187
- $message = Mage::helper('catalog')->__('Skip import row, required field "%s" not defined', 'sku');
188
- Mage::throwException($message);
189
- }
190
- $sku = $iceimportAttributes['sku'];
191
-
192
- if (!empty($iceimportAttributes['categories'])) {
193
- if (!empty($iceimportAttributes['categories'])) {
194
- $cat_names = explode('/', $iceimportAttributes['categories']);
195
- foreach ($cat_names as $cat_name) {
196
- if (empty($cat_name)) {
197
- $message = Mage::helper('catalog')->__('Skip import row, some of categories does not have name');
198
- Mage::throwException($message);
199
- }
200
- }
201
- }
202
- }
203
- if (!empty($iceimportAttributes['categories'])) {
204
- $category = $iceimportAttributes['categories'];
205
- if (empty($iceimportAttributes['unspsc'])) {
206
- $message = Mage::helper('catalog')->__('Skip import. Category UNSPSC not defined in store');
207
- Mage::throwException($message);
208
- }
209
- $unspsc = $iceimportAttributes['unspsc'];
210
- $unspsc = preg_replace("/[^a-zA-Z0-9]/", "", $unspsc);
211
- if (empty($iceimportAttributes['unspsc_path'])) {
212
- $message = Mage::helper('catalog')->__('Skip import. Category UNSPSC path not defined in store');
213
- Mage::throwException($message);
214
- }
215
- if (!empty($iceimportAttributes['unspsc_path'])) {
216
- $cat_unspscs = explode('/', $iceimportAttributes['unspsc_path']);
217
- foreach ($cat_unspscs as $cat_unspsc) {
218
- if (empty($cat_unspsc)) {
219
- $message = Mage::helper('catalog')->__('Skip import row, some of categories does not have UNSPSC');
220
- Mage::throwException($message);
221
- }
222
- }
223
- }
224
- $unspscPath = $iceimportAttributes['unspsc_path'];
225
- $unspscPath = preg_replace("/[^a-zA-Z0-9\/]/", "", $unspscPath);
226
- if (!empty($cat_unspscs) && !empty($cat_names) && count($cat_names) != count($cat_unspscs)) {
227
- $message = Mage::helper('catalog')->__('Skip import row, categories names does not match categories UNSPSC');
228
- Mage::throwException($message);
229
- }
230
- }
231
-
232
- // set website id;
233
- $websites = Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/websites');
234
- if (empty($websites)) {
235
- $message = Mage::helper('catalog')->__('Skip import row, required field "%s" not defined', 'websites');
236
- Mage::throwException($message);
237
- }
238
-
239
- $website = Mage::app()->getWebsite(trim($websites));
240
- $websiteId = $website->getId();
241
-
242
- // set in / out of stock
243
- $isInStock = 0;
244
- if (!empty($iceimportAttributes['is_in_stock'])) {
245
- $isInStock = $iceimportAttributes['is_in_stock'];
246
- }
247
-
248
- // set qty
249
- $qty = 0;
250
- if (!empty($iceimportAttributes['qty'])) {
251
- $qty = $iceimportAttributes['qty'];
252
- }
253
-
254
- // set price
255
- $price = 0.00;
256
- if (!empty($iceimportAttributes['price'])) {
257
- $price = $iceimportAttributes['price'];
258
- }
259
-
260
- // set tax_auvibel
261
- $tax_auvibel = 0.00;
262
- if (!empty($iceimportAttributes['tax_auvibel'])) {
263
- $tax_auvibel = $iceimportAttributes['tax_auvibel'];
264
- }
265
-
266
- // set tax_bebat
267
- $tax_bebat = 0.00;
268
- if (!empty($iceimportAttributes['tax_bebat'])) {
269
- $tax_bebat = $iceimportAttributes['tax_bebat'];
270
- }
271
-
272
- // set tax_recupel
273
- $tax_recupel = 0.00;
274
- if (!empty($iceimportAttributes['tax_recupel'])) {
275
- $tax_recupel = $iceimportAttributes['tax_recupel'];
276
- }
277
-
278
- // set tax_reprobel
279
- $tax_reprobel = 0.00;
280
- if (!empty($iceimportAttributes['tax_reprobel'])) {
281
- $tax_reprobel = $iceimportAttributes['tax_reprobel'];
282
- }
283
-
284
- // set status value
285
- $statusValue = (!empty($iceimportAttributes['status']) && $iceimportAttributes['status'] == 'Enabled') ? 1 : 2;
286
- $productData['int']['status'] = $statusValue;
287
-
288
- // set visibility value
289
- $visibilityValue = 1;
290
- if (!empty($iceimportAttributes['visibility'])) {
291
- switch ($iceimportAttributes['visibility']) {
292
- case 'Not Visible Individually':
293
- $visibilityValue = 1;
294
- break;
295
- case 'Catalog':
296
- $visibilityValue = 2;
297
- break;
298
- case 'Search':
299
- $visibilityValue = 3;
300
- break;
301
- case 'Catalog, Search':
302
- $visibilityValue = 4;
303
- break;
304
- }
305
- }
306
- $productData['int']['visibility'] = $visibilityValue;
307
-
308
- // set product image
309
- $productImage = '';
310
- if (!empty($iceimportAttributes['image'])) {
311
- $productImage = $iceimportAttributes['image'];
312
- }
313
-
314
- $initAttributes = '';
315
- // init general attributes query
316
- $initAttributes .= "SELECT @product_entity_type_id := `entity_type_id`
317
- FROM `{$this->_tablePrefix}eav_entity_type`
318
- WHERE entity_type_code = 'catalog_product';";
319
-
320
- $initAttributes .= "SELECT @price_id := `attribute_id`
321
- FROM `{$this->_tablePrefix}eav_attribute`
322
- WHERE `attribute_code` = 'price'
323
- AND entity_type_id = @product_entity_type_id;";
324
-
325
- $initAttributes .= "SELECT @attribute_set_id := `attribute_set_id`
326
- FROM `{$this->_tablePrefix}eav_attribute_set`
327
- WHERE attribute_set_name = :attribute_set
328
- AND entity_type_id = @product_entity_type_id;";
329
-
330
- if (!empty($iceimportAttributes['categories'])) {
331
- $initAttributes .= "SELECT @category_entity_type_id := `entity_type_id`
332
- FROM `{$this->_tablePrefix}eav_entity_type`
333
- WHERE entity_type_code = 'catalog_category';";
334
- }
335
-
336
- if (!empty($iceimportAttributes['categories'])) {
337
- $initAttributes .= "SELECT @unspsc_id := `attribute_id`
338
- FROM `{$this->_tablePrefix}eav_attribute`
339
- WHERE `attribute_code` = 'unspsc'
340
- AND entity_type_id = @category_entity_type_id;";
341
-
342
- $initAttributes .= "SELECT @category_name_id := `attribute_id`
343
- FROM `{$this->_tablePrefix}eav_attribute`
344
- WHERE `attribute_code` = 'name'
345
- AND entity_type_id = @category_entity_type_id;";
346
-
347
- $initAttributes .= "SELECT @category_active_id := `attribute_id`
348
- FROM `{$this->_tablePrefix}eav_attribute`
349
- WHERE `attribute_code` = 'is_active'
350
- AND entity_type_id = @category_entity_type_id;";
351
-
352
- $initAttributes .= "SELECT @include_nav_bar_id := `attribute_id`
353
- FROM `{$this->_tablePrefix}eav_attribute`
354
- WHERE `attribute_code` = 'include_in_menu'
355
- AND entity_type_id = @category_entity_type_id;";
356
-
357
- $initAttributes .= "SELECT @category_is_anchor_id := `attribute_id`
358
- FROM `{$this->_tablePrefix}eav_attribute`
359
- WHERE `attribute_code` = 'is_anchor'
360
- AND entity_type_id = @category_entity_type_id;";
361
- }
362
-
363
- $initAttributes .= "SELECT @tax_auvibel_id := `attribute_id`
364
- FROM `{$this->_tablePrefix}eav_attribute`
365
- WHERE `attribute_code` = 'tax_auvibel'
366
- AND entity_type_id = @product_entity_type_id;";
367
-
368
- $initAttributes .= "SELECT @tax_bebat_id := `attribute_id`
369
- FROM `{$this->_tablePrefix}eav_attribute`
370
- WHERE `attribute_code` = 'tax_bebat'
371
- AND entity_type_id = @product_entity_type_id;";
372
-
373
- $initAttributes .= "SELECT @tax_recupel_id := `attribute_id`
374
- FROM `{$this->_tablePrefix}eav_attribute`
375
- WHERE `attribute_code` = 'tax_recupel'
376
- AND entity_type_id = @product_entity_type_id;";
377
-
378
- $initAttributes .= "SELECT @tax_reprobel_id := `attribute_id`
379
- FROM `{$this->_tablePrefix}eav_attribute`
380
- WHERE `attribute_code` = 'tax_reprobel'
381
- AND entity_type_id = @product_entity_type_id;";
382
-
383
- if (!empty($stock_name)) {
384
- $stock_id = $this->_connRes->fetchRow("SELECT stock_id FROM `{$this->_tablePrefix}cataloginventory_stock` WHERE stock_name = :stock_name LIMIT 1", array(
385
- ':stock_name' => $stock_name
386
- ));
387
- if (!empty($stock_id)) {
388
- $initAttributes .= "SELECT @stock_id := `stock_id` FROM `{$this->_tablePrefix}cataloginventory_stock` WHERE stock_name = '" . $stock_name . "';";
389
- } else {
390
- $message = Mage::helper('catalog')->__('Skip import row, stock name "' . $stock_name . '" does not exists in the shop');
391
- Mage::throwException($message);
392
- }
393
- } else {
394
- $initAttributes .= "SELECT @stock_id := `stock_id` FROM `{$this->_tablePrefix}cataloginventory_stock` WHERE stock_name = 'Default';";
395
- }
396
- $this->_connRes->query($initAttributes, array(':attribute_set' => $iceimportAttributes['attribute_set']));
397
-
398
- // get tax class id
399
-
400
- $productData['int']['tax_class_id'] = $defaulttaxConf;
401
-
402
- if (!empty($iceimportAttributes['categories'])) {
403
- // get category id
404
- $categoryIds = $this->_addCategories($category, $storeId, $unspsc, $unspscPath, $categoriesToActiveConf);
405
- }
406
-
407
- // get url key
408
- $url = '';
409
- if (!empty($productData['varchar']['name'])) {
410
- $preUrl = explode(' ', strtolower($productData['varchar']['name']));
411
- $url = implode('-', $preUrl);
412
- }
413
- $productData['varchar']['url_key'] = $url;
414
-
415
- $prodIdFetch = $this->_connRes->fetchRow("SELECT entity_id FROM `{$this->_tablePrefix}catalog_product_entity` WHERE sku = :sku LIMIT 1", array(
416
- ':sku' => $sku
417
- ));
418
- $productId = $prodIdFetch['entity_id'];
419
-
420
- if (!empty($productId)) {
421
- // check import type (Import only price & qty or all product info)
422
-
423
- if (!empty($iceimportAttributes['categories'])) {
424
- $productId = $this->_coreSave($productData, $productId, $storeId, $sku, $categoryIds);
425
- } else {
426
- $productId = $this->_coreSave($productData, $productId, $storeId, $sku);
427
- }
428
-
429
- $this->_corePriceStock($websiteId, $productId, $price, $qty, $sku, $isInStock, $stockConf, $priceConf, 0);
430
-
431
- $this->_connRes->query("INSERT INTO {$this->_tablePrefix}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));
432
- } else {
433
- if ($this->_getRefreshSetting('import_new_products') == 0) {
434
- $DB_helper->setConfigData("skipped_counter", (int)++$skipped_counter);
435
- return true;
436
- }
437
-
438
- if (!empty($iceimportAttributes['categories'])) {
439
- $productId = $this->_coreSave($productData, $productId, $storeId, $sku, $categoryIds);
440
- } else {
441
- $productId = $this->_coreSave($productData, $productId, $storeId, $sku);
442
- }
443
- // add price & stock
444
- if ($productId) {
445
- $this->_corePriceStock($websiteId, $productId, $price, $qty, $sku, $isInStock);
446
- $this->_connRes->query("INSERT INTO {$this->_tablePrefix}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));
447
- }
448
- }
449
-
450
- $this->_connRes->query("DELETE FROM {$this->_tablePrefix}weee_tax WHERE entity_id = :prod_id AND attribute_id = @tax_auvibel_id", array(':prod_id' => $productId));
451
- $this->_connRes->query("DELETE FROM {$this->_tablePrefix}weee_tax WHERE entity_id = :prod_id AND attribute_id = @tax_bebat_id", array(':prod_id' => $productId));
452
- $this->_connRes->query("DELETE FROM {$this->_tablePrefix}weee_tax WHERE entity_id = :prod_id AND attribute_id = @tax_recupel_id", array(':prod_id' => $productId));
453
- $this->_connRes->query("DELETE FROM {$this->_tablePrefix}weee_tax WHERE entity_id = :prod_id AND attribute_id = @tax_reprobel_id", array(':prod_id' => $productId));
454
-
455
- $countryCode = Mage::getStoreConfig('general/country/default');
456
- if ($tax_auvibel > 0) {
457
- $query = "INSERT INTO {$this->_tablePrefix}weee_tax (website_id, entity_id, country, value, state, attribute_id, entity_type_id)"
458
- . "VALUES (0, :prod_id, :country, :value, '*', @tax_auvibel_id, @product_entity_type_id)";
459
- $this->_connRes->query($query, [':prod_id' => $productId, ':country' => $countryCode, ':value' => $tax_auvibel]);
460
- }
461
-
462
- if ($tax_bebat > 0) {
463
- $query = "INSERT INTO {$this->_tablePrefix}weee_tax (website_id, entity_id, country, value, state, attribute_id, entity_type_id)"
464
- . "VALUES (0, :prod_id, :country, :value, '*', @tax_bebat_id, @product_entity_type_id)";
465
- $this->_connRes->query($query, [':prod_id' => $productId, ':country' => $countryCode, ':value' => $tax_bebat]);
466
- }
467
-
468
- if ($tax_recupel > 0) {
469
- $query = "INSERT INTO {$this->_tablePrefix}weee_tax (website_id, entity_id, country, value, state, attribute_id, entity_type_id)"
470
- . "VALUES (0, :prod_id, :country, :value, '*', @tax_recupel_id, @product_entity_type_id)";
471
- $this->_connRes->query($query, [':prod_id' => $productId, ':country' => $countryCode, ':value' => $tax_recupel]);
472
- }
473
-
474
- if ($tax_reprobel > 0) {
475
- $query = "INSERT INTO {$this->_tablePrefix}weee_tax (website_id, entity_id, country, value, state, attribute_id, entity_type_id)"
476
- . "VALUES (0, :prod_id, :country, :value, '*', @tax_reprobel_id, @product_entity_type_id)";
477
- $this->_connRes->query($query, [':prod_id' => $productId, ':country' => $countryCode, ':value' => $tax_reprobel]);
478
- }
479
-
480
- // add product image to queue
481
- if ($addImages) {
482
- $this->_addImageToQueue($productId, $productImage);
483
- }
484
-
485
-
486
- $counter_sum = $counter + $skipped_counter;
487
-
488
- if (isset($counter) && isset($skipped_counter) && isset($import_total) && $counter_sum == $import_total) {
489
-
490
- $this->_runCategoriesSorting();
491
-
492
- $this->deleteOldProducts($DB_logger);
493
-
494
- $DB_logger->insertLogEntry('error' . md5(microtime(true)), 'New products skipped while export according to Iceimport settings: ' . $skipped_counter, 'stat');
495
-
496
- $date = date('m/d/Y H:i:s');
497
- $DB_logger->insertLogEntry('iceimport_import_ended', $date);
498
- }
499
- if ($counter < $import_total) {
500
- $DB_helper->setConfigData("counter", (int)++$counter);
501
- }
502
-
503
- if ($transactions_enabled != 0 && !$manually) {
504
- $this->_counter++;
505
-
506
- if ($this->_counter % $batch_size == 0) {
507
- try {
508
- $this->_connRes->commit();
509
- } catch (Exception $e) {
510
- $this->_connRes->rollBack();
511
- throw $e;
512
- }
513
- $this->_connRes->beginTransaction();
514
- }
515
- if ($this->_counter == count($importData)) {
516
- try {
517
- $this->_connRes->commit();
518
- } catch (Exception $e) {
519
- $this->_connRes->rollBack();
520
- throw $e;
521
- }
522
- }
523
- }
524
- }
525
- return true;
526
- }
527
-
528
- /**
529
- * @param $arg_attribute
530
- * @param $arg_value
531
- * @return bool
532
- */
533
- public function getAttributeOptionValue($arg_attribute, $arg_value)
534
- {
535
- $attribute_model = Mage::getModel('eav/entity_attribute');
536
- $attribute_options_model = Mage::getModel('eav/entity_attribute_source_table');
537
-
538
- $attribute_code = $attribute_model->getIdByCode('catalog_product', $arg_attribute);
539
- $attribute = $attribute_model->load($attribute_code);
540
-
541
- $attribute_options_model->setAttribute($attribute);
542
- $options = $attribute_options_model->getAllOptions(false);
543
-
544
- foreach ($options as $option) {
545
- if ($option['label'] == $arg_value) {
546
- return $option['value'];
547
- }
548
- }
549
- return false;
550
- }
551
-
552
-
553
- /**
554
- * @param $arg_attribute
555
- * @param $arg_value
556
- * @return bool
557
- * @throws Exception
558
- */
559
- public function addAttributeOption($arg_attribute, $arg_value)
560
- {
561
- $attribute_model = Mage::getModel('eav/entity_attribute');
562
- $attribute_options_model = Mage::getModel('eav/entity_attribute_source_table');
563
-
564
- $attribute_code = $attribute_model->getIdByCode('catalog_product', $arg_attribute);
565
- $attribute = $attribute_model->load($attribute_code);
566
-
567
- $attribute_options_model->setAttribute($attribute);
568
- $attribute_options_model->getAllOptions(false);
569
-
570
- $value = array();
571
- $value['option'] = array($arg_value, $arg_value);
572
- $result = array('value' => $value);
573
-
574
- $attribute->setData('option', $result);
575
- $attribute->save();
576
-
577
- return $this->getAttributeOptionValue($arg_attribute, $arg_value);
578
- }
579
-
580
-
581
- /**
582
- * @param array $entityData
583
- * @param null $productId
584
- * @param int $storeId
585
- * @param $sku
586
- * @param $categoryIds
587
- * @return null
588
- */
589
- protected function _coreSave(array $entityData, $productId = null, $storeId = 0, $sku, $categoryIds =NULL)
590
- {
591
-
592
- $currentDate = Mage::app()->getLocale()->date(null, null, null, false)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
593
-
594
- $coreSaveSQL = '';
595
- $newProduct = false;
596
- if ($productId === null) {
597
- // add product to store
598
- $coreSaveProduct = "INSERT INTO `{$this->_tablePrefix}catalog_product_entity` (`entity_type_id`, `attribute_set_id`, `type_id`, `sku`, `created_at`, `updated_at`)
599
- VALUES (@product_entity_type_id, @attribute_set_id, 'simple', :sku, :current_date, :current_date);
600
- SELECT @product_id := LAST_INSERT_ID();";
601
-
602
- $this->_connRes->query($coreSaveProduct, array(':sku' => $sku, ':current_date' => $currentDate));
603
- $prodFetch = $this->_connRes->fetchRow("SELECT @product_id AS prod_id");
604
- $productId = $prodFetch['prod_id'];
605
- $newProduct = TRUE;
606
-
607
- } else {
608
- $productId = (int)$productId;
609
- $coreSaveSQL .= "SELECT @product_id := {$productId}; ";
610
- $producteanConf = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/import_product_ean', $storeId);
611
- $productmpnConf = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/import_product_mpn', $storeId);
612
- $productnameConf = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/import_product_name', $storeId);
613
- $productshdescriptionConf = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/import_product_short_description', $storeId);
614
- $productdescriptionConf = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/import_product_description', $storeId);
615
- $productbrandConf = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/import_product_brand_name', $storeId);
616
- $deliveryetaConf = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/import_product_delivery_eta', $storeId);
617
- $attribute_mapping_mpn = Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/attribute_mapping_mpn');
618
- $attribute_mapping_brand_name = Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/attribute_mapping_brand_name');
619
- $attribute_mapping_ean = Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/attribute_mapping_ean');
620
- $attribute_mapping_delivery_eta = Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/attribute_mapping_delivery_eta');
621
-
622
- foreach ($entityData as $type => $typeAttributes) {
623
- foreach ($typeAttributes as $attribute => $value) {
624
- if (
625
- (
626
- ($attribute == $attribute_mapping_mpn && $productmpnConf == 0) ||
627
- ($attribute == $attribute_mapping_brand_name && $productbrandConf == 0) ||
628
- ($attribute == $attribute_mapping_ean && $producteanConf == 0) ||
629
- ($attribute == 'name' && $productnameConf == 0) ||
630
- ($attribute == 'short_description' && $productshdescriptionConf == 0) ||
631
- ($attribute == 'description' && $productdescriptionConf == 0) ||
632
- ($attribute == $attribute_mapping_delivery_eta && $deliveryetaConf == 0)
633
- ) || (
634
- $attribute == 'sku' ||
635
- ($attribute == 'attribute_set') ||
636
- ($attribute == 'categories' && $this->_getRefreshSetting('categories') == 0) ||
637
- ($attribute == 'unspsc') ||
638
- ($attribute == 'price') ||
639
- ($attribute == 'qty') ||
640
- ($attribute == 'status' && $this->_getRefreshSetting('status') == 0) ||
641
- ($attribute == 'visibility' && $this->_getRefreshSetting('visibility') == 0) ||
642
- ($attribute == 'store') ||
643
- ($attribute == 'websites') ||
644
- ($attribute == 'is_in_stock' && $this->_getRefreshSetting('is_in_stock') == 0) ||
645
- ($attribute == 'url_key' && $this->_getRefreshSetting('url_key') == 0) ||
646
- ($attribute == 'image') ||
647
- ($attribute == 'unspsc_path') ||
648
- ($attribute == 'stock_name') ||
649
- ($attribute == 'tax_auvibel') ||
650
- ($attribute == 'tax_bebat') ||
651
- ($attribute == 'tax_recupel') ||
652
- ($attribute == 'tax_reprobel')
653
- )
654
- ) {
655
- unset($entityData[$type][$attribute]);
656
- }
657
- }
658
- }
659
-
660
- $updateDate = "UPDATE `{$this->_tablePrefix}catalog_product_entity` SET `updated_at` = :current_date where entity_id = {$productId}";
661
- $this->_connRes->query($updateDate, array(':current_date' => $currentDate));
662
- }
663
-
664
- $bindArray[':store_id'] = $storeId;
665
-
666
- foreach ($entityData as $type => $typeAttributes) {
667
-
668
- if ($type != 'spec') {
669
- $tailCoreSaveSQL = '';
670
- $attributesInit = '';
671
- if ($type == 'select') {
672
- $type = 'int';
673
- $is_select = 1;
674
- } else {
675
- $is_select = 0;
676
- }
677
- if (!empty($typeAttributes)) {
678
- $tailCoreSaveSQL .= "INSERT INTO `{$this->_tablePrefix}catalog_product_entity_{$type}` (`entity_type_id`, `attribute_id`, `store_id`, `entity_id`, `value`) VALUES ";
679
- foreach ($typeAttributes as $attribute => $value) {
680
- if($this->_checkAttributeExist($attribute)){
681
- if ($is_select == 1) {
682
- $option_id = $this->getAttributeOptionValue($attribute, $value);
683
- if (empty($option_id)) {
684
- $option_id = $this->addAttributeOption($attribute, $value);
685
- }
686
- $value = $option_id;
687
- }
688
- $attributesInit .= "SELECT @product_entity_type_id := `entity_type_id`
689
- FROM `{$this->_tablePrefix}eav_entity_type`
690
- WHERE entity_type_code = 'catalog_product';";
691
- $attributesInit .= "SELECT @{$attribute}_id := `attribute_id`
692
- FROM `{$this->_tablePrefix}eav_attribute`
693
- WHERE `attribute_code` = '{$attribute}'
694
- AND entity_type_id = @product_entity_type_id;";
695
-
696
- $tailCoreSaveSQL .= "
697
- (@product_entity_type_id, @{$attribute}_id, 0, @product_id, :{$attribute} ),
698
- (@product_entity_type_id, @{$attribute}_id, :store_id, @product_id, :{$attribute} ), ";
699
- $bindArray[':' . $attribute] = $value;
700
- }
701
- }
702
- $tailCoreSaveSQL = substr($tailCoreSaveSQL, 0, -2);
703
- $tailCoreSaveSQL .= "
704
- ON DUPLICATE KEY UPDATE
705
- `value` = VALUES (`value`);";
706
- }
707
- $coreSaveSQL .= $attributesInit . $tailCoreSaveSQL;
708
- } else {
709
- foreach ($typeAttributes as $attribute => $attributeData) {
710
- if($this->_checkAttributeExist($attribute)){
711
- $prod_id_field = $attributeData['prod_id_field'];
712
- $table = $attributeData['table'];
713
- $field = $attributeData['field'];
714
- $value = $attributeData['value'];
715
- if (!empty($table) && !empty($field)) {
716
- $coreSaveSQL .= "UPDATE `{$this->_tablePrefix}{$table}`
717
- SET `{$field}` = :{$attribute}
718
- WHERE `{$prod_id_field}` = @product_id;";
719
- $bindArray[':' . $attribute] = $value;
720
- }
721
- }
722
- }
723
- }
724
- }
725
- // categories
726
- if (($newProduct || ($productId === null) || ($productId !== null && $this->_getRefreshSetting('categories') == 1)) && !empty($categoryIds)) {
727
- $coreSaveSQL .= "INSERT INTO `{$this->_tablePrefix}catalog_category_product` (`category_id`, `product_id`, `position`) VALUES ";
728
- $counter = 1;
729
-
730
- $mapCategoryIds = array();
731
- $mapCategoryIds[] = array_pop($categoryIds);
732
- $delCategoryIds = array_diff($categoryIds, $mapCategoryIds);
733
-
734
- foreach ($mapCategoryIds as $categoryId) {
735
- if ($counter < count($mapCategoryIds)) {
736
- $coreSaveSQL .= " (" . (int)$categoryId . ", @product_id, 1) , ";
737
- } else if ($counter == count($mapCategoryIds)) {
738
- $coreSaveSQL .= " (" . (int)$categoryId . ", @product_id, 1) ON DUPLICATE KEY UPDATE `position` = 1; ";
739
- }
740
- $counter++;
741
- }
742
-
743
- $not_delete_category = $this->getCategoryIdEmtyUnspsc($storeId);
744
- $noDelCategory = '';
745
- if(!empty($not_delete_category)){
746
- foreach ($not_delete_category as $category_ID ){
747
- $noDelCategory .= ''.$category_ID['entity_id'] . ',';
748
- }
749
- }
750
- if(!empty($noDelCategory)){
751
- $noDelCategory = substr($noDelCategory, 0, -1);
752
- }
753
-
754
- if (!empty($mapCategoryIds)) {
755
- foreach ($mapCategoryIds as $delCategoryId) {
756
- $delCategoryId = (int)$delCategoryId;
757
- $coreSaveSQL .= "DELETE FROM `{$this->_tablePrefix}catalog_category_product`";
758
- if(!empty($noDelCategory)){
759
- $coreSaveSQL .= "WHERE `category_id` NOT IN({$noDelCategory},{$delCategoryId}) AND `product_id` = @product_id;";
760
- } else {
761
- $coreSaveSQL .= "WHERE `category_id`!={$delCategoryId} AND `product_id` = @product_id;";
762
- }
763
- }
764
- }
765
- try {
766
- $this->_connRes->query($coreSaveSQL, $bindArray);
767
- unset($coreSaveSQL, $bindArray);
768
- } catch (Exception $e) {
769
- echo $e->getMessage();
770
- }
771
- } else {
772
- try {
773
- $this->_connRes->query($coreSaveSQL, $bindArray);
774
- unset($coreSaveSQL, $bindArray);
775
- } catch (Exception $e) {
776
- echo $e->getMessage();
777
- }
778
- }
779
- return $productId;
780
- }
781
-
782
- /**
783
- * Verify the existence of an attribute
784
- * @param string $attributeCode
785
- * @return boolean
786
- */
787
- protected function _checkAttributeExist($attributeCode){
788
- $query = "SELECT `attribute_id` FROM `{$this->_tablePrefix}eav_attribute` WHERE attribute_code='{$attributeCode}';";
789
- $attributeCheck = $this->_connRes->fetchRow($query);
790
- $attributeId = $attributeCheck['attribute_id'];
791
- if(empty($attributeId)){
792
- return false;
793
- }
794
- return true;
795
- }
796
-
797
- /**
798
- * @param int $website
799
- * @param bool $productId
800
- * @param float $price
801
- * @param float $qty
802
- * @param bool $sku
803
- * @param int $isInStock
804
- * @param int $stockConf
805
- * @param int $priceConf
806
- * @param int $new_product
807
- * @throws Mage_Core_Exception
808
- */
809
- protected function _corePriceStock($website = 0, $productId = false, $price = 0.00, $qty = 0.00, $sku = false, $isInStock = 0, $stockConf = 1, $priceConf = 1, $new_product = 1)
810
- {
811
-
812
- if (!$productId) {
813
- $message = Mage::helper('catalog')->__('Skip import row, product_id for product "%s" not defined ', $sku);
814
- Mage::throwException($message);
815
- }
816
- $stockSaveSQL = '';
817
- if ($stockConf == 1) {
818
- $stockSaveSQL .= "INSERT INTO `{$this->_tablePrefix}cataloginventory_stock_item` (`product_id`, `stock_id`, `qty`, `is_in_stock`)
819
- VALUES (:product_id, @stock_id, :qty,1)
820
- ON DUPLICATE KEY UPDATE
821
- `product_id` = :product_id,
822
- `stock_id` = @stock_id,
823
- `qty` = :qty";
824
-
825
- if ($new_product == 1 || $this->_getRefreshSetting('is_in_stock') == 1) {
826
- $stockSaveSQL .= ",
827
- `is_in_stock` = :is_in_stock";
828
- }
829
- $stockSaveSQL .= ";";
830
- $fields_values = array(
831
- ':product_id' => $productId,
832
- ':websiteId' => $website,
833
- ':qty' => $qty
834
- );
835
- if ($new_product == 1 || $this->_getRefreshSetting('is_in_stock') == 1) {
836
- $fields_values[':is_in_stock'] = $isInStock;
837
- }
838
- $this->_connRes->query($stockSaveSQL, $fields_values);
839
- $stockSaveSQL = "";
840
-
841
- $stockSaveSQL .= "INSERT INTO `{$this->_tablePrefix}cataloginventory_stock_status` (`product_id`, `website_id`, `stock_id`, `qty`, `stock_status`)
842
- VALUES (:product_id, :websiteId, @stock_id, :qty, 1)
843
- ON DUPLICATE KEY UPDATE
844
- `product_id` = :product_id,
845
- `website_id` = :websiteId,
846
- `stock_id` = @stock_id,
847
- `qty` = :qty";
848
- if ($new_product == 1 || $this->_getRefreshSetting('is_in_stock') == 1) {
849
- $stockSaveSQL .= ",
850
- `stock_status` = :is_in_stock";
851
- }
852
- $stockSaveSQL .= ";";
853
- $fields_values = array(
854
- ':product_id' => $productId,
855
- ':websiteId' => $website,
856
- ':qty' => $qty
857
- );
858
- if ($new_product == 1 || $this->_getRefreshSetting('is_in_stock') == 1) {
859
- $fields_values[':is_in_stock'] = $isInStock;
860
- }
861
- $this->_connRes->query($stockSaveSQL, $fields_values);
862
- $stockSaveSQL = "";
863
-
864
- } elseif ($new_product == 0) {
865
- //existent product
866
- if ($this->_getRefreshSetting('is_in_stock') == 1) {
867
- $stockSaveSQL .= "UPDATE `{$this->_tablePrefix}cataloginventory_stock_item` SET `is_in_stock` = :is_in_stock WHERE `product_id` = :product_id AND `stock_id` = @stock_id;";
868
- $stockSaveSQL .= "UPDATE `{$this->_tablePrefix}cataloginventory_stock_status` SET `stock_status` = :is_in_stock WHERE `product_id` = :product_id AND `website_id` = :websiteId AND `stock_id` = @stock_id;";
869
- $fields_values = array(
870
- ':websiteId' => $website,
871
- ':product_id' => $productId,
872
- ':is_in_stock' => $isInStock
873
- );
874
- $this->_connRes->query($stockSaveSQL, $fields_values);
875
- $stockSaveSQL = '';
876
- }
877
- }
878
-
879
- if ($priceConf == 1) {
880
- $stockSaveSQL .= "INSERT INTO `{$this->_tablePrefix}catalog_product_website` (`product_id`, `website_id`)
881
- VALUES (:product_id, :websiteId)
882
- ON DUPLICATE KEY UPDATE
883
- `product_id` = :product_id,
884
- `website_id` = :websiteId;";
885
-
886
- $fields_values = array(
887
- ':websiteId' => $website,
888
- ':product_id' => $productId
889
- );
890
- $this->_connRes->query($stockSaveSQL, $fields_values);
891
- $stockSaveSQL = "";
892
- $stockSaveSQL .= "INSERT INTO `{$this->_tablePrefix}catalog_product_entity_decimal` (`entity_type_id`,`attribute_id`,`store_id`, `entity_id`, `value`)
893
- VALUES (@product_entity_type_id, @price_id, 0, :product_id, :price)
894
- ON DUPLICATE KEY UPDATE
895
- `entity_type_id` = @product_entity_type_id,
896
- `attribute_id` = @price_id,
897
- `store_id` = 0,
898
- `entity_id` = :product_id,
899
- `value` = :price;";
900
- $stockSaveSQL .= "INSERT INTO `{$this->_tablePrefix}catalog_product_entity_decimal` (`entity_type_id`,`attribute_id`,`store_id`, `entity_id`, `value`)
901
- VALUES (@product_entity_type_id, @price_id, {$website}, :product_id, :price)
902
- ON DUPLICATE KEY UPDATE
903
- `entity_type_id` = @product_entity_type_id,
904
- `attribute_id` = @price_id,
905
- `store_id` = {$website},
906
- `entity_id` = :product_id,
907
- `value` = :price;";
908
- $fields_values = array(
909
- ':product_id' => $productId,
910
- ':price' => $price,
911
- ':qty' => $qty
912
- );
913
- if ($new_product == 1 || $this->_getRefreshSetting('is_in_stock') == 1) {
914
- $fields_values[':is_in_stock'] = $isInStock;
915
- }
916
- $this->_connRes->query($stockSaveSQL, $fields_values);
917
- $stockSaveSQL = "";
918
- }
919
- if (($priceConf == 1 || $stockConf == 1) && !empty($stockSaveSQL)) {
920
- $fields_values = array(
921
- ':websiteId' => $website,
922
- ':product_id' => $productId,
923
- ':price' => $price,
924
- ':qty' => $qty
925
- );
926
- if ($this->_getRefreshSetting('is_in_stock') == 1) {
927
- $fields_values[':is_in_stock'] = $isInStock;
928
- }
929
- $this->_connRes->query($stockSaveSQL, $fields_values);
930
- unset($stockSaveSQL);
931
- }
932
- unset($fields_values);
933
- }
934
-
935
- /**
936
- * @param bool $productId
937
- * @param $productImageUrl
938
- */
939
- protected function _addImageToQueue($productId = false, $productImageUrl)
940
- {
941
- $productImageUrl = trim($productImageUrl);
942
- if ($productId && !empty($productImageUrl)) {
943
- // add image if not exists to queue
944
- $this->_connRes->query(
945
- "INSERT IGNORE INTO `{$this->_tablePrefix}iceshop_iceimport_image_queue` (`entity_id`, `image_url` )
946
- VALUES (:product_id, :image_url)",
947
- array(
948
- ':product_id' => $productId,
949
- ':image_url' => $productImageUrl
950
- )
951
- );
952
- }
953
- }
954
-
955
- /**
956
- * @return mixed
957
- */
958
- private function getImageQueue()
959
- {
960
- return $this->_connRes->fetchAll("SELECT `queue_id`, `entity_id`, `image_url`
961
- FROM `{$this->_tablePrefix}iceshop_iceimport_image_queue`
962
- WHERE `is_downloaded` = 0");
963
- }
964
-
965
- /**
966
- * @param $logFileName
967
- * @throws Exception
968
- */
969
- public function processImageQueue($logFileName)
970
- {
971
- // download & set product images
972
- $queueList = $this->getImageQueue();
973
- if (count($queueList) > 0) {
974
- $mediaDir = Mage::getBaseDir('media');
975
- foreach ($queueList as $queue) {
976
- $queueId = $queue['queue_id'];
977
- $productId = $queue['entity_id'];
978
- $imageUrl = $queue['image_url'];
979
-
980
- $preImageName = explode('/', $imageUrl);
981
- $imageName = array_pop($preImageName);
982
- if (file_exists($mediaDir . DS . $imageName)) {
983
- $imageName = rand() . '_' . time() . $imageName;
984
- }
985
-
986
- if (file_put_contents($mediaDir . DS . $imageName, file_get_contents($imageUrl))) {
987
- $product = Mage::getModel('catalog/product')->load($productId);
988
- $product->addImageToMediaGallery($mediaDir . DS . $imageName,
989
- array('image', 'small_image', 'thumbnail'),
990
- true, true
991
- );
992
- $product->save();
993
- $this->setImageAsDownloaded($queueId);
994
- unset($product);
995
- } else {
996
- $this->setImageAsDownloadedError($queueId);
997
- Mage::log('Unable download file to ' . $productId, $logFileName);
998
- continue;
999
- }
1000
- }
1001
- }
1002
- }
1003
-
1004
- /**
1005
- * @param bool $queueId
1006
- */
1007
- private function setImageAsDownloaded($queueId = false)
1008
- {
1009
- if ($queueId) {
1010
- $this->_connRes->query(
1011
- "UPDATE `{$this->_tablePrefix}iceshop_iceimport_image_queue`
1012
- SET is_downloaded = 1
1013
- WHERE queue_id = :queue_id",
1014
- array(':queue_id' => $queueId)
1015
- );
1016
- }
1017
- }
1018
-
1019
- /**
1020
- * @param bool $queueId
1021
- */
1022
- private function setImageAsDownloadedError($queueId = false)
1023
- {
1024
- if ($queueId) {
1025
- $this->_connRes->query(
1026
- "UPDATE `{$this->_tablePrefix}iceshop_iceimport_image_queue`
1027
- SET is_downloaded = 2
1028
- WHERE queue_id = :queue_id",
1029
- array(':queue_id' => $queueId)
1030
- );
1031
- }
1032
- }
1033
-
1034
- /**
1035
- * @param $categories
1036
- * @param $storeId
1037
- * @param $unspsc
1038
- * @param $unspscPath
1039
- * @param int $categoryActive
1040
- * @return array
1041
- */
1042
- protected function _addCategories($categories, $storeId, $unspsc, $unspscPath, $categoryActive = 1)
1043
- {
1044
-
1045
- // check if product exists
1046
- $categoryId = $this->_getCategoryIdByUnspsc($unspsc,$storeId);
1047
-
1048
- $categoryIds = array();
1049
- if (!empty($categoryId)) {
1050
-
1051
- // merge categories by unspsc
1052
- $categoryMergedArray = $this->_categoryMapper($categories, $unspscPath);
1053
- foreach ($categoryMergedArray as $category) {
1054
-
1055
- $categoryName = $category['name'];
1056
- $categoryUnspsc = $category['unspsc'];
1057
- $categoryTreeId = $this->_getCategoryIdByUnspsc($categoryUnspsc,$storeId);
1058
- // check category name to current store
1059
- $categoryBindArray = array(
1060
- ':store_id' => 0,
1061
- ':category_id' => $categoryTreeId
1062
- );
1063
- $nameCheckerFetch = $this->_connRes->fetchRow(
1064
- "SELECT value_id
1065
- FROM `{$this->_tablePrefix}catalog_category_entity_varchar`
1066
- WHERE store_id = :store_id
1067
- AND entity_id = :category_id
1068
- AND attribute_id = @category_name_id",
1069
- $categoryBindArray
1070
- );
1071
- $nameChecker = $nameCheckerFetch['value_id'];
1072
- if (!$nameChecker) {
1073
-
1074
- // add category name to current store
1075
- $categoryBindArray[':category_name'] = $categoryName;
1076
- if (!empty($categoryBindArray[':category_id'])) {
1077
- $this->_connRes->query(
1078
- "INSERT INTO `{$this->_tablePrefix}catalog_category_entity_varchar` (`entity_type_id`, `attribute_id`, `store_id`, `entity_id`, `value`)
1079
- VALUES (@category_entity_type_id, @category_name_id, :store_id, :category_id, :category_name)",
1080
- $categoryBindArray
1081
- );
1082
- }
1083
- }
1084
- }
1085
- //
1086
-
1087
- $activeSetter = '';
1088
- // get current path of category
1089
- $categoryPath = $this->_connRes->fetchRow(
1090
- "SELECT path
1091
- FROM `{$this->_tablePrefix}catalog_category_entity`
1092
- WHERE entity_id = :entity_id",
1093
- array(':entity_id' => $categoryId)
1094
- );
1095
- $categoryPathArray = explode('/', $categoryPath['path']);
1096
- if ($categoryPathArray) {
1097
- $activeSetter = "INSERT INTO `{$this->_tablePrefix}catalog_category_entity_int` (`entity_type_id`, `attribute_id`, `store_id`, `entity_id`, `value`) VALUES ";
1098
- }
1099
-
1100
- $falseCounter = 0;
1101
- foreach ($categoryPathArray as $categoryId) {
1102
- $category = Mage::getModel('catalog/category')->load($categoryId);
1103
- $cid = $category->getId();
1104
- if (!empty($cid)) {
1105
- if (!empty($categoryId)) {
1106
- $categoryIds[] = (int)$categoryId;
1107
- $activeSetter .= "(@category_entity_type_id, @category_active_id, :store_id, " . $categoryId . ", 1),
1108
- (@category_entity_type_id, @category_active_id, 0, " . $categoryId . ", 1), ";
1109
- } else {
1110
- $falseCounter++;
1111
- }
1112
- } else {
1113
- $falseCounter++;
1114
- }
1115
- }
1116
- $activeSetter = substr($activeSetter, 0, -2);
1117
- $activeSetter .= "
1118
- ON DUPLICATE KEY UPDATE
1119
- `value` = 1
1120
- ";
1121
- if (1 == $categoryActive) {
1122
- if ($falseCounter < count($categoryPathArray)) {
1123
- $this->_connRes->query($activeSetter, array(':store_id' => $storeId));
1124
- }
1125
- }
1126
- return $categoryIds;
1127
- } else {
1128
-
1129
- // merge unspsc to current name in unspsc & name path's
1130
- $categoryMergedArray = $this->_categoryMapper($categories, $unspscPath);
1131
- // get max created parent category
1132
- $categoryCreateArray = array();
1133
- for ($i = count($categoryMergedArray) - 1; $i >= 0; $i--) {
1134
- $category = $categoryMergedArray[$i];
1135
- $checkCategoryId = $this->_getCategoryIdByUnspsc($category['unspsc'],$storeId);
1136
- if ($checkCategoryId != null) {
1137
- $categoryId = $this->_buildCategoryTree($checkCategoryId, $storeId, $categoryCreateArray, $categoryActive);
1138
- $categoryIds[] = (int)$categoryId;
1139
- break;
1140
- } else {
1141
- $categoryCreateArray[] = $category;
1142
- }
1143
- }
1144
- return $categoryIds;
1145
- }
1146
- }
1147
-
1148
- /**
1149
- * @param $categoryPath
1150
- * @param $unspscPath
1151
- * @return array
1152
- * @throws Mage_Core_Exception
1153
- */
1154
- protected function _categoryMapper($categoryPath, $unspscPath)
1155
- {
1156
- $nameArray = explode('/', $categoryPath);
1157
- $unspscArray = explode('/', $unspscPath);
1158
-
1159
- if (count($nameArray) != count($unspscArray)) {
1160
- $message = Mage::helper('catalog')->__('Skip import row, @categories data is invalid');
1161
- Mage::throwException($message);
1162
- }
1163
-
1164
- $categoryMergedArray = array(
1165
- array(
1166
- 'unspsc' => 'default_root',
1167
- 'name' => 'Default category'
1168
- )
1169
- );
1170
-
1171
- for ($i = 0; $i < count($unspscArray); $i++) {
1172
- $categoryMergedArray[] = array('name' => $nameArray[$i],
1173
- 'unspsc' => $unspscArray[$i]);
1174
- }
1175
-
1176
- return $categoryMergedArray;
1177
- }
1178
-
1179
- /**
1180
- * @param $unspsc
1181
- * @return int|null
1182
- */
1183
- protected function _getCategoryIdByUnspsc($unspsc,$storeId = 0)
1184
- {
1185
- if ($unspsc == 'default_root') {
1186
- return Mage::app()->getStore($storeId)->getRootCategoryId();
1187
- } else {
1188
- // $replace = array(']','[', '{','}','^','-','<','>','(',')');
1189
- // $unspsc = str_replace($replace, '', $unspsc);
1190
- $categoryId = $this->_connRes->fetchRow(
1191
- "SELECT entity_id
1192
- FROM `{$this->_tablePrefix}catalog_category_entity_varchar`
1193
- WHERE `value` REGEXP '[[:<:]]".addslashes($unspsc)."[[:>:]]'
1194
- AND attribute_id = @unspsc_id"
1195
- );
1196
- return ($categoryId['entity_id']) ? $categoryId['entity_id'] : null;
1197
- }
1198
- }
1199
-
1200
- /**
1201
- * @param $parentCategoryId
1202
- * @param $storeId
1203
- * @param $pathArray
1204
- * @param int $categoryActive
1205
- * @return mixed
1206
- */
1207
- protected function _buildCategoryTree($parentCategoryId, $storeId, $pathArray, $categoryActive = 0)
1208
- {
1209
- for ($i = count($pathArray) - 1; $i >= 0; $i--) {
1210
- $category = $pathArray[$i];
1211
- $parentCategoryId = $this->_createCategory($parentCategoryId, $category['unspsc'], $storeId, $category['name'], $categoryActive);
1212
- }
1213
-
1214
- return $parentCategoryId;
1215
- }
1216
-
1217
- /**
1218
- * @param $parentId
1219
- * @param $unspsc
1220
- * @param $storeId
1221
- * @param $name
1222
- * @param int $categoryActive
1223
- * @return mixed
1224
- */
1225
- protected function _createCategory($parentId, $unspsc, $storeId, $name, $categoryActive = 0)
1226
- {
1227
-
1228
- $addCategory = "SELECT @tPath := `path`, @tLevel := `level`
1229
- FROM `{$this->_tablePrefix}catalog_category_entity`
1230
- WHERE `entity_id` = :parent_id;";
1231
- $addCategory .= "SET @tLevel = @tLevel +1;";
1232
-
1233
- $addCategory .= "SET @path := CONCAT(@tPath, '/',(SELECT MAX(entity_id) FROM `{$this->_tablePrefix}catalog_category_entity`) +1 );";
1234
-
1235
- $addCategory .= "INSERT INTO `{$this->_tablePrefix}catalog_category_entity` (`entity_type_id`, `attribute_set_id`, `parent_id`, `created_at`, `path`, `position`, `level`, `children_count`)
1236
- VALUES (@category_entity_type_id, 0, :parent_id, NOW(), @path, 1, @tLevel, 0);";
1237
-
1238
- $addCategory .= "SELECT @catId := LAST_INSERT_ID();";
1239
-
1240
- $addCategory .= "UPDATE `{$this->_tablePrefix}catalog_category_entity`
1241
- SET `path` = CONCAT(@tPath, '/', @catId)
1242
- WHERE entity_id = LAST_INSERT_ID();";
1243
-
1244
- $addCategory .= "UPDATE `{$this->_tablePrefix}catalog_category_entity`
1245
- SET children_count = children_count +1
1246
- WHERE entity_id = :parent_id;";
1247
-
1248
- $addCategory .= "INSERT IGNORE INTO `{$this->_tablePrefix}catalog_category_entity_int` (`entity_type_id`, `attribute_id`,`store_id`, `entity_id`, `value`)
1249
- VALUES (@category_entity_type_id, @category_active_id, 0, @catId, :category_active),
1250
- (@category_entity_type_id, @category_active_id, :store, @catId, :category_active),
1251
- (@category_entity_type_id, @category_is_anchor_id, 0, @catId, 1),
1252
- (@category_entity_type_id, @category_is_anchor_id, :store, @catId, 1),
1253
- (@category_entity_type_id, @include_nav_bar_id, 0, @catId, 1),
1254
- (@category_entity_type_id, @include_nav_bar_id, :store, @catId, 1);";
1255
-
1256
- $addCategory .= "INSERT IGNORE INTO `{$this->_tablePrefix}catalog_category_entity_varchar` (`entity_type_id`, `attribute_id`, `store_id`, `entity_id`, `value`)
1257
- VALUES (@category_entity_type_id, @category_name_id, 0, @catId, :category_name),
1258
- (@category_entity_type_id, @category_name_id, :store, @catId, :category_name),
1259
- (@category_entity_type_id, @unspsc_id, 0, @catId, :unspsc_val),
1260
- (@category_entity_type_id, @unspsc_id, :store, @catId, :unspsc_val);
1261
- ";
1262
-
1263
- $this->_connRes->query($addCategory, array(
1264
- ':store' => $storeId,
1265
- ':parent_id' => $parentId,
1266
- ':category_name' => $name,
1267
- ':unspsc_val' => $unspsc,
1268
- ':category_active' => (int)$categoryActive
1269
- ));
1270
-
1271
- $categoryIdFetch = $this->_connRes->fetchRow('SELECT @catId AS category_id');
1272
-
1273
- return $categoryIdFetch['category_id'];
1274
- }
1275
-
1276
- /**
1277
- * @param array $importData
1278
- * @return array
1279
- */
1280
- protected function _mapAttributes(array $importData)
1281
- {
1282
-
1283
- // map iceimport attributes, skip some attributes
1284
- $iceAttributes = array();
1285
- foreach ($importData as $attribute => $value) {
1286
- // map iceimport attributes
1287
-
1288
- if ($attribute == 'sku' ||
1289
- $attribute == 'attribute_set' ||
1290
- $attribute == 'categories' ||
1291
- $attribute == 'unspsc' ||
1292
- $attribute == 'price' ||
1293
- $attribute == 'qty' ||
1294
- $attribute == 'status' ||
1295
- $attribute == 'visibility' ||
1296
- $attribute == 'store' ||
1297
- $attribute == 'websites' ||
1298
- $attribute == 'is_in_stock' ||
1299
- $attribute == 'image' ||
1300
- $attribute == 'unspsc_path' ||
1301
- $attribute == 'stock_name' ||
1302
- $attribute == 'tax_auvibel' ||
1303
- $attribute == 'tax_bebat' ||
1304
- $attribute == 'tax_recupel' ||
1305
- $attribute == 'tax_reprobel'
1306
- ) {
1307
-
1308
- $iceAttributes[$attribute] = $value;
1309
- unset($importData[$attribute]);
1310
-
1311
- }
1312
- }
1313
-
1314
- // map default attributes
1315
- $productData = array();
1316
- foreach ($this->_getDefaultAttributesList() as $backendType => $attributesList) {
1317
- if ($backendType != 'spec') {
1318
- foreach ($attributesList as $attribute) {
1319
- if (isset($importData[$attribute]) && $importData[$attribute] != '') {
1320
- $productData[$backendType][$attribute] = $importData[$attribute];
1321
- unset($importData[$attribute]);
1322
- }
1323
- }
1324
- } else {
1325
- foreach ($attributesList as $attributeCode => $attributeSpecs) {
1326
- if (isset($importData[$attributeCode]) && $importData[$attributeCode] != false) {
1327
- $attributeSpecs['value'] = $importData[$attributeCode];
1328
- $productData[$backendType][$attributeCode] = $attributeSpecs;
1329
- unset($importData[$attributeCode]);
1330
- }
1331
- }
1332
- }
1333
- }
1334
-
1335
- if (!empty($importData)) {
1336
- foreach ($importData as $attributeCode => $value) {
1337
- $frontendTypeFetch = $this->_connRes->fetchRow(
1338
- "SELECT frontend_input FROM `{$this->_tablePrefix}eav_attribute` WHERE `attribute_code` = :code",
1339
- array(':code' => $attributeCode)
1340
- );
1341
- if ($frontendTypeFetch['frontend_input'] == 'select') {
1342
- $frontendType = $frontendTypeFetch['frontend_input'];
1343
- if ($frontendType != 'static' && !empty($frontendType) && $value != '') {
1344
- $productData[$frontendType][$attributeCode] = $value;
1345
- unset($importData[$attributeCode]);
1346
- }
1347
- }
1348
- }
1349
- }
1350
- // map custom attributes
1351
- if (!empty($importData)) {
1352
- foreach ($importData as $attributeCode => $value) {
1353
- $backendTypeFetch = $this->_connRes->fetchRow("SELECT backend_type FROM `{$this->_tablePrefix}eav_attribute` WHERE `attribute_code` = :code", array(':code' => $attributeCode));
1354
- $backendType = $backendTypeFetch['backend_type'];
1355
- if (($backendType != 'static' && !empty($backendType) && $value != '')) {
1356
- $productData[$backendType][$attributeCode] = $value;
1357
- unset($importData[$attributeCode]);
1358
- }
1359
- }
1360
- }
1361
-
1362
- $failedAttributes = array();
1363
- if (count($importData) > 0) {
1364
- $failedAttributes = array_keys($importData);
1365
- }
1366
-
1367
- return array(
1368
- 'iceimportAttributes' => $iceAttributes,
1369
- 'productData' => $productData,
1370
- 'failedAttributes' => $failedAttributes
1371
- );
1372
-
1373
- }
1374
-
1375
-
1376
- /**
1377
- * @return array
1378
- */
1379
- protected function _getDefaultAttributesList()
1380
- {
1381
-
1382
- return array(
1383
- 'varchar' => array(
1384
- 'gift_message_available',
1385
- 'custom_design',
1386
- 'msrp_display_actual_price_type',
1387
- 'msrp_enabled',
1388
- 'options_container',
1389
- 'page_layout',
1390
- 'mpn',
1391
- 'name',
1392
- 'url_key',
1393
- 'meta_description',
1394
- 'meta_title'
1395
- ),
1396
- 'int' => array(
1397
- 'enable_googlecheckout',
1398
- 'is_recurring',
1399
- 'links_purchased_separately',
1400
- 'links_exist',
1401
- 'status',
1402
- 'visibility',
1403
- 'tax_class_id',
1404
- 'price_view'
1405
- ),
1406
- 'text' => array(
1407
- 'recurring_profile',
1408
- 'description',
1409
- 'custom_layout_update',
1410
- 'meta_keyword',
1411
- 'short_description',
1412
- 'total_supplier_stock'
1413
- ),
1414
- 'decimal' => array(
1415
- 'group_price',
1416
- 'weight',
1417
- 'special_price',
1418
- 'msrp',
1419
- 'tax_auvibel',
1420
- 'tax_bebat',
1421
- 'tax_recupel',
1422
- 'tax_reprobel'
1423
- ),
1424
- 'datetime' => array(
1425
- 'custom_design_from',
1426
- 'custom_design_to',
1427
- 'news_from_date',
1428
- 'news_to_date',
1429
- 'special_from_date',
1430
- 'special_to_date'
1431
- ),
1432
- 'spec' => array(
1433
- 'is_qty_decimal' => array(
1434
- 'prod_id_field' => 'product_id',
1435
- 'table' => 'cataloginventory_stock_item',
1436
- 'field' => 'is_qty_decimal'
1437
- ),
1438
- 'use_config_min_qty' => array(
1439
- 'prod_id_field' => 'product_id',
1440
- 'table' => 'cataloginventory_stock_item',
1441
- 'field' => 'use_config_min_qty'
1442
- ),
1443
- 'use_config_min_sale_qty' => array(
1444
- 'prod_id_field' => 'product_id',
1445
- 'table' => 'cataloginventory_stock_item',
1446
- 'field' => 'use_config_min_sale_qty'
1447
- ),
1448
- 'use_config_max_sale_qty' => array(
1449
- 'prod_id_field' => 'product_id',
1450
- 'table' => 'cataloginventory_stock_item',
1451
- 'field' => 'use_config_max_sale_qty'
1452
- ),
1453
- 'use_config_manage_stock' => array(
1454
- 'prod_id_field' => 'product_id',
1455
- 'table' => 'cataloginventory_stock_item',
1456
- 'field' => 'use_config_manage_stock'
1457
- ),
1458
- 'is_decimal_divided' => array(
1459
- 'prod_id_field' => 'product_id',
1460
- 'table' => 'cataloginventory_stock_item',
1461
- 'field' => 'is_decimal_divided'
1462
- ),
1463
- 'use_config_backorders' => array(
1464
- 'prod_id_field' => 'product_id',
1465
- 'table' => 'cataloginventory_stock_item',
1466
- 'field' => 'use_config_backorders'
1467
- ),
1468
- 'use_config_notify_stock_qty' => array(
1469
- 'prod_id_field' => 'product_id',
1470
- 'table' => 'cataloginventory_stock_item',
1471
- 'field' => 'use_config_notify_stock_qty'
1472
- ),
1473
- 'max_sale_qty' => array(
1474
- 'prod_id_field' => 'product_id',
1475
- 'table' => 'cataloginventory_stock_item',
1476
- 'field' => 'max_sale_qty'
1477
- ),
1478
- 'min_sale_qty' => array(
1479
- 'prod_id_field' => 'product_id',
1480
- 'table' => 'cataloginventory_stock_item',
1481
- 'field' => 'min_sale_qty'
1482
- ),
1483
- 'notify_stock_qty' => array(
1484
- 'prod_id_field' => 'product_id',
1485
- 'table' => 'cataloginventory_stock_item',
1486
- 'field' => 'notify_stock_qty'
1487
- ),
1488
- 'backorders' => array(
1489
- 'prod_id_field' => 'product_id',
1490
- 'table' => 'cataloginventory_stock_item',
1491
- 'field' => 'backorders'
1492
- ),
1493
- 'created_at' => array(
1494
- 'prod_id_field' => 'entity_id',
1495
- 'table' => 'catalog_product_entity',
1496
- 'field' => 'created_at'
1497
- ),
1498
- 'min_qty' => array(
1499
- 'prod_id_field' => 'product_id',
1500
- 'table' => 'cataloginventory_stock_item',
1501
- 'field' => 'min_qty'
1502
- ),
1503
- 'updated_at' => array(
1504
- 'prod_id_field' => 'entity_id',
1505
- 'table' => 'catalog_product_entity',
1506
- 'field' => 'updated_at'
1507
- )
1508
- )
1509
- );
1510
- }
1511
-
1512
- /**
1513
- * Count child categories products and set them inactive if they have no products
1514
- *
1515
- * @param $child_cat
1516
- */
1517
- public function CountChildProd($child_cat)
1518
- {
1519
- foreach ($child_cat as $cat) {
1520
- $query = "SELECT `entity_id`
1521
- FROM `{$this->_tablePrefix}catalog_category_entity`
1522
- WHERE parent_id = :cat_id";
1523
- $child_cat = $this->_connRes->fetchAll(
1524
- $query,
1525
- array(
1526
- ':cat_id' => $cat['entity_id']
1527
- )
1528
- );
1529
-
1530
- $query = "SELECT COUNT(*)
1531
- FROM `{$this->_tablePrefix}catalog_category_product`
1532
- WHERE category_id = :cat_id ";
1533
- $cat_products = $this->_connRes->fetchRow(
1534
- $query,
1535
- array(
1536
- ':cat_id' => $cat['entity_id']
1537
- )
1538
- );
1539
-
1540
- if ($cat_products['COUNT(*)'] == 0 && empty($child_cat) && $this->_getRefreshSetting('update_hide_category') == 1) {
1541
- $this->_connRes->query(
1542
- "UPDATE `{$this->_tablePrefix}catalog_category_entity_int`
1543
- SET `value` = 0
1544
- WHERE `attribute_id` = @category_active_id
1545
- AND entity_id = :cat_id",
1546
- array(
1547
- ':cat_id' => $cat['entity_id']
1548
- )
1549
- );
1550
- } else if (!empty($child_cat)) {
1551
- $this->CountChildProd($child_cat);
1552
- }
1553
- }
1554
- }
1555
-
1556
- /**
1557
- * Run categories resorting procedure
1558
- */
1559
- private function _runCategoriesSorting()
1560
- {
1561
- // Check if this is last imported product
1562
- // Do category sort and set categories without products to inactive
1563
- $catCollection = Mage::getModel('catalog/category')
1564
- ->getCollection()
1565
- ->addAttributeToSort('name', 'ASC');
1566
-
1567
- $category_sort = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/category_sort');
1568
- if ($category_sort == 1) {
1569
- $position = 1;
1570
- }
1571
- foreach ($catCollection as $category) {
1572
-
1573
- if ($category_sort) {
1574
- $query = "UPDATE `{$this->_tablePrefix}catalog_category_entity` SET position = :position WHERE entity_id = :cat_id ";
1575
- $this->_connRes->query($query, array(
1576
- ':position' => $position++,
1577
- ':cat_id' => $category->getId()
1578
- ));
1579
- }
1580
-
1581
- $query = "SELECT COUNT(*) FROM `{$this->_tablePrefix}catalog_category_product` WHERE category_id = :cat_id ";
1582
- //$query = "SELECT COUNT(category_id) FROM `{$this->_tablePrefix}catalog_category_product` WHERE category_id = :cat_id ";
1583
- $cat_products = $this->_connRes->fetchRow($query, array(
1584
- ':cat_id' => $category->getId()
1585
- ));
1586
-
1587
- //if ($cat_products['COUNT(category_id)'] == 0) {
1588
- if ($cat_products['COUNT(*)'] == 0) {
1589
- $query = "SELECT `entity_id` FROM `{$this->_tablePrefix}catalog_category_entity` WHERE parent_id = :cat_id";
1590
- $child_cat = $this->_connRes->fetchAll($query, array(
1591
- ':cat_id' => $category->getId()
1592
- ));
1593
-
1594
- if (isset($child_cat) && count($child_cat) > 0) {
1595
- //Count child categories products and set them to inactive if they have no
1596
- $this->CountChildProd($child_cat);
1597
- } elseif($this->_getRefreshSetting('update_hide_category') == 1) {
1598
-
1599
- $this->_connRes->query("UPDATE `{$this->_tablePrefix}catalog_category_entity_int`
1600
- SET `value` = 0 WHERE `attribute_id` = @category_active_id AND entity_id = :cat_id", array(
1601
- ':cat_id' => $category->getId()
1602
- ));
1603
- $query = "SELECT path
1604
- FROM `{$this->_tablePrefix}catalog_category_entity`
1605
- WHERE entity_id = :cat_id ";
1606
- $cat_products = $this->_connRes->fetchRow(
1607
- $query,
1608
- array(
1609
- ':cat_id' => $category->getId()
1610
- )
1611
- );
1612
- $ar_cat_products = explode("/", $cat_products['path']);
1613
-
1614
- $count_of_all_products = 0;
1615
-
1616
- foreach($ar_cat_products as $key => $value) {
1617
- $query = "SELECT COUNT(*) FROM `{$this->_tablePrefix}catalog_category_product` WHERE category_id = :cat_id ";
1618
- //$query = "SELECT COUNT(category_id) FROM `{$this->_tablePrefix}catalog_category_product` WHERE category_id = :cat_id ";
1619
- $products_of_category = $this->_connRes->fetchRow($query, array(
1620
- ':cat_id' => $value
1621
- ));
1622
-
1623
- $cat = Mage::getModel('catalog/category')->load($value);
1624
-
1625
- $subcats = $cat->getChildren();
1626
- $ar_subcatgs = explode(',',$subcats);
1627
- foreach($ar_subcatgs as $item) {
1628
- $query = "SELECT COUNT(*) FROM `{$this->_tablePrefix}catalog_category_product` WHERE category_id = :cat_id ";
1629
- //$query = "SELECT COUNT(category_id) FROM `{$this->_tablePrefix}catalog_category_product` WHERE category_id = :cat_id ";
1630
- $products_of_category_children = $this->_connRes->fetchRow($query, array(
1631
- ':cat_id' => $item
1632
- ));
1633
- //$count_of_all_products += $products_of_category_children['COUNT(*)'];
1634
- if($products_of_category_children > 0) {
1635
- $count_of_all_products += $products_of_category_children['COUNT(*)'];
1636
- }
1637
- }
1638
-
1639
- //p($count_of_all_products);
1640
- if($products_of_category['COUNT(*)'] == 0 && $count_of_all_products == 0) {
1641
- //if($products_of_category['COUNT(category_id)'] == 0 && $count_of_all_products == 0) {
1642
- $this->_connRes->query("UPDATE `{$this->_tablePrefix}catalog_category_entity_int`
1643
- SET `value` = 0 WHERE `attribute_id` = @category_active_id AND entity_id = :cat_id", array(
1644
- ':cat_id' => $value
1645
- ));
1646
- }
1647
- else {
1648
- $this->_connRes->query("UPDATE `{$this->_tablePrefix}catalog_category_entity_int`
1649
- SET `value` = 1 WHERE `attribute_id` = @category_active_id AND entity_id = :cat_id", array(
1650
- ':cat_id' => $value
1651
- ));
1652
- }
1653
- }
1654
- }
1655
- else {
1656
- $this->_connRes->query("UPDATE `{$this->_tablePrefix}catalog_category_entity_int`
1657
- SET `value` = 1 WHERE `attribute_id` = @category_active_id AND entity_id = :cat_id", array(
1658
- ':cat_id' => $category->getId()
1659
- ));
1660
- }
1661
- }
1662
- }
1663
- }
1664
-
1665
- /**
1666
- * @param object $DB_logger
1667
- * @throws Exception
1668
- */
1669
- public function deleteOldProducts($DB_logger)
1670
- {
1671
- $delete_old_products = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/delete_old_products');
1672
- if ($delete_old_products) {
1673
-
1674
- try {
1675
- $db_res = Mage::getSingleton('core/resource')->getConnection('core_write');
1676
- $db_res->query("SELECT @is_iceimport_id := `attribute_id`
1677
- FROM {$this->_tablePrefix}eav_attribute
1678
- WHERE attribute_code = 'is_iceimport'");
1679
-
1680
- //$count_prod = $db_res->fetchRow("SELECT COUNT(*) AS count_prod
1681
- $count_prod = $db_res->fetchRow("SELECT COUNT(cpe.entity_id) AS count_prod
1682
- FROM {$this->_tablePrefix}catalog_product_entity AS cpe
1683
- JOIN {$this->_tablePrefix}catalog_product_entity_varchar AS cpev
1684
- ON cpe.entity_id = cpev.entity_id
1685
- AND cpev.value = 1
1686
- AND cpev.attribute_id = @is_iceimport_id");
1687
-
1688
- $count_prod = $count_prod['count_prod'];
1689
-
1690
- if ($count_prod > 0) {
1691
- //iceimport products exists, amount > 0
1692
- //$count_del_prod = $db_res->fetchRow("SELECT COUNT(*) AS count__del_prod
1693
- $count_del_prod = $db_res->fetchRow("SELECT COUNT(cpe.entity_id) AS count__del_prod
1694
- FROM {$this->_tablePrefix}catalog_product_entity AS cpe
1695
- JOIN {$this->_tablePrefix}catalog_product_entity_varchar AS cpev
1696
- ON cpe.entity_id = cpev.entity_id
1697
- AND cpev.value = 1
1698
- AND cpev.attribute_id = @is_iceimport_id
1699
- LEFT JOIN {$this->_tablePrefix}iceshop_iceimport_imported_product_ids AS iip
1700
- ON cpe.entity_id = iip.product_id
1701
- WHERE iip.product_id IS NULL");
1702
-
1703
- if(!empty($count_del_prod['count__del_prod'])){
1704
- $count_del_prod = $count_del_prod['count__del_prod'];
1705
- } else {
1706
- $count_del_prod = 0;
1707
- }
1708
-
1709
- $delete_old_products_tolerance = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/delete_old_products_tolerance');
1710
-
1711
- if ($count_del_prod > 0) {
1712
- //iceimport products to delete exists, amount > 0
1713
- $delete_old_products_tolerance = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/delete_old_products_tolerance');
1714
-
1715
- if (round(($count_del_prod / $count_prod * 100), 0) < $delete_old_products_tolerance) {
1716
-
1717
- //iceimport products to delete franction is less than allowed tolerance, deletion approved
1718
- $DB_logger->insertLogEntry('iceimport_count_delete_product', $count_del_prod);
1719
- $db_res->query("DELETE cpe
1720
- FROM {$this->_tablePrefix}catalog_product_entity AS cpe
1721
- JOIN {$this->_tablePrefix}catalog_product_entity_varchar AS cpev
1722
- ON cpe.entity_id = cpev.entity_id
1723
- AND cpev.value = 1
1724
- AND cpev.attribute_id = @is_iceimport_id
1725
- LEFT JOIN {$this->_tablePrefix}iceshop_iceimport_imported_product_ids AS iip
1726
- ON cpe.entity_id = iip.product_id
1727
- WHERE iip.product_id IS NULL");
1728
-
1729
- $db_res->query("DELETE FROM {$this->_tablePrefix}iceshop_iceimport_imported_product_ids");
1730
- } else {
1731
- $error_message = 'Attempt to delete more old products than allowed in Iceimport configuration. Interruption of the process.';
1732
- $DB_logger->insertLogEntry('error_try_delete_product', $error_message);
1733
- $error_message2 = 'Old product percentage: ' . round(($count_del_prod / $count_prod * 100), 2) . '%';
1734
- $DB_logger->insertLogEntry('error_try_delete_product_percentage', $error_message2);
1735
-
1736
- //flag to warning notice
1737
- $DB_logger->insertLogEntry('try_delete_product_percentage_warning_flag', 'SHOW');
1738
- print $error_message;
1739
- print $error_message2;
1740
- exit;
1741
- }
1742
- }
1743
- }
1744
- } catch (Exception $e) {
1745
- throw new Exception($e->getMessage());
1746
- }
1747
- }
1748
- }
1749
-
1750
- /**
1751
- * @throws Exception
1752
- */
1753
- public function finish()
1754
- {
1755
- /**
1756
- * Back compatibility event
1757
- */
1758
- $this->_checkAndSetIceField();
1759
- $DB_logger = Mage::helper('iceimport/db');
1760
- $tablePrefix = '';
1761
- $tPrefix = (array)Mage::getConfig()->getTablePrefix();
1762
- if (!empty($tPrefix)) {
1763
- $tablePrefix = $tPrefix[0];
1764
- }
1765
- $count_imported_products = $DB_logger->getRowsCount($tablePrefix . "iceshop_iceimport_imported_product_ids");
1766
- $DB_logger->insertLogEntry('iceimport_count_imported_products', $count_imported_products);
1767
-
1768
- Mage::dispatchEvent($this->_eventPrefix . '_after', array());
1769
-
1770
- $re_index_required = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/is_reindex_required_import');
1771
- if ((isset($re_index_required)) && ($re_index_required == 1)) {
1772
- $entity = new Varien_Object();
1773
- Mage::getSingleton('index/indexer')->processEntityAction(
1774
- $entity,
1775
- self::ENTITY,
1776
- Mage_Index_Model_Event::TYPE_SAVE
1777
- );
1778
- }
1779
- }
1780
-
1781
-
1782
- /**
1783
- * Method return id categoryees where 'unspsc' empty.
1784
- * @param intneger $store_id
1785
- * @return array
1786
- */
1787
- public function getCategoryIdEmtyUnspsc($store_id=0){
1788
-
1789
- $db_res = Mage::getSingleton('core/resource')->getConnection('core_write');
1790
- $query = "SELECT ccev.`entity_id` FROM `{$this->_tablePrefix}catalog_category_entity_varchar` AS ccev
1791
- LEFT JOIN `{$this->_tablePrefix}eav_attribute` AS ea
1792
- ON ea.`attribute_id` = ccev.`attribute_id`
1793
- WHERE ea.`attribute_code`='unspsc' AND (ccev.`store_id` = 0 OR ccev.`store_id`=:store_id) AND ccev.`value` IS NULL;";
1794
-
1795
- return $this->_connRes->fetchAll($query, array( ':store_id' => $store_id ));
1796
- }
1797
-
1798
- /**
1799
- * Check active_ice field and update if need
1800
- * @throws Mage_Core_Exception
1801
- */
1802
- private function _checkAndSetIceField()
1803
- {
1804
- $attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'active_ice')->getData();
1805
- if (isset($attribute['attribute_id'])) {
1806
- $write = Mage::getSingleton('core/resource')->getConnection('core_write');
1807
- $read = Mage::getSingleton('core/resource')->getConnection('core_read');
1808
- $prefix = Mage::getConfig()->getTablePrefix();
1809
- if (!empty($prefix[0])) {
1810
- $prefix = $prefix[0];
1811
- } else {
1812
- $prefix = '';
1813
- }
1814
-
1815
- $sql = "DROP PROCEDURE IF EXISTS FIELD_EXISTS;";
1816
- $write->query($sql);
1817
-
1818
- $sql = "CREATE PROCEDURE FIELD_EXISTS(
1819
- OUT _exists BOOLEAN, -- return value
1820
- IN tableName CHAR(255) CHARACTER SET 'utf8', -- name of table to look for
1821
- IN columnName CHAR(255) CHARACTER SET 'utf8', -- name of column to look for
1822
- IN dbName CHAR(255) CHARACTER SET 'utf8' -- optional specific db
1823
- ) BEGIN
1824
- -- try to lookup db if none provided
1825
- SET @_dbName := IF(dbName IS NULL, database(), dbName);
1826
-
1827
- IF CHAR_LENGTH(@_dbName) = 0
1828
- THEN -- no specific or current db to check against
1829
- SELECT
1830
- FALSE
1831
- INTO _exists;
1832
- ELSE -- we have a db to work with
1833
- SELECT
1834
- IF(count(*) > 0, TRUE, FALSE)
1835
- INTO _exists
1836
- FROM information_schema.COLUMNS c
1837
- WHERE
1838
- c.TABLE_SCHEMA = @_dbName
1839
- AND c.TABLE_NAME = tableName
1840
- AND c.COLUMN_NAME = columnName;
1841
- END IF;
1842
- END;";
1843
- $write->query($sql);
1844
-
1845
- $sql = "CALL FIELD_EXISTS(@_exists, '{$prefix}catalog_product_entity', 'active_ice', NULL);";
1846
- $read->query($sql);
1847
-
1848
- $sql = "SELECT @_exists;";
1849
- $res = $read->fetchCol($sql);
1850
- if (array_shift($res)) {
1851
- $options = Mage::getModel('eav/config')->getAttribute('catalog_product', 'active_ice')->getSource()->getAllOptions();
1852
- $optionId = false;
1853
- foreach ($options as $option) {
1854
- if ($option['label'] == 'Yes') {
1855
- $optionId = $option['value'];
1856
- break;
1857
- }
1858
- }
1859
- if ($optionId) {
1860
- $sql = "UPDATE `{$prefix}catalog_product_entity` SET `active_ice` = '{$optionId}' WHERE `active_ice` IS NULL;";
1861
- $write->query($sql);
1862
- }
1863
- }
1864
- }
1865
- }
1866
- }
1867
-
1868
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/ICEshop/Iceimport/Model/Dataflow/Batch/Import.php CHANGED
@@ -49,5 +49,4 @@ class ICEshop_Iceimport_Model_Dataflow_Batch_Import extends Mage_Dataflow_Model_
49
 
50
  return $this;
51
  }
52
-
53
  }
49
 
50
  return $this;
51
  }
 
52
  }
app/code/community/ICEshop/Iceimport/Model/Observer.php CHANGED
@@ -1,5 +1,7 @@
1
  <?php
2
 
 
 
3
  class ICEshop_Iceimport_Model_Observer
4
  {
5
  /**
@@ -29,13 +31,17 @@ class ICEshop_Iceimport_Model_Observer
29
 
30
  //init logger
31
 
32
- $transactions_enabled = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/transactions_enabled');
 
 
 
 
 
33
  $DB_logger = Mage::helper('iceimport/db');
34
- $date_crone_start = date('Y-m-d H:i:s');
35
  $date = date('m/d/Y H:i:s');
36
  $DB_logger->insertLogEntry('iceimport_import_status_cron', 'Started');
37
  $DB_logger->insertLogEntry('iceimport_import_started', $date);
38
- $DB_logger->insertLogEntry('iceimport_import_ended', '');
39
  $DB_logger->deleteLogEntry('error_try_delete_product');
40
  $DB_logger->deleteLogEntry('error_try_delete_product_percentage');
41
  $DB_logger->deleteLogEntry('try_delete_product_percentage_warning_flag');
@@ -48,17 +54,20 @@ class ICEshop_Iceimport_Model_Observer
48
  $tablePrefix = $tPrefix[0];
49
  }
50
 
 
 
 
 
51
  //service actions
52
  ini_set('max_execution_time', 0);
53
- ini_set("memory_limit","-1");
54
 
55
- $profileId = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/iceimport_profile');
56
 
57
- if (!$profileId) {
58
  $profileId = 3;
59
- }
 
60
  $logFileName = 'test.log';
61
- $recordCount = 0;
62
 
63
  //checking locks
64
  $this->indexProcess = new Mage_Index_Model_Process();
@@ -79,20 +88,23 @@ class ICEshop_Iceimport_Model_Observer
79
  $userModel->setUserId(0);
80
  Mage::getSingleton('admin/session')->setUser($userModel);
81
 
82
- if ($profileId) {
83
  $profile->load($profileId);
84
  if (!$profile->getId()) {
85
  Mage::getSingleton('adminhtml/session')->addError('The profile that you are trying to save no longer exists');
86
  }
87
- }
88
- $profile->run();
 
89
  $batchModel = Mage::getSingleton('dataflow/batch');
90
  $allMsg = '';
91
 
 
 
92
  //batch processing
93
 
94
- if ($batchModel->getId()) {
95
- if ($batchModel->getAdapter()) {
96
 
97
  $batchId = $batchModel->getId();
98
 
@@ -103,7 +115,6 @@ class ICEshop_Iceimport_Model_Observer
103
  $adapter = Mage::getModel($batchModel->getAdapter());
104
  $run_only_images = 0;
105
 
106
-
107
  try {
108
  if (method_exists($adapter, 'getAdapterSetting')) {
109
  $run_only_images = $adapter->getAdapterSetting('iceshop_iceimport_importprod_root/importprod/images_queue_processing_only');
@@ -118,42 +129,47 @@ class ICEshop_Iceimport_Model_Observer
118
  $DB_logger->insertLogEntry('iceimport_import_status_cron', 'Failed');
119
  throw new Exception($e->getMessage());
120
  }
121
- $importData = array();
122
  if ($run_only_images == 0) {
123
 
124
- foreach ($importIds as $key => $importId) {
125
-
126
- $recordCount++;
127
- try {
128
- $batchImportModel->load($importId);
129
- if (!$batchImportModel->getId()) {
130
- $errors[] = Mage::helper('dataflow')->__('Skip undefined row');
131
- continue;
132
- }
133
-
134
- $importData[$key] = $batchImportModel->getBatchData();
135
- $importData[$key]['batchId'] = $batchId;
136
-
137
- } catch (Exception $ex) {
138
- if (!empty($importData['sku'])) {
139
- Mage::log('Record# ' . $recordCount . ' - SKU = ' . $importData['sku'] . ' - Error - ' . $ex->getMessage(), null, $logFileName);
140
- } else {
141
- Mage::log('Record# ' . $recordCount . ' - SKU = undefined - Error - ' . $ex->getMessage(), null, $logFileName);
142
- }
143
  }
144
- }
145
 
146
- try {
147
- $adapter->saveRow($importData);
148
  } catch (Exception $e) {
149
- $DB_logger->insertLogEntry('iceimport_import_status_cron', 'Failed');
150
  Mage::log($e->getMessage(), null, $logFileName);
 
 
 
 
 
 
 
 
 
 
 
151
  }
152
  }
153
 
154
  //run image queue processing
155
 
156
- $adapter->processImageQueue($logFileName);
 
 
157
 
158
  //check indexes and run reindex
159
 
@@ -177,8 +193,8 @@ class ICEshop_Iceimport_Model_Observer
177
  foreach ($profile->getExceptions() as $e) {
178
  Mage::log($e->getMessage(), null, $logFileName);
179
  }
180
- }
181
- }
182
 
183
  print 'Import Completed';
184
 
@@ -187,13 +203,10 @@ class ICEshop_Iceimport_Model_Observer
187
 
188
  //extra logging
189
  Mage::log("Import Completed", null, $logFileName);
190
- $count_imported_products = $DB_logger->getRowsCount($tablePrefix . "iceshop_iceimport_imported_product_ids");
191
- $DB_logger->insertLogEntry('iceimport_count_imported_products', $count_imported_products);
192
 
193
  // clear dataflow_batch_import table
194
  try {
195
  $this->updateCatalogCategoryChildren();
196
- $db_res->query("DELETE FROM {$tablePrefix}iceshop_iceimport_imported_product_ids");
197
  $db_res->query("TRUNCATE {$tablePrefix}dataflow_batch_import");
198
  } catch (Exception $e) {
199
  $DB_logger->insertLogEntry('iceimport_import_status_cron', 'Failed');
@@ -204,8 +217,11 @@ class ICEshop_Iceimport_Model_Observer
204
  $date = date('m/d/Y H:i:s');
205
  $DB_logger->insertLogEntry('iceimport_import_ended', $date);
206
  $this->setCroneStatus('finished', $date);
207
- //$db_res->commit();
208
- unset($db_res, $DB_logger, $date, $profile, $profileId, $logFileName);
 
 
 
209
  }
210
 
211
  /**
1
  <?php
2
 
3
+ include dirname(__DIR__).DIRECTORY_SEPARATOR.'/include.php';
4
+
5
  class ICEshop_Iceimport_Model_Observer
6
  {
7
  /**
31
 
32
  //init logger
33
 
34
+ //$time_start = microtime(1);
35
+
36
+ $delete_old_products = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/delete_old_products');
37
+ $process_image_queue = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/process_image_queue');
38
+ $category_sort = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/category_sort');
39
+
40
  $DB_logger = Mage::helper('iceimport/db');
41
+ $date_crone_start = date('m/d/Y H:i:s');
42
  $date = date('m/d/Y H:i:s');
43
  $DB_logger->insertLogEntry('iceimport_import_status_cron', 'Started');
44
  $DB_logger->insertLogEntry('iceimport_import_started', $date);
 
45
  $DB_logger->deleteLogEntry('error_try_delete_product');
46
  $DB_logger->deleteLogEntry('error_try_delete_product_percentage');
47
  $DB_logger->deleteLogEntry('try_delete_product_percentage_warning_flag');
54
  $tablePrefix = $tPrefix[0];
55
  }
56
 
57
+ /*ini_set('display_errors', 1);
58
+ ini_set('display_startup_errors', 1);
59
+ error_reporting(E_ALL);*/
60
+
61
  //service actions
62
  ini_set('max_execution_time', 0);
 
63
 
64
+ //$profileId = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/iceimport_profile');
65
 
66
+ /* if (!$profileId) {
67
  $profileId = 3;
68
+ }*/
69
+
70
  $logFileName = 'test.log';
 
71
 
72
  //checking locks
73
  $this->indexProcess = new Mage_Index_Model_Process();
88
  $userModel->setUserId(0);
89
  Mage::getSingleton('admin/session')->setUser($userModel);
90
 
91
+ /*if ($profileId) {
92
  $profile->load($profileId);
93
  if (!$profile->getId()) {
94
  Mage::getSingleton('adminhtml/session')->addError('The profile that you are trying to save no longer exists');
95
  }
96
+ }*/
97
+
98
+ //$profile->run();
99
  $batchModel = Mage::getSingleton('dataflow/batch');
100
  $allMsg = '';
101
 
102
+ $iceimport = new Iceimport();
103
+
104
  //batch processing
105
 
106
+ //if ($batchModel->getId()) {
107
+ //if ($batchModel->getAdapter()) {
108
 
109
  $batchId = $batchModel->getId();
110
 
115
  $adapter = Mage::getModel($batchModel->getAdapter());
116
  $run_only_images = 0;
117
 
 
118
  try {
119
  if (method_exists($adapter, 'getAdapterSetting')) {
120
  $run_only_images = $adapter->getAdapterSetting('iceshop_iceimport_importprod_root/importprod/images_queue_processing_only');
129
  $DB_logger->insertLogEntry('iceimport_import_status_cron', 'Failed');
130
  throw new Exception($e->getMessage());
131
  }
132
+
133
  if ($run_only_images == 0) {
134
 
135
+ try {
136
+
137
+ $iceimport->importProduct();
138
+
139
+ //$count_imported_products = $DB_logger->getRowsCount($tablePrefix . "iceshop_iceimport_imported_product_ids");
140
+ $select_count_imported_products = $db_res->query("SELECT COUNT(DISTINCT product_sku) as count FROM {$tablePrefix}iceshop_iceimport_imported_product_ids WHERE product_sku IS NOT NULL;");
141
+ $count_imported_products = $select_count_imported_products->fetch()['count'];
142
+ $DB_logger->insertLogEntry('iceimport_count_imported_products', $count_imported_products);
143
+
144
+ if ($delete_old_products) {
145
+ $iceimport->deleteOldProducts($DB_logger);
146
+ }
147
+
148
+ if ($category_sort) {
149
+ $iceimport->runCategoriesSorting();
 
 
 
 
150
  }
 
151
 
 
 
152
  } catch (Exception $e) {
 
153
  Mage::log($e->getMessage(), null, $logFileName);
154
+ $DB_logger->insertLogEntry('iceimport_import_status_cron', 'Failed');
155
+ $date = date('m/d/Y H:i:s');
156
+ $DB_logger->insertLogEntry('iceimport_import_ended', $date);
157
+ $this->setCroneStatus('Failed', $date);
158
+ print 'Import failed';
159
+ $iceimport->deleteTemFileForAttributes();
160
+ $iceimport->deleteTempFileForCategories();
161
+ $iceimport->deleteTempFileForCatalogCategoryProductInsert();
162
+ $iceimport->deleteTempTableCats();
163
+ $iceimport->deleteTempTableProds();
164
+ exit;
165
  }
166
  }
167
 
168
  //run image queue processing
169
 
170
+ if ($process_image_queue) {
171
+ $iceimport->processImageQueue($logFileName);
172
+ }
173
 
174
  //check indexes and run reindex
175
 
193
  foreach ($profile->getExceptions() as $e) {
194
  Mage::log($e->getMessage(), null, $logFileName);
195
  }
196
+ //}
197
+ //}
198
 
199
  print 'Import Completed';
200
 
203
 
204
  //extra logging
205
  Mage::log("Import Completed", null, $logFileName);
 
 
206
 
207
  // clear dataflow_batch_import table
208
  try {
209
  $this->updateCatalogCategoryChildren();
 
210
  $db_res->query("TRUNCATE {$tablePrefix}dataflow_batch_import");
211
  } catch (Exception $e) {
212
  $DB_logger->insertLogEntry('iceimport_import_status_cron', 'Failed');
217
  $date = date('m/d/Y H:i:s');
218
  $DB_logger->insertLogEntry('iceimport_import_ended', $date);
219
  $this->setCroneStatus('finished', $date);
220
+ unset($db_res, $DB_logger, $date, $profile, $logFileName);
221
+ /*$time_end = microtime(1);
222
+ var_dump(memory_get_peak_usage(true) / 1024 / 1024);
223
+
224
+ echo $time_start - $time_end;*/
225
  }
226
 
227
  /**
app/code/community/ICEshop/Iceimport/Model/System/Config/Category.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class ICEshop_Iceimport_Model_System_Config_Category
4
+ {
5
+
6
+ public function toOptionArray()
7
+ {
8
+
9
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
10
+ $prefix = Mage::getConfig()->getTablePrefix();
11
+
12
+ $select_category_entity_type = $read->query("SELECT entity_type_id FROM `{$prefix}eav_entity_type` WHERE entity_type_code = 'catalog_category';");
13
+ $category_entity_type = $select_category_entity_type->fetch()['entity_type_id'];
14
+
15
+ $select_name_id = $read->query("SELECT attribute_id FROM `{$prefix}eav_attribute` WHERE attribute_code = 'name' AND entity_type_id = $category_entity_type;");
16
+ $name_id = $select_name_id->fetch()['attribute_id'];
17
+
18
+ $sql = "SELECT ccev.value, cce.entity_id FROM {$prefix}catalog_category_entity cce JOIN {$prefix}catalog_category_entity_varchar ccev ON cce.entity_id = ccev.entity_id WHERE cce.level = 1 AND attribute_id = $name_id;";
19
+ $result = $read->fetchAll($sql);
20
+
21
+ $paramsArray = [];
22
+
23
+ if (!empty($result)) {
24
+ foreach ($result as $key => $value) {
25
+ $paramsArray[$value['entity_id']] = $value['value'];
26
+ }
27
+ }
28
+
29
+ return $paramsArray;
30
+ }
31
+ }
32
+
33
+ ?>
app/code/community/ICEshop/Iceimport/controllers/Adminhtml/IceimportController.php CHANGED
@@ -201,15 +201,6 @@ class ICEshop_Iceimport_Adminhtml_IceimportController extends Mage_Adminhtml_Con
201
  <?php if (!empty($import_status_cron['log_value'])) echo $import_status_cron['log_value']; else print $helper->__("Never started till now"); ?>
202
  </td>
203
  </tr>
204
- <?php if (!empty($currently_imported_products) && ($import_status_cron['log_value'] == 'Running' || $import_status_cron['log_value'] == 'Failed')) { ?>
205
- <tr>
206
- <td class="label"><label><?php print $helper->__("Currently products imported"); ?>
207
- :</label></td>
208
- <td class="value">
209
- <?php echo $currently_imported_products . ' from ' . $data_flows[0]['row_count']; ?>
210
- </td>
211
- </tr>
212
- <?php } ?>
213
  <tr>
214
  <td colspan="2" class="label">
215
  <label class="iceimport-label-uppercase iceimport-label-bold">
201
  <?php if (!empty($import_status_cron['log_value'])) echo $import_status_cron['log_value']; else print $helper->__("Never started till now"); ?>
202
  </td>
203
  </tr>
 
 
 
 
 
 
 
 
 
204
  <tr>
205
  <td colspan="2" class="label">
206
  <label class="iceimport-label-uppercase iceimport-label-bold">
app/code/community/ICEshop/Iceimport/controllers/Adminhtml/System/Convert/GuiController.php CHANGED
@@ -2,18 +2,18 @@
2
 
3
  require_once Mage::getModuleDir('controllers', 'Mage_Adminhtml') . DS . 'System' . DS . 'Convert' . DS . 'GuiController.php';
4
 
 
 
5
  class ICEshop_Iceimport_Adminhtml_System_Convert_GuiController extends Mage_Adminhtml_System_Convert_GuiController
6
  {
7
 
8
  public function batchRunAction()
9
  {
10
-
11
  if ($this->getRequest()->isPost()) {
12
 
13
- $transactions_enabled = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/transactions_enabled');
14
  $batchId = $this->getRequest()->getPost('batch_id', 0);
15
  $rowIds = $this->getRequest()->getPost('rows');
16
- $db_res = Mage::getSingleton('core/resource')->getConnection('core_write');
17
  /* @var $batchModel Mage_Dataflow_Model_Batch */
18
  $batchModel = Mage::getModel('dataflow/batch')->load($batchId);
19
 
@@ -52,18 +52,13 @@ class ICEshop_Iceimport_Adminhtml_System_Convert_GuiController extends Mage_Admi
52
  $saved ++;
53
  }
54
 
55
- if ($transactions_enabled != 0) {
56
- try {
57
- $db_res->beginTransaction();
58
- $adapter->saveRow($importData, true);
59
- $db_res->commit();
60
- } catch (Exception $e) {
61
- $db_res->rollBack();
62
- throw $e;
63
- }
64
- }
65
- else {
66
- $adapter->saveRow($importData);
67
  }
68
 
69
  if (method_exists($adapter, 'getEventPrefix')) {
@@ -87,4 +82,34 @@ class ICEshop_Iceimport_Adminhtml_System_Convert_GuiController extends Mage_Admi
87
  $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
88
  }
89
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  }
2
 
3
  require_once Mage::getModuleDir('controllers', 'Mage_Adminhtml') . DS . 'System' . DS . 'Convert' . DS . 'GuiController.php';
4
 
5
+ include dirname(__DIR__).DIRECTORY_SEPARATOR.'../../../include.php';
6
+
7
  class ICEshop_Iceimport_Adminhtml_System_Convert_GuiController extends Mage_Adminhtml_System_Convert_GuiController
8
  {
9
 
10
  public function batchRunAction()
11
  {
 
12
  if ($this->getRequest()->isPost()) {
13
 
 
14
  $batchId = $this->getRequest()->getPost('batch_id', 0);
15
  $rowIds = $this->getRequest()->getPost('rows');
16
+
17
  /* @var $batchModel Mage_Dataflow_Model_Batch */
18
  $batchModel = Mage::getModel('dataflow/batch')->load($batchId);
19
 
52
  $saved ++;
53
  }
54
 
55
+ $iceimport = new Iceimport();
56
+
57
+ try {
58
+
59
+ $iceimport->importProduct($importData);
60
+ } catch (Exception $e) {
61
+ $errors[] = $e->getMessage();
 
 
 
 
 
62
  }
63
 
64
  if (method_exists($adapter, 'getEventPrefix')) {
82
  $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
83
  }
84
  }
85
+
86
+ public function batchFinishAction()
87
+ {
88
+
89
+ $DB_logger = Mage::helper('iceimport/db');
90
+ $delete_old_products = (int)Mage::getStoreConfig('iceshop_iceimport_importprod_root/importprod/delete_old_products');
91
+
92
+ $batchId = $this->getRequest()->getParam('id');
93
+ if ($batchId) {
94
+ $batchModel = Mage::getModel('dataflow/batch')->load($batchId);
95
+ /* @var $batchModel Mage_Dataflow_Model_Batch */
96
+
97
+ if ($batchModel->getId()) {
98
+ $result = array();
99
+ try {
100
+ $batchModel->beforeFinish();
101
+ } catch (Mage_Core_Exception $e) {
102
+ $result['error'] = $e->getMessage();
103
+ } catch (Exception $e) {
104
+ $result['error'] = Mage::helper('adminhtml')->__('An error occurred while finishing process. Please refresh the cache');
105
+ }
106
+ $batchModel->delete();
107
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
108
+ }
109
+ }
110
+ if ($delete_old_products) {
111
+ $iceimport = new Iceimport();
112
+ $iceimport->deleteOldProducts($DB_logger);
113
+ }
114
+ }
115
  }
app/code/community/ICEshop/Iceimport/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <ICEshop_Iceimport>
5
- <version>1.7.23</version>
6
  </ICEshop_Iceimport>
7
  </modules>
8
  <admin>
@@ -41,12 +41,6 @@
41
  </iceimport>
42
  </blocks>
43
  <models>
44
- <catalog>
45
- <rewrite>
46
- <!-- Override Mage_Catalog_Model_Convert_Adapter_Product -->
47
- <convert_adapter_product>ICEshop_Iceimport_Model_Convert_Adapter_Product</convert_adapter_product>
48
- </rewrite>
49
- </catalog>
50
  <dataflow>
51
  <rewrite>
52
  <!-- Override Mage_Catalog_Model_Convert_Adapter_Product -->
@@ -126,18 +120,19 @@
126
  <import_product_short_description>1</import_product_short_description>
127
  <import_product_description>1</import_product_description>
128
  <iceimport_profile>3</iceimport_profile>
129
- <transactions_enabled>0</transactions_enabled>
130
  <import_prices>1</import_prices>
131
  <import_stock>1</import_stock>
 
 
132
  <import_product_delivery_eta>1</import_product_delivery_eta>
133
  <import_images>1</import_images>
 
134
  <update_categories_from_csv>1</update_categories_from_csv>
135
  <update_status_from_csv>1</update_status_from_csv>
136
  <update_visibility_from_csv>1</update_visibility_from_csv>
137
  <update_is_in_stock_from_csv>1</update_is_in_stock_from_csv>
138
  <update_hide_category>1</update_hide_category>
139
  <update_url_key_from_csv>1</update_url_key_from_csv>
140
- <iceimport_batch_size>10</iceimport_batch_size>
141
  <import_new_products>1</import_new_products>
142
  <delete_old_products_tolerance>25</delete_old_products_tolerance>
143
  <images_queue_processing_only>0</images_queue_processing_only>
2
  <config>
3
  <modules>
4
  <ICEshop_Iceimport>
5
+ <version>1.8.0</version>
6
  </ICEshop_Iceimport>
7
  </modules>
8
  <admin>
41
  </iceimport>
42
  </blocks>
43
  <models>
 
 
 
 
 
 
44
  <dataflow>
45
  <rewrite>
46
  <!-- Override Mage_Catalog_Model_Convert_Adapter_Product -->
120
  <import_product_short_description>1</import_product_short_description>
121
  <import_product_description>1</import_product_description>
122
  <iceimport_profile>3</iceimport_profile>
 
123
  <import_prices>1</import_prices>
124
  <import_stock>1</import_stock>
125
+ <batch_size>100000</batch_size>
126
+ <default_category>2</default_category>
127
  <import_product_delivery_eta>1</import_product_delivery_eta>
128
  <import_images>1</import_images>
129
+ <process_image_queue>0</process_image_queue>
130
  <update_categories_from_csv>1</update_categories_from_csv>
131
  <update_status_from_csv>1</update_status_from_csv>
132
  <update_visibility_from_csv>1</update_visibility_from_csv>
133
  <update_is_in_stock_from_csv>1</update_is_in_stock_from_csv>
134
  <update_hide_category>1</update_hide_category>
135
  <update_url_key_from_csv>1</update_url_key_from_csv>
 
136
  <import_new_products>1</import_new_products>
137
  <delete_old_products_tolerance>25</delete_old_products_tolerance>
138
  <images_queue_processing_only>0</images_queue_processing_only>
app/code/community/ICEshop/Iceimport/etc/system.xml CHANGED
@@ -202,12 +202,21 @@
202
  <show_in_website>1</show_in_website>
203
  <show_in_store>1</show_in_store>
204
  </import_images>
 
 
 
 
 
 
 
 
 
205
  <is_reindex_required_import translate="label comment">
206
  <label>Re-index Required</label>
207
  <comment>Choose run re-index all the content after finishing ICEimport or not.</comment>
208
  <frontend_type>select</frontend_type>
209
  <source_model>iceimport/system_config_yesno</source_model>
210
- <sort_order>38</sort_order>
211
  <show_in_default>1</show_in_default>
212
  <show_in_website>1</show_in_website>
213
  <show_in_store>1</show_in_store>
@@ -217,7 +226,7 @@
217
  <comment><![CDATA[Import profile]]></comment>
218
  <frontend_type>select</frontend_type>
219
  <source_model>iceimport/system_config_profiles</source_model>
220
- <sort_order>39</sort_order>
221
  <show_in_default>1</show_in_default>
222
  <show_in_website>1</show_in_website>
223
  <show_in_store>1</show_in_store>
@@ -225,7 +234,7 @@
225
  <cron_settings>
226
  <label>When you want to run cron ?</label>
227
  <frontend_type>text</frontend_type>
228
- <sort_order>40</sort_order>
229
  <validate>required-entry</validate>
230
  <comment>Use Crontab Format (Eg. "30 7 * * *" in 7:30 AM). Don't forget `Flush Magento Cache` and `Flush Cache Storage` after changes.</comment>
231
  <show_in_default>1</show_in_default>
@@ -301,6 +310,16 @@
301
  <show_in_website>1</show_in_website>
302
  <show_in_store>1</show_in_store>
303
  </stock_inventory>
 
 
 
 
 
 
 
 
 
 
304
  <refresh_settings_heading translate="label">
305
  <label>Import Parameters</label>
306
  <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
@@ -309,16 +328,14 @@
309
  <show_in_website>1</show_in_website>
310
  <show_in_store>1</show_in_store>
311
  </refresh_settings_heading>
312
- <iceimport_batch_size translate="label">
313
- <label><![CDATA[Batch size]]></label>
314
- <comment><![CDATA[]]></comment>
315
  <frontend_type>text</frontend_type>
316
- <validate>validate-greater-than-zero</validate>
317
- <sort_order>130</sort_order>
 
318
  <show_in_default>1</show_in_default>
319
- <show_in_website>1</show_in_website>
320
- <show_in_store>1</show_in_store>
321
- </iceimport_batch_size>
322
  <import_new_products translate="label">
323
  <label>Import new products</label>
324
  <comment><![CDATA[Add products from import file if they aren't presented in shop's assortment.]]></comment>
@@ -389,15 +406,6 @@
389
  <show_in_website>1</show_in_website>
390
  <show_in_store>1</show_in_store>
391
  </default_tax>
392
- <transactions_enabled translate="label">
393
- <label>Transactions enabled</label>
394
- <frontend_type>select</frontend_type>
395
- <source_model>iceimport/system_config_yesno</source_model>
396
- <sort_order>145</sort_order>
397
- <show_in_default>1</show_in_default>
398
- <show_in_website>1</show_in_website>
399
- <show_in_store>1</show_in_store>
400
- </transactions_enabled>
401
  <images_queue_processing_only translate="label">
402
  <label><![CDATA[ImagesQueueProcessing only]]></label>
403
  <comment><![CDATA[Run <strong>ONLY</strong> images queue processing instead of whole actions stack. Setting used <strong>ONLY</strong> while running via Cron.]]></comment>
202
  <show_in_website>1</show_in_website>
203
  <show_in_store>1</show_in_store>
204
  </import_images>
205
+ <process_image_queue translate="label">
206
+ <label>Run image queue processing</label>
207
+ <frontend_type>select</frontend_type>
208
+ <source_model>iceimport/system_config_yesno</source_model>
209
+ <sort_order>38</sort_order>
210
+ <show_in_default>1</show_in_default>
211
+ <show_in_website>1</show_in_website>
212
+ <show_in_store>1</show_in_store>
213
+ </process_image_queue>
214
  <is_reindex_required_import translate="label comment">
215
  <label>Re-index Required</label>
216
  <comment>Choose run re-index all the content after finishing ICEimport or not.</comment>
217
  <frontend_type>select</frontend_type>
218
  <source_model>iceimport/system_config_yesno</source_model>
219
+ <sort_order>39</sort_order>
220
  <show_in_default>1</show_in_default>
221
  <show_in_website>1</show_in_website>
222
  <show_in_store>1</show_in_store>
226
  <comment><![CDATA[Import profile]]></comment>
227
  <frontend_type>select</frontend_type>
228
  <source_model>iceimport/system_config_profiles</source_model>
229
+ <sort_order>40</sort_order>
230
  <show_in_default>1</show_in_default>
231
  <show_in_website>1</show_in_website>
232
  <show_in_store>1</show_in_store>
234
  <cron_settings>
235
  <label>When you want to run cron ?</label>
236
  <frontend_type>text</frontend_type>
237
+ <sort_order>41</sort_order>
238
  <validate>required-entry</validate>
239
  <comment>Use Crontab Format (Eg. "30 7 * * *" in 7:30 AM). Don't forget `Flush Magento Cache` and `Flush Cache Storage` after changes.</comment>
240
  <show_in_default>1</show_in_default>
310
  <show_in_website>1</show_in_website>
311
  <show_in_store>1</show_in_store>
312
  </stock_inventory>
313
+ <default_category translate="label">
314
+ <label>Category for import</label>
315
+ <validate>required-entry</validate>
316
+ <frontend_type>select</frontend_type>
317
+ <source_model>iceimport/system_config_category</source_model>
318
+ <sort_order>57</sort_order>
319
+ <show_in_default>1</show_in_default>
320
+ <show_in_website>1</show_in_website>
321
+ <show_in_store>1</show_in_store>
322
+ </default_category>
323
  <refresh_settings_heading translate="label">
324
  <label>Import Parameters</label>
325
  <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
328
  <show_in_website>1</show_in_website>
329
  <show_in_store>1</show_in_store>
330
  </refresh_settings_heading>
331
+ <batch_size translate="label">
332
+ <label>Size of batch</label>
 
333
  <frontend_type>text</frontend_type>
334
+ <sort_order>121</sort_order>
335
+ <validate>required-entry</validate>
336
+ <comment>This is service config. Please contact ICEShop team before changing this setting.</comment>
337
  <show_in_default>1</show_in_default>
338
+ </batch_size>
 
 
339
  <import_new_products translate="label">
340
  <label>Import new products</label>
341
  <comment><![CDATA[Add products from import file if they aren't presented in shop's assortment.]]></comment>
406
  <show_in_website>1</show_in_website>
407
  <show_in_store>1</show_in_store>
408
  </default_tax>
 
 
 
 
 
 
 
 
 
409
  <images_queue_processing_only translate="label">
410
  <label><![CDATA[ImagesQueueProcessing only]]></label>
411
  <comment><![CDATA[Run <strong>ONLY</strong> images queue processing instead of whole actions stack. Setting used <strong>ONLY</strong> while running via Cron.]]></comment>
app/code/community/ICEshop/Iceimport/include.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ function iceimport_autoload($className = null)
4
+ {
5
+ $path = dirname(__FILE__). DIRECTORY_SEPARATOR . 'Model' . DIRECTORY_SEPARATOR . 'Convert' . DIRECTORY_SEPARATOR . 'Adapter' . DIRECTORY_SEPARATOR . 'Iceimport.php';
6
+ require_once($path);
7
+ }
8
+
9
+ spl_autoload_register('iceimport_autoload');
10
+
11
+ ?>
app/code/community/ICEshop/Iceimport/sql/iceimport_setup/{mysql4-install-1.7.22.php → mysql4-install-1.8.0.php} RENAMED
File without changes
app/code/community/ICEshop/Iceimport/sql/iceimport_setup/{mysql4-upgrade-1.7.15-1.7.22.php → mysql4-upgrade-1.7.15-1.8.0.php} RENAMED
File without changes
app/code/community/ICEshop/Iceimport/sql/iceimport_setup/{mysql4-upgrade-1.7.16-1.7.22.php → mysql4-upgrade-1.7.16-1.8.0.php} RENAMED
File without changes
app/code/community/ICEshop/Iceimport/sql/iceimport_setup/{mysql4-upgrade-1.7.17-1.7.22.php → mysql4-upgrade-1.7.17-1.8.0.php} RENAMED
File without changes
app/code/community/ICEshop/Iceimport/sql/iceimport_setup/{mysql4-upgrade-1.7.18-1.7.22.php → mysql4-upgrade-1.7.18-1.8.0.php} RENAMED
File without changes
app/code/community/ICEshop/Iceimport/sql/iceimport_setup/{mysql4-upgrade-1.7.19-1.7.22.php → mysql4-upgrade-1.7.19-1.8.0.php} RENAMED
File without changes
app/code/community/ICEshop/Iceimport/sql/iceimport_setup/{mysql4-upgrade-1.7.20-1.7.22.php → mysql4-upgrade-1.7.20-1.8.0.php} RENAMED
File without changes
app/code/community/ICEshop/Iceimport/sql/iceimport_setup/{mysql4-upgrade-1.7.21-1.7.22.php → mysql4-upgrade-1.7.21-1.8.0.php} RENAMED
File without changes
app/code/community/ICEshop/Iceimport/sql/iceimport_setup/mysql4-upgrade-1.7.22-1.8.0.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*$file = 'text.txt';
4
+ $version_greeting = 'Hello from 1.7.21 - 1.7.22';
5
+ file_put_contents($file, $version_greeting, FILE_APPEND);*/
6
+
7
+ include_once('upgrade_run.php');
app/code/community/ICEshop/Iceimport/sql/iceimport_setup/{mysql4-upgrade-1.7.8-1.7.22.php → mysql4-upgrade-1.7.8-1.8.0.php} RENAMED
File without changes
package.xml CHANGED
@@ -1,27 +1,20 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>ice_import</name>
4
- <version>1.7.23</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v.3</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Import categories &amp; products</summary>
10
  <description>This extension can use to import products with categories, multiple images and custom options from CSV file.</description>
11
- <notes>Bug fix:&#xD;
12
- &#xD;
13
- - Add noticing&#xD;
14
- - Fix user permissions&#xD;
15
- - Renaming some attributes&#xD;
16
- - Add explanations&#xD;
17
- - Add new option 'run reindex'&#xD;
18
- - Added new option to change cron scheduled time&#xD;
19
- - Added new feature settings&#xD;
20
- - Added transactions</notes>
21
  <authors><author><name>IceShop</name><user>IceShop</user><email>support@iceshop.nl</email></author></authors>
22
- <date>2017-04-19</date>
23
- <time>12:36:37</time>
24
- <contents><target name="magecommunity"><dir name="ICEshop"><dir name="Iceimport"><dir name="Block"><dir name="Adminhtml"><file name="Dashboard.php" hash="c5bc53548068c2cc8b97087d4f56d9cd"/><dir name="Images"><dir name="List"><file name="Grid.php" hash="e3c9190844dd7d829ec8c95a3edb53a9"/></dir></dir><file name="Notifications.php" hash="2c917dd62d7119cc0f5b3fda87efc537"/><dir name="System"><dir name="Config"><dir name="Form"><file name="Button.php" hash="a716ac837c2a3548c2b0c8ab7d871321"/><file name="Exportall.php" hash="38bbe2ec93f492230f2ffcee56dd259b"/><file name="Updatebutton.php" hash="bf0344ecdb7b2756f10830c51324f5a2"/></dir></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="29b0d1ddc50a67eaf7160cf1228f24da"/><file name="Db.php" hash="e4214f988bc3e030ad1f73f275453aaf"/><file name="Format.php" hash="20e0c6e3be6ce66b5c5fa2091fe04f4a"/><dir name="System"><file name="System.php" hash="2645d278ecfdd0bcb2bfaf4a9c8ea53e"/><file name="Systemcheck.php" hash="8b4916b33bf1b92610e01758b8f4492f"/></dir></dir><dir name="Model"><dir name="Convert"><dir name="Adapter"><file name="Product.php" hash="7b67df269a68b2e2e66b4f849fdafa73"/></dir></dir><dir name="Dataflow"><dir name="Batch"><file name="Import.php" hash="718a615ac6c585ecefaa9aab93f07b8b"/></dir><dir name="Convert"><dir name="Adapter"><file name="Io.php" hash="0fc5cdfdce12eda0553711355b3c2405"/></dir><dir name="Parser"><file name="Csv.php" hash="c031459fe50a569fbe655262ef286c40"/></dir></dir></dir><file name="Observer.php" hash="ed8d502da60d571dde4521c264faf2d1"/><dir name="System"><dir name="Config"><file name="Checksystem.php" hash="86cda2191bea190d59bdfaf904cd55fd"/><file name="Defaulttax.php" hash="2baea942efcc3880d785da9f021f04fc"/><file name="Explanations.php" hash="5452b370335ef4c03272c11c527e4ca3"/><dir name="Fields"><file name="Attributes.php" hash="e493e1f8a09aee4e5e603b292ac17fef"/></dir><file name="Iceshoplink.php" hash="5a5b523ab4bb13ad8f94c82f321ba19e"/><file name="Profiles.php" hash="6f8525946e12b116c7c2435c74b82e43"/><file name="Stock.php" hash="db933dc508d917904915771de54a998c"/><file name="Websites.php" hash="de666d4e92f777646839e73717e20fd3"/><file name="Yesno.php" hash="273e501e78300ac78360fd787d5f9d1b"/></dir></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="IceimagesController.php" hash="4ab35558c030e353a54cfe64b3d81df1"/><file name="IceimportController.php" hash="53adf9b0bf0fd2be3ce8d7ffd71a51e1"/><file name="IceimportimagesController.php" hash="51d383100bf1b6a4fc97866f0e0a51bb"/><dir name="System"><dir name="Convert"><file name="GuiController.php" hash="aad0c2043b8386312c1a30f9f73c22d9"/></dir></dir></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="aae63620174bbe5791cad5ce154eb8da"/><file name="config.xml" hash="b9611fb0c434c49422fc9bea31dc430f"/><file name="system.xml" hash="9b90997dd2f7e4f93f0384151799f103"/></dir><dir name="sql"><dir name="iceimport_setup"><file name="mysql4-install-1.7.22.php" hash="4f3769e113bf3359d8e31e7ed541f6df"/><file name="mysql4-upgrade-1.7.15-1.7.22.php" hash="51e7eab2a26c9521b3ee1463b66adadd"/><file name="mysql4-upgrade-1.7.16-1.7.22.php" hash="e82b29207bc0bb92b15bdea5b60c071d"/><file name="mysql4-upgrade-1.7.17-1.7.22.php" hash="f6b22ec5557cb2b0e5f6aa469c034937"/><file name="mysql4-upgrade-1.7.18-1.7.22.php" hash="8e6fbf57ebe0a1f38ac8bcbf64eee746"/><file name="mysql4-upgrade-1.7.19-1.7.22.php" hash="7c03da0f59ead15cb1e0a0f7ee2d5d28"/><file name="mysql4-upgrade-1.7.20-1.7.22.php" hash="ac6d4efbd15ba801242635c43ce24270"/><file name="mysql4-upgrade-1.7.21-1.7.22.php" hash="0e7237d0cc4bae04d2f5b931cbc9f5ba"/><file name="mysql4-upgrade-1.7.8-1.7.22.php" hash="361c8fe17ee33d289094fc252501f7a1"/><file name="upgrade_run.php" hash="f77e33b196d987239f7b3176bed27e90"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="ICEshop_Iceimport.xml" hash="ba688dd33def1bb1c1c3f6d312eff468"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="ICEshop_Iceimport.xml" hash="af53e1e9c59f2e351ec75e6b2a452360"/></dir><dir name="template"><dir name="iceshop"><dir name="iceimport"><file name="dashboard.phtml" hash="0fb362cb59eaff591b8b33e812798986"/><file name="notifications.phtml" hash="d41bd462ebfee9392a086530dfd13c55"/></dir></dir></dir></dir></dir></dir></target><target name="mageweb"><dir name="js"><dir name="ICEshop"><dir name="Iceimport"><file name="dashboard.js" hash="54ebceb6b8be6a0cc8f012248a5ea1ba"/><file name="jquery-1.11.1.min.js" hash="00581ba93329e1af4e422831174588f9"/><file name="script.js" hash="3c00573b09de4b67d0776dccb5acf139"/></dir></dir></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="iceshop"><dir name="iceimport"><dir name="images"><file name="iceshop_logo_small_16px.png" hash="4ef632b4b89a047789307b301b9dfb6e"/></dir><file name="styles.css" hash="dfde1444b1d962bae2e0b8f0a7076334"/></dir></dir></dir></dir></dir></target></contents>
25
  <compatible/>
26
- <dependencies><required><php><min>5.2.0</min><max>7.0.17</max></php></required></dependencies>
27
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>ice_import</name>
4
+ <version>1.8.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v.3</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Import categories &amp; products</summary>
10
  <description>This extension can use to import products with categories, multiple images and custom options from CSV file.</description>
11
+ <notes>- Updated logic of importing of products and categories&#xD;
12
+ - Speed improvement&#xD;
13
+ - Reduced memory usage</notes>
 
 
 
 
 
 
 
14
  <authors><author><name>IceShop</name><user>IceShop</user><email>support@iceshop.nl</email></author></authors>
15
+ <date>2017-07-20</date>
16
+ <time>11:26:07</time>
17
+ <contents><target name="magecommunity"><dir name="ICEshop"><dir name="Iceimport"><dir name="Block"><dir name="Adminhtml"><file name="Dashboard.php" hash="2eee914402e5610ba273109994e6ca6a"/><dir name="Images"><dir name="List"><file name="Grid.php" hash="e3c9190844dd7d829ec8c95a3edb53a9"/></dir></dir><file name="Notifications.php" hash="2c917dd62d7119cc0f5b3fda87efc537"/><dir name="System"><dir name="Config"><dir name="Form"><file name="Button.php" hash="a716ac837c2a3548c2b0c8ab7d871321"/><file name="Exportall.php" hash="38bbe2ec93f492230f2ffcee56dd259b"/><file name="Updatebutton.php" hash="bf0344ecdb7b2756f10830c51324f5a2"/></dir></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="29b0d1ddc50a67eaf7160cf1228f24da"/><file name="Db.php" hash="e4214f988bc3e030ad1f73f275453aaf"/><file name="Format.php" hash="20e0c6e3be6ce66b5c5fa2091fe04f4a"/><dir name="System"><file name="System.php" hash="2645d278ecfdd0bcb2bfaf4a9c8ea53e"/><file name="Systemcheck.php" hash="8b4916b33bf1b92610e01758b8f4492f"/></dir></dir><dir name="Model"><dir name="Convert"><dir name="Adapter"><file name="Iceimport.php" hash="11266bd8d7cf995fdfafee349a380063"/></dir></dir><dir name="Dataflow"><dir name="Batch"><file name="Import.php" hash="b47a93c74ce8c785ad69eb47803ef3db"/></dir><dir name="Convert"><dir name="Adapter"><file name="Io.php" hash="0fc5cdfdce12eda0553711355b3c2405"/></dir><dir name="Parser"><file name="Csv.php" hash="c031459fe50a569fbe655262ef286c40"/></dir></dir></dir><file name="Observer.php" hash="1d4ea7dbd0f707071e8a77f24049bfd4"/><dir name="System"><dir name="Config"><file name="Category.php" hash="d20fe0979a1ed5d56a1e91374d0f566b"/><file name="Checksystem.php" hash="86cda2191bea190d59bdfaf904cd55fd"/><file name="Defaulttax.php" hash="2baea942efcc3880d785da9f021f04fc"/><file name="Explanations.php" hash="5452b370335ef4c03272c11c527e4ca3"/><dir name="Fields"><file name="Attributes.php" hash="e493e1f8a09aee4e5e603b292ac17fef"/></dir><file name="Iceshoplink.php" hash="5a5b523ab4bb13ad8f94c82f321ba19e"/><file name="Profiles.php" hash="6f8525946e12b116c7c2435c74b82e43"/><file name="Stock.php" hash="db933dc508d917904915771de54a998c"/><file name="Websites.php" hash="de666d4e92f777646839e73717e20fd3"/><file name="Yesno.php" hash="273e501e78300ac78360fd787d5f9d1b"/></dir></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="IceimagesController.php" hash="4ab35558c030e353a54cfe64b3d81df1"/><file name="IceimportController.php" hash="13505b537014587f3178a920b30d63bb"/><file name="IceimportimagesController.php" hash="51d383100bf1b6a4fc97866f0e0a51bb"/><dir name="System"><dir name="Convert"><file name="GuiController.php" hash="7b7be25a6ada3d075ed67f3a7dac0038"/></dir></dir></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="aae63620174bbe5791cad5ce154eb8da"/><file name="config.xml" hash="d7d44877fee1f2b205f6966ea0be44fb"/><file name="system.xml" hash="206b0646605eeabf2be1e899de25b092"/></dir><file name="include.php" hash="4feef8b32dce3375a9d48f817a90c396"/><dir name="sql"><dir name="iceimport_setup"><file name="mysql4-install-1.8.0.php" hash="4f3769e113bf3359d8e31e7ed541f6df"/><file name="mysql4-upgrade-1.7.15-1.8.0.php" hash="51e7eab2a26c9521b3ee1463b66adadd"/><file name="mysql4-upgrade-1.7.16-1.8.0.php" hash="e82b29207bc0bb92b15bdea5b60c071d"/><file name="mysql4-upgrade-1.7.17-1.8.0.php" hash="f6b22ec5557cb2b0e5f6aa469c034937"/><file name="mysql4-upgrade-1.7.18-1.8.0.php" hash="8e6fbf57ebe0a1f38ac8bcbf64eee746"/><file name="mysql4-upgrade-1.7.19-1.8.0.php" hash="7c03da0f59ead15cb1e0a0f7ee2d5d28"/><file name="mysql4-upgrade-1.7.20-1.8.0.php" hash="ac6d4efbd15ba801242635c43ce24270"/><file name="mysql4-upgrade-1.7.21-1.8.0.php" hash="0e7237d0cc4bae04d2f5b931cbc9f5ba"/><file name="mysql4-upgrade-1.7.22-1.8.0.php" hash="0e7237d0cc4bae04d2f5b931cbc9f5ba"/><file name="mysql4-upgrade-1.7.8-1.8.0.php" hash="361c8fe17ee33d289094fc252501f7a1"/><file name="upgrade_run.php" hash="f77e33b196d987239f7b3176bed27e90"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="ICEshop_Iceimport.xml" hash="ba688dd33def1bb1c1c3f6d312eff468"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="ICEshop_Iceimport.xml" hash="af53e1e9c59f2e351ec75e6b2a452360"/></dir><dir name="template"><dir name="iceshop"><dir name="iceimport"><file name="dashboard.phtml" hash="0fb362cb59eaff591b8b33e812798986"/><file name="notifications.phtml" hash="d41bd462ebfee9392a086530dfd13c55"/></dir></dir></dir></dir></dir></dir></target><target name="mageweb"><dir name="js"><dir name="ICEshop"><dir name="Iceimport"><file name="dashboard.js" hash="54ebceb6b8be6a0cc8f012248a5ea1ba"/><file name="jquery-1.11.1.min.js" hash="00581ba93329e1af4e422831174588f9"/><file name="script.js" hash="3c00573b09de4b67d0776dccb5acf139"/></dir></dir></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="iceshop"><dir name="iceimport"><dir name="images"><file name="iceshop_logo_small_16px.png" hash="4ef632b4b89a047789307b301b9dfb6e"/></dir><file name="styles.css" hash="dfde1444b1d962bae2e0b8f0a7076334"/></dir></dir></dir></dir></dir></target></contents>
18
  <compatible/>
19
+ <dependencies><required><php><min>5.2.0</min><max>7.1.7</max></php></required></dependencies>
20
  </package>