예제 #1
0
 static function upgrade($version)
 {
     $db = Database::instance();
     if ($version == 1) {
         // fix for allowing decimel place in money
         $db->query("ALTER TABLE {products} CHANGE COLUMN `cost` `cost` DECIMAL(10,2) default 0;");
         $db->query("ALTER TABLE {item_products} CHANGE COLUMN `cost` `cost` DECIMAL(10,2) default -1;");
         // postage bands
         $db->query("ALTER TABLE {products} ADD COLUMN `postage_band_id` int(9) default 1");
         $db->query("CREATE TABLE IF NOT EXISTS {postage_bands} (\n                 `id` int(9) NOT NULL auto_increment,\n                 `name` TEXT NOT NULL,\n                 `flat_rate` DECIMAL(10,2) default 0,\n                 `per_item` DECIMAL(10,2) default 0,\n                 PRIMARY KEY (`id`))\n                 ENGINE=InnoDB DEFAULT CHARSET=utf8;");
         postage_band::create("No Postage", 0, 0);
         module::set_version("basket", $version = 2);
     }
     if ($version == 2) {
         $db->query("CREATE TABLE IF NOT EXISTS {orders} (\n                 `id` int(9) NOT NULL auto_increment,\n                 `text` TEXT NOT NULL,\n                 PRIMARY KEY (`id`))\n                 ENGINE=InnoDB DEFAULT CHARSET=utf8;");
         basket::setPaymentDetails("<p>Use the following options to pay for this order.</p>\n<p>Send a chequre to..</p>\n<p>Visit the shop..</p>\n<p>By using internet banking..</p>");
         basket::setOrderPrefix("ORDER");
         basket::setOrderCompletePage("<p>Your order number is %order_number. To pay for this order please either:</p>\n<p> - Send a cheque for %total_cost to with reference %order_number..</p>\n<p> - Visit the shop and quote the order %order_number..</p>\n<p> - Transfer %total_cost using internet banking with reference %order_number..</p>\n<p>Order will be processed as soon as payment is received. You should receive an e-mail with your order details shortly.</p>");
         basket::setOrderCompleteEmail("Hi %name,\n\nThank you for your order the order details are below. To pay for this order please either:\n\n- Send a cheque for %total_cost to with reference %order_number..\n- Visit the shop and quote the order %order_number..\n- Transfer %total_cost using internet banking with reference %order_number..\n\nOrder will be processed as soon as payment is received. For order pick-ups please visit..\n\nOrder Details\n-------------\n%order_details\n\nThanks");
         basket::setOrderCompleteEmailSubject("Photography Order %order_number");
         module::set_version("basket", $version = 3);
     }
     if ($version == 3) {
         $db->query("ALTER TABLE {orders} ADD COLUMN `status` int(9) DEFAULT 0;");
         $db->query("CREATE TABLE IF NOT EXISTS {ipn_messages} (\n        `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,\n        `date`  int(11) NOT NULL,\n        `key` varchar(20) NOT NULL,\n        `txn_id` varchar(20) NOT NULL,\n        `status` varchar(20) NOT NULL,\n        `success` bool default false,\n        `text` text,\n        PRIMARY KEY  (`id`)\n      ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;");
         module::set_version("basket", $version = 4);
     }
     if ($version == 4) {
         $db->query("ALTER TABLE {orders} ADD COLUMN `name` varchar(1024);");
         $db->query("ALTER TABLE {orders} ADD COLUMN `email` varchar(1024);");
         $db->query("ALTER TABLE {orders} ADD COLUMN `method` int(9) DEFAULT 0;");
         $db->query("ALTER TABLE {orders} ADD COLUMN `cost` DECIMAL(10,2) default 0");
         module::set_version("basket", $version = 5);
     }
 }
 static function upgrade($version)
 {
     $db = Database::instance();
     if ($version == 1) {
         // fix for allowing decimel place in money
         $db->query("ALTER TABLE {products} CHANGE COLUMN `cost` `cost` DECIMAL(10,2) default 0;");
         $db->query("ALTER TABLE {item_products} CHANGE COLUMN `cost` `cost` DECIMAL(10,2) default -1;");
         // postage bands
         $db->query("ALTER TABLE {products} ADD COLUMN `postage_band_id` int(9) default 1");
         $db->query("CREATE TABLE IF NOT EXISTS {postage_bands} (\n                 `id` int(9) NOT NULL auto_increment,\n                 `name` TEXT NOT NULL,\n                 `flat_rate` DECIMAL(10,2) default 0,\n                 `per_item` DECIMAL(10,2) default 0,\n                 PRIMARY KEY (`id`))\n                 ENGINE=InnoDB DEFAULT CHARSET=utf8;");
         postage_band::create("No Postage", 0, 0);
         module::set_version("basket", $version = 2);
     }
 }
 public function add_postage_band()
 {
     access::verify_csrf();
     $form = postage_band::get_add_form_admin();
     $valid = $form->validate();
     $name = $form->add_postage->inputs["name"]->value;
     $postage = ORM::factory("postage_band")->where("name", "=", $name)->find();
     if ($postage->loaded()) {
         $form->add_postage->inputs["name"]->add_error("in_use", 1);
         $valid = false;
     }
     if ($valid) {
         $postage = postage_band::create($name, $form->add_postage->flat_rate->value, $form->add_postage->per_item->value);
         $postage->save();
         message::success(t("Created postage band %postage_name", array("postage_name" => html::clean($postage->name))));
         print json::reply(array("result" => "success"));
     } else {
         print $form;
     }
 }