Ejemplo n.º 1
0
 public function __construct($id = null)
 {
     global $user;
     // if an ID is passed in we'll look up the cart from the database...it means this is
     // probably a completed order an admin is looking at it via the order admin interface.
     //if (empty($id)) {
     //    global $order;
     //} else {
     //$order = new order($id);
     //}
     /*
             // check for this users billing method object.  If it hasn't been created yet then lets do it now.
             if (empty($order->billingmethod)) {
                 $order->billingmethod[0] = new billingmethod();
                 $order->billingmethod[0]->update(array('orders_id'=>$order->id)); 
             } */
     //if (empty($order->billingmethod[0]->addresses_id) && $user->isLoggedIn()) {
     //if ($user->isLoggedIn()) {
     if ($id == null) {
         // since this is a new billingmethod object, lets initialize it with the users billing address.
         global $order;
         $address = new address();
         //FJD $defaultaddy = $address->find('first', 'user_id='.$user->id.' AND is_default=1');
         if (empty($order->billingmethod)) {
             $order->billingmethod[0] = new billingmethod();
             $order->billingmethod[0]->update(array('orders_id' => @$order->id));
             // @ added to ditch notice when ecom is off
         }
         $billingAddy = $address->find('first', 'user_id=' . $user->id . ' AND is_billing=1');
         $order->billingmethod[0]->setAddress($billingAddy);
     } else {
         $order = new order($id);
         if (empty($order->id)) {
             return false;
         }
     }
     //}
     $this->address = new address($order->billingmethod[0]->addresses_id);
     //$this->address = new address($order->billingmethod[0]->id);
     $this->available_calculators = billing::listAvailableCalculators();
     $this->selectable_calculators = $this->selectableCalculators();
     $this->calculator_views = $this->getCalcViews();
     // if there is only one available calculator we'll force it on the user
     // also if the user hasn't selected a calculator yet well set it to a default.
     $number_of_calculators = count($this->available_calculators);
     if ($number_of_calculators == 1 || empty($order->billingmethod[0]->billingcalculator_id)) {
         reset($this->available_calculators);
         $calcid = key($this->available_calculators);
         $order->billingmethod[0]->update(array('billingcalculator_id' => $calcid));
     }
     if ($number_of_calculators > 0) {
         $calcname = $this->available_calculators[$order->billingmethod[0]->billingcalculator_id];
         $this->calculator = new $calcname($order->billingmethod[0]->billingcalculator_id);
     } else {
         $this->calculator = null;
     }
     $this->billingmethod = $order->billingmethod[0];
     $options = unserialize($this->billingmethod->billing_options);
     $this->info = empty($this->calculator->id) ? '' : $this->calculator->userView($options);
     foreach ($this->available_calculators as $key => $item) {
         $calc = new $item($key);
         $this->form[$key] = $calc->userForm();
     }
     // eDebug($this->form, true);
 }