  |
1 | 1 | | <?php |
| |
2 | 2 | | /* |
  |
3 | | - | $Id: shopping_cart.php 830 2006-08-29 12:44:39Z hpdl $ |
| |
| 3 | + | $Id: shopping_cart.php 1420 2007-03-08 00:21:12Z hpdl $ |
|
4 | 4 | | |
| |
5 | 5 | | osCommerce, Open Source E-Commerce Solutions |
| |
6 | 6 | | http://www.oscommerce.com |
| |
7 | 7 | | |
  |
8 | | - | Copyright (c) 2006 osCommerce |
| |
| 8 | + | Copyright (c) 2007 osCommerce |
|
9 | 9 | | |
| |
10 | 10 | | Released under the GNU General Public License |
| |
11 | 11 | | */ |
| |
|
|
 |
… |
|
17 | 17 | | $_weight = 0, |
| |
18 | 18 | | $_tax = 0, |
| |
19 | 19 | | $_tax_groups = array(), |
  |
20 | | - | $_cartID, |
|
21 | 20 | | $_content_type, |
| |
22 | 21 | | $_products_in_stock = true; |
| |
23 | 22 | | |
| |
|
|
 |
… |
|
31 | 30 | | 'tax_groups' => array(), |
| |
32 | 31 | | 'shipping_boxes_weight' => 0, |
| |
33 | 32 | | 'shipping_boxes' => 1, |
  |
34 | | - | 'cart_id' => $this->generateCartID(), |
|
35 | 33 | | 'shipping_address' => array('zone_id' => STORE_ZONE, 'country_id' => STORE_COUNTRY), |
| |
36 | 34 | | 'shipping_method' => array(), |
| |
37 | 35 | | 'billing_address' => array('zone_id' => STORE_ZONE, 'country_id' => STORE_COUNTRY), |
| |
38 | 36 | | 'billing_method' => array(), |
  |
| 37 | + | 'shipping_quotes' => array(), |
|
39 | 38 | | 'order_totals' => array()); |
| |
40 | 39 | | |
| |
41 | 40 | | $this->resetShippingAddress(); |
| |
|
|
 |
… |
|
50 | 49 | | $this->_tax_groups =& $_SESSION['osC_ShoppingCart_data']['tax_groups']; |
| |
51 | 50 | | $this->_shipping_boxes_weight =& $_SESSION['osC_ShoppingCart_data']['shipping_boxes_weight']; |
| |
52 | 51 | | $this->_shipping_boxes =& $_SESSION['osC_ShoppingCart_data']['shipping_boxes']; |
  |
53 | | - | $this->_cartID =& $_SESSION['osC_ShoppingCart_data']['cart_id']; |
|
54 | 52 | | $this->_shipping_address =& $_SESSION['osC_ShoppingCart_data']['shipping_address']; |
| |
55 | 53 | | $this->_shipping_method =& $_SESSION['osC_ShoppingCart_data']['shipping_method']; |
| |
56 | 54 | | $this->_billing_address =& $_SESSION['osC_ShoppingCart_data']['billing_address']; |
| |
57 | 55 | | $this->_billing_method =& $_SESSION['osC_ShoppingCart_data']['billing_method']; |
  |
| 56 | + | $this->_shipping_quotes =& $_SESSION['osC_ShoppingCart_data']['shipping_quotes']; |
|
58 | 57 | | $this->_order_totals =& $_SESSION['osC_ShoppingCart_data']['order_totals']; |
| |
59 | 58 | | } |
| |
60 | 59 | | |
  |
| 60 | + | function update() { |
| |
| 61 | + | if ( !isset($_SESSION['cartID']) ) { |
| |
| 62 | + | $this->_calculate(); |
| |
| 63 | + | } |
| |
| 64 | + | } |
| |
| 65 | + | |
|
61 | 66 | | function hasContents() { |
| |
62 | 67 | | return !empty($this->_contents); |
| |
63 | 68 | | } |
| |
|
|
 |
… |
|
203 | 208 | | $this->_weight = 0; |
| |
204 | 209 | | $this->_tax = 0; |
| |
205 | 210 | | $this->_tax_groups = array(); |
  |
206 | | - | $this->_cartID = $this->generateCartID(); |
|
207 | 211 | | $this->_content_type = null; |
| |
208 | 212 | | |
| |
209 | 213 | | $this->resetShippingAddress(); |
| |
210 | 214 | | $this->resetShippingMethod(); |
| |
211 | 215 | | $this->resetBillingAddress(); |
| |
212 | 216 | | $this->resetBillingMethod(); |
  |
| 217 | + | |
| |
| 218 | + | if ( isset($_SESSION['cartID']) ) { |
| |
| 219 | + | unset($_SESSION['cartID']); |
| |
| 220 | + | } |
|
213 | 221 | | } |
| |
214 | 222 | | |
| |
215 | 223 | | function add($products_id_string, $attributes = null, $quantity = null) { |
| |
|
|
 |
… |
|
390 | 398 | | return osc_create_random_string($length, 'digits'); |
| |
391 | 399 | | } |
| |
392 | 400 | | |
  |
393 | | - | function hasCartID() { |
| |
394 | | - | return isset($this->_cartID); |
| |
395 | | - | } |
| |
396 | | - | |
|
397 | 401 | | function getCartID() { |
  |
398 | | - | return $this->_cartID; |
| |
| 402 | + | return $_SESSION['cartID']; |
|
399 | 403 | | } |
| |
400 | 404 | | |
| |
401 | 405 | | function getContentType() { |
| |
|
|
 |
… |
|
728 | 732 | | $this->_weight = 0; |
| |
729 | 733 | | $this->_tax = 0; |
| |
730 | 734 | | $this->_tax_groups = array(); |
  |
731 | | - | $this->_cartID = $this->generateCartID(); |
| |
| 735 | + | $this->_shipping_boxes_weight = 0; |
| |
| 736 | + | $this->_shipping_boxes = 0; |
| |
| 737 | + | $this->_shipping_quotes = array(); |
| |
| 738 | + | $this->_order_totals = array(); |
|
732 | 739 | | |
  |
| 740 | + | $_SESSION['cartID'] = $this->generateCartID(); |
| |
| 741 | + | |
|
733 | 742 | | if ($this->hasContents()) { |
| |
734 | 743 | | foreach ($this->_contents as $data) { |
| |
735 | 744 | | $products_weight = $osC_Weight->convert($data['weight'], $data['weight_class_id'], SHIPPING_WEIGHT_UNIT); |
| |
|
|
 |
… |
|
759 | 768 | | $this->_tax_groups[$tax_description] = $tax_amount; |
| |
760 | 769 | | } |
| |
761 | 770 | | } |
  |
762 | | - | } |
|
763 | 771 | | |
  |
764 | | - | $this->_shipping_boxes_weight = $this->_weight; |
| |
765 | | - | $this->_shipping_boxes = 1; |
| |
| 772 | + | $this->_shipping_boxes_weight = $this->_weight; |
| |
| 773 | + | $this->_shipping_boxes = 1; |
|
766 | 774 | | |
  |
767 | | - | if (SHIPPING_BOX_WEIGHT >= ($this->_shipping_boxes_weight * SHIPPING_BOX_PADDING/100)) { |
| |
768 | | - | $this->_shipping_boxes_weight = $this->_shipping_boxes_weight + SHIPPING_BOX_WEIGHT; |
| |
769 | | - | } else { |
| |
770 | | - | $this->_shipping_boxes_weight = $this->_shipping_boxes_weight + ($this->_shipping_boxes_weight * SHIPPING_BOX_PADDING/100); |
| |
771 | | - | } |
| |
| 775 | + | if (SHIPPING_BOX_WEIGHT >= ($this->_shipping_boxes_weight * SHIPPING_BOX_PADDING/100)) { |
| |
| 776 | + | $this->_shipping_boxes_weight = $this->_shipping_boxes_weight + SHIPPING_BOX_WEIGHT; |
| |
| 777 | + | } else { |
| |
| 778 | + | $this->_shipping_boxes_weight = $this->_shipping_boxes_weight + ($this->_shipping_boxes_weight * SHIPPING_BOX_PADDING/100); |
| |
| 779 | + | } |
|
772 | 780 | | |
  |
773 | | - | if ($this->_shipping_boxes_weight > SHIPPING_MAX_WEIGHT) { // Split into many boxes |
| |
774 | | - | $this->_shipping_boxes = ceil($this->_shipping_boxes_weight / SHIPPING_MAX_WEIGHT); |
| |
775 | | - | $this->_shipping_boxes_weight = $this->_shipping_boxes_weight / $this->_shipping_boxes; |
| |
776 | | - | } |
| |
| 781 | + | if ($this->_shipping_boxes_weight > SHIPPING_MAX_WEIGHT) { // Split into many boxes |
| |
| 782 | + | $this->_shipping_boxes = ceil($this->_shipping_boxes_weight / SHIPPING_MAX_WEIGHT); |
| |
| 783 | + | $this->_shipping_boxes_weight = $this->_shipping_boxes_weight / $this->_shipping_boxes; |
| |
| 784 | + | } |
|
777 | 785 | | |
  |
778 | | - | if ($set_shipping === true) { |
| |
779 | | - | if (!class_exists('osC_Shipping')) { |
| |
780 | | - | include('includes/classes/shipping.php'); |
| |
| 786 | + | if ($set_shipping === true) { |
| |
| 787 | + | if (!class_exists('osC_Shipping')) { |
| |
| 788 | + | include('includes/classes/shipping.php'); |
| |
| 789 | + | } |
| |
| 790 | + | |
| |
| 791 | + | if (!$this->hasShippingMethod() || ($this->getShippingMethod('is_cheapest') === true)) { |
| |
| 792 | + | $osC_Shipping = new osC_Shipping(); |
| |
| 793 | + | $this->setShippingMethod($osC_Shipping->getCheapestQuote(), false); |
| |
| 794 | + | } else { |
| |
| 795 | + | $osC_Shipping = new osC_Shipping($this->getShippingMethod('id')); |
| |
| 796 | + | $this->setShippingMethod($osC_Shipping->getQuote(), false); |
| |
| 797 | + | } |
|
781 | 798 | | } |
| |
782 | 799 | | |
  |
783 | | - | if (!$this->hasShippingMethod() || ($this->getShippingMethod('is_cheapest') === true)) { |
| |
784 | | - | $osC_Shipping = new osC_Shipping(); |
| |
785 | | - | $this->setShippingMethod($osC_Shipping->getCheapestQuote(), false); |
| |
786 | | - | } else { |
| |
787 | | - | $osC_Shipping = new osC_Shipping($this->getShippingMethod('id')); |
| |
788 | | - | $this->setShippingMethod($osC_Shipping->getQuote(), false); |
| |
| 800 | + | if (!class_exists('osC_OrderTotal')) { |
| |
| 801 | + | include('includes/classes/order_total.php'); |
|
789 | 802 | | } |
  |
790 | | - | } |
|
791 | 803 | | |
  |
792 | | - | if (!class_exists('osC_OrderTotal')) { |
| |
793 | | - | include('includes/classes/order_total.php'); |
| |
| 804 | + | $osC_OrderTotal = new osC_OrderTotal(); |
| |
| 805 | + | $this->_order_totals = $osC_OrderTotal->getResult(); |
|
794 | 806 | | } |
  |
795 | | - | |
| |
796 | | - | $osC_OrderTotal = new osC_OrderTotal(); |
| |
797 | | - | $this->_order_totals = $osC_OrderTotal->getResult(); |
  |
798 | 807 | | } |
| |
799 | 808 | | |
| |
800 | 809 | | function _uasortProductsByDateAdded($a, $b) { |