<?php
/*
  $Id: cn_shopping_cart.php $
  TomatoCart Open Source Shopping Cart Solutions
  http://www.tomatocart.com

  Copyright (c) 2010 Wuxi Elootec Technology Co., Ltd

  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.
*/
  require_once('includes/classes/address_book.php');
  
  class toC_CnShoppingCart extends osC_ShoppingCart {
    
    function toC_CnShoppingCart () {
      parent::osC_ShoppingCart();
    }
    
//    function saveBillingAddress() {
//      global $osC_Language, $osC_ShoppingCart, $osC_Shipping, $toC_Json, $osC_Customer, $osC_Payment, $osC_Currencies;
//
//      $Qaddresses = osC_AddressBook::getListing();
//      $address = array();
//      
//      while ($Qaddresses->next()) {
//        $address[] = array('id' => $Qaddresses->valueInt('address_book_id'));
//      }
//      
//      if (sizeof($address) > 0) {
//        $osC_ShoppingCart->setBillingAddress($address[0]['id']);
//      }
//    }
    
//    function saveShippingAddress() {
//      global $osC_Language, $osC_ShoppingCart, $osC_Shipping, $toC_Json, $osC_Customer, $osC_Payment, $osC_Currencies;
//
//      include('includes/classes/address_book.php');
//      $Qaddresses = osC_AddressBook::getListing();
//      $address = array();
//      
//      while ($Qaddresses->next()) {
//        $address[] = array('id' => $Qaddresses->valueInt('address_book_id'));
//      }
//      
//      if (sizeof($address) > 0) {
//        $osC_ShoppingCart->setShippingAddress($address[0]['id']);
//      }
//    }
    
//    function saveShippingMethod($shippingMethod = null) {
//      global $osC_Language, $osC_ShoppingCart, $osC_Shipping, $toC_Json, $osC_Customer, $osC_Payment, $osC_Currencies;
//      
//      $errors = array();
//
//      if (class_exists('osC_Shipping') === false) {
//        include('includes/classes/shipping.php');
//      }
//
//      $osC_Shipping = new osC_Shipping();
//
//      if ($osC_ShoppingCart->hasShippingMethod() === false) {
//        $osC_ShoppingCart->setShippingMethod($osC_Shipping->getCheapestQuote());
//      }
//      
//      if ($osC_Shipping->hasQuotes()) {
//        if ($shippingMethod != null && strpos($shippingMethod, '_')) {
//          list($module, $method) = explode('_', $shippingMethod);
//          $module = 'osC_Shipping_' . $module;
//
//          if (is_object($GLOBALS[$module]) && $GLOBALS[$module]->isEnabled()) {
//            $quote = $osC_Shipping->getQuote($shippingMethod);
//
//            if (isset($quote['error'])) {
//              $osC_ShoppingCart->resetShippingMethod();
//              
//              $errors[] = $quote['error'];
//            } else {
//              $osC_ShoppingCart->setShippingMethod($quote);
//            }
//          } else {
//            $osC_ShoppingCart->resetShippingMethod();
//          }
//        }
//      } else {
//        if ($osC_Shipping->numberOfQuotes() >= 1) {
//          $i = 1;
//          foreach ($osC_Shipping->getQuotes() as $quotes) {
//            if ($i == 1) {
//              $quote = $osC_Shipping->getQuote($quotes['id']);
//              $osC_ShoppingCart->setShippingMethod($quote);
//            }
//          }
//        }
//      }
//    }
//    
//    function savePaymentMethod() {
//      global $osC_Language, $osC_ShoppingCart, $osC_Payment, $messageStack, $toC_Json, $osC_Currencies;
//      
//      include('includes/classes/payment.php');
//      $osC_Payment = new osC_Payment((isset($_REQUEST['payment_method']) ? $_REQUEST['payment_method'] : $osC_ShoppingCart->getBillingMethod('id')));
//      
//      $errors = array();
//      
//      $osC_Language->load('account');
//      $osC_Language->load('checkout');
//      $osC_Language->load('order');
//      
//      if($osC_ShoppingCart->isTotalZero() == false) {
//        if (isset($_REQUEST['payment_method'])) {
//          $osC_ShoppingCart->setBillingMethod(array('id' => $_REQUEST['payment_method'], 'title' => $GLOBALS['osC_Payment_' . $_REQUEST['payment_method']]->getMethodTitle()));
//        }
//  
//        if ( $osC_Payment->hasActive() && ((isset($GLOBALS['osC_Payment_' . $osC_ShoppingCart->getBillingMethod('id')]) === false) || (isset($GLOBALS['osC_Payment_' . $osC_ShoppingCart->getBillingMethod('id')]) && is_object($GLOBALS['osC_Payment_' . $osC_ShoppingCart->getBillingMethod('id')]) && ($GLOBALS['osC_Payment_' . $osC_ShoppingCart->getBillingMethod('id')]->isEnabled() === false))) ) {
//          $errors[] = $osC_Language->get('error_no_payment_module_selected');
//        }
//  
//        if ($osC_Payment->hasActive()) {
//          $osC_Payment->pre_confirmation_check();
//        }
//        
//        if ($messageStack->size('checkout_payment') > 0) {
//          $errors =  array_merge($errors, $messageStack->getMessages('checkout_payment'));
//        }
//      } else {
//        $selection = $osC_Payment->selection();
//        $i = 1;
//        
//        foreach ($selection as $select) {
//          if ($i == 1) {
//            $osC_ShoppingCart->setBillingMethod(array('id' => $select['id'], 'title' => $GLOBALS['osC_Payment_' . $select['module']]->getMethodTitle()));
//          }
//        }
//      }
//    }
    
//    function numberOfItems() {
//      $total = 0;
//
//      return $total;
//    }
    
//    function saveOrder() {
//      global $toC_Json, $osC_Language, $osC_Payment, $osC_ShoppingCart;
//      
//      // load selected payment module
//      include('includes/classes/payment.php');
//      $osC_Payment = new osC_Payment($osC_ShoppingCart->getBillingMethod('id'));
//
//      if ($osC_Payment->hasActive() && ($osC_ShoppingCart->hasBillingMethod() === false)) {
//        osc_redirect(osc_href_link(FILENAME_CHECKOUT, 'payment', 'SSL'));
//      }
//
//      include('includes/classes/order.php');
//
//      $osC_Payment->process();
//      
//      $response = array('success' => true); 
//        
//      echo $toC_Json->encode($response);
//    }
  }
?>