shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

fba.php (2695B)


      1 <?php
      2 class ModelExtensionOpenBayFba extends Model {
      3     public function install() {
      4         $this->load->model('setting/event');
      5 
      6 		$this->model_setting_event->addEvent('openbay_fba_add_order', 'catalog/model/checkout/order/addOrder/after', 'extension/openbay/fba/eventAddOrder');
      7 		$this->model_setting_event->addEvent('openbay_fba_add_orderhistory', 'catalog/model/checkout/order/addOrderHistory/after', 'extension/openbay/fba/eventAddOrderHistory');
      8 
      9         $this->db->query("
     10 				CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "fba_order` (
     11 					`order_id` INT(11) NOT NULL,
     12 					`fba_order_fulfillment_id` INT(11) NOT NULL,
     13 					`fba_order_fulfillment_ref` CHAR(50) NOT NULL,
     14 					`status` CHAR(10) NOT NULL,
     15 				    `created` DATETIME NOT NULL,
     16   				    KEY `fba_order_id` (`order_id`)
     17 				) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;");
     18 
     19         $this->db->query("
     20 				CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "fba_order_fulfillment` (
     21 					`fba_order_fulfillment_id` INT(11) NOT NULL AUTO_INCREMENT,
     22 					`order_id` INT(11) NOT NULL,
     23 				    `created` DATETIME NOT NULL,
     24 					`request_body` TEXT NOT NULL,
     25 					`response_body` TEXT NOT NULL,
     26 					`response_header_code` INT(3) NOT NULL,
     27 					`type` INT(3) NOT NULL,
     28 					PRIMARY KEY (`fba_order_fulfillment_id`),
     29   				    KEY `order_id` (`order_id`)
     30 				) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;");
     31 
     32         // Default settings
     33         $setting = array();
     34         $setting["openbay_fba_status"] = 0;
     35         $setting["openbay_fba_send_orders"] = 0;
     36         $setting["openbay_fba_debug_log"] = 1;
     37         $setting["openbay_fba_order_trigger_status"] = 15;
     38         $setting["openbay_fba_cancel_order_trigger_status"] = 7;
     39         $setting["openbay_fba_fulfill_policy"] = 'FillAllAvailable';
     40         $setting["openbay_fba_shipping_speed"] = 'Standard';
     41         $setting["openbay_fba_order_prefix"] = 'OC-';
     42 
     43 		$this->model_setting_setting->editSetting('openbay_fba', $setting);
     44     }
     45 
     46     public function uninstall() {
     47         $this->db->query("DELETE FROM `" . DB_PREFIX . "setting` WHERE `code` = 'openbay_fba'");
     48 
     49         $this->load->model('setting/event');
     50         $this->model_setting_event->deleteEventByCode('openbay_fba_add_order');
     51         $this->model_setting_event->deleteEventByCode('openbay_fba_add_orderhistory');
     52     }
     53 
     54     public function patch() {
     55         if ($this->config->get('openbay_fba_status') == 1) {
     56 
     57         }
     58     }
     59 
     60     public function countFbaOrders() {
     61         $query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "fba_order`");
     62 
     63         return (int)$query->row['total'];
     64     }
     65 }