/** * Write the order header record * * @author Oscar van Eijk * @param object $_cart The cart data * @param object $_usr User object * @param array $_prices Price data * @return integer The new ordernumber */ private function _createOrder($_cart, $_usr, $_prices) { // TODO We need tablefields for the new values: // Shipment: // $_prices['shipmentValue'] w/out tax // $_prices['shipmentTax'] Tax // $_prices['salesPriceShipment'] Total // // Payment: // $_prices['paymentValue'] w/out tax // $_prices['paymentTax'] Tax // $_prices['paymentDiscount'] Discount // $_prices['salesPricePayment'] Total $_orderData = new stdClass(); $_orderData->virtuemart_order_id = null; $_orderData->virtuemart_user_id = $_usr->get('id'); $_orderData->virtuemart_vendor_id = $_cart->vendorId; //Note as long we do not have an extra table only storing addresses, the virtuemart_userinfo_id is not needed. //The virtuemart_userinfo_id is just the id of a stored address and is only necessary in the user maintance view or for choosing addresses. //the saved order should be an snapshot with plain data written in it. // $_orderData->virtuemart_userinfo_id = 'TODO'; // $_cart['BT']['virtuemart_userinfo_id']; // TODO; Add it in the cart... but where is this used? Obsolete? $_orderData->order_total = $_prices['billTotal']; $_orderData->order_salesPrice = $_prices['salesPrice']; $_orderData->order_billTaxAmount = $_prices['billTaxAmount']; $_orderData->order_billDiscountAmount = $_prices['billDiscountAmount']; $_orderData->order_discountAmount = $_prices['discountAmount']; $_orderData->order_subtotal = $_prices['priceWithoutTax']; $_orderData->order_tax = $_prices['taxAmount']; $_orderData->order_shipment = $_prices['shipmentValue']; $_orderData->order_shipment_tax = $_prices['shipmentTax']; $_orderData->order_payment = $_prices['paymentValue']; $_orderData->order_payment_tax = $_prices['paymentTax']; if (!empty($_cart->couponCode)) { $_orderData->coupon_code = $_cart->couponCode; $_orderData->coupon_discount = $_prices['salesPriceCoupon']; } $_orderData->order_discount = $_prices['discountAmount']; // discount order_items $_orderData->order_status = 'P'; if (isset($_cart->pricesCurrency)) { $_orderData->user_currency_id = $_cart->pricesCurrency; //$this->getCurrencyIsoCode($_cart->pricesCurrency); $currency = CurrencyDisplay::getInstance(); if (!empty($currency->exchangeRateShopper)) { $_orderData->user_currency_rate = $currency->exchangeRateShopper; } else { $_orderData->user_currency_rate = 1.0; } } $_orderData->order_currency = $this->getVendorCurrencyId($_orderData->virtuemart_vendor_id); $_orderData->virtuemart_paymentmethod_id = $_cart->virtuemart_paymentmethod_id; $_orderData->virtuemart_shipmentmethod_id = $_cart->virtuemart_shipmentmethod_id; $_filter = JFilterInput::getInstance(array('br', 'i', 'em', 'b', 'strong'), array(), 0, 0, 1); $_orderData->customer_note = $_filter->clean($_cart->customer_comment); // $_orderData->ip_address = $_SERVER['REMOTE_ADDR']; $_orderData->ip_address = $_SERVER['HTTP_X_REAL_IP']; $_orderData->order_number = ''; JPluginHelper::importPlugin('vmshopper'); $dispatcher = JDispatcher::getInstance(); $plg_datas = $dispatcher->trigger('plgVmOnUserOrder', array(&$_orderData)); foreach ($plg_datas as $plg_data) { // $data = array_merge($plg_data,$data); } if (empty($_orderData->order_number)) { $_orderData->order_number = $this->generateOrderNumber($_usr->get('id'), 4, $_orderData->virtuemart_vendor_id); } if (empty($_orderData->order_pass)) { $_orderData->order_pass = '******' . substr(md5((string) time() . rand(1, 1000) . $_orderData->order_number), 0, 5); } $orderTable = $this->getTable('orders'); $orderTable->bindChecknStore($_orderData); $errors = $orderTable->getErrors(); foreach ($errors as $error) { vmError($error); } $db = JFactory::getDBO(); $_orderID = $db->insertid(); if (!empty($_cart->couponCode)) { //set the virtuemart_order_id in the Request for 3rd party coupon components (by Seyi and Max) JRequest::setVar('virtuemart_order_id', $_orderData->virtuemart_order_id); // If a gift coupon was used, remove it now CouponHelper::RemoveCoupon($_cart->couponCode); } // the order number is saved into the session to make sure that the correct cart is emptied with the payment notification $_cart->order_number = $_orderData->order_number; $_cart->setCartIntoSession(); return $_orderID; }
function updateStatusForOneOrder($virtuemart_order_id, $inputOrder, $useTriggers = true) { // vmdebug('updateStatusForOneOrder', $inputOrder); /* Update the order */ $data = $this->getTable('orders'); $data->load($virtuemart_order_id); $old_order_status = $data->order_status; $data->bind($inputOrder); $cp_rm = VmConfig::get('cp_rm', array('C')); if (!is_array($cp_rm)) { $cp_rm = array($cp_rm); } if (in_array((string) $data->order_status, $cp_rm)) { if (!empty($data->coupon_code)) { if (!class_exists('CouponHelper')) { require JPATH_VM_SITE . DS . 'helpers' . DS . 'coupon.php'; } CouponHelper::RemoveCoupon($data->coupon_code); } } //First we must call the payment, the payment manipulates the result of the order_status if ($useTriggers) { if (!class_exists('vmPSPlugin')) { require JPATH_VM_PLUGINS . DS . 'vmpsplugin.php'; } // Payment decides what to do when order status is updated JPluginHelper::importPlugin('vmcalculation'); JPluginHelper::importPlugin('vmcustom'); JPluginHelper::importPlugin('vmshipment'); JPluginHelper::importPlugin('vmpayment'); $_dispatcher = JDispatcher::getInstance(); //Should we add this? $inputOrder $_returnValues = $_dispatcher->trigger('plgVmOnUpdateOrderPayment', array(&$data, $old_order_status)); foreach ($_returnValues as $_returnValue) { if ($_returnValue === true) { break; // Plugin was successfull } elseif ($_returnValue === false) { return false; // Plugin failed } // Ignore null status and look for the next returnValue } $_dispatcher = JDispatcher::getInstance(); //Should we add this? $inputOrder $_returnValues = $_dispatcher->trigger('plgVmOnUpdateOrderShipment', array(&$data, $old_order_status)); /** * If an order gets cancelled, fire a plugin event, perhaps * some authorization needs to be voided */ if ($data->order_status == "X") { $_dispatcher = JDispatcher::getInstance(); //Should be renamed to plgVmOnCancelOrder $_dispatcher->trigger('plgVmOnCancelPayment', array(&$data, $old_order_status)); } } if (empty($data->delivery_date)) { $del_date_type = VmConfig::get('del_date_type', 'm'); if (strpos($del_date_type, 'os') !== FALSE) { //for example osS $os = substr($del_date_type, 2); if ($data->order_status == $os) { $date = JFactory::getDate(); $data->delivery_date = $date->toMySQL(); } } else { VmConfig::loadJLang('com_virtuemart_orders', true); $data->delivery_date = JText::_('COM_VIRTUEMART_DELDATE_INV'); } } if ($data->store()) { $task = JRequest::getCmd('task', 0); $view = JRequest::getWord('view', 0); /*if($task=='edit'){ $update_lines = JRequest::getInt('update_lines'); } else /*/ if ($task == 'updatestatus' and $view == 'orders') { $lines = JRequest::getVar('orders'); $update_lines = $lines[$virtuemart_order_id]['update_lines']; } else { $update_lines = 1; } if ($update_lines == 1) { vmdebug('$update_lines ' . $update_lines); $q = 'SELECT virtuemart_order_item_id FROM #__virtuemart_order_items WHERE virtuemart_order_id="' . $virtuemart_order_id . '"'; $db = JFactory::getDBO(); $db->setQuery($q); $order_items = $db->loadObjectList(); if ($order_items) { // vmdebug('updateStatusForOneOrder',$data); foreach ($order_items as $order_item) { //$this->updateSingleItem($order_item->virtuemart_order_item_id, $data->order_status, $order['comments'] , $virtuemart_order_id, $data->order_pass); $this->updateSingleItem($order_item->virtuemart_order_item_id, $data); } } } /* Update the order history */ $this->_updateOrderHist($virtuemart_order_id, $data->order_status, $inputOrder['customer_notified'], $inputOrder['comments']); // When the plugins did not already notified the user, do it here (the normal way) //Attention the ! prevents at the moment that an email is sent. But it should used that way. // if (!$inputOrder['customer_notified']) { $this->notifyCustomer($data->virtuemart_order_id, $inputOrder); // } JPluginHelper::importPlugin('vmcoupon'); $dispatcher = JDispatcher::getInstance(); $returnValues = $dispatcher->trigger('plgVmCouponUpdateOrderStatus', array($data, $old_order_status)); if (!empty($returnValues)) { foreach ($returnValues as $returnValue) { if ($returnValue !== null) { return $returnValue; } } } return true; } else { return false; } }