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'])) { Citruscart::load('CitruscartHelperCurrency', 'helpers.currency'); $order->currency_id = CitruscartHelperCurrency::getCurrentCurrency(); } // Store the text verion of the currency for order integrity Citruscart::load('CitruscartHelperOrder', 'helpers.order'); $order->order_currency = CitruscartHelperOrder::currencyToParameters($order->currency_id); $saveAddressesToDB = empty($options["save_addresses"]) ? false : true; $this->setAddresses($values, $saveAddressesToDB); // set the shipping method if (isset($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 Citruscart::load('CitruscartHelperCarts', 'helpers.carts'); $reviewitems = CitruscartHelperCarts::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; }
/** * Saves the order to the database * * param $values * return unknown_type */ function saveOrder($values, $user_id, $ajax = false) { $error = false; $guest = $user_id < Citruscart::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 (isset($values['shippingrequired']) || isset($values['shipping_plugin'])) { $order->shipping = new JObject(); $order->shipping->shipping_price = isset($values['shipping_price']) ? $values['shipping_price'] : ""; $order->shipping->shipping_extra = isset($values['shipping_extra']) ? $values['shipping_extra'] : ""; $order->shipping->shipping_name = isset($values['shipping_name']) ? $values['shipping_name'] : ""; $order->shipping->shipping_tax = isset($values['shipping_tax']) ? $values['shipping_tax'] : ""; } // Store the text verion of the currency for order integrity Citruscart::load('CitruscartHelperOrder', 'helpers.order'); $order->order_currency = CitruscartHelperOrder::currencyToParameters($order->currency_id); //get the items and add them to the order Citruscart::load('CitruscartHelperCarts', '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 = CitruscartHelperCarts::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 = JModelLegacy::getInstance('Orders', 'CitruscartModel'); //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($values['shipping_plugin'])) { 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; }
function saveOrder($values) { $session = JFactory::getSession(); $user_id = $session->get('user_id', '', 'citruscart_pos'); $error = false; JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables'); $order = JTable::getInstance('Orders', 'CitruscartTable'); $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', '', 'citruscart_pos'); $order->shipping->shipping_extra = $session->get('shipping_extra', '', 'citruscart_pos'); $order->shipping->shipping_name = $session->get('shipping_name', '', 'citruscart_pos'); $order->shipping->shipping_tax = $session->get('shipping_tax', '', 'citruscart_pos'); } // Store the text verion of the currency for order integrity Citruscart::load('CitruscartHelperOrder', 'helpers.order'); $order->order_currency = CitruscartHelperOrder::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 = Citruscart::getInstance()->get('coupons_enabled'); $mult_enabled = Citruscart::getInstance()->get('multiple_usercoupons_enabled'); if (!empty($values['coupons']) && $coupons_enabled) { foreach ($values['coupons'] as $coupon_id) { $coupon = JTable::getInstance('Coupons', 'CitruscartTable'); $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', 'CitruscartModel'); 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; }