Skip to the content

Import script Shoptrader naar Magento

Ieder webshop systeem heeft zijn eigen manier om categorieën, producten en andere data op te slaan. Hierdoor is het vaak erg lastig om categorieën en/of producten over te zetten van het ene systeem naar het andere. Voor een klant hebben wij een bestaande Shoptrader webshop omgebouwd naar een Magento webshop. Dit hebben we gedaan omdat de klant graag functionaliteiten wilde die Magento wel biedt. De kennis die we hebben opgedaan delen we graag en om die reden hebben we dit blog geschreven en het complete script voor de export van producten van Shoptrader naar Magento.

Vanuit Shoptrader kan een CSV export bestand worden gemaakt met daarin alle categorieën en producten. Dit bestand is zo opgemaakt dat de eerste regel de kolomnamen bevat en iedere regel daarna een specifiek product. Als een product zich in meerdere categorieën bevindt dan staat het product meerdere malen, telkens met een gekoppelde categorienaam, in het CSV bestand.

Magento is zo veelzijdig omdat bijna ieder deel van een webshop is opgedeeld in aparte delen. Hierdoor kun je ieder deel binnen Magento aanpassen zonder hele grote stukken code te schrijven. Het gevolg hiervan is dat ook ieder onderdeel zijn eigen ruimte heeft in de database om informatie op te slaan. Dus om een product aan te maken binnen Magento moet er soms ook informatie automatisch gegenereerd of verzonnen worden.

In het voorbeeld script worden er producten overgezet met verschillende kleuren. Binnen Shoptrader is dit één product met verschillende kolommen voor de kleuren. Binnen Magento zijn dit meerdere eenvoudige producten die gegroepeerd worden in een geconfigureerd product.

In het onderstaande voorbeeld script tonen wij hoe we deze casus hebben getackeld en de producten zo hebben overgezet dat de producten binnen Magento worden getoond als een enkel product met meerdere opties in plaats van meerdere producten met ieder een eigen kleur.

Wat is een Simpel product?

Een Magento simpel product is een product dat geen noodzakelijke relatie heeft met een ander Magento product. Denk hierbij aan een product dat je al op voorraad hebt en welke in geen één andere maat, kleur of type leverbaar is. Oftewel, een product dat maar in 1 versie is te bestellen. Binnen de Magento productinstellingen, via de tabbladen [Verwante producten], [Up Selling] en [Cross Selling], zijn natuurlijk altijd voorkeursrelaties met andere Magento producten te leggen.

Wat is een configureerbaar product?

Een Magento configureerbaar product is een product dat in diverse varianten verkrijgbaar is. Denk bijvoorbeeld aan een mooie blouse dat in een aantal maten beschikbaar is. JE maakt slechts één Magento configureerbaar product aan waar je verschillende simpele producten aan koppelt. Deze simpele producten zijn elk een variant, bijvoorbeeld kleur en maat: rood in maat XL, geel in maat L, groen in maat S en paars in maat XS. Dit zijn aparte simpele producten die in 1 bepaalde kleur en in 1 bepaalde maat beschikbaar zijn, gekoppeld aan het configureerbaar product zoals hieronder staat weergegeven.

Het script in 10 stappen

  • De basisinformatie die gebruikt wordt om bepaalde keuzes te maken tijdens het importeren.
  • Het inlezen van het Export bestand en omzetten naar een object, zodat deze gemakkelijker uitgelezen kan worden door het script.
  • Het aanmaken van de hoofdcategorie indien deze nog niet bestaat binnen Magento.
  • Het aanmaken van de subcategorie indien deze er is en nog niet bestaat binnen Magento.
  • De start om een geconfigureerd product te maken indien deze nog niet bestaat binnen Magento.
  • Het aanmaken van de simpele producten (in dit geval per kleur: wit, zwart, groen) en opslaan.
  • Het instellen van de voorraad per simpel product (dit kan pas nadat een product is opgeslagen aangezien de voorraad gekoppeld moet worden aan een bestaand product).
  • Het koppelen van de simpele producten aan het nog niet opgeslagen geconfigureerd product.
  • Het instellen van de voorraad bij het geconfigureerd product, zodat deze de voorraad gebruikt van de gekoppelde simpele producten.
  • Het geconfigureerd product opslaan.

 

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
<?php
set_time_limit(0);																								  									//SET TIME LIMIT
ini_set("auto_detect_line_endings", true);																		  									//SET AUTODETECT LINEENDINGS FOR IN CSV
ini_set('memory_limit', '1024M');																				  									//ENLARGE MEMORY LIMIT FOR BETTER PARSING
include_once "app/Mage.php";																					  									//INCLUDE MAGE CLASSES	
include_once "downloader/Maged/Controller.php";																
Mage::init();																									  									//INIT MAGE 
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);												  									//SET DEFAULT WEBPAGE WHERE ADMIN SESSION IS RUNNING
Mage::getSingleton('core/session', array('name' => 'adminhtml'));												  									//FETCH SESSION CORE MAGENTO
$userModel = Mage::getModel('admin/user');																		  									//FETCH ADMIN MODEL
$userModel->setUserId(1);																						  									//SET ADMIN USER ID
$session = Mage::getSingleton('admin/session');																	  									//FETCH SESSION CLASS
$session->setUser($userModel);																					  									//SET USER AS ADMIN			
$session->setAcl(Mage::getResourceModel('admin/acl')->loadAcl());												  									//START SESSION AS ADMIN 

$file = 'export.csv';                                                                       				  									    //SET FILENAME IMPORT CSV
$max_rows = 5000;                                                                                           	  									//SET MAX ROWS TO INSERT AT ONCE, KEEP IN MIND THAT THE SERVER HAS RESTRICTIONS. YOU'LL NEED TO CHANGE TIS VALUE WHEN GETTING "MAX EXECUTION TIME ERROR"
$add_media = true;                                                                                         	  										//SET TO FALSE IF MEDIA IS NOT UPLOADED TO SERVER, THIS WILL DISABLE ADDING MEDIA LINKS TO PRODUCTS
$website_id = 4;                                                                                            	  									//SET WEBSITE ID
$store_id = 3;                                                                                              	  									//SET STORE ID
$parent_id = 6;                                                                                             	  									//SET ROOT CATEGORY ID                                 
$mediapath_categories = Mage::getBaseDir('media') . DS . 'catalog/category/';                               	  									//SET MEDIA PATH OF THE CATEGORIES 
$mediapath_products = Mage::getBaseDir('media') . DS . 'catalog/import/product/';                                  	  								//SET MEDIA PATH OF THE PRODUCTS
$managestock_storeConfig = 0;                                                                               	  									//USE STORE STOCK CONFIG
$managestock = true;                                                                                        	  									//MANAGE STOCK GLOBAL - overrules $managestock_IfNull if is set false
$managestock_IfNull = true;                                                                                 	  									//MANAGE STOCK IF QUANTITY PRODUCT IS NULL OF 0
$default_atr = 4;                                                                                           	  									//SET DEFAULT ATTRIBUTESET ID    
$manufacturer_atr = 81;                                                                                     	  									//SET MANUFACTURER ATTRIBUTE ID
$color_atr = 92;  																																	//SET COLOR ATTRIBUTE ID
$show_only_config = true;                                                                                          	  								//SHOW ONLY CONFIGURAL PRODUCTS IN WEBSHOP	

if (($handle = fopen($file, "r")) !== FALSE)                                                                	  									//OPEN CSV FILE
{
    $row = 0;
    while (($Buffer = fgets($handle, $max_rows)) !== false)														  									//FETCH CSV AS STRING 
    {
        if($row == 0)
        {
            echo "This is no datarow, This is the heading"."<br/>";                                         	  									//FILTER OUT HEADING DATA
        }
        else
        {
            $arr = explode('""";"""',$Buffer);                                                              	  									//PARSE CSV STRING TO ARRAY 
					/*
					*          ███████╗██╗██████╗ ███████╗████████╗     ██████╗ █████╗ ████████╗███████╗ ██████╗  ██████╗ ██████╗ ██╗   ██╗
					*          ██╔════╝██║██╔══██╗██╔════╝╚══██╔══╝    ██╔════╝██╔══██╗╚══██╔══╝██╔════╝██╔════╝ ██╔═══██╗██╔══██╗╚██╗ ██╔╝
					*          █████╗  ██║██████╔╝███████╗   ██║       ██║     ███████║   ██║   █████╗  ██║  ███╗██║   ██║██████╔╝ ╚████╔╝ 
					*          ██╔══╝  ██║██╔══██╗╚════██║   ██║       ██║     ██╔══██║   ██║   ██╔══╝  ██║   ██║██║   ██║██╔══██╗  ╚██╔╝  
					*          ██║     ██║██║  ██║███████║   ██║       ╚██████╗██║  ██║   ██║   ███████╗╚██████╔╝╚██████╔╝██║  ██║   ██║   
					*          ╚═╝     ╚═╝╚═╝  ╚═╝╚══════╝   ╚═╝        ╚═════╝╚═╝  ╚═╝   ╚═╝   ╚══════╝ ╚═════╝  ╚═════╝ ╚═╝  ╚═╝   ╚═╝ 
					*/        
            $name1 = $arr[27];                                                                              	  									//SET COLUMN NUMBER PARENT CATEGORY
            $categories1 = Mage::getResourceModel('catalog/category_collection');                           	  									//FETCH CATEGORIES COLLECTION
            $categories1->addAttributeToFilter('name', $name1)
                        ->setStoreId($store_id)                                                             	  									//EXTRA STORE ID CHECK
                        ->addAttributeToFilter('level','2')->setCurPage(1)->setPageSize(1)->load();         	  									//FILTER ON CATEGORY NAME 
                if(!empty($categories1->getFirstItem()->getName()) && strlen($name1) > 0)                                       
                {
                    $category1 = $categories1->getFirstItem();
                    echo 'CATEGORY ALREADY EXISTS: '. strtolower($category1->getName()).'<br/>';            	  									//RETURN EXISTSING CATEGORY NAMES
                } 
                elseif(empty($categories1->getFirstItem()->getName()) && strlen($name1) > 0) 
                {           
                    echo 'CATEGORY IS MADE - ' . strtolower($name1) . '<br/>';                              	  									//RETURN MISSING CATEGORY NAMES
                    $category1 = Mage::getModel('catalog/category');                                        	  									//FETCH CATEGORY MODEL MAGENTO
                    $category1->setName(strtolower($name1));                                                	  									//SET NAME
                    $category1->setUrlKey(strtolower($name1));                                              	  									//SET URL KEY
                    $category1->setIsActive(1);                                                             	  									//IS ACTIVE 0/1
                    $category1->setDisplayMode('PRODUCTS');                                                 	  									//SET DISPLAY MODE
                    $category1->setIsAnchor(1);                                                             	  									//ANCHOR IS ACTIVE
                    $category1->setStoreId($store_id);                                                      	  									//FETCH STORE ID OR SET HARCODED
                    $parentCategory1 = Mage::getModel('catalog/category')->load($parent_id);                	  									//SET PARENT CATEGORY "FIRST PARENT IS ALWAYS ID OF DEFAULT STORE CATEGORY"  
                    $category1->setPath($parentCategory1->getPath());                                       	  									//SET PATH OF PARENT CATEGORY  
                    
                    $path =  $mediapath_categories.$arr[26];

	                                if (file_exists($path))                                                	  										//EXTRA CHECK FOR MISSING IMAGES
	                                {
	                                    try 
	                                    {
	                                        $category1->setImage($arr[26]);	  																		//ADD IMAGES TO PRODUCT GALLERY
	                                    } 
	                                    catch(Exception $e) 
	                                    {
	                                        echo $e->getMessage();
	                                    }
	                                } 
	                                else 
	                                {
	                                    echo "<a style='color:red;'>{$imageType} file does not exist: {$path},". 
	                                         "please check your media folder. If no images are uploaded!!!,". 
	                                         "please disable this setting $add_media to FALSE</a><br/>";
	                                }


                    $category1->save();                                                                   		  									//SAVE NEW CATEGORY    
                }
                else 
                {         
                    echo 'CATEGORY HAS NO NAME<br/>';                                                       	  									//RETURN MISSING CATEGORY WITHOUT NAME
                }

            		/*
            		*         ███████╗███████╗ ██████╗ ██████╗ ███╗   ██╗██████╗      ██████╗ █████╗ ████████╗███████╗ ██████╗  ██████╗ ██████╗ ██╗   ██╗
            		*         ██╔════╝██╔════╝██╔════╝██╔═══██╗████╗  ██║██╔══██╗    ██╔════╝██╔══██╗╚══██╔══╝██╔════╝██╔════╝ ██╔═══██╗██╔══██╗╚██╗ ██╔╝
            		*         ███████╗█████╗  ██║     ██║   ██║██╔██╗ ██║██║  ██║    ██║     ███████║   ██║   █████╗  ██║  ███╗██║   ██║██████╔╝ ╚████╔╝ 
            		*         ╚════██║██╔══╝  ██║     ██║   ██║██║╚██╗██║██║  ██║    ██║     ██╔══██║   ██║   ██╔══╝  ██║   ██║██║   ██║██╔══██╗  ╚██╔╝  
            		*         ███████║███████╗╚██████╗╚██████╔╝██║ ╚████║██████╔╝    ╚██████╗██║  ██║   ██║   ███████╗╚██████╔╝╚██████╔╝██║  ██║   ██║   
            		*         ╚══════╝╚══════╝ ╚═════╝ ╚═════╝ ╚═╝  ╚═══╝╚═════╝      ╚═════╝╚═╝  ╚═╝   ╚═╝   ╚══════╝ ╚═════╝  ╚═════╝ ╚═╝  ╚═╝   ╚═╝   
            		*/
            $name2 = $arr[29];                                                                              	  									//SET COLUMN NUMBER PARENT CATEGORY
            $categories2 = Mage::getResourceModel('catalog/category_collection');                           	  									//FETCH CATEGORIES COLLECTION
            $categories2->addAttributeToFilter('name', $name2)
                        ->setStoreId($store_id)                                                             	  									//EXTRA STORE ID CHECK
                        ->addAttributeToFilter('level','3')->setCurPage(1)->setPageSize(1)->load();         	  									//FILTER ON CATEGORY NAME 

                if(!empty($categories2->getFirstItem()->getName()) && strlen($name2) > 0)                                       
                {
                    $category2 = $categories2->getFirstItem();
                    echo 'CATEGORY ALREADY EXISTS: '. strtolower($category2->getName()).'<br/>';                                                    //RETURN EXISTSING CATEGORY NAMES
                } 
                elseif(empty($categories2->getFirstItem()->getName()) && strlen($name2) > 0) 
                {           
                    echo 'CATEGORY IS MADE - ' . strtolower($name2) . '<br/>';                                                                      //RETURN MISSING CATEGORY NAMES
                    $category2 = Mage::getModel('catalog/category');                                                                                //FETCH CATEGORY MODEL MAGENTO
                    $category2->setName(strtolower($name2));                                                                                        //SET NAME
                    $category2->setUrlKey(strtolower($name2));                                                                                      //SET URL KEY
                    $category2->setIsActive(1);                                                                                                     //IS ACTIVE 0/1
                    $category2->setDisplayMode('PRODUCTS');                                                                                         //SET DISPLAY MODE
                    $category2->setIsAnchor(1);                                                                                                     //ANCHOR IS ACTIVE
                    $category2->setStoreId($store_id);                                                                                              //FETCH STORE ID OR SET HARCODED
                    $parentCategory2 = Mage::getModel('catalog/category')->load($category1->getId());                                               //SET PARENT CATEGORY  
                    $category2->setPath($parentCategory2->getPath());                                                                               //SET PATH OF PARENT CATEGORY  
                    
                    $path =  $mediapath_categories.$arr[26];

                                    if (file_exists($path))                                                                                         //EXTRA CHECK FOR MISSING IMAGES
                                    {
                                        try 
                                        {
                                            $category2->setImage($arr[26]);                                                                         //ADD IMAGES TO PRODUCT GALLERY
                                        } 
                                        catch(Exception $e) 
                                        {
                                            echo $e->getMessage();
                                        }
                                    } 
                                    else 
                                    {
                                        echo "<a style='color:red;'>{$imageType} file does not exist: {$path},". 
                                             "please check your media folder. If no images are uploaded!!!,". 
                                             "please disable this setting $add_media to FALSE</a><br/>";
                                    }


                    $category2->save();                                                                                                             //SAVE NEW CATEGORY    
                }
                else 
                {         
                    echo 'CATEGORY HAS NO NAME<br/>';                                                                                               //RETURN MISSING CATEGORY WITHOUT NAME
                }


					/*	 	
					*	 	██████╗ ██████╗  ██████╗ ██████╗ ██╗   ██╗ ██████╗████████╗███████╗
					*	 	██╔══██╗██╔══██╗██╔═══██╗██╔══██╗██║   ██║██╔════╝╚══██╔══╝██╔════╝
					*	 	██████╔╝██████╔╝██║   ██║██║  ██║██║   ██║██║        ██║   ███████╗
					*	 	██╔═══╝ ██╔══██╗██║   ██║██║  ██║██║   ██║██║        ██║   ╚════██║
					*	 	██║     ██║  ██║╚██████╔╝██████╔╝╚██████╔╝╚██████╗   ██║   ███████║
					*	 	╚═╝     ╚═╝  ╚═╝ ╚═════╝ ╚═════╝  ╚═════╝  ╚═════╝   ╚═╝   ╚══════╝
					*/	 	                                                                   

            $color_list = array('Wit','Zwart','Groen');   


            	/*
				* 		    ╔═╗╔═╗╔╗╔╔═╗╦╔═╗╦ ╦╦═╗╔═╗╔╗ ╦  ╔═╗  ╔═╗╦═╗╔═╗╔╦╗╦ ╦╔═╗╔╦╗
				* 			║  ║ ║║║║╠╣ ║║ ╦║ ║╠╦╝╠═╣╠╩╗║  ║╣   ╠═╝╠╦╝║ ║ ║║║ ║║   ║ 
				* 			╚═╝╚═╝╝╚╝╚  ╩╚═╝╚═╝╩╚═╩ ╩╚═╝╩═╝╚═╝  ╩  ╩╚═╚═╝═╩╝╚═╝╚═╝ ╩ 
				*/	
            if(strtolower($arr[1]) == 'test' && strtolower($arr[1]) == 'verzendkosten' && strtolower($arr[1]) == 'concept_product' && strtolower($arr[1]) == 'home')
            {
                continue;
            }

			try
			{
                if(!empty(Mage::getModel('catalog/product')->getIdBySku(str_replace('"""', '', $arr[0]))))
                {
                    $product = Mage::getModel('catalog/product')->loadByAttribute('sku',str_replace('"""', '', $arr[0]));
                    $cats = $product->getCategoryIds();
                    
                    if(!empty($category1))
                    {
                        array_push($cats,$category1->getId());
                    }

                    if(!empty($category2))
                    {   
                        array_push($cats,$category2->getId());   
                    }

                    $product->setCategoryIds($cats);
                    $product->save();

                    echo '<br/>The categories of product: '.$product->getName().' are updated! <br/>';
                    continue;
                } 
                else
                {
				    $configProduct = Mage::getModel('catalog/product');								
                }
			   	
                $configProduct->setWebsiteIds(array($website_id))                                          		  									//WEBSITE ID THE PRODUCT IS ASSIGNED TO, AS AN ARRAY
                ->setStatus(1)                                                                             		  									//SET ACTIVE
                ->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)                    		  									//CATALOG AND SEARCH VISIBILITY
                ->setAttributeSetId($default_atr)                                                          		  									//DEFAULT ATTRIBUTES
                ->setCreatedAt(strtotime('now'))                                                           		  									//PRODUCT CREATION TIME
                ->setUpdatedAt(strtotime('now'))                                                           		  									//PRODUCT UPDATE TIME
                ->setSku(str_replace('"""', '', $arr[0]))                                                  		  									//SET SKU
                ->setName($arr[1])                                                                         		  									//SET PRODUCTNAME
                ->setTypeId('configurable')                                                                		  									//SET PRODUCT TYPE
                ->setDescription($arr[2].$arr[4])                                                          		  									//SET DESCRIPTION 
                ->setShortDescription($arr[5])                                                             		  									//SET SHORT DESCRIPTION
                ->setMetaTitle($arr[7])                                                                    		  									//SET META TITLE
                ->setMetaKeyword($arr[6])                                                                  		  									//SET META KEYWORD
                ->setMetaDescription($arr[9])                                                              		  									//SET META DESCRIPTION
                ->setPrice($arr[20])                                                                       		  									//SET BASIC PRICE
                ->setSpecialPrice($arr[21])                                                                		  									//SET SPECIAL PRICE
                ->setSpecialFromDate(strtotime('now'))                                                     		  									//SPECIAL PRICE FROM (MM-DD-YYYY)
                ->setSpecialToDate(strtotime('now'))                                                       		  									//SPECIAL PRICE TO (MM-DD-YYYY)
                ->setWeight($arr[24])                                                                      		  									//SET PACKAGE WEIGHT
                ->setTaxClassId(2);																													//SET TAX ID 
                
  
                        if($add_media)                                                                     	  										//IF MEDIA IS UPLOADED TO MEDIA FOLDER MAGENTO
                        {
                            $data = [];
                            if(strlen($arr[14]) > 3)                                                       	  										//CHECK IMAGE COLUMN 1
                            {
                                array_push($data, array("type"=>"thumbnail", "data"=>"". $arr[14].""));
                                array_push($data, array("type"=>"small_image", "data"=>"". $arr[14].""));
                                array_push($data, array("type"=>"image", "data"=>"". $arr[14].""));
                            }
                            if(strlen($arr[15]) > 3)                                                       	  										//CHECK IMAGE COLUMN 2
                            {
                                array_push($data, array("type"=>"thumbnail", "data"=>"". $arr[15].""));
                                array_push($data, array("type"=>"small_image", "data"=>"". $arr[15].""));
                                array_push($data, array("type"=>"image", "data"=>"". $arr[15].""));
                            }
                            if(strlen($arr[16]) > 3)                                                       	  										//CHECK IMAGE COLUMN 3
                            {
                                array_push($data, array("type"=>"thumbnail", "data"=>"". $arr[16].""));
                                array_push($data, array("type"=>"small_image", "data"=>"". $arr[16].""));
                                array_push($data, array("type"=>"image", "data"=>"". $arr[16].""));
                            }
                            if(strlen($arr[17]) > 3)                                                       	  										//CHECK IMAGE COLUMN 4
                            {
                                array_push($data, array("type"=>"thumbnail", "data"=>"". $arr[17].""));
                                array_push($data, array("type"=>"small_image", "data"=>"". $arr[17].""));
                                array_push($data, array("type"=>"image", "data"=>"". $arr[17].""));
                            }
                            if(strlen($arr[18]) > 3)                                                       	  										//CHECK IMAGE COLUMN 5
                            {
                                array_push($data, array("type"=>"thumbnail", "data"=>"". $arr[18].""));
                                array_push($data, array("type"=>"small_image", "data"=>"". $arr[18].""));
                                array_push($data, array("type"=>"image", "data"=>"". $arr[18].""));
                            }
                            if(strlen($arr[19]) > 3)                                                       	  										//CHECK IMAGE COLUMN 6
                            {
                                array_push($data, array("type"=>"thumbnail", "data"=>"". $arr[19].""));
                                array_push($data, array("type"=>"small_image", "data"=>"". $arr[19].""));
                                array_push($data, array("type"=>"image", "data"=>"". $arr[19].""));
                            }
                            echo '<p>';

	                            foreach ($data as $value)
	                            { 
	                                $path =  $mediapath_products.$value['data'];

	                                $imageType = $value['type']; 
	                                if (file_exists($path))                                                	  										//EXTRA CHECK FOR MISSING IMAGES
	                                {
	                                    try 
	                                    {
	                                        $configProduct->addImageToMediaGallery($path,$imageType,false);	  										//ADD IMAGES TO PRODUCT GALLERY
	                                    } 
	                                    catch(Exception $e) 
	                                    {
	                                        echo $e->getMessage();
	                                    }
	                                } 
	                                else 
	                                {
	                                    echo "<a style='color:red;'>{$imageType} file does not exist: {$path},". 
	                                         "please check your media folder. If no images are uploaded!!!,". 
	                                         "please disable this setting $add_media to FALSE</a><br/>";
	                                }
	                            }
                            }  
                            $cat1 = Mage::getResourceModel('catalog/category_collection')                 	  										//FETCH CATEGORY ID OF PRODUCT MAIN CATEGORY
                                            ->addAttributeToFilter('name', $arr[27])
                                            ->setStoreId($store_id)
                                            ->addAttributeToFilter('level','2')
                                            ->getFirstItem()
                                            ->getID();
                            $cat2 = Mage::getResourceModel('catalog/category_collection')                 	  										//FETCH CATEGORY ID OF PRODUCT SUB CATEGORY
                                            ->addAttributeToFilter('name', $arr[29])
                                            ->setStoreId($store_id)
                                            ->addAttributeToFilter('level','3')
                                            ->getFirstItem()
                                            ->getID();

                            $cats = [];
                                      
                            if($cat1 > 0)
                            {
                                array_push($cats, $cat1);
                            }   
                            if($cat2 > 0)
                            {
                                array_push($cats, $cat2);
                            }  

                            array_push($cats, $parent_id);																							//ADD              
                            $configProduct->setCategoryIds($cats);                                        	  										//SET CATEGORY ID'S FOR CONFIG PRODUCT
					/*		 
					* 		╔═╗╔╦╗╔═╗╦═╗╔╦╗  ╔═╗╦╔╦╗╔═╗╦  ╔═╗  ╔═╗╦═╗╔═╗╔╦╗╦ ╦╔═╗╔╦╗
					* 		╚═╗ ║ ╠═╣╠╦╝ ║   ╚═╗║║║║╠═╝║  ║╣   ╠═╝╠╦╝║ ║ ║║║ ║║   ║ 
					* 		╚═╝ ╩ ╩ ╩╩╚═ ╩   ╚═╝╩╩ ╩╩  ╩═╝╚═╝  ╩  ╩╚═╚═╝═╩╝╚═╝╚═╝ ╩                      
					*/		 
		            $simpleProductArray=[];																	  									   //DECLARE EMPTY ARRAY FOR ADDING SIMPLE PRODUCT CONFIG TO CONFIGURABLE PRODUCT
		            try 
		            {
		                foreach ($color_list as $attribute)												  										   //LOOP TROUGH CONNECTING ATTRIBUTES FOR CONFIGURABLE PRODUCT
		                {
                            if(!empty(Mage::getModel('catalog/product')->getIdBySku(str_replace('"""', '', $arr[0].strtolower($attribute)))))
                            {
                                $product = Mage::getModel('catalog/product')->loadByAttribute('sku' , str_replace('"""', '', $arr[0].strtolower($attribute)));
                                $cats = $product->getCategoryIds();
                                
                                if(!empty($category1))
                                {
                                    array_push($cats,$category1->getId());
                                }

                                if(!empty($category2))
                                {   
                                    array_push($cats,$category2->getId());   
                                }

                                $product->setCategoryIds($cats);
                                $product->save();
                                echo '<br/>The categories of product: '.$product->getName().' are updated! <br/>';

                                continue;
                            } 
                            else
                            {
                                $simpleProduct = Mage::getModel('catalog/product');                             
                            }

		                        $check = strpos(strtolower($arr[64]), 'active');							  										//CHECK IF PRODUCT IS ACTIVE 
		                        if($check === false)
		                        {
		                            $simpleProduct->setStatus(2);                                       	  										//PRODUCT STATUS (1 - ENABLED, 2 - DISABLED)
		                        }
		                        else
		                        {
		                            $simpleProduct->setStatus(1);                                             										//PRODUCT STATUS (1 - ENABLED, 2 - DISABLED)
		                        }    
		                        $simpleProduct->setWebsiteIds(array($website_id))                             										//WEBSITE ID THE PRODUCT IS ASSIGNED TO, AS AN ARRAY
		                        ->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)       										//CATALOG AND SEARCH VISIBILITY
		                        ->setAttributeSetId($default_atr)                                             										//DEFAULT ATTRIBUTES
		                        ->setCreatedAt(strtotime('now'))                                              										//PRODUCT CREATION TIME
		                        ->setUpdatedAt(strtotime('now'))                                              										//PRODUCT UPDATE TIME
		                        ->setSku(str_replace('"""', '', $arr[0]).strtolower($attribute))              										//SET SKU
		                        ->setName($arr[1])                                                            										//SET PRODUCTNAME
		                        ->setTypeId('simple')                                                         										//SET PRODUCT TYPE
		                        ->setDescription($arr[2].$arr[4])                                             										//SET DESCRIPTION 
		                        ->setShortDescription($arr[5])                                                										//SET SHORT DESCRIPTION
		                        ->setMetaTitle($arr[7])                                                       										//SET META TITLE
		                        ->setMetaKeyword($arr[6])                                                     										//SET META KEYWORD
		                        ->setMetaDescription($arr[9])                                                 										//SET META DESCRIPTION  
		                        ->setPrice($arr[20])                                                          										//SET BASIC PRICE
		                        ->setSpecialPrice($arr[21])                                                   										//SET SPECIAL PRICE
		                        ->setSpecialFromDate(strtotime('now'))                                        										//SPECIAL PRICE FROM (MM-DD-YYYY)
		                        ->setSpecialToDate(strtotime('now'))                                          										//SPECIAL PRICE TO (MM-DD-YYYY)
		                        ->setWeight($arr[24])                                                         										//SET PACKAGE WEIGHT
		                        ->setTaxClassId(2);                                                           										//TAX CLASS (0 - NONE, 1 - DEFAULT, 2 - TAXABLE, 4 - SHIPPING)
		  
		                        if($add_media)                                                                										//IF MEDIA IS UPLOADED TO MEDIA FOLDER MAGENTO
		                        {
		                            $data = [];
		                            if(strlen($arr[14]) > 3)                                                  										//CHECK IMAGE COLUMN 1
		                            {
		                                array_push($data, array("type"=>"thumbnail", "data"=>"". $arr[14].""));
		                                array_push($data, array("type"=>"small_image", "data"=>"". $arr[14].""));
		                                array_push($data, array("type"=>"image", "data"=>"". $arr[14].""));
		                            }
		                            if(strlen($arr[15]) > 3)                                                   										//CHECK IMAGE COLUMN 2
		                            {
		                                array_push($data, array("type"=>"thumbnail", "data"=>"". $arr[15].""));
		                                array_push($data, array("type"=>"small_image", "data"=>"". $arr[15].""));
		                                array_push($data, array("type"=>"image", "data"=>"". $arr[15].""));
		                            }
		                            if(strlen($arr[16]) > 3)                                               	   										//CHECK IMAGE COLUMN 3
		                            {
		                                array_push($data, array("type"=>"thumbnail", "data"=>"". $arr[16].""));
		                                array_push($data, array("type"=>"small_image", "data"=>"". $arr[16].""));
		                                array_push($data, array("type"=>"image", "data"=>"". $arr[16].""));
		                            }
		                            if(strlen($arr[17]) > 3)                                               	   										//CHECK IMAGE COLUMN 4
		                            {
		                                array_push($data, array("type"=>"thumbnail", "data"=>"". $arr[17].""));
		                                array_push($data, array("type"=>"small_image", "data"=>"". $arr[17].""));
		                                array_push($data, array("type"=>"image", "data"=>"". $arr[17].""));
		                            }
		                            if(strlen($arr[18]) > 3)                                               	   										//CHECK IMAGE COLUMN 5
		                            {
		                                array_push($data, array("type"=>"thumbnail", "data"=>"". $arr[18].""));
		                                array_push($data, array("type"=>"small_image", "data"=>"". $arr[18].""));
		                                array_push($data, array("type"=>"image", "data"=>"". $arr[18].""));
		                            }
		                            if(strlen($arr[19]) > 3)                                               	   										//CHECK IMAGE COLUMN 6
		                            {
		                                array_push($data, array("type"=>"thumbnail", "data"=>"". $arr[19].""));
		                                array_push($data, array("type"=>"small_image", "data"=>"". $arr[19].""));
		                                array_push($data, array("type"=>"image", "data"=>"". $arr[19].""));
		                            }
		                            echo '<p>';

		                            foreach ($data as $value)
		                            { 
		                                $path =  $mediapath_products.$value['data'];
		                                $imageType = $value['type']; 
		                                if (file_exists($path))                                                										//EXTRA CHECK FOR MISSING IMAGES
		                                {
		                                    try 
		                                    {
		                                        $simpleProduct->addImageToMediaGallery($path,$imageType,false);										//ADD IMAGES TO PRODUCT GALLERY
		                                    } 
		                                    catch(Exception $e) 
		                                    {
		                                        echo $e->getMessage();
		                                    }
		                                } 
		                                else 
		                                {
		                                    echo "{$imageType} file does not exist: {$path}, please check your media folder. ".
		                                    	 "If no images are uploaded!!!, please disable this setting $add_media to FALSE<br/>";
		                                }
		                            }
		                        }
		                        /*
		                         *      ╔═╗╔╦╗╔═╗╦═╗╔╦╗  ╔═╗╦═╗╔═╗╔═╗╔╦╗╔═╗  ╔═╗╦═╗  ╦╔╦╗╔═╗╔═╗╦═╗╔╦╗  ╔═╗╦═╗╔═╗╔╦╗╦ ╦╔═╗╔╦╗  ╔═╗╔╦╗╔╦╗╦═╗╦╔╗ ╦ ╦╔╦╗╔═╗╔═╗
		                         *      ╚═╗ ║ ╠═╣╠╦╝ ║   ║  ╠╦╝║╣ ╠═╣ ║ ║╣   ║ ║╠╦╝  ║║║║╠═╝║ ║╠╦╝ ║   ╠═╝╠╦╝║ ║ ║║║ ║║   ║   ╠═╣ ║  ║ ╠╦╝║╠╩╗║ ║ ║ ║╣ ╚═╗
		                         *      ╚═╝ ╩ ╩ ╩╩╚═ ╩   ╚═╝╩╚═╚═╝╩ ╩ ╩ ╚═╝  ╚═╝╩╚═  ╩╩ ╩╩  ╚═╝╩╚═ ╩   ╩  ╩╚═╚═╝═╩╝╚═╝╚═╝ ╩   ╩ ╩ ╩  ╩ ╩╚═╩╚═╝╚═╝ ╩ ╚═╝╚═╝ 
		                        */ 
		                         
		                        if(!$show_only_config)
		                        {
		                            $cat1 = Mage::getResourceModel('catalog/category_collection')                                   	  			//FETCH CATEGORY ID OF PRODUCT MAIN CATEGORY
		                                            ->addAttributeToFilter('name', $arr[27])
		                                            ->setStoreId($store_id)
		                                            ->addAttributeToFilter('level','2')
		                                            ->getFirstItem()
		                                            ->getID();
		                            $cat2 = Mage::getResourceModel('catalog/category_collection')                                   	  			//FETCH CATEGORY ID OF PRODUCT SUB CATEGORY
		                                            ->addAttributeToFilter('name', $arr[29])
		                                            ->setStoreId($store_id)
		                                            ->addAttributeToFilter('level','3')
		                                            ->getFirstItem()
		                                            ->getID();

		                            $cats = [];
                                      
		                            if($cat1 > 0)
		                            {
		                                array_push($cats, $cat1);
		                            }   
		                            if($cat2 > 0)
		                            {
		                                array_push($cats, $cat2);
		                            }  

		                            array_push($cats, $parent_id);																					//ADD MAIN STORE CATEGORY                               

		                            $simpleProduct->setCategoryIds($cats);                                                   						//SET CATEGORY ID'S
		                        }	
		                            
		                            $attribute_manufacturer = Mage::getModel('catalog/resource_eav_attribute')                      				//FETCH ATTRIBUTES MODEL 'manufactures'
		                                                      ->loadByCode(Mage_Catalog_Model_Product::ENTITY, 'manufacturer');
		                            $manufacturer_options = Mage::getResourceModel('eav/entity_attribute_option_collection')        				//FETCH ATTRIUBUTE OPTIONS
		                                                    ->setAttributeFilter($attribute_manufacturer->getId())
		                                                    ->setStoreFilter(Mage_Core_Model_App::ADMIN_STORE_ID)
		                                                    ->addFieldToFilter('tdv.value', $arr[40])->getFirstItem()->getId();
		                                                                                                                                			//Check if option already exists                        
		                            if(strlen($manufacturer_options) > 0)
		                            {
		                                $simpleProduct->setManufacturer($manufacturer_options);                                           			//SET MANUFACTURER IF EXISTS
		                            }
		                            else                            
		                            {
		                                $value['option'] = array($arr[40]);                                                        					//SET DATA NEW ATTRIBUTE
		                                $result = array('value' => $value);                                                         				//BUILD NEEDED ARRAY
		                                $attribute_manufacturer->setData('option',$result);                                         				//SET DATA TO OBJECT
		                                $attribute_manufacturer->save();                                                          					//SAVE ATTRIBUTE
		                                $simpleProduct->setManufacturer($attribute_manufacturer->getId());                                      	//SET MANUFACTURER IF EXISTS
		                            }

		                            $attribute_color = Mage::getModel('catalog/resource_eav_attribute')                      						//FETCH ATTRIBUTES MODEL 'manufactures'
		                                                      ->loadByCode(Mage_Catalog_Model_Product::ENTITY, 'color');
		                            $color_options = Mage::getResourceModel('eav/entity_attribute_option_collection')               				//FETCH ATTRIUBUTE OPTIONS
		                                                    ->setAttributeFilter($attribute_color->getId())
		                                                    ->setStoreFilter(Mage_Core_Model_App::ADMIN_STORE_ID)
		                                                    ->addFieldToFilter('tdv.value', $attribute)->getFirstItem()->getId();
		                                                                                                                            				//CHECK IF OPTION EXISTS                        
		                            if(strlen($color_options) > 0)
		                            {
		                                $simpleProduct->setColor($color_options);                                                  					//SET MANUFACTURER IF EXISTS
		                            }
		                            else                            
		                            {


		                                $option['option'] = array($attribute);                                                        				//SET DATA NEW ATTRIBUTE
		                                $result = array('value' => $option); 
		                                                                                                                               				//BUILD NEEDED ARRAY
		                                $attribute_color->setData('option',$result);                                                				//SET DATA TO OBJECT
		                                $attribute_color->save();                                                                 					//SAVE ATTRIBUTE
		                                $simpleProduct->setColor($attribute_color->getId());                                                  		//SET MANUFACTURER IF EXISTS
		                            }

											                       

		                               if($simpleProduct->save())
		                               {
		                                array_push($simpleProductArray, array('product_id'=>$simpleProduct->getId(),
		                                	'label'=>$attribute,'color_id'=>$attribute_color->getId()));

		                                echo '<a style="color:green;">The product '. str_replace('"""', '', $arr[0]) . '-' . $arr[1] . 
		                                	 ' is added to your Magento store</a><br/>';
		                               }
		                               else
		                               {
		                                echo '<a style="color:red;">The product '. str_replace('"""', '', $arr[0]) . '-' . $arr[1] . 
		                                	 'failed to be added to your Magento store</a><br/>';
		                               } 
		                              

		                        /**
		                         *   ╔═╗╔╗╔╔╦╗  ╔═╗╦═╗╔═╗╔═╗╔╦╗╔═╗  ╔═╗╦═╗  ╦╔╦╗╔═╗╔═╗╦═╗╔╦╗  ╔═╗╦═╗╔═╗╔╦╗╦ ╦╔═╗╔╦╗  ╔═╗╔╦╗╔╦╗╦═╗╦╔╗ ╦ ╦╔╦╗╔═╗╔═╗
		                         *   ║╣ ║║║ ║║  ║  ╠╦╝║╣ ╠═╣ ║ ║╣   ║ ║╠╦╝  ║║║║╠═╝║ ║╠╦╝ ║   ╠═╝╠╦╝║ ║ ║║║ ║║   ║   ╠═╣ ║  ║ ╠╦╝║╠╩╗║ ║ ║ ║╣ ╚═╗
		                         *   ╚═╝╝╚╝═╩╝  ╚═╝╩╚═╚═╝╩ ╩ ╩ ╚═╝  ╚═╝╩╚═  ╩╩ ╩╩  ╚═╝╩╚═ ╩   ╩  ╩╚═╚═╝═╩╝╚═╝╚═╝ ╩   ╩ ╩ ╩  ╩ ╩╚═╩╚═╝╚═╝ ╩ ╚═╝╚═╝
		                         */  
		                              	
		                                          
		                        if($managestock && $arr[23] > 0)                                                           							//MANAGE STOCK IS TRUE AND QTY IS MORE THAN 0
		                        {
		                            	$stockItem = Mage::getModel('cataloginventory/stock_item');													//GET STOCK ITEM MODEL
										$stockItem->assignProduct($simpleProduct);																	//ASSIGN PRODUCT ID
										$stockItem->setData('is_in_stock', 1);																		//SET IS IN STOCK 0/1
										$stockItem->setData('stock_id', 1);																			//SET STOCK ID FOR PRODUCT
										$stockItem->setData('store_id', $store_id);																	//SET STORE ID
										$stockItem->setData('manage_stock', 1);																		//SET MANAGE STOCK 0/1
										$stockItem->setData('use_config_manage_stock', $managestock_storeConfig);									//SET USE CONFIG MANAGE STOCK
										$stockItem->setData('min_sale_qty', 1);																		//SET MIN. ORDER QUANTITY	
										$stockItem->setData('use_config_min_sale_qty', 0);															//SET USE CONFIG MIN. ORDER QUANTITY	
										$stockItem->setData('max_sale_qty', 1000);																	//SET MAX. ORDER QUANTITY	
										$stockItem->setData('use_config_max_sale_qty', 0);															//SET USE CONFIG MAX. ORDER QUANTITY
										$stockItem->setData('qty', $arr[23]);																		//SET STOCK QUANTITY	
										$stockItem->save();              
		                        }
		                        elseif($managestock && $arr[23] < 1)                                                           						//MANAGE STOCK IS TRUE AND QTY IS LESS THAN 0
		                        {
		                            if($managestock_IfNull)                                                                                 		//MANAGESTOCK IF NULL IS TRUE
		                            {
		                                $stockItem = Mage::getModel('cataloginventory/stock_item');																												
										$stockItem->assignProduct($simpleProduct);																																
										$stockItem->setData('is_in_stock', 1);																																	
										$stockItem->setData('stock_id', 1);																
										$stockItem->setData('store_id', $store_id);																
										$stockItem->setData('manage_stock', 1);																
										$stockItem->setData('use_config_manage_stock',$managestock_storeConfig);																
										$stockItem->setData('min_sale_qty', 1);																
										$stockItem->setData('use_config_min_sale_qty', 0);																
										$stockItem->setData('max_sale_qty', 1000);																
										$stockItem->setData('use_config_max_sale_qty', 0);																
										$stockItem->setData('qty', 1);																
										$stockItem->save();
		                            }
		                            else
		                            {
		                                $stockItem = Mage::getModel('cataloginventory/stock_item');
										$stockItem->assignProduct($simpleProduct);
										$stockItem->setData('is_in_stock', 1);
										$stockItem->setData('stock_id', 1);
										$stockItem->setData('store_id', $store_id);
										$stockItem->setData('manage_stock', 0);
										$stockItem->setData('use_config_manage_stock',$managestock_storeConfig);
										$stockItem->setData('min_sale_qty', 1);
										$stockItem->setData('use_config_min_sale_qty', 0);
										$stockItem->setData('max_sale_qty', 1000);
										$stockItem->setData('use_config_max_sale_qty', 0);
										$stockItem->setData('qty', $arr[23]);
										$stockItem->save();
		                            }    
		                        }
		                        else
		                        {
		                                $stockItem = Mage::getModel('cataloginventory/stock_item');
										$stockItem->assignProduct($simpleProduct);
										$stockItem->setData('is_in_stock', 0);
										$stockItem->setData('stock_id', 1);
										$stockItem->setData('store_id', $store_id);
										$stockItem->setData('manage_stock', 0);
										$stockItem->setData('use_config_manage_stock',$managestock_storeConfig);
										$stockItem->setData('min_sale_qty', 1);
										$stockItem->setData('use_config_min_sale_qty', 0);
										$stockItem->setData('max_sale_qty', 1000);
										$stockItem->setData('use_config_max_sale_qty', 0);
										$stockItem->setData('qty', $arr[23]);
										$stockItem->save();
		                        } 
		                }
		            } 
		            catch(Exception $e) 
		            {
		                Mage::log($e->getMessage());																
		                echo 'Error in Simple Product :' . $e->getMessage();																		//EXCEPTION MESSAGE WHEN CONFIGURABLE PRODUCT FAILED TO SAVE
		            }
					/*
					* 		╔═╗╔╗╔╔╦╗  ╔═╗╦╔╦╗╔═╗╦  ╔═╗  ╔═╗╦═╗╔═╗╔╦╗╦ ╦╔═╗╔╦╗
					* 		║╣ ║║║ ║║  ╚═╗║║║║╠═╝║  ║╣   ╠═╝╠╦╝║ ║ ║║║ ║║   ║ 
					* 		╚═╝╝╚╝═╩╝  ╚═╝╩╩ ╩╩  ╩═╝╚═╝  ╩  ╩╚═╚═╝═╩╝╚═╝╚═╝ ╩ 		            
					*/
				
					/* 
					*      ╔═╗╔═╗╔╗╔╔═╗╦╔═╗╦ ╦╦═╗╔═╗╔╗ ╦  ╔═╗  ╔═╗╦═╗╔═╗╔╦╗╦ ╦╔═╗╔╦╗
					*  	   ║  ║ ║║║║╠╣ ║║ ╦║ ║╠╦╝╠═╣╠╩╗║  ║╣   ╠═╝╠╦╝║ ║ ║║║ ║║   ║ 
					*  	   ╚═╝╚═╝╝╚╝╚  ╩╚═╝╚═╝╩╚═╩ ╩╚═╝╩═╝╚═╝  ╩  ╩╚═╚═╝═╩╝╚═╝╚═╝ ╩ 
                    */
                $configProduct->getTypeInstance()->setUsedProductAttributeIds(array($color_atr));                                                   //SET COLOR ATRIBUTE ID 
                $configurableAttributesData = $configProduct->getTypeInstance()->getConfigurableAttributesAsArray();                                //FECTH ATTRIBUTES AS ARRAY
             
                $configProduct->setCanSaveConfigurableAttributes(true);
                $configProduct->setConfigurableAttributesData($configurableAttributesData);
             
                $configurableProductsData = array();
                $i=0;
                foreach ($simpleProductArray as $key => $value)                                                                                     //LOOP TROUGH NEW BUILD SIMPLE PRODUCT DATA ARRAY
                {
                    $configurableProductsData[$value['product_id']] = array('0' => array(                                                           //SET CONNECTED SIMPLE PRODUCT ID
                            'label' => $value['label'],                                                                                             //SET LABEL
                            'attribute_id' => $value['color_id'],                                                                                   //SET COLOR ID
                            'value_index' => '0',                                                                                                   //SET BACKEND INDEX
                            'is_percent' => '0',                                                                                                    //SET IF PRICE IS BUILD FROM PERCENTAGE
                            'pricing_value' => ''));                                                                                                //SET NEW PRICE VALUE, KEEP EMPTY WHEN USING SIMPLE PRODUCT PRICES
                    $i++;
                }


                
                $configProduct->setConfigurableProductsData($configurableProductsData);

                if($configProduct->save())                                                                                                          //SAVE CONFIGURABLE PRODUCT
                {
                    $stockItem = Mage::getModel('cataloginventory/stock_item');                                                                     //SET STOCK DATA AFTER CONFIGURABLE PRODUCT IS SAVED                                                                                                        
                    $stockItem->assignProduct($configProduct);                                                                                      //ASSIGN CONFIGURABLE PRODUCT                                                                                                                            
                    $stockItem->setData('is_in_stock', 1);                                                                                          //SET IS IN STOCK                                        
                    $stockItem->setData('stock_id', 1);                                                                                             //SET STOCK ID
                    $stockItem->setData('store_id', $store_id);                                                                                     //SET STORE ID
                    $stockItem->setData('manage_stock', 1);                                                                                         //SET MANAGE STOCK 0/1
                    $stockItem->setData('use_config_manage_stock',$managestock_storeConfig);                                                        //SET MANAGE STORE CONFIG                                                           
                    $stockItem->save();


                 echo '<br/><a style="color:green;">The config product '. str_replace('"""', '', $arr[0]) . '-' . $arr[1] .
                      ' is added to your Magento store</a><br/>';
                }
                else
                {
                 echo '<br/><a style="color:red;">The config product '. str_replace('"""', '', $arr[0]) . '-' . $arr[1] . 
                      'failed to be added to your Magento store</a><br/>';
                }     



				echo '</p>';
			} 
			catch(Exception $e) 
			{
			    Mage::log($e->getMessage());																										//EXCEPTION MESSAGE WHEN CONFIGURABLE PRODUCT FAILED TO SAVE
			    echo 'Error in Configurable Product :' . $e->getMessage();
			}
        }
        $row++;																									
    }
    if (!feof($handle))                                                                                     										//CHECK IF CSV FILE IS VALID OR FAILING
    {
        echo "Error: unexpected fgets() fail\n";                                                    
    }   
    fclose($handle);                                                                                        										//CLOSE CSV FILE AND BUFFER
}
?>

 

 

Incidenten registratie

In iedere organisatie worden fouten gemaakt en vinden incidenten plaats. Om hier inzicht in te krijgen en de kans op herhaling te voorkomen, is het van belang incidenten op de juiste manier te registreren. Bekijk de voordelen van ons incidenten registratiesysteem.

Incidenten registratie

"Wie op zoek is naar een teamplayer, een man van zijn woord en een uitmuntende programmeur, dan kan ik Reinder zeker aanbevelen. Reinder bedankt en tot de volgende uitdaging."

Marijn Snoek - Fleetaccess