-
Notifications
You must be signed in to change notification settings - Fork 11
/
magento-tax-class
executable file
·79 lines (68 loc) · 2.63 KB
/
magento-tax-class
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
#!/usr/bin/env php
<?php
//
// List magento tax classes and interactively allow the
// user to modify that list of classes.
//
// @author Joseph Mastey <joseph.mastey@gmail.com>
// @author $Author$
// @version $Id$
// @copyright Copyright (c) JRM Ventures LLC, 2010-
require_once("lib/base.php");
require_once("lib/db.php");
require_once("lib/taxes.php");
init_magento();
$classes = tax_classes();
$vars = user_action_vars(array("classes" => $classes));
$actions = array(
"l" => array("name" => "List tax classes", "callback" => "list_tax_classes"),
"a" => array("name" => "Add a tax class", "callback" => "add_tax_class"),
"d" => array("name" => "Delete a tax class", "callback" => "delete_tax_class"),
"w" => array("name" => "Write changes", "callback" => "write_user_action_changes"),
"x" => array("name" => "Abandon changes and exit", "callback" => "abandon_user_action_changes"),
);
print_graph();
list_tax_classes($vars);
user_action($actions, $vars);
function list_tax_classes($vars) {
print "\nTax Classes:\n";
foreach($vars->classes as $type => $classlist) {
print "$type:\n";
foreach($classlist as $class) {
print "\t$class\n";
}
print "\n";
}
}
function delete_tax_class($vars) {
print "\nDeleting an existing tax class.\n";
$ids = array();
foreach($vars->classes as $type => $classes) {
print "$type\n";
foreach($classes as $id => $name) {
$ids[$id] = $type;
print " $id: $name\n";
}
}
$choices = array("") + array_keys($ids);
$id = user_array_choice("Select an id to delete or press enter to skip and cancel", $choices);
if(0 == strcmp("", $id)) { return; }
$type = $ids[$id];
$name = $vars->classes[$type][$id];
unset($vars->classes[$type][$id]);
array_push($vars->query_stack, "delete from tax_class where class_name = '$name' and class_type = '$type' limit 1");
}
function add_tax_class($vars) {
print "\nAdding a new tax class.\n";
$type = user_array_choice("Select a tax class type (".implode("/", array_keys($vars->classes))."):", array_keys($vars->classes));
$name = user_text("Select a name for the new tax class");
$vars->classes[$type][rand(5000,9999)] = $name;
array_push($vars->query_stack, "insert into tax_class (class_name, class_type) values ('$name', '$type')");
}
function putdocs() {
require_once("lib/taxes.php");
print_error("List magento tax classes and interactively allow the user to modify that list of classes.\n");
print_error("Usage: magento-tax-class\n");
print_error("\n\n");
print_graph(true);
}