shopping_cart.php

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

PHP
820
字号
            }            $this->_contents[$products_id_string] = array('id' => $products_id_string,                                                          'name' => $Qproduct->value('products_name'),                                                          'keyword' => $Qproduct->value('products_keyword'),                                                          'image' => $Qcheck->value('image'),                                                          'price' => $price,                                                          'final_price' => $price,                                                          'quantity' => $quantity,                                                          'weight' => $Qcheck->value('products_weight'),                                                          'tax_class_id' => $Qcheck->valueInt('products_tax_class_id'),                                                          'date_added' => osC_DateTime::getShort(osC_DateTime::getNow()),                                                          'weight_class_id' => $Qcheck->valueInt('products_weight_class'));// insert into database            if ($osC_Customer->isLoggedOn()) {              $Qnew = $osC_Database->query('insert into :table_customers_basket (customers_id, products_id, customers_basket_quantity, customers_basket_date_added) values (:customers_id, :products_id, :customers_basket_quantity, now())');              $Qnew->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);              $Qnew->bindInt(':customers_id', $osC_Customer->getID());              $Qnew->bindValue(':products_id', $products_id_string);              $Qnew->bindInt(':customers_basket_quantity', $quantity);              $Qnew->execute();            }            if (is_array($attributes) && !empty($attributes)) {              foreach ($attributes as $option => $value) {                $Qattributes = $osC_Database->query('select pa.options_values_price, pa.price_prefix, po.products_options_name, pov.products_options_values_name from :table_products_attributes pa, :table_products_options po, :table_products_options_values pov where pa.products_id = :products_id and pa.options_id = :options_id and pa.options_values_id = :options_values_id and pa.options_id = po.products_options_id and po.language_id = :language_id and pa.options_values_id = pov.products_options_values_id and pov.language_id = :language_id');                $Qattributes->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES);                $Qattributes->bindTable(':table_products_options', TABLE_PRODUCTS_OPTIONS);                $Qattributes->bindTable(':table_products_options_values', TABLE_PRODUCTS_OPTIONS_VALUES);                $Qattributes->bindValue(':products_id', $products_id);                $Qattributes->bindInt(':options_id', $option);                $Qattributes->bindInt(':options_values_id', $value);                $Qattributes->bindInt(':language_id', $osC_Language->getID());                $Qattributes->bindInt(':language_id', $osC_Language->getID());                $Qattributes->execute();                $this->_contents[$products_id_string]['attributes'][$option] = array('options_id' => $option,                                                                                     'options_values_id' => $value,                                                                                     'products_options_name' => $Qattributes->value('products_options_name'),                                                                                     'products_options_values_name' => $Qattributes->value('products_options_values_name'),                                                                                     'options_values_price' => $Qattributes->value('options_values_price'),                                                                                     'price_prefix' => $Qattributes->value('price_prefix'));                if ($Qattributes->value('price_prefix') == '+') {                  $this->_contents[$products_id_string]['final_price'] += $Qattributes->value('options_values_price');                } else {                  $this->_contents[$products_id_string]['final_price'] -= $Qattributes->value('options_values_price');                }              }            }          }          $this->_cleanUp();          $this->_calculate();        }      }    }    function numberOfItems() {      $total = 0;      if ($this->hasContents()) {        foreach (array_keys($this->_contents) as $products_id) {          $total += $this->getQuantity($products_id);        }      }      return $total;    }    function getQuantity($products_id) {      if (isset($this->_contents[$products_id])) {        return $this->_contents[$products_id]['quantity'];      }      return 0;    }    function exists($products_id) {      return isset($this->_contents[$products_id]);    }    function remove($products_id) {      global $osC_Database, $osC_Customer;      unset($this->_contents[$products_id]);// remove from database      if ($osC_Customer->isLoggedOn()) {        $Qdelete = $osC_Database->query('delete from :table_customers_basket where customers_id = :customers_id and products_id = :products_id');        $Qdelete->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);        $Qdelete->bindInt(':customers_id', $osC_Customer->getID());        $Qdelete->bindValue(':products_id', $products_id);        $Qdelete->execute();      }      $this->_calculate();    }    function getProducts() {      static $_is_sorted = false;      if ($_is_sorted === false) {        $_is_sorted = true;        uasort($this->_contents, array('osC_ShoppingCart', '_uasortProductsByDateAdded'));      }      return $this->_contents;    }    function getSubTotal() {      return $this->_sub_total;    }    function getTotal() {      return $this->_total;    }    function getWeight() {      return $this->_weight;    }    function generateCartID($length = 5) {      return osc_create_random_string($length, 'digits');    }    function getCartID() {      return $_SESSION['cartID'];    }    function getContentType() {      global $osC_Database;      $this->_content_type = 'physical';      if ( (DOWNLOAD_ENABLED == '1') && $this->hasContents() ) {        foreach ($this->_contents as $products_id => $data) {          if (isset($data['attributes'])) {            foreach ($data['attributes'] as $value) {              $Qcheck = $osC_Database->query('select count(*) as total from :table_products_attributes pa, :table_products_attributes_download pad where pa.products_id = :products_id and pa.options_values_id = :options_values_id and pa.products_attributes_id = pad.products_attributes_id');              $Qcheck->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES);              $Qcheck->bindTable(':table_products_attributes_download', TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD);              $Qcheck->bindInt(':products_id', $products_id);              $Qcheck->bindInt(':options_values_id', $value['options_values_id']);              $Qcheck->execute();              if ($Qcheck->valueInt('total') > 0) {                switch ($this->_content_type) {                  case 'physical':                    $this->_content_type = 'mixed';                    return $this->_content_type;                    break;                  default:                    $this->_content_type = 'virtual';                    break;                }              } else {                switch ($this->_content_type) {                  case 'virtual':                    $this->_content_type = 'mixed';                    return $this->_content_type;                    break;                  default:                    $this->_content_type = 'physical';                    break;                }              }            }          } else {            switch ($this->_content_type) {              case 'virtual':                $this->_content_type = 'mixed';                return $this->_content_type;                break;              default:                $this->_content_type = 'physical';                break;            }          }        }      }      return $this->_content_type;    }    function hasAttributes($products_id) {      return isset($this->_contents[$products_id]['attributes']) && !empty($this->_contents[$products_id]['attributes']);    }    function getAttributes($products_id) {      if (isset($this->_contents[$products_id]['attributes']) && !empty($this->_contents[$products_id]['attributes'])) {        return $this->_contents[$products_id]['attributes'];      }    }    function isInStock($products_id) {      global $osC_Database;      $Qstock = $osC_Database->query('select products_quantity from :table_products where products_id = :products_id');      $Qstock->bindTable(':table_products', TABLE_PRODUCTS);      $Qstock->bindInt(':products_id', osc_get_product_id($products_id));      $Qstock->execute();      if (($Qstock->valueInt('products_quantity') - $this->_contents[$products_id]['quantity']) > 0) {        return true;      } elseif ($this->_products_in_stock === true) {        $this->_products_in_stock = false;      }      return false;    }    function hasStock() {      return $this->_products_in_stock;    }    function hasShippingAddress() {      return isset($this->_shipping_address) && isset($this->_shipping_address['id']);    }    function setShippingAddress($address_id) {      global $osC_Database, $osC_Customer;      $previous_address = false;      if (isset($this->_shipping_address['id'])) {        $previous_address = $this->getShippingAddress();      }      $Qaddress = $osC_Database->query('select ab.entry_firstname, ab.entry_lastname, ab.entry_company, ab.entry_street_address, ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id, ab.entry_telephone, z.zone_code, z.zone_name, ab.entry_country_id, c.countries_name, c.countries_iso_code_2, c.countries_iso_code_3, c.address_format, ab.entry_state from :table_address_book ab left join :table_zones z on (ab.entry_zone_id = z.zone_id) left join :table_countries c on (ab.entry_country_id = c.countries_id) where ab.customers_id = :customers_id and ab.address_book_id = :address_book_id');      $Qaddress->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);      $Qaddress->bindTable(':table_zones', TABLE_ZONES);      $Qaddress->bindTable(':table_countries', TABLE_COUNTRIES);      $Qaddress->bindInt(':customers_id', $osC_Customer->getID());      $Qaddress->bindInt(':address_book_id', $address_id);      $Qaddress->execute();      $this->_shipping_address = array('id' => $address_id,                                       'firstname' => $Qaddress->valueProtected('entry_firstname'),                                       'lastname' => $Qaddress->valueProtected('entry_lastname'),                                       'company' => $Qaddress->valueProtected('entry_company'),                                       'street_address' => $Qaddress->valueProtected('entry_street_address'),                                       'suburb' => $Qaddress->valueProtected('entry_suburb'),                                       'city' => $Qaddress->valueProtected('entry_city'),                                       'postcode' => $Qaddress->valueProtected('entry_postcode'),                                       'state' => (!osc_empty($Qaddress->valueProtected('entry_state'))) ? $Qaddress->valueProtected('entry_state') : $Qaddress->valueProtected('zone_name'),                                       'zone_id' => $Qaddress->valueInt('entry_zone_id'),                                       'zone_code' => $Qaddress->value('zone_code'),                                       'country_id' => $Qaddress->valueInt('entry_country_id'),                                       'country_title' => $Qaddress->value('countries_name'),                                       'country_iso_code_2' => $Qaddress->value('countries_iso_code_2'),                                       'country_iso_code_3' => $Qaddress->value('countries_iso_code_3'),                                       'format' => $Qaddress->value('address_format'),                                       'telephone_number' => $Qaddress->value('entry_telephone'));      if ( is_array($previous_address) && ( ($previous_address['id'] != $this->_shipping_address['id']) || ($previous_address['country_id'] != $this->_shipping_address['country_id']) || ($previous_address['zone_id'] != $this->_shipping_address['zone_id']) || ($previous_address['state'] != $this->_shipping_address['state']) || ($previous_address['postcode'] != $this->_shipping_address['postcode']) ) ) {        $this->_calculate();      }    }    function getShippingAddress($key = '') {      if (empty($key)) {        return $this->_shipping_address;      }      return $this->_shipping_address[$key];    }    function resetShippingAddress() {

⌨️ 快捷键说明

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