-
Notifications
You must be signed in to change notification settings - Fork 7
/
attr-import.php
executable file
·69 lines (65 loc) · 2.43 KB
/
attr-import.php
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
#!/usr/bin/php
<?php
require_once 'lib/init.php';
require_once 'lib/attribute_functions.php';
if (count($argv) < 2) {
echo "Import attributes\n";
echo "Usage: attr-import.php INPUT_XML\n";
exit(1);
}
$defaultParentId = Mage::app()->getDefaultStoreView()->getRootCategoryId();
// Load File XML
$xmlFilename = $argv[1];
echo "Loading $xmlFilename...";
$attrsXml = simplexml_load_file($xmlFilename);
echo " Loaded.\n";
foreach ($attrsXml as $attrEl) {
$code = (string) $attrEl->id;
$label = (string) $attrEl->name;
$type = (string) $attrEl->type;
$configurable = $attrEl->type == '1' || $attrEl->type == 'true';
$overrides = array(
'is_searchable' => $attrEl->isSearchable != '' ? $attrEl->isSearchable == 'true' : 1,
'is_visible_in_advanced_search' => $attrEl->isVisibleInAdvancedSearch != '' ? $attrEl->isVisibleInAdvancedSearch == 'true' : 1,
'is_comparable' => $attrEl->isComparable != '' ? $attrEl->isComparable == 'true' : 1,
'is_filterable' => $attrEl->isFilterableInSearch != '' ? $attrEl->isFilterableInSearch == 'true' : 1,
'is_filterable_in_search' => $attrEl->isFilterableInSearch != '' ? $attrEl->isFilterableInSearch == 'true' : 1,
'is_visible_on_front' => $attrEl->isVisibleOnFront != '' ? $attrEl->isVisibleOnFront == 'true' : 1,
'used_in_product_listing' => $attrEl->usedInProductListing != '' ? $attrEl->usedInProductListing == 'true' : 1,
'used_for_sort_by' => $attrEl->usedForSortBy != '' ? $attrEl->usedForSortBy == 'true' : 1,
);
switch ($type) {
case 'data':
$datatype = (string) $attrEl->datatype;
$backendTypes = array(
'string' => 'varchar',
'varchar' => 'varchar',
'int' => 'int',
'decimal' => 'decimal',
'double' => 'decimal',
'datetime' => 'datetime',
'text' => 'text',
'currency' => 'decimal');
$frontendInputs = array(
'string' => 'text',
'varchar' => 'text',
'int' => 'text',
'decimal' => 'text',
'double' => 'text',
'datetime' => 'date',
'text' => 'textarea',
'currency' => 'price');
createDataAttribute($code, $label,
$backendTypes[$datatype], $frontendInputs[$datatype],
$configurable, $overrides);
break;
case 'select':
$optionsStr = (string) $attrEl->options;;
$options = isset($optionsStr) ? explode(',', $optionsStr) : array();
createSelectAttribute($code, $label, $configurable, $options,
$overrides);
break;
default:
throw new Exception("Unknown attribute type: $type");
}
}