/** * Add an order for display * * @param string $passkey * @param string $strId * @param int $intDttDate * @param int $intDttDue * @param string $strPrintedNotes * @param string $strStatus * @param string $strEmail * @param string $strPhone * @param string $strZipcode * @param int $intTaxcode * @param float $fltShippingSell * @param float $fltShippingCost * @return string */ public function add_order($passkey, $strId, $intDttDate, $intDttDue, $strPrintedNotes, $strStatus, $strEmail, $strPhone, $strZipcode, $intTaxcode, $fltShippingSell, $fltShippingCost) { if (!$this->check_passkey($passkey)) { return self::FAIL_AUTH; } $objDocument = Document::LoadByIdStr($strId); if (!$objDocument instanceof Document) { $objDocument = new Document(); } else { // if cart already exists then delete the items foreach ($objDocument->documentItems as $item) { $item->qty = 0; $item->save(); $item->product->SetAvailableInventory(); $item->delete(); } } $objDocument->order_type = CartType::order; $objDocument->order_str = $strId; $objDocument->printed_notes = $strPrintedNotes; $objDocument->datetime_cre = date("Y-m-d H:i:s", trim($intDttDate)); $objDocument->datetime_due = date("Y-m-d H:i:s", trim($intDttDue)); $objDocument->fk_tax_code_id = $intTaxcode ? $intTaxcode : 0; $objDocument->status = $strStatus; $objCustomer = Customer::LoadByEmail($strEmail); if ($objCustomer instanceof Customer) { $objDocument->customer_id = $objCustomer->id; } $objCart = Cart::LoadByIdStr($strId); if ($objCart instanceof Cart) { $objDocument->cart_id = $objCart->id; } $objDocument->status = $strStatus; if (!$objDocument->save()) { Yii::log("SOAP ERROR : add_order " . print_r($objDocument->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__); return self::UNKNOWN_ERROR; } if ($objCart instanceof Cart) { $objCart->document_id = $objDocument->id; $objCart->save(); } if (substr($strId, 0, 3) == "WO-") { Configuration::SetHighestWO(); } return self::OK; }
/** * Add an order for display * * @param string $passkey * @param string $strId * @param int $intDttDate * @param int $intDttDue * @param string $strPrintedNotes * @param string $strStatus * @param int $lightspeed_id * @param int $intTaxcode * @return string * @throws SoapFault * * @soap */ public function add_order($passkey, $strId, $intDttDate, $intDttDue, $strPrintedNotes, $strStatus, $lightspeed_id, $intTaxcode) { self::check_passkey($passkey); $objDocument = Document::LoadByIdStr($strId); if (!$objDocument instanceof Document) { $objDocument = new Document(); $objDocument->status = $strStatus; } else { // if cart already exists then delete the items foreach ($objDocument->documentItems as $item) { try { $item->qty = 0; $item->save(); $item->product->SetAvailableInventory(); $item->delete(); } catch (Exception $ex) { Yii::log($ex->getMessage() . "Store: " . $_SERVER['HTTP_HOST'] . "Item: " . CVarDumper::dumpAsString($item), CLogger::LEVEL_ERROR, 'application.' . __CLASS__ . "." . __FUNCTION__); } } } $objDocument->order_type = CartType::order; $objDocument->order_str = $strId; $objDocument->printed_notes = $strPrintedNotes; $objDocument->datetime_cre = date("Y-m-d H:i:s", trim($intDttDate)); $objDocument->datetime_due = date("Y-m-d H:i:s", trim($intDttDue)); $objDocument->fk_tax_code_id = $intTaxcode ? $intTaxcode : 0; $objCustomer = Customer::model()->findByAttributes(array('lightspeed_id' => $lightspeed_id)); if ($objCustomer instanceof Customer) { $objDocument->customer_id = $objCustomer->id; } $objCart = Cart::LoadByIdStr($strId); if ($objCart instanceof Cart) { $objDocument->cart_id = $objCart->id; } /** * WS-2555 * This is to deal with cases where bronze makes update_order_status call before add_order. * In that case, we need to compare the order status between the two calls and change the order status * only if the status in add_order call is later than one in update_order_status call. */ if ($objDocument->status == self::BRONZE_ORDER_PROCESSING || empty($objDocument->status)) { $objDocument->status = $strStatus; } if (!$objDocument->save()) { Yii::log("SOAP ERROR : add_order " . print_r($objDocument->getErrors(), true), CLogger::LEVEL_ERROR, 'application.' . __CLASS__ . "." . __FUNCTION__); throw new SoapFault("Unknown error", WsSoapException::ERROR_UNKNOWN); } if ($objCart instanceof Cart) { $objCart->document_id = $objDocument->id; $objCart->save(); } if (substr($strId, 0, 3) == "WO-") { Configuration::SetHighestWO(); } return self::OK; }