· 8 years ago · Jul 08, 2018, 05:30 AM
1$this->startSetup();
2
3$this->run("
4DROP TABLE IF EXISTS `{$this->getTable('groupswitcher_rule')}`;
5CREATE TABLE `{$this->getTable('groupswitcher_rule')}` (
6 `id` INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
7 `name` VARCHAR(255) NOT NULL DEFAULT '',
8 `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
9 `group_id_before` SMALLINT(3) UNSIGNED NULL,
10 `group_id_after` SMALLINT(3) UNSIGNED NOT NULL,
11 `rule_type` ENUM('buy_product', 'num_orders', 'order_total', 'total_orders') NOT NULL,
12 `rule_value` VARCHAR(255) NOT NULL DEFAULT '',
13 `note` VARCHAR(500) NOT NULL DEFAULT '',
14 CONSTRAINT `FK_group_id_before` FOREIGN KEY (`group_id_before`) REFERENCES {$this->getTable('customer_group')} (`customer_group_id`) ON DELETE CASCADE ON UPDATE CASCADE,
15 CONSTRAINT `FK_group_id_after` FOREIGN KEY (`group_id_after`) REFERENCES {$this->getTable('customer_group')} (`customer_group_id`) ON DELETE CASCADE ON UPDATE CASCADE,
16 INDEX `IDX_rules` (`rule_type`),
17 UNIQUE INDEX `UIDX_name` (`name`)
18) ENGINE=InnoDB DEFAULT CHARSET=utf8;
19");
20
21$this->installEntities(array(
22 'groupswitch_rule' => array(
23 'entity_model' => 'GroupSwitcher/rule',
24 'table' => 'GroupSwitcher/rule',
25 'attributes' => array(
26 'name' => array('type' => 'static', 'label' => 'Rule Name'),
27 'group_id_before' => array('type' => 'static', 'label' => 'Switch if Group'),
28 'group_id_after' => array('type' => 'static', 'label' => 'Switch to Group'),
29 'created_at' => array('type' => 'static', 'label' => 'Created At'),
30 'rule_type' => array('type' => 'static', 'label' => 'Rule Type'),
31 'rule_value' => array('type' => 'static', 'label' => 'Rule Condition Value'),
32 'note' => array('type' => 'static', 'label' => 'Comment'),
33 ),
34 ),
35));