/** * @param array $data * @param StorePaymentMethod $pm * @param string $transactionReference * @param boolean $status * @return Order */ public function add($data, $pm, $transactionReference = '', $status = null) { $customer = new StoreCustomer(); $now = new \DateTime(); $smName = StoreShippingMethod::getActiveShippingMethodName(); $shippingTotal = StoreCalculator::getShippingTotal(); $taxes = StoreTax::getConcatenatedTaxStrings(); $totals = StoreCalculator::getTotals(); $total = $totals['total']; $pmName = $pm->getPaymentMethodName(); $order = new Order(); $order->setCustomerID($customer->getUserID()); $order->setOrderDate($now); $order->setPaymentMethodName($pmName); $order->setShippingMethodName($smName); $order->setShippingTotal($shippingTotal); $order->setTaxTotals($taxes['taxTotals']); $order->setTaxIncluded($taxes['taxIncludedTotal']); $order->setTaxLabels($taxes['taxLabels']); $order->setOrderTotal($total); $order->save(); $customer->setLastOrderID($order->getOrderID()); $order->updateStatus($status); $order->addCustomerAddress($customer, $order->isShippable()); $order->addOrderItems(StoreCart::getCart()); $order->createNeededAccounts(); $order->assignFilePermissions(); if (!$pm->getMethodController()->external) { $order->completeOrder($transactionReference); } return $order; }