public function getShippingCost($sessionId = null, $cartItems = null) { $session = Session::getActiveSession($sessionId); $sessionId = $session->getId(); if (!is_array($cartItems)) { $cartItems = CartItem::getAll($sessionId); } return $this->calculateCost($session, $cartItems); }
public function getPaymentForm() { $form = new Form('payment_form', 'payment_form', '/Store/Payment'); $paypalHost = 'https://' . $this->hostName . '/cgi-bin/webscr'; $form->updateAttributes(array('action' => $paypalHost)); $form->updateAttributes(array('onSubmit' => "return checkBeforePayment()")); $tid = @$_SESSION['ECommTID']; if ($tid) { $transaction = Transaction::getTransactionBasedOnTID($tid); $sessionId = $transaction->getSession(); $session = Session::getActiveSession($sessionId); $cartItems = CartItem::getAll($sessionId); //$form->setConstants( array ( 'cmd' => '_cart' ) ); $form->setConstants(array('cmd' => '_xclick')); $form->addElement('hidden', 'cmd'); $form->setConstants(array('upload' => 1)); $form->addElement('hidden', 'upload'); //Set the ID of the transaction for this order $form->setConstants(array('custom' => $tid)); $form->addElement('hidden', 'custom'); $form->setConstants(array('currency_code' => SiteConfig::get("EComm::Currency"))); $form->addElement('hidden', 'currency_code'); $form->setConstants(array('business' => $this->accountEmail)); $form->addElement('hidden', 'business'); $form->setConstants(array('return' => "http://" . $_SERVER['HTTP_HOST'] . "/Store/IPN/&action=OrderComplete&tid={$tid}")); $form->addElement('hidden', 'return'); $cartDetails = Module_EComm::getCartDetails($sessionId, $cartItems); $form->setConstants(array('amount' => $cartDetails["subTotal"])); $form->addElement('hidden', 'amount'); $form->setConstants(array('shipping' => $cartDetails["shipping"])); $form->addElement('hidden', 'shipping'); $form->setConstants(array('tax' => $cartDetails["tax"])); $form->addElement('hidden', 'tax'); } $form->addElement('image', 'cart_submit', 'https://www.paypal.com/en_US/i/btn/x-click-but23.gif'); return $form->display(); }
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; }