示例#1
0
 public function process()
 {
     global $db, $order, $user;
     //eDebug($order,true);
     if (!$user->isLoggedIn() && empty($this->params['nologin'])) {
         flash('message', gt("It appears that your session has expired. Please log in to continue the checkout process."));
         expHistory::back();
         //expHistory::redirecto_login(makeLink(array('module'=>'cart','action'=>'checkout'), 'secure'));
     }
     // if this error hits then something went horribly wrong or the user has tried to hit this
     // action themselves before the cart was ready or is refreshing the page after they've confirmed the
     // order.
     if (empty($order->orderitem)) {
         flash('error', gt('There are no items in your cart.'));
     }
     if (!expQueue::isQueueEmpty('error')) {
         redirect_to(array('controller' => 'store', 'action' => 'showall'));
     }
     // set the gift comments
     $order->update($this->params);
     // get the biling & shipping info
     $shipping = new shipping();
     $billing = new billing();
     // finalize the total to bill
     $order->calculateGrandTotal();
     //eDebug($order,true);
     $invNum = $order->getInvoiceNumber();
     // call the billing calculators process method - this will handle saving the billing options to the database.
     $result = $billing->calculator->process($billing->billingmethod, expSession::get('billing_options'), $this->params, $invNum);
     if (empty($result->errorCode)) {
         // if ($result->errorCode === "0" || $result->errorCode === 0)
         // {
         // save out the cart total to the database
         $billing->billingmethod->update(array('billing_cost' => $order->grand_total));
         // set the invoice number and purchase date in the order table..this finializes the order
         //$invoice_num = $db->max('orders', 'invoice_id') + 1;
         //if ($invoice_num < ecomconfig::getConfig('starting_invoice_number')) $invoice_num += ecomconfig::getConfig('starting_invoice_number');
         // get the first order status and set it for this order
         $order->update(array('invoice_id' => $invNum, 'purchased' => time(), 'updated' => time(), 'comment' => serialize($comment)));
         //$order->setDefaultStatus(); --FJD?
         //$order->setDefaultOrderType(); --FJD?
         $order->refresh();
         // run each items process callback function
         foreach ($order->orderitem as $item) {
             $product = new $item->product_type($item->product_id);
             $product->process($item, $order->order_type->affects_inventory);
         }
         $billing->calculator->postProcess($order, $this->params);
         orderController::clearCartCookie();
     } else {
         flash('error', gt('An error was encountered while processing your transaction.') . '<br /><br />' . $result->message);
         expHistory::back();
         //redirect_to(array('controller'=>'cart', 'action'=>'checkout'));
     }
     $billinginfo = $billing->calculator->userView(unserialize($billing->billingmethod->billing_options));
     if (!DEVELOPMENT) {
         // send email invoices to the admins & users if needed
         if ($order->order_type->emails_customer) {
             $invoice = renderAction(array('controller' => 'order', 'action' => 'email', 'id' => $order->id));
         }
     } else {
         flash('message', gt('Development on, skipping email sending.'));
     }
     //assign_to_template(array('order'=>$order, 'billing'=>$billing, 'shipping'=>$shipping, 'result'=>$result, 'billinginfo'=>$billinginfo));
     flash('message', gt('Your order has been submitted.'));
     redirect_to(array('controller' => 'order', 'action' => 'myOrder', 'id' => $order->id, 'tc' => 1));
 }