Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezfreetradeimport.php
Go to the documentation of this file.
1 <?
3 //
4 // $Id: ezfreetradeimport.php 6849 2001-09-03 11:13:38Z ce $
5 //
6 // ezfreetradeimport class
7 //
8 // Christoffer A. Elo <ce@ez.no>
9 // Created on: <12-Jul-2001 12:23:54 ce>
10 //
11 // Copyright (C) Christoffer A. Elo. All rights reserved.
12 //
13
16
23 // include_once( "classes/ezdb.php" );
24 // include_once( "classes/ezmysqldb.php" );
25 // include_once( "eztrade/classes/ezproduct.php" );
26 // include_once( "eztrade/classes/ezproductcategory.php" );
27
28 class eZFreeTradeImport
29 {
30
34 function __construct()
35 {
36 }
37
38 function importCategories( )
39 {
40 set_time_limit( 0 );
41 $categories = $this->getCategoriesFromImport();
42 $db =& eZDB::globalDatabase();
43
44 if ( is_array ( $categories ) )
45 {
46 foreach( $categories as $importCategory )
47 {
48 $importID = $importCategory["ID"];
49 $parentID = $importCategory["Parent"];
50 $db->array_query( $ParentFromRemoteID, "SELECT ID FROM eZTrade_Category WHERE RemoteID='$parentID'" );
51
52 if ( count ( $ParentFromRemoteID ) == 1 )
53 $parentID = $ParentFromRemoteID[0]["ID"];
54 else
55 $parentID = 0;
56
57 $category = new eZProductCategory();
58 $category->setName( mysql_escape_string( $importCategory["Name"] ) );
59 $category->setDescription( mysql_escape_string( $importCategory["Description"] ) );
60 $category->setParent( mysql_escape_string( $parentID ) );
61 $category->setRemoteID( mysql_escape_string( $importID ) );
62
63 if ( $importCategory["Graphic"] )
64 {
65 $imageFromFS = "freetrade/images/departments/" . $importCategory["Graphic"];
66 if ( file_exists( $imageFromFS ) )
67 {
68 $image = new eZImage();
69 $file = new eZPBImageFile();
70 if ( $file->getFile( $imageFromFS ) )
71 {
72 $image->setName( "Image" );
73 $image->setImage( $file );
74
75 $image->store();
76 $category->setImage( $image );
77 }
78 }
79 }
80 $category->store();
81 }
82 return true;
83 }
84 else
85 return false;
86 }
87
88 function importItems( )
89 {
90 set_time_limit( 0 );
91 $categories = $this->getItemsFromImport();
92
93 $db =& eZDB::globalDatabase();
94 if ( is_array ( $categories ) )
95 {
96 foreach( $categories as $category )
97 {
98 $depID = $category["Department"];
99 $importID = "item-" . $category["ID"];
100 $db->array_query( $ParentFromRemoteID, "SELECT ID FROM eZTrade_Category WHERE RemoteID='$depID'" );
101
102 if ( count ( $ParentFromRemoteID ) == 1 )
103 {
104 $parentID = $ParentFromRemoteID[0]["ID"];
105
106 $categoryObj = new eZProductCategory();
107 $categoryObj->setName( mysql_escape_string( strip_tags( $category["Name"] ) ) );
108 $categoryObj->setDescription( mysql_escape_string( strip_tags( $category["Description"] ) ) );
109 $categoryObj->setParent( mysql_escape_string( $parentID ) );
110 $categoryObj->setRemoteID( mysql_escape_string( $importID ) );
111 $categoryObj->store();
112
113 // print( "Added: ". $categoryObj->name() . "<br>" );
114 }
115 }
116 }
117 }
118
119 function importProducts( )
120 {
121 set_time_limit( 0 );
122 $products = $this->getProductsFromImport();
123
124 $db =& eZDB::globalDatabase();
125 if ( is_array ( $products ) )
126 {
127 $i=0;
128 foreach( $products as $importProduct )
129 {
130
131 $product = new eZProduct();
132
133 $product->setName( mysql_escape_string( $importProduct["Name"] ) );
134 // $product->setDescription( mysql_escape_string( $importProduct["Description"] ) );
135 // $product->setKeywords( mysql_escape_string( $importProduct["Keywords"] ) );
136 $product->setRemoteID( $importProduct["ID"] );
137
138 if ( $importProduct["SalePrice" ] != 0 )
139 {
140 $product->setPrice( $importProduct["SalePrice" ] );
141 }
142 elseif ( $importProduct["ListPrice" ] )
143 {
144 $price = ( ( $importProduct["ListPrice" ] * 10 ) / 100 );
145 $product->setPrice( $importProduct["ListPrice" ] - $price );
146 }
147
148 if ( $importProduct["Active"] == "Y" )
149 $product->setShowProduct( true );
150 else
151 $product->setShowProduct( false );
152
153 $product->store();
154
155 /*
156 if ( $importProduct["Graphic"] )
157 {
158 $imageFromFS = "freetrade/images/items/" . $importProduct["Graphic"];
159 if ( file_exists( $imageFromFS ) )
160 {
161 $image = new eZImage();
162 $file = new eZPBImageFile();
163 if ( $file->getFile( $imageFromFS ) )
164 {
165 $image->setName( "Image" );
166 $image->setImage( $file );
167
168 $image->store();
169 $product->addImage( $image );
170 $product->setThumbnailImage( $image );
171 $product->setMainImage( $image );
172 $product->store();
173 }
174 }
175 }
176 */
177
178
179 $parent = "item-" . $importProduct["Item"];
180 $db->array_query( $CategoryIDFromRemoteID, "SELECT ID FROM eZTrade_Category WHERE RemoteID='$parent'" );
181
182 $category = new eZProductCategory( $CategoryIDFromRemoteID[0][0] );
183
184 if ( is_numeric( $category->id() ) )
185 {
186 $category->addProduct( $product );
187 $product->setCategoryDefinition( $category );
188 }
189
190 $this->importOptions( $product );
191
192 // print( "Lagt til produkt: " . $product->name() . "<br>" );
193 $i++;
194
195 }
196 // print( $i );
197 return true;
198 }
199 else
200 return false;
201 }
202
203 function importOptions( $product )
204 {
205 if ( is_a( $product, "eZProduct" ) )
206 {
207 $productID = $product->id();
208
209 $options = $this->getOptionsFromImport( $productID );
210
211 if ( count ( $options ) > 0 )
212 {
213 if ( is_array( $options ) )
214 {
215 foreach( $options as $importOption )
216 {
217 $option = new eZOption();
218 $option->setName( $importOption[6]["Name"] );
219 $option->store();
220
221 $product->addOption( $option );
222
223 $value = new eZOptionValue();
224 $value->setRemoteID( $importOption["ID"] );
225 $value->store();
226 $value->addDescription( mysql_escape_string( $importOption["Name"] ) );
227 $option->addValue( $value );
228
229
230
231 // $quantityArray = $this->getQuantity( $importOption["ID"] );
232
233 // $value->setTotalQuantity( $quantityArray["Available"] );
234
235 // print( "ID: " . $value->id() . " - Price: ". $importOption["SalePrice" ] . "<br>");
236 }
237 }
238 }
239 }
240 }
241
242 function getOptionsFromImport( $id )
243 {
244 $this->dbInit();
245
246 if ( is_numeric( $id ) )
247 {
248 $db =& eZDB::globalDatabase();
249 $db->array_query( $RemoteIDFromProductID, "SELECT RemoteID FROM eZTrade_Product WHERE ID='$id'" );
250
251 $remoteID = $RemoteIDFromProductID[0][0];
252
253 $this->dbImport->array_query( $array, "select variation.* from variation, sku_variation WHERE sku_variation.Variation = variation.ID AND sku_variation.SKU='$remoteID'" );
254
255 for( $i=0; $i<count( $array ); $i++ )
256 {
257 if ( is_numeric( $array[$i]["Attribute"] ) )
258 {
259 $att = array();
260 $id = $array[$i]["Attribute"];
261 $this->dbImport->array_query( $att, "select * from attribute where ID='$id'" );
262 array_push( $array[$i], $att[0] );
263 }
264
265 }
266 return $array;
267 }
268 else
269 $this->dbImport->array_query( $array, "SELECT * FROM sku" );
270
271 $this->dbImport->close();
272
273 return $array;
274 }
275
276 function getCategoriesFromImport()
277 {
278 $this->dbInit();
279 $this->dbImport->array_query( $array, "SELECT * FROM department ORDER BY Parent" );
280
281
282 $this->dbImport->close();
283
284 return $array;
285 }
286
287 function getProductsFromImport()
288 {
289 $this->dbInit();
290 // $this->dbImport->array_query( $array, "SELECT * FROM item" );
291 $this->dbImport->array_query( $array, "SELECT * FROM sku" );
292
293 $this->dbImport->close();
294
295 return $array;
296 }
297
298 function getItemsFromImport()
299 {
300 $this->dbInit();
301 $this->dbImport->array_query( $array, "SELECT * FROM item" );
302
303 $this->dbImport->close();
304
305 return $array;
306 }
307
308 function getQuantity( $id )
309 {
310 $this->dbInit();
311
312 if ( is_numeric( $id ) )
313 {
314 $this->dbImport->array_query( $array, "SELECT * FROM inventory WHERE SKU='$id'" );
315
316 $this->dbImport->close();
317
318 return $array[0];
319 }
320 else
321 return false;
322 }
323
324 function makeOption()
325 {
326 $db =& eZDB::globalDatabase();
327 $this->dbInit();
328
329 $this->dbImport->array_query( $attribute, "SELECT * FROM attribute" );
330
331 foreach( $attribute as $att )
332 {
333 $option = new eZOption();
334
335 $option->setName( $att["Name"] );
336 $option->setDescription( $att["Description"] );
337 $option->setRemoteID( $att["ID"] );
338 $option->store();
339 }
340 }
341
342 function makeLinks()
343 {
344 $this->dbInit();
345 $this->dbImport->array_query( $links, "SELECT * FROM sku_variation" );
346 foreach ( $links as $link )
347 {
348 $product = eZProduct::getByRemoteID( $link["SKU"] );
349 $optionValue = eZOptionValue::getByRemoteID( $link["Variation"] );
350 if ( ( $product ) and ( $optionValue ) )
351 {
352 $option = $optionValue->option();
353 $product->addOption( $option );
354 }
355
356 if ( !$product )
357 print( "Product dosen't exists!: " . $link["SKU"] . "\n" );
358 if ( !$option )
359 print( "Option dosen't exists!: " . $link["Variation"] . "\n" );
360
361 }
362 }
363
364 function makeValue( )
365 {
366
367 $db =& eZDB::globalDatabase();
368 $this->dbInit();
369 $this->dbImport->array_query( $optionValues, "SELECT * FROM variation" );
370
371 foreach ( $optionValues as $value )
372 {
373 if ( $value["Attribute"] != 0 )
374 {
375 $value1 = new eZOptionValue( );
376 $value1->setRemoteID( $value["ID"] );
377 $value1->store();
378 $value1->addDescription( $value["Name"] );
379
380 $option = eZOption::getByRemoteID( $value["Attribute"] );
381 $option->addValue( $value1 );
382 }
383 }
384 }
385
386 function setDatabaseImport( $host="localhost", $username="import", $password="import", $database="import" )
387 {
388 $this->Host = $host;
389 $this->UserName = $username;
390 $this->Password = $password;
391 $this->Database = $database;
392 }
393
394 function dbInit()
395 {
396 $this->dbImport = new eZMySQLDB( $this->Host, $this->UserName, $this->Password, $this->Database );
397 }
398
399 var $Host;
400 var $UserName;
401 var $Password;
402 var $Database;
403 var $dbImport;
404 }
405
406 ?>
$category
if( $Action=="Edit") $category
Definition: adedit.php:378
$i
$i
Definition: admin/adlist.php:91
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZFreeTradeImport
Definition: ezfreetradeimport.php:29
eZFreeTradeImport\makeLinks
makeLinks()
Definition: ezfreetradeimport.php:342
eZFreeTradeImport\importOptions
importOptions( $product)
Definition: ezfreetradeimport.php:203
eZFreeTradeImport\getProductsFromImport
getProductsFromImport()
Definition: ezfreetradeimport.php:287
eZFreeTradeImport\importItems
importItems()
Definition: ezfreetradeimport.php:88
eZFreeTradeImport\getItemsFromImport
getItemsFromImport()
Definition: ezfreetradeimport.php:298
eZFreeTradeImport\__construct
__construct()
Definition: ezfreetradeimport.php:34
eZFreeTradeImport\$Password
$Password
Definition: ezfreetradeimport.php:401
eZFreeTradeImport\importProducts
importProducts()
Definition: ezfreetradeimport.php:119
eZFreeTradeImport\getCategoriesFromImport
getCategoriesFromImport()
Definition: ezfreetradeimport.php:276
eZFreeTradeImport\$Database
$Database
Definition: ezfreetradeimport.php:402
eZFreeTradeImport\dbInit
dbInit()
Definition: ezfreetradeimport.php:394
eZFreeTradeImport\$Host
$Host
Definition: ezfreetradeimport.php:399
eZFreeTradeImport\$dbImport
$dbImport
Definition: ezfreetradeimport.php:403
eZFreeTradeImport\getQuantity
getQuantity( $id)
Definition: ezfreetradeimport.php:308
eZFreeTradeImport\importCategories
importCategories()
Definition: ezfreetradeimport.php:38
eZFreeTradeImport\makeOption
makeOption()
Definition: ezfreetradeimport.php:324
eZFreeTradeImport\$UserName
$UserName
Definition: ezfreetradeimport.php:400
eZFreeTradeImport\getOptionsFromImport
getOptionsFromImport( $id)
Definition: ezfreetradeimport.php:242
eZFreeTradeImport\makeValue
makeValue()
Definition: ezfreetradeimport.php:364
eZFreeTradeImport\setDatabaseImport
setDatabaseImport( $host="localhost", $username="import", $password="import", $database="import")
Definition: ezfreetradeimport.php:386
eZImage
Definition: ezimage.php:95
eZMySQLDB
Definition: ezmysqldb.php:37
eZOptionValue
Definition: ezoptionvalue.php:54
eZOptionValue\getByRemoteID
getByRemoteID( $id)
Definition: ezoptionvalue.php:383
eZOption
Definition: ezoption.php:82
eZOption\getByRemoteID
getByRemoteID( $id)
Definition: ezoption.php:383
eZPBImageFile
Definition: ezpbimagefile.php:71
eZProductCategory
Definition: ezproductcategory.php:90
eZProduct
Definition: ezproduct.php:71
eZProduct\getByRemoteID
getByRemoteID( $id)
Definition: ezproduct.php:2369
$id
$id
Definition: companytypelist.php:193
file_exists
static file_exists( $inifilename)
Definition: eZPBINIFile.php:195
$categories
$categories
Definition: ezarticle/admin/categoryedit.php:636
$db
$db
Definition: ezarticle/user/authorlist.php:53
$file
$file
Definition: ezfilemanager/user/filedownload.php:35
$link
$link
Definition: ezlink/admin/attributeedit.php:49
$product
$product
Definition: homepage.php:202
$options
$options
Definition: optionlist.php:56
$price
$price
Definition: pricegroupedit.php:39
Password
</td ></tr >< tr >< td style="color:<?= isset( $error['password1'] ) ?> Password
Definition: step1.php:146
$image
$image
Definition: user/articlelist.php:242
$products
$products
Definition: user/imageview.php:142
$links
$links
Definition: user/linkcategorylist.php:181
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.