order.php

来自「this the oscommerce 3.0 aplha 4」· PHP 代码 · 共 725 行 · 第 1/3 页

PHP
725
字号
<?php/*  $Id: order.php 1498 2007-03-29 14:04:50Z hpdl $  osCommerce, Open Source E-Commerce Solutions  http://www.oscommerce.com  Copyright (c) 2006 osCommerce  This program is free software; you can redistribute it and/or modify  it under the terms of the GNU General Public License v2 (1991)  as published by the Free Software Foundation.*/  class osC_Order {    var $info, $totals, $products, $customer, $delivery, $content_type;/* Private variables */    var $_id;/* Class constructor */    function osC_Order($order_id = '') {      if (is_numeric($order_id)) {        $this->_id = $order_id;      }      $this->info = array();      $this->totals = array();      $this->products = array();      $this->customer = array();      $this->delivery = array();      if (!empty($order_id)) {        $this->query($order_id);      } else {        $this->cart();      }    }/* Public methods */    function getStatusID($id) {      global $osC_Database;      $Qorder = $osC_Database->query('select orders_status from :table_orders where orders_id = :orders_id');      $Qorder->bindTable(':table_orders', TABLE_ORDERS);      $Qorder->bindInt(':orders_id', $id);      $Qorder->execute();      if ($Qorder->numberOfRows()) {        return $Qorder->valueInt('orders_status');      }      return false;    }    function remove($id) {      global $osC_Database;      $Qcheck = $osC_Database->query('select orders_status from :table_orders where orders_id = :orders_id');      $Qcheck->bindTable(':table_orders', TABLE_ORDERS);      $Qcheck->bindInt(':orders_id', $id);      $Qcheck->execute();      if ($Qcheck->valueInt('orders_status') === 4) {        $Qdel = $osC_Database->query('delete from :table_orders_products_download where orders_id = :orders_id');        $Qdel->bindTable(':table_orders_products_download', TABLE_ORDERS_PRODUCTS_DOWNLOAD);        $Qdel->bindInt(':orders_id', $id);        $Qdel->execute();        $Qdel = $osC_Database->query('delete from :table_orders_products_attributes where orders_id = :orders_id');        $Qdel->bindTable(':table_orders_products_attributes', TABLE_ORDERS_PRODUCTS_ATTRIBUTES);        $Qdel->bindInt(':orders_id', $id);        $Qdel->execute();        $Qdel = $osC_Database->query('delete from :table_orders_products where orders_id = :orders_id');        $Qdel->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);        $Qdel->bindInt(':orders_id', $id);        $Qdel->execute();        $Qdel = $osC_Database->query('delete from :table_orders_status_history where orders_id = :orders_id');        $Qdel->bindTable(':table_orders_status_history', TABLE_ORDERS_STATUS_HISTORY);        $Qdel->bindInt(':orders_id', $id);        $Qdel->execute();        $Qdel = $osC_Database->query('delete from :table_orders_total where orders_id = :orders_id');        $Qdel->bindTable(':table_orders_total', TABLE_ORDERS_TOTAL);        $Qdel->bindInt(':orders_id', $id);        $Qdel->execute();        $Qdel = $osC_Database->query('delete from :table_orders where orders_id = :orders_id');        $Qdel->bindTable(':table_orders', TABLE_ORDERS);        $Qdel->bindInt(':orders_id', $id);        $Qdel->execute();      }      if (isset($_SESSION['prepOrderID'])) {        unset($_SESSION['prepOrderID']);      }    }    function insert() {      global $osC_Database, $osC_Customer, $osC_Language, $osC_Currencies, $osC_ShoppingCart;      if (isset($_SESSION['prepOrderID'])) {        $_prep = explode('-', $_SESSION['prepOrderID']);        if ($_prep[0] == $osC_ShoppingCart->getCartID()) {          return $_prep[1]; // order_id        } else {          if (osC_Order::getStatusID($_prep[1]) === 4) {            osC_Order::remove($_prep[1]);          }        }      }      $Qorder = $osC_Database->query('insert into :table_orders (customers_id, customers_name, customers_company, customers_street_address, customers_suburb, customers_city, customers_postcode, customers_state, customers_state_code, customers_country, customers_country_iso2, customers_country_iso3, customers_telephone, customers_email_address, customers_address_format, customers_ip_address, delivery_name, delivery_company, delivery_street_address, delivery_suburb, delivery_city, delivery_postcode, delivery_state, delivery_state_code, delivery_country, delivery_country_iso2, delivery_country_iso3, delivery_address_format, billing_name, billing_company, billing_street_address, billing_suburb, billing_city, billing_postcode, billing_state, billing_state_code, billing_country, billing_country_iso2, billing_country_iso3, billing_address_format, payment_method, payment_module, date_purchased, orders_status, currency, currency_value) values (:customers_id, :customers_name, :customers_company, :customers_street_address, :customers_suburb, :customers_city, :customers_postcode, :customers_state, :customers_state_code, :customers_country, :customers_country_iso2, :customers_country_iso3, :customers_telephone, :customers_email_address, :customers_address_format, :customers_ip_address, :delivery_name, :delivery_company, :delivery_street_address, :delivery_suburb, :delivery_city, :delivery_postcode, :delivery_state, :delivery_state_code, :delivery_country, :delivery_country_iso2, :delivery_country_iso3, :delivery_address_format, :billing_name, :billing_company, :billing_street_address, :billing_suburb, :billing_city, :billing_postcode, :billing_state, :billing_state_code, :billing_country, :billing_country_iso2, :billing_country_iso3, :billing_address_format, :payment_method, :payment_module, now(), :orders_status, :currency, :currency_value)');      $Qorder->bindTable(':table_orders', TABLE_ORDERS);      $Qorder->bindInt(':customers_id', $osC_Customer->getID());      $Qorder->bindValue(':customers_name', $osC_Customer->getName());      $Qorder->bindValue(':customers_company', '' /*$order->customer['company']*/);      $Qorder->bindValue(':customers_street_address', '' /*$order->customer['street_address']*/);      $Qorder->bindValue(':customers_suburb', '' /*$order->customer['suburb']*/);      $Qorder->bindValue(':customers_city', '' /*$order->customer['city']*/);      $Qorder->bindValue(':customers_postcode', '' /*$order->customer['postcode']*/);      $Qorder->bindValue(':customers_state', '' /*$order->customer['state']*/);      $Qorder->bindValue(':customers_state_code', '');      $Qorder->bindValue(':customers_country', '' /*$order->customer['country']['title']*/);      $Qorder->bindValue(':customers_country_iso2', '');      $Qorder->bindValue(':customers_country_iso3', '');      $Qorder->bindValue(':customers_telephone', '' /*$order->customer['telephone']*/);      $Qorder->bindValue(':customers_email_address', $osC_Customer->getEmailAddress());      $Qorder->bindValue(':customers_address_format', '');      $Qorder->bindValue(':customers_ip_address', osc_get_ip_address());      $Qorder->bindValue(':delivery_name', $osC_ShoppingCart->getShippingAddress('firstname') . ' ' . $osC_ShoppingCart->getShippingAddress('lastname'));      $Qorder->bindValue(':delivery_company', $osC_ShoppingCart->getShippingAddress('company'));      $Qorder->bindValue(':delivery_street_address', $osC_ShoppingCart->getShippingAddress('street_address'));      $Qorder->bindValue(':delivery_suburb', $osC_ShoppingCart->getShippingAddress('suburb'));      $Qorder->bindValue(':delivery_city', $osC_ShoppingCart->getShippingAddress('city'));      $Qorder->bindValue(':delivery_postcode', $osC_ShoppingCart->getShippingAddress('postcode'));      $Qorder->bindValue(':delivery_state', $osC_ShoppingCart->getShippingAddress('state'));      $Qorder->bindValue(':delivery_state_code', $osC_ShoppingCart->getShippingAddress('zone_code'));      $Qorder->bindValue(':delivery_country', $osC_ShoppingCart->getShippingAddress('country_title'));      $Qorder->bindValue(':delivery_country_iso2', $osC_ShoppingCart->getShippingAddress('country_iso_code_2'));      $Qorder->bindValue(':delivery_country_iso3', $osC_ShoppingCart->getShippingAddress('country_iso_code_3'));      $Qorder->bindValue(':delivery_address_format', $osC_ShoppingCart->getShippingAddress('format'));      $Qorder->bindValue(':billing_name', $osC_ShoppingCart->getBillingAddress('firstname') . ' ' . $osC_ShoppingCart->getBillingAddress('lastname'));      $Qorder->bindValue(':billing_company', $osC_ShoppingCart->getBillingAddress('company'));      $Qorder->bindValue(':billing_street_address', $osC_ShoppingCart->getBillingAddress('street_address'));      $Qorder->bindValue(':billing_suburb', $osC_ShoppingCart->getBillingAddress('suburb'));      $Qorder->bindValue(':billing_city', $osC_ShoppingCart->getBillingAddress('city'));      $Qorder->bindValue(':billing_postcode', $osC_ShoppingCart->getBillingAddress('postcode'));      $Qorder->bindValue(':billing_state', $osC_ShoppingCart->getBillingAddress('state'));      $Qorder->bindValue(':billing_state_code', $osC_ShoppingCart->getBillingAddress('zone_code'));      $Qorder->bindValue(':billing_country', $osC_ShoppingCart->getBillingAddress('country_title'));      $Qorder->bindValue(':billing_country_iso2', $osC_ShoppingCart->getBillingAddress('country_iso_code_2'));      $Qorder->bindValue(':billing_country_iso3', $osC_ShoppingCart->getBillingAddress('country_iso_code_3'));      $Qorder->bindValue(':billing_address_format', $osC_ShoppingCart->getBillingAddress('format'));      $Qorder->bindValue(':payment_method', $osC_ShoppingCart->getBillingMethod('title'));      $Qorder->bindValue(':payment_module', $GLOBALS['osC_Payment_' . $osC_ShoppingCart->getBillingMethod('id')]->getCode());      $Qorder->bindInt(':orders_status', 4);      $Qorder->bindValue(':currency', $osC_Currencies->getCode());      $Qorder->bindValue(':currency_value', $osC_Currencies->value($osC_Currencies->getCode()));      $Qorder->execute();      $insert_id = $osC_Database->nextID();      foreach ($osC_ShoppingCart->getOrderTotals() as $module) {        $Qtotals = $osC_Database->query('insert into :table_orders_total (orders_id, title, text, value, class, sort_order) values (:orders_id, :title, :text, :value, :class, :sort_order)');        $Qtotals->bindTable(':table_orders_total', TABLE_ORDERS_TOTAL);        $Qtotals->bindInt(':orders_id', $insert_id);        $Qtotals->bindValue(':title', $module['title']);        $Qtotals->bindValue(':text', $module['text']);        $Qtotals->bindValue(':value', $module['value']);        $Qtotals->bindValue(':class', $module['code']);        $Qtotals->bindInt(':sort_order', $module['sort_order']);        $Qtotals->execute();      }      $Qstatus = $osC_Database->query('insert into :table_orders_status_history (orders_id, orders_status_id, date_added, customer_notified, comments) values (:orders_id, :orders_status_id, now(), :customer_notified, :comments)');      $Qstatus->bindTable(':table_orders_status_history', TABLE_ORDERS_STATUS_HISTORY);      $Qstatus->bindInt(':orders_id', $insert_id);      $Qstatus->bindInt(':orders_status_id', 4);      $Qstatus->bindInt(':customer_notified', '0');      $Qstatus->bindValue(':comments', (isset($_SESSION['comments']) ? $_SESSION['comments'] : ''));      $Qstatus->execute();      foreach ($osC_ShoppingCart->getProducts() as $products) {        $Qproducts = $osC_Database->query('insert into :table_orders_products (orders_id, products_id, products_model, products_name, products_price, final_price, products_tax, products_quantity) values (:orders_id, :products_id, :products_model, :products_name, :products_price, :final_price, :products_tax, :products_quantity)');        $Qproducts->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);        $Qproducts->bindInt(':orders_id', $insert_id);        $Qproducts->bindInt(':products_id', osc_get_product_id($products['id']));        $Qproducts->bindValue(':products_model', '' /*$products['model']*/);        $Qproducts->bindValue(':products_name', $products['name']);        $Qproducts->bindValue(':products_price', $products['price']);        $Qproducts->bindValue(':final_price', $products['final_price']);        $Qproducts->bindValue(':products_tax', '' /*$products['tax']*/);        $Qproducts->bindInt(':products_quantity', $products['quantity']);        $Qproducts->execute();        $order_products_id = $osC_Database->nextID();        if ($osC_ShoppingCart->hasAttributes($products['id'])) {          foreach ($osC_ShoppingCart->getAttributes($products['id']) as $attributes) {            if (DOWNLOAD_ENABLED == '1') {              $Qattributes = $osC_Database->query('select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix, pad.products_attributes_maxdays, pad.products_attributes_maxcount, pad.products_attributes_filename from :table_products_options popt, :table_products_options_values poval, :table_products_attributes pa left join :table_products_attributes_download pad on (pa.products_attributes_id = pad.products_attributes_id) where pa.products_id = :products_id and pa.options_id = :options_id and pa.options_id = popt.products_options_id and pa.options_values_id = :options_values_id and pa.options_values_id = poval.products_options_values_id and popt.language_id = :popt_language_id and poval.language_id = :poval_language_id');              $Qattributes->bindTable(':table_products_options', TABLE_PRODUCTS_OPTIONS);              $Qattributes->bindTable(':table_products_options_values', TABLE_PRODUCTS_OPTIONS_VALUES);              $Qattributes->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES);              $Qattributes->bindTable(':table_products_attributes_download', TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD);              $Qattributes->bindInt(':products_id', $products['id']);              $Qattributes->bindInt(':options_id', $attributes['options_id']);              $Qattributes->bindInt(':options_values_id', $attributes['options_values_id']);              $Qattributes->bindInt(':popt_language_id', $osC_Language->getID());              $Qattributes->bindInt(':poval_language_id', $osC_Language->getID());            } else {              $Qattributes = $osC_Database->query('select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix from :table_products_options popt, :table_products_options_values poval, :table_products_attributes pa where pa.products_id = :products_id and pa.options_id = :options_id and pa.options_id = popt.products_options_id and pa.options_values_id = :options_values_id and pa.options_values_id = poval.products_options_values_id and popt.language_id = :popt_language_id and poval.language_id = :poval_language_id');              $Qattributes->bindTable(':table_products_options', TABLE_PRODUCTS_OPTIONS);              $Qattributes->bindTable(':table_products_options_values', TABLE_PRODUCTS_OPTIONS_VALUES);              $Qattributes->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES);              $Qattributes->bindInt(':products_id', $products['id']);              $Qattributes->bindInt(':options_id', $attributes['options_id']);              $Qattributes->bindInt(':options_values_id', $attributes['options_values_id']);              $Qattributes->bindInt(':popt_language_id', $osC_Language->getID());              $Qattributes->bindInt(':poval_language_id', $osC_Language->getID());            }            $Qattributes->execute();            $Qopa = $osC_Database->query('insert into :table_orders_products_attributes (orders_id, orders_products_id, products_options, products_options_values, options_values_price, price_prefix) values (:orders_id, :orders_products_id, :products_options, :products_options_values, :options_values_price, :price_prefix)');            $Qopa->bindTable(':table_orders_products_attributes', TABLE_ORDERS_PRODUCTS_ATTRIBUTES);            $Qopa->bindInt(':orders_id', $insert_id);            $Qopa->bindInt(':orders_products_id', $order_products_id);            $Qopa->bindValue(':products_options', $Qattributes->value('products_options_name'));            $Qopa->bindValue(':products_options_values', $Qattributes->value('products_options_values_name'));            $Qopa->bindValue(':options_values_price', $Qattributes->value('options_values_price'));            $Qopa->bindValue(':price_prefix', $Qattributes->value('price_prefix'));            $Qopa->execute();            if ((DOWNLOAD_ENABLED == '1') && (strlen($Qattributes->value('products_attributes_filename')) > 0)) {              $Qopd = $osC_Database->query('insert into :table_orders_products_download (orders_id, orders_products_id, orders_products_filename, download_maxdays, download_count) values (:orders_id, :orders_products_id, :orders_products_filename, :download_maxdays, :download_count)');

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?