$allOrders = array_slice($allOrders, 0, (int) $_POST['vars']['limit']); } else { $allOrdersQuery = "SELECT * FROM " . $wpdb->prefix . $this->pluginOrderTable . " WHERE payment_status IN (" . $inStatus . ") " . $orderstatus . " ORDER BY id DESC " . $limit . " "; $allOrders = $wpdb->get_results($allOrdersQuery); } /**************************************************** * * check if there are orders and if so do loop * ***************************************************/ /******************** if we have orders ********************/ if (is_array($allOrders) && count($allOrders) > 0) { /*get any -perhaps filtered - customised order status */ $customOrderStatus = wppizza_custom_order_status(); $customOrderStatusGetTxt = wppizza_order_status_default(); /*admin only notice if able to delete order*/ if (current_user_can('wppizza_cap_delete_order')) { $output['notice_delete'] = "<div>" . __('Note: deleting an order will <b>ONLY</b> delete it from the database table. It will <b>NOT</b> issue any refunds, cancel the order, send emails etc.', $this->pluginLocale) . "</div>"; } /*notice regarding status change*/ $output['notice_info'] = "<div style='color:red'>" . __('"Status" is solely for your internal reference. Updating/changing the value will have no other effects but might help you to identify which orders have not been processed.', $this->pluginLocale) . "</div>"; /******************************************************************************************** * * [TABLE OPEN] * ********************************************************************************************/ $output['table_open'] = "<table>"; /**************************************************************************** [header row]
} /*Exit if accessed directly*/ global $wpdb; /*no backticks or apostrophies around fieldnames please**/ /** indexes should be called KEY instead of INDEX. PRIMARY KEY must have 2 spaces before the ()**/ /** if using multiple column keys there can be no spaces between commas**/ /** see http://codex.wordpress.org/Creating_Tables_with_Plugins **/ //Drop Old Indexes if table exists to avoid duplicates and all sorts of other issues $table_name = "" . $wpdb->prefix . $this->pluginOrderTable . ""; if ($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") == $table_name) { $tblIndexes = $wpdb->get_results("SHOW INDEX FROM " . $table_name . "", ARRAY_A); $tIdx = array(); foreach ($tblIndexes as $idx) { if ($idx['Key_name'] != 'PRIMARY' && !in_array($idx['Key_name'], $tIdx)) { $tIdx[] = $idx['Key_name']; } } if (count($tIdx) > 0) { $sql = "ALTER TABLE " . $table_name . " DROP INDEX `" . implode("`, DROP INDEX `", $tIdx) . "`"; $wpdb->query($sql); } } /**create and alter table via dbDelta**/ if (isset($setNewOrderStatus) && is_array($setNewOrderStatus)) { $dbOrderStatus = "'" . implode("','", $setNewOrderStatus) . "'"; } else { $dbOrderStatus = "'" . implode("','", wppizza_custom_order_status()) . "'"; } $sql = "CREATE TABLE " . $wpdb->prefix . "wppizza_orders (\n\tid INT(10) NOT NULL AUTO_INCREMENT,\n\twp_user_id INT(10) NOT NULL DEFAULT '0',\n\torder_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\n\torder_update TIMESTAMP,\n\tcustomer_details TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL,\n\torder_details MEDIUMTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL,\n\torder_status ENUM({$dbOrderStatus}) NOT NULL DEFAULT 'NEW',\n\thash VARCHAR(64) NULL DEFAULT NULL,\n\torder_ini MEDIUMTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL,\n\tcustomer_ini TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL,\n\tpayment_status ENUM('INITIALIZED','COMPLETED','PENDING','REFUNDED','AUTHORIZED','FAILED','EXPIRED','INVALID','CANCELLED','OTHER','CAPTURED','COD','NOTAPPLICABLE') NULL DEFAULT 'COD',\n\ttransaction_id VARCHAR(48) NULL DEFAULT NULL,\n\ttransaction_details TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL,\n\ttransaction_errors TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL,\n\tinitiator VARCHAR(32) NULL DEFAULT 'COD',\n\tmail_construct TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL,\n\tmail_sent ENUM('Y','N','ERROR') NULL DEFAULT 'N',\n\tmail_error TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL,\n\tnotes TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL,\n\tuser_data TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL,\t\t\n\tPRIMARY KEY (id),\n\tKEY hash (hash),\n\tKEY wp_user_id (wp_user_id),\n\tKEY orderdate_paymentstatus (order_date,payment_status),\n\tKEY payment_status (payment_status),\n\tKEY transaction_id (transaction_id),\n\tKEY ident (hash,payment_status,initiator),\n\tKEY history (wp_user_id,order_date,payment_status),\n\tKEY paymentstatus_userid (payment_status,wp_user_id),\n\tKEY mail_sent (mail_sent)\n) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; dbDelta($sql);
function wppizza_set_order_status() { $setStatus = wppizza_custom_order_status(); /**compare and see if we have to do anything**/ if ($this->pluginOptions != 0 && (!isset($this->pluginOptions['plugin_data']['db_order_status_options']) || $this->pluginOptions['plugin_data']['db_order_status_options'] != $setStatus)) { global $wpdb; $usedOrderStatus = $wpdb->get_col("SELECT DISTINCT(order_status) FROM " . $wpdb->prefix . $this->pluginOrderTable . " "); $newStatus = array(); foreach ($setStatus as $k => $v) { $newStatus[] = wppizza_validate_alpha_only(str_replace(" ", "_", strtoupper($v))); } /**implicitly add all options already in use**/ foreach ($usedOrderStatus as $k => $v) { $newStatus[] = wppizza_validate_alpha_only(str_replace(" ", "_", strtoupper($v))); } /**implicitly add NEW option (as its default)*****/ $newStatus[] = 'NEW'; /**update options**/ $update_options = $this->pluginOptions; $update_options['plugin_data']['db_order_status_options'] = $setStatus; update_option($this->pluginSlug, $update_options); /**ALTER TABLE**/ $setNewOrderStatus = array_unique($newStatus); require_once WPPIZZA_PATH . 'inc/admin.create.order.table.inc.php'; } }