public function addOrder($customer_id, $package_guid, $quantity, $userid) { $guid_order = Options::getUUIDv6(); $package = new Packages(); $package_toorder = array(); $package_toorder = $package->getPackageToOrderByGuid($package_guid); if ($package_toorder["id"] > 0) { $db = new clsDBdbConnection(); //Calculating total amount based on quantities taxes and fees $this->subtotal = $package_toorder["price"] * $quantity; $this->tax_total = $this->tax_percent * $this->subtotal; $this->paypal_totalfee = $this->paypal_ratepercent * $this->subtotal + $this->paypal_extrafee; $this->total = $this->subtotal + $this->tax_total + $this->paypal_totalfee; //Adding the order $sql = "insert into orders (guid,customer_id,subtotal,tax,paypal_fee,total,currency,created_iduser)\n values ('{$guid_order}',{$customer_id},{$this->subtotal},{$this->tax_total},{$this->paypal_totalfee},{$this->total},'{$this->currency}',{$userid})"; $db->query($sql); $db->query("select last_insert_id() as id"); $db->next_record(); $order_id = (int) $db->f("id"); //Add order detail $this->addOrderDetail($order_id, $quantity, $package_toorder, $db, $userid); $db->close(); //After order creation, set email notification to buyer //Notifications are sent via a separate module $this->setEmailNotification($order_id, $userid); return $this->getHumanOrderId($order_id); } else { //No package to set into the order return 0; } }