array(), 'sub_total_cost' => 0, 'total_cost' => 0, 'total_weight' => 0, 'tax' => 0, 'tax_groups' => array(), 'shipping_boxes_weight' => 0, 'shipping_boxes' => 1, 'shipping_address' => array('zone_id' => STORE_ZONE, 'country_id' => STORE_COUNTRY), 'shipping_method' => array(), 'billing_address' => array('zone_id' => STORE_ZONE, 'country_id' => STORE_COUNTRY), 'billing_method' => array(), 'shipping_quotes' => array(), 'order_totals' => array()); $this->resetShippingAddress(); $this->resetBillingAddress(); } $this->_contents =& $_SESSION['osC_ShoppingCart_data']['contents']; $this->_sub_total =& $_SESSION['osC_ShoppingCart_data']['sub_total_cost']; $this->_total =& $_SESSION['osC_ShoppingCart_data']['total_cost']; $this->_weight =& $_SESSION['osC_ShoppingCart_data']['total_weight']; $this->_tax =& $_SESSION['osC_ShoppingCart_data']['tax']; $this->_tax_groups =& $_SESSION['osC_ShoppingCart_data']['tax_groups']; $this->_shipping_boxes_weight =& $_SESSION['osC_ShoppingCart_data']['shipping_boxes_weight']; $this->_shipping_boxes =& $_SESSION['osC_ShoppingCart_data']['shipping_boxes']; $this->_shipping_address =& $_SESSION['osC_ShoppingCart_data']['shipping_address']; $this->_shipping_method =& $_SESSION['osC_ShoppingCart_data']['shipping_method']; $this->_billing_address =& $_SESSION['osC_ShoppingCart_data']['billing_address']; $this->_billing_method =& $_SESSION['osC_ShoppingCart_data']['billing_method']; $this->_shipping_quotes =& $_SESSION['osC_ShoppingCart_data']['shipping_quotes']; $this->_order_totals =& $_SESSION['osC_ShoppingCart_data']['order_totals']; } public function update() { if ( !isset($_SESSION['cartID']) ) { $this->_calculate(); } } public function hasContents() { return !empty($this->_contents); } public function synchronizeWithDatabase() { global $osC_Database, $osC_Services, $osC_Language, $osC_Customer, $osC_Specials; if ( !$osC_Customer->isLoggedOn() ) { return false; } // insert current cart contents in database if ( $this->hasContents() ) { foreach ( $this->_contents as $product_id => $data ) { $Qproduct = $osC_Database->query('select products_id, customers_basket_quantity from :table_customers_basket where customers_id = :customers_id and products_id = :products_id'); $Qproduct->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET); $Qproduct->bindInt(':customers_id', $osC_Customer->getID()); $Qproduct->bindInt(':products_id', $product_id); $Qproduct->execute(); if ( $Qproduct->numberOfRows() > 0 ) { $Qupdate = $osC_Database->query('update :table_customers_basket set customers_basket_quantity = :customers_basket_quantity where customers_id = :customers_id and products_id = :products_id'); $Qupdate->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET); $Qupdate->bindInt(':customers_basket_quantity', $data['quantity'] + $Qproduct->valueInt('customers_basket_quantity')); $Qupdate->bindInt(':customers_id', $osC_Customer->getID()); $Qupdate->bindInt(':products_id', $product_id); $Qupdate->execute(); } else { $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', $product_id); $Qnew->bindInt(':customers_basket_quantity', $data['quantity']); $Qnew->execute(); } } } // reset per-session cart contents, but not the database contents $this->reset(); $_delete_array = array(); $Qproducts = $osC_Database->query('select cb.products_id, cb.customers_basket_quantity, cb.customers_basket_date_added, p.parent_id, p.products_price, p.products_tax_class_id, p.products_weight, p.products_weight_class, p.products_status from :table_customers_basket cb, :table_products p where cb.customers_id = :customers_id and cb.products_id = p.products_id order by cb.customers_basket_date_added desc'); $Qproducts->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET); $Qproducts->bindTable(':table_products', TABLE_PRODUCTS); $Qproducts->bindInt(':customers_id', $osC_Customer->getID()); $Qproducts->execute(); while ( $Qproducts->next() ) { if ( $Qproducts->valueInt('products_status') === 1 ) { $Qdesc = $osC_Database->query('select products_name, products_keyword from :table_products_description where products_id = :products_id and language_id = :language_id'); $Qdesc->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION); $Qdesc->bindInt(':products_id', ($Qproducts->valueInt('parent_id') > 0) ? $Qproducts->valueInt('parent_id') : $Qproducts->valueInt('products_id')); $Qdesc->bindInt(':language_id', $osC_Language->getID()); $Qdesc->execute(); $Qimage = $osC_Database->query('select image from :table_products_images where products_id = :products_id and i.default_flag = :default_flag'); $Qimage->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES); $Qimage->bindInt(':products_id', ($Qproducts->valueInt('parent_id') > 0) ? $Qproducts->valueInt('parent_id') : $Qproducts->valueInt('products_id')); $Qimage->bindInt(':default_flag', 1); $Qimage->execute(); $price = $Qproducts->value('products_price'); if ( $osC_Services->isStarted('specials') ) { if ( $new_price = $osC_Specials->getPrice($Qproducts->valueInt('products_id')) ) { $price = $new_price; } } $this->_contents[$Qproducts->valueInt('products_id')] = array('id' => $Qproducts->valueInt('products_id'), 'parent_id' => $Qproducts->valueInt('parent_id'), 'name' => $Qdesc->value('products_name'), 'keyword' => $Qdesc->value('products_keyword'), 'image' => ($Qimage->numberOfRows() === 1) ? $Qimage->value('image') : '', 'price' => $price, 'quantity' => $Qproducts->valueInt('customers_basket_quantity'), 'weight' => $Qproducts->value('products_weight'), 'tax_class_id' => $Qproducts->valueInt('products_tax_class_id'), 'date_added' => osC_DateTime::getShort($Qproducts->value('customers_basket_date_added')), 'weight_class_id' => $Qproducts->valueInt('products_weight_class')); if ( $Qproducts->valueInt('parent_id') > 0 ) { $Qcheck = $osC_Database->query('select products_status from :table_products where products_id = :products_id'); $Qcheck->bindTable(':table_products', TABLE_PRODUCTS); $Qcheck->bindInt(':products_id', $Qproducts->valueInt('parent_id')); $Qcheck->execute(); if ( $Qcheck->valueInt('products_status') === 1 ) { $Qvariant = $osC_Database->query('select pvg.id as group_id, pvg.title as group_title, pvv.id as value_id, pvv.title as value_title from :table_products_variants pv, :table_products_variants_values pvv, :table_products_variants_groups pvg where pv.products_id = :products_id and pv.variants_values_id = pvv.id and pvv.languages_id = :languages_id and pvv.products_variants_groups_id = pvg.id and pvg.languages_id = :languages_id'); $Qvariant->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS); $Qvariant->bindTable(':table_products_variants_values', TABLE_PRODUCTS_VARIANTS_VALUES); $Qvariant->bindTable(':table_products_variants_groups', TABLE_PRODUCTS_VARIANTS_GROUPS); $Qvariant->bindInt(':products_id', $Qproducts->valueInt('products_id')); $Qvariant->bindInt(':languages_id', $osC_Language->getID()); $Qvariant->bindInt(':languages_id', $osC_Language->getID()); $Qvariant->execute(); if ( $Qproducts->numberOfRows() > 0 ) { while ( $Qvariant->next() ) { $this->_contents[$Qproducts->valueInt('products_id')]['variants'][$Qvariant->valueInt('group_id')] = array('group_id' => $Qvariant->valueInt('group_id'), 'value_id' => $Qvariant->valueInt('value_id'), 'group_title' => $Qvariant->value('group_title'), 'value_title' => $Qvariant->value('value_title')); } } else { $_delete_array[] = $Qproducts->valueInt('products_id'); } } else { $_delete_array[] = $Qproducts->valueInt('products_id'); } } } else { $_delete_array[] = $Qproducts->valueInt('products_id'); } } if ( !empty($_delete_array) ) { foreach ( $_delete_array as $product_id ) { unset($this->_contents[$product_id]); } $Qdelete = $osC_Database->query('delete from :table_customers_basket where customers_id = :customers_id and products_id in (":products_id")'); $Qdelete->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET); $Qdelete->bindInt(':customers_id', $osC_Customer->getID()); $Qdelete->bindRaw(':products_id', implode('", "', $_delete_array)); $Qdelete->execute(); } $this->_cleanUp(); $this->_calculate(); } public function reset($reset_database = false) { global $osC_Database, $osC_Customer; if ( ($reset_database === true) && $osC_Customer->isLoggedOn() ) { $Qdelete = $osC_Database->query('delete from :table_customers_basket where customers_id = :customers_id'); $Qdelete->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET); $Qdelete->bindInt(':customers_id', $osC_Customer->getID()); $Qdelete->execute(); } $this->_contents = array(); $this->_sub_total = 0; $this->_total = 0; $this->_weight = 0; $this->_tax = 0; $this->_tax_groups = array(); $this->_content_type = null; $this->resetShippingAddress(); $this->resetShippingMethod(); $this->resetBillingAddress(); $this->resetBillingMethod(); if ( isset($_SESSION['cartID']) ) { unset($_SESSION['cartID']); } } public function add($product_id, $quantity = null) { global $osC_Database, $osC_Services, $osC_Language, $osC_Customer; if ( is_numeric($product_id) ) { $Qproduct = $osC_Database->query('select p.parent_id, p.products_price, p.products_tax_class_id, p.products_weight, p.products_weight_class, p.products_status, i.image from :table_products p left join :table_products_images i on (p.products_id = i.products_id and i.default_flag = :default_flag) where p.products_id = :products_id'); $Qproduct->bindTable(':table_products', TABLE_PRODUCTS); $Qproduct->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES); $Qproduct->bindInt(':default_flag', 1); $Qproduct->bindInt(':products_id', $product_id); $Qproduct->execute(); if ( $Qproduct->valueInt('products_status') === 1 ) { if ( $this->exists($product_id) ) { if ( !is_numeric($quantity) ) { $quantity = $this->getQuantity($product_id) + 1; } $this->_contents[$product_id]['quantity'] = $quantity; if ( $osC_Customer->isLoggedOn() ) { $Qupdate = $osC_Database->query('update :table_customers_basket set customers_basket_quantity = :customers_basket_quantity where customers_id = :customers_id and products_id = :products_id'); $Qupdate->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET); $Qupdate->bindInt(':customers_basket_quantity', $quantity); $Qupdate->bindInt(':customers_id', $osC_Customer->getID()); $Qupdate->bindInt(':products_id', $product_id); $Qupdate->execute(); } } else { if ( !is_numeric($quantity) ) { $quantity = 1; } $Qdescription = $osC_Database->query('select products_name, products_keyword from :table_products_description where products_id = :products_id and language_id = :language_id'); $Qdescription->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION); $Qdescription->bindInt(':products_id', ($Qproduct->valueInt('parent_id') > 0) ? $Qproduct->valueInt('parent_id') : $product_id); $Qdescription->bindInt(':language_id', $osC_Language->getID()); $Qdescription->execute(); $price = $Qproduct->value('products_price'); if ( $osC_Services->isStarted('specials') ) { global $osC_Specials; if ( $new_price = $osC_Specials->getPrice($product_id) ) { $price = $new_price; } } $this->_contents[$product_id] = array('id' => $product_id, 'parent_id' => $Qproduct->valueInt('parent_id'), 'name' => $Qdescription->value('products_name'), 'keyword' => $Qdescription->value('products_keyword'), 'image' => $Qproduct->value('image'), 'price' => $price, 'quantity' => $quantity, 'weight' => $Qproduct->value('products_weight'), 'tax_class_id' => $Qproduct->valueInt('products_tax_class_id'), 'date_added' => osC_DateTime::getShort(osC_DateTime::getNow()), 'weight_class_id' => $Qproduct->valueInt('products_weight_class')); 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->bindInt(':products_id', $product_id); $Qnew->bindInt(':customers_basket_quantity', $quantity); $Qnew->execute(); } if ( $Qproduct->valueInt('parent_id') > 0 ) { $Qvariant = $osC_Database->query('select pvg.id as group_id, pvg.title as group_title, pvv.id as value_id, pvv.title as value_title from :table_products_variants pv, :table_products_variants_values pvv, :table_products_variants_groups pvg where pv.products_id = :products_id and pv.variants_values_id = pvv.id and pvv.languages_id = :languages_id and pvv.products_variants_groups_id = pvg.id and pvg.languages_id = :languages_id'); $Qvariant->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS); $Qvariant->bindTable(':table_products_variants_values', TABLE_PRODUCTS_VARIANTS_VALUES); $Qvariant->bindTable(':table_products_variants_groups', TABLE_PRODUCTS_VARIANTS_GROUPS); $Qvariant->bindInt(':products_id', $product_id); $Qvariant->bindInt(':languages_id', $osC_Language->getID()); $Qvariant->bindInt(':languages_id', $osC_Language->getID()); $Qvariant->execute(); while ( $Qvariant->next() ) { $this->_contents[$product_id]['variants'][$Qvariant->valueInt('group_id')] = array('group_id' => $Qvariant->valueInt('group_id'), 'value_id' => $Qvariant->valueInt('value_id'), 'group_title' => $Qvariant->value('group_title'), 'value_title' => $Qvariant->value('value_title')); } } } $this->_cleanUp(); $this->_calculate(); } } } public function numberOfItems() { $total = 0; if ( $this->hasContents() ) { foreach ( $this->_contents as $product ) { $total += $this->getQuantity($product['id']); } } return $total; } public function getQuantity($product_id) { return ( isset($this->_contents[$product_id]) ) ? $this->_contents[$product_id]['quantity'] : 0; } public function exists($product_id) { return isset($this->_contents[$product_id]); } public function remove($product_id) { global $osC_Database, $osC_Customer; unset($this->_contents[$product_id]); 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->bindInt(':products_id', $product_id); $Qdelete->execute(); } $this->_calculate(); } public function getProducts() { static $_is_sorted = false; if ( $_is_sorted === false ) { $_is_sorted = true; uasort($this->_contents, array('osC_ShoppingCart', '_uasortProductsByDateAdded')); } return $this->_contents; } public function getSubTotal() { return $this->_sub_total; } public function getTotal() { return $this->_total; } public function getWeight() { return $this->_weight; } public function generateCartID($length = 5) { return osc_create_random_string($length, 'digits'); } public function getCartID() { return $_SESSION['cartID']; } public function getContentType() { global $osC_Database; $this->_content_type = 'physical'; if ( (DOWNLOAD_ENABLED == '1') && $this->hasContents() ) { foreach ( $this->_contents as $product_id => $data ) { /* HPDL 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'; break 2; default: $this->_content_type = 'physical'; break; } // } } } return $this->_content_type; } public function isVariant($id) { return isset($this->_contents[$id]['variants']) && !empty($this->_contents[$id]['variants']); } public function getVariant($id) { if ( isset($this->_contents[$id]['variants']) && !empty($this->_contents[$id]['variants']) ) { return $this->_contents[$id]['variants']; } } public function isInStock($product_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', $product_id); $Qstock->execute(); if ( ($Qstock->valueInt('products_quantity') - $this->_contents[$product_id]['quantity']) > 0 ) { return true; } elseif ( $this->_products_in_stock === true ) { $this->_products_in_stock = false; } return false; } public function hasStock() { return $this->_products_in_stock; } public function hasShippingAddress() { return isset($this->_shipping_address['id']); } public function setShippingAddress($address_id) { global $osC_Database, $osC_Customer; $previous_address = null; 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(); if ( $Qaddress->numberOfRows() === 1 ) { $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(); } } } public function getShippingAddress($key = null) { if ( empty($key) ) { return $this->_shipping_address; } return $this->_shipping_address[$key]; } public function resetShippingAddress() { global $osC_Customer; $this->_shipping_address = array('zone_id' => STORE_ZONE, 'country_id' => STORE_COUNTRY); if ( $osC_Customer->isLoggedOn() && $osC_Customer->hasDefaultAddress() ) { $this->setShippingAddress($osC_Customer->getDefaultAddressID()); } } public function setShippingMethod($shipping_array, $calculate_total = true) { $this->_shipping_method = $shipping_array; if ( $calculate_total === true ) { $this->_calculate(false); } } public function getShippingMethod($key = null) { if ( empty($key) ) { return $this->_shipping_method; } return $this->_shipping_method[$key]; } public function resetShippingMethod() { $this->_shipping_method = array(); $this->_calculate(); } public function hasShippingMethod() { return !empty($this->_shipping_method); } public function hasBillingAddress() { return isset($this->_billing_address['id']); } public function setBillingAddress($address_id) { global $osC_Database, $osC_Customer; $previous_address = false; if ( isset($this->_billing_address['id']) ) { $previous_address = $this->getBillingAddress(); } $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(); if ( $Qaddress->numberOfRows() === 1 ) { $this->_billing_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->_billing_address['id']) || ($previous_address['country_id'] != $this->_billing_address['country_id']) || ($previous_address['zone_id'] != $this->_billing_address['zone_id']) || ($previous_address['state'] != $this->_billing_address['state']) || ($previous_address['postcode'] != $this->_billing_address['postcode']) ) ) { $this->_calculate(); } } } public function getBillingAddress($key = null) { if ( empty($key) ) { return $this->_billing_address; } return $this->_billing_address[$key]; } public function resetBillingAddress() { global $osC_Customer; $this->_billing_address = array('zone_id' => STORE_ZONE, 'country_id' => STORE_COUNTRY); if ( $osC_Customer->isLoggedOn() && $osC_Customer->hasDefaultAddress() ) { $this->setBillingAddress($osC_Customer->getDefaultAddressID()); } } public function setBillingMethod($billing_array) { $this->_billing_method = $billing_array; $this->_calculate(); } public function getBillingMethod($key = null) { if ( empty($key) ) { return $this->_billing_method; } return $this->_billing_method[$key]; } public function resetBillingMethod() { $this->_billing_method = array(); $this->_calculate(); } public function hasBillingMethod() { return !empty($this->_billing_method); } public function getTaxingAddress($id = null) { if ( $this->getContentType() == 'virtual' ) { return $this->getBillingAddress($id); } return $this->getShippingAddress($id); } public function addTaxAmount($amount) { $this->_tax += $amount; } public function numberOfTaxGroups() { return sizeof($this->_tax_groups); } public function addTaxGroup($group, $amount) { if ( isset($this->_tax_groups[$group]) ) { $this->_tax_groups[$group] += $amount; } else { $this->_tax_groups[$group] = $amount; } } public function getTaxGroups() { return $this->_tax_groups; } public function addToTotal($amount) { $this->_total += $amount; } public function getOrderTotals() { return $this->_order_totals; } public function getShippingBoxesWeight() { return $this->_shipping_boxes_weight; } public function numberOfShippingBoxes() { return $this->_shipping_boxes; } private function _cleanUp() { global $osC_Database, $osC_Customer; foreach ( $this->_contents as $product_id => $data ) { if ( $data['quantity'] < 1 ) { unset($this->_contents[$product_id]); 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', $product_id); $Qdelete->execute(); } } } } private function _calculate($set_shipping = true) { global $osC_Currencies, $osC_Tax, $osC_Weight, $osC_Shipping, $osC_OrderTotal; $this->_sub_total = 0; $this->_total = 0; $this->_weight = 0; $this->_tax = 0; $this->_tax_groups = array(); $this->_shipping_boxes_weight = 0; $this->_shipping_boxes = 0; $this->_shipping_quotes = array(); $this->_order_totals = array(); $_SESSION['cartID'] = $this->generateCartID(); if ( $this->hasContents() ) { foreach ( $this->_contents as $data ) { $products_weight = $osC_Weight->convert($data['weight'], $data['weight_class_id'], SHIPPING_WEIGHT_UNIT); $this->_weight += $products_weight * $data['quantity']; $tax = $osC_Tax->getTaxRate($data['tax_class_id'], $this->getTaxingAddress('country_id'), $this->getTaxingAddress('zone_id')); $tax_description = $osC_Tax->getTaxRateDescription($data['tax_class_id'], $this->getTaxingAddress('country_id'), $this->getTaxingAddress('zone_id')); $shown_price = $osC_Currencies->addTaxRateToPrice($data['price'], $tax, $data['quantity']); $this->_sub_total += $shown_price; $this->_total += $shown_price; if ( DISPLAY_PRICE_WITH_TAX == '1' ) { $tax_amount = $shown_price - ($shown_price / (($tax < 10) ? '1.0' . str_replace('.', '', $tax) : '1.' . str_replace('.', '', $tax))); } else { $tax_amount = ($tax / 100) * $shown_price; $this->_total += $tax_amount; } $this->_tax += $tax_amount; if ( isset($this->_tax_groups[$tax_description]) ) { $this->_tax_groups[$tax_description] += $tax_amount; } else { $this->_tax_groups[$tax_description] = $tax_amount; } } $this->_shipping_boxes_weight = $this->_weight; $this->_shipping_boxes = 1; if ( SHIPPING_BOX_WEIGHT >= ($this->_shipping_boxes_weight * SHIPPING_BOX_PADDING/100) ) { $this->_shipping_boxes_weight = $this->_shipping_boxes_weight + SHIPPING_BOX_WEIGHT; } else { $this->_shipping_boxes_weight = $this->_shipping_boxes_weight + ($this->_shipping_boxes_weight * SHIPPING_BOX_PADDING/100); } if ( $this->_shipping_boxes_weight > SHIPPING_MAX_WEIGHT ) { // Split into many boxes $this->_shipping_boxes = ceil($this->_shipping_boxes_weight / SHIPPING_MAX_WEIGHT); $this->_shipping_boxes_weight = $this->_shipping_boxes_weight / $this->_shipping_boxes; } if ( $set_shipping === true ) { if ( !class_exists('osC_Shipping') ) { include('includes/classes/shipping.php'); } if ( !$this->hasShippingMethod() || ($this->getShippingMethod('is_cheapest') === true) ) { $osC_Shipping = new osC_Shipping(); $this->setShippingMethod($osC_Shipping->getCheapestQuote(), false); } else { $osC_Shipping = new osC_Shipping($this->getShippingMethod('id')); $this->setShippingMethod($osC_Shipping->getQuote(), false); } } if ( !class_exists('osC_OrderTotal') ) { include('includes/classes/order_total.php'); } $osC_OrderTotal = new osC_OrderTotal(); $this->_order_totals = $osC_OrderTotal->getResult(); } } static private function _uasortProductsByDateAdded($a, $b) { if ($a['date_added'] == $b['date_added']) { return strnatcasecmp($a['name'], $b['name']); } return ($a['date_added'] > $b['date_added']) ? -1 : 1; } } ?>