示例#1
0
文件: pos.php 项目: annggeel/tienda
 function saveOrder($values)
 {
     $session = JFactory::getSession();
     $user_id = $session->get('user_id', '', 'tienda_pos');
     $error = false;
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables');
     $order = JTable::getInstance('Orders', 'TiendaTable');
     $order->bind($values);
     $order->user_id = $user_id;
     $order->ip_address = $_SERVER['REMOTE_ADDR'];
     $this->setAddresses($order, $values);
     $session = JFactory::getSession();
     // set the shipping method
     if ($values['shippingrequired']) {
         $order->shipping = new JObject();
         $order->shipping->shipping_price = $session->get('shipping_price', '', 'tienda_pos');
         $order->shipping->shipping_extra = $session->get('shipping_extra', '', 'tienda_pos');
         $order->shipping->shipping_name = $session->get('shipping_name', '', 'tienda_pos');
         $order->shipping->shipping_tax = $session->get('shipping_tax', '', 'tienda_pos');
     }
     // Store the text verion of the currency for order integrity
     Tienda::load('TiendaHelperOrder', 'helpers.order');
     $order->order_currency = TiendaHelperOrder::currencyToParameters($order->currency_id);
     $reviewitems = $this->getProductsInfo();
     foreach ($reviewitems as $reviewitem) {
         $order->addItem($reviewitem);
     }
     // get all coupons and add them to the order
     $coupons_enabled = Tienda::getInstance()->get('coupons_enabled');
     $mult_enabled = Tienda::getInstance()->get('multiple_usercoupons_enabled');
     if (!empty($values['coupons']) && $coupons_enabled) {
         foreach ($values['coupons'] as $coupon_id) {
             $coupon = JTable::getInstance('Coupons', 'TiendaTable');
             $coupon->load(array('coupon_id' => $coupon_id));
             $order->addCoupon($coupon);
             if (empty($mult_enabled)) {
                 // this prevents Firebug users from adding multiple coupons to orders
                 break;
             }
         }
     }
     $order->order_state_id = 15;
     $order->calculateTotals();
     $order->getShippingTotal();
     $order->getInvoiceNumber();
     $model = DSCModel::getInstance('Orders', 'TiendaModel');
     if ($order->save()) {
         $model->setId($order->order_id);
         // save the order items
         if (!$this->saveOrderItems($order)) {
             // TODO What to do if saving order items fails?
             $error = true;
         }
         // save the order vendors
         if (!$this->saveOrderVendors($order)) {
             // TODO What to do if saving order vendors fails?
             $error = true;
         }
         // save the order info
         if (!$this->saveOrderInfo($order)) {
             // TODO What to do if saving order info fails?
             $error = true;
         }
         // save the order history
         if (!$this->saveOrderHistory($order)) {
             // TODO What to do if saving order history fails?
             $error = true;
         }
         // save the order taxes
         if (!$this->saveOrderTaxes($order)) {
             // TODO What to do if saving order taxes fails?
             $error = true;
         }
         // save the order shipping info
         if (!$this->saveOrderShippings($order)) {
             // TODO What to do if saving order shippings fails?
             $error = true;
         }
         // save the order coupons
         if (!$this->saveOrderCoupons($order)) {
             // TODO What to do if saving order coupons fails?
             $error = true;
         }
         $model->clearCache();
     }
     return $order;
 }
示例#2
0
 /**
  * Saves the order to the database
  *
  * @param $values
  * @return unknown_type
  */
 function saveOrder($values, $user_id, $ajax = false)
 {
     $error = false;
     $guest = $user_id < Tienda::getGuestIdStart();
     $order = $this->_order;
     // a TableOrders object (see constructor)
     $order->_adjustCredits = true;
     // this is not a POS order, so adjust the user's credits (if any used)
     $order->bind($values);
     $order->user_id = $user_id;
     $order->ip_address = $_SERVER['REMOTE_ADDR'];
     $this->setAddresses($values, false, $ajax);
     // set the shipping method
     if (@$values['shippingrequired'] || !empty($values['shipping_plugin'])) {
         $order->shipping = new JObject();
         $order->shipping->shipping_price = $values['shipping_price'];
         $order->shipping->shipping_extra = $values['shipping_extra'];
         $order->shipping->shipping_name = $values['shipping_name'];
         $order->shipping->shipping_tax = $values['shipping_tax'];
     }
     // Store the text verion of the currency for order integrity
     Tienda::load('TiendaHelperOrder', 'helpers.order');
     $order->order_currency = TiendaHelperOrder::currencyToParameters($order->currency_id);
     //get the items and add them to the order
     Tienda::load('TiendaHelperCarts', 'helpers.carts');
     //we dont need to add items in the order if onepage checkout since its already added in the shipping validation
     if (!$this->onepage_checkout) {
         $reviewitems = TiendaHelperCarts::getProductsInfo();
         foreach ($reviewitems as $reviewitem) {
             $order->addItem($reviewitem);
         }
     }
     $this->addCoupons($values);
     $order->order_state_id = $this->initial_order_state;
     $order->calculateTotals();
     $order->getShippingTotal();
     $order->getInvoiceNumber();
     $model = JModel::getInstance('Orders', 'TiendaModel');
     //TODO: Do Something with Payment Infomation
     if ($order->save()) {
         $model->setId($order->order_id);
         // save the order items
         if (!$this->saveOrderItems()) {
             // TODO What to do if saving order items fails?
             $error = true;
         }
         // save the order vendors
         if (!$this->saveOrderVendors()) {
             // TODO What to do if saving order vendors fails?
             $error = true;
         }
         // save the order info
         if (!$this->saveOrderInfo()) {
             // TODO What to do if saving order info fails?
             $error = true;
         }
         // save the order history
         if (!$this->saveOrderHistory()) {
             // TODO What to do if saving order history fails?
             $error = true;
         }
         // save the order taxes
         if (!$this->saveOrderTaxes()) {
             // TODO What to do if saving order taxes fails?
             $error = true;
         }
         // save the order shipping info
         if (isset($order->shipping) && !$this->saveOrderShippings($values)) {
             // TODO What to do if saving order shippings fails?
             $error = true;
         }
         // save the order coupons
         if (!$this->saveOrderCoupons()) {
             // TODO What to do if saving order coupons fails?
             $error = true;
         }
         $model->clearCache();
     }
     if ($error) {
         return false;
     }
     return true;
 }
示例#3
0
 public function prepare($values, $options = array(), &$order = null)
 {
     if (empty($order)) {
         $order = $this->getTable();
     }
     $this->_order =& $order;
     $this->_values = $values;
     $this->_options = $options;
     if (empty($options['skip_adjust_credits'])) {
         $order->_adjustCredits = true;
         // this is not a POS order, so adjust the user's credits (if any used)
     }
     $order->bind($values);
     $order->user_id = $values['user_id'];
     $order->ip_address = $values['ip_address'];
     //$_SERVER['REMOTE_ADDR'];
     // set the currency
     if (empty($values['currency_id'])) {
         Tienda::load('TiendaHelperCurrency', 'helpers.currency');
         $order->currency_id = TiendaHelperCurrency::getCurrentCurrency();
     }
     // Store the text verion of the currency for order integrity
     Tienda::load('TiendaHelperOrder', 'helpers.order');
     $order->order_currency = TiendaHelperOrder::currencyToParameters($order->currency_id);
     $saveAddressesToDB = empty($options["save_addresses"]) ? false : true;
     $this->setAddresses($values, $saveAddressesToDB);
     // set the shipping method
     if (@$values['shippingrequired'] || !empty($values['shipping_plugin'])) {
         $order->shipping = new JObject();
         $order->shipping->shipping_price = $values['shipping_price'];
         $order->shipping->shipping_extra = $values['shipping_extra'];
         $order->shipping->shipping_name = $values['shipping_name'];
         $order->shipping->shipping_tax = $values['shipping_tax'];
     }
     if (empty($options['skip_add_items'])) {
         //get the items from the current user's cart and add them to the order
         Tienda::load('TiendaHelperCarts', 'helpers.carts');
         $reviewitems = TiendaHelperCarts::getProductsInfo();
         foreach ($reviewitems as $reviewitem) {
             $order->addItem($reviewitem);
         }
     }
     if (empty($options['skip_add_coupons'])) {
         $this->addCoupons($values);
     }
     if (empty($options['skip_add_credit']) && !empty($values['order_credit'])) {
         $order->addCredit($values['order_credit']);
     }
     $order->order_state_id = empty($values['orderstate_id']) ? $this->initial_order_state : $values['orderstate_id'];
     $order->calculateTotals();
     $order->getShippingTotal();
     $order->getInvoiceNumber();
     return $order;
 }