/** * insert a new order * * @return unknown */ function insertOrder($order_data) { // set status to 0 (Not processed payment) $order_data['status'] = 0; $insert_order_data = $order_data; $insert_order_data['other_data'] = serialize($insert_order_data['other_data']); $insert_order_data['created'] = date('c'); $insert_order_data['modified'] = date('c'); if (is_numeric($id = $this->insert($insert_order_data))) { $order_data['id'] = $id; //insert delivery record //need to be inserted before recording usage of promotion code, otherwise delivery calculation thinks coupon has be already used when uses_per_customer = 1 if (!$this->insertDelivery($order_data)) { msg("Cannot insert delivery data", 'error'); return false; } //record promotion code use if ($order_data['other_data']['promotion_code']) { require_once 'models/ecommerce/ecommerce_promotion_code.php'; $Promotion_code = new ecommerce_promotion_code(); if ($inserted_code_id = $Promotion_code->insertPromotionCode($order_data['other_data']['promotion_code'], $order_data['id'])) { // } else { msg("Can't insert promotion code {$order_data['other_data']['promotion_code']} ", 'error'); } } //get full order data $order_data = $this->getOrder($id); //descrement stock $this->decrementStock($order_data); // calculate payable amount $this->updatePayableDue($order_data); //set status $this->setStatus($id, 0); //send email to admin require_once 'models/common/common_email.php'; $EmailForm = new common_email(); $_Onxshop_Request = new Onxshop_Request("component/ecommerce/order_detail~order_id={$order_data['id']}~"); $order_data['order_detail'] = $_Onxshop_Request->getContent(); //this allows use customer data and company data in the mail template //is passed as DATA to template in common_email->_format $GLOBALS['common_email']['order'] = $order_data; if ($this->conf['mail_unpaid']) { if (!$EmailForm->sendEmail('new_order_unpaid', 'n/a', $this->conf['mail_to_address'], $this->conf['mail_to_name'])) { msg("ecommerce_order: can't send email", 'error', 2); } } //return order.id return $id; } else { return false; } }
/** * get code for an order */ public function getPromotionCodeForOrder($order_id) { if (!is_numeric($order_id)) { return false; } require_once 'models/ecommerce/ecommerce_promotion_code.php'; $Promotion_code = new ecommerce_promotion_code(); return $Promotion_code->getPromotionCodeForOrder($order_id); }