public function completeOrder($tid) { $transaction = Transaction::getTransactionBasedOnTID($tid); $user = new User($transaction->getUser()); $order = new Order(); $order->setTid($transaction->getTid()); $order->setUser($transaction->getUser()); $order->setCustomerName($user->getName()); $order->setUserEmail($user->getEmail()); $order->setPhone($transaction->getPhone()); $order->setShippingStreet($transaction->getShippingStreet()); $order->setShippingCity($transaction->getShippingCity()); $order->setShippingPostal($transaction->getShippingPostal()); $order->setShippingProvince($transaction->getShippingProvince()); $order->setShippingCountry($transaction->getShippingCountry()); $order->setBillingStreet($transaction->getBillingStreet()); $order->setBillingCity($transaction->getBillingCity()); $order->setBillingPostal($transaction->getBillingPostal()); $order->setBillingProvince($transaction->getBillingProvince()); $order->setBillingCountry($transaction->getBillingCountry()); $order->setCostSubtotal($transaction->getCostSubtotal()); $order->setCostTax($transaction->getCostTax()); $order->setCostShipping($transaction->getCostShipping()); $order->setCostTotal($transaction->getCostTotal()); $order->setIp($transaction->getIp()); $order->setShippingClass($transaction->getShippingClass()); $order->setPaymentClass($transaction->getPaymentClass()); $order->setDeliveryInstructions($transaction->getDeliveryInstructions()); $order->setStatus('Pending'); $order->save(); $cartItems = CartItem::getAll($transaction->getSession()); foreach ($cartItems as $cartItem) { $product = new Product($cartItem->getProduct()); $orderDetail = new OrderDetail(); $orderDetail->setOrderNb($order->getId()); $orderDetail->setProduct($product->getId()); $orderDetail->setProductName($product->getName()); $orderDetail->setQuantity($cartItem->getQuantity()); $orderDetail->save(); $cartItem->delete(); } $transaction->delete(); //Send an email to the user $this->sendEmailOrderComplete($order->getId()); return true; }