public function main() { //init controller data $this->extensions->hk_InitData($this, __FUNCTION__); if (isset($this->session->data['order_id'])) { $amount = $this->session->data['used_balance']; // in default currency if ($amount) { $transaction_data = array('order_id' => (int) $this->session->data['order_id'], 'amount' => $amount, 'transaction_type' => 'order', 'created_by' => $this->customer->getId(), 'description' => sprintf($this->language->get('text_applied_balance_to_order'), $this->currency->format($this->currency->convert($amount, $this->config->get('config_currency'), $this->session->data['currency']), $this->session->data['currency'], 1), (int) $this->session->data['order_id'])); $this->customer->debitTransaction($transaction_data); } // google analytics data for js-script in footer.tpl $order = new AOrder($this->registry); $order_data = $order->buildOrderData($this->session->data); $order_tax = $order_total = $order_shipping = 0.0; foreach ($order_data['totals'] as $total) { if ($total['total_type'] == 'total') { $order_total += $total['value']; } elseif ($total['total_type'] == 'tax') { $order_tax += $total['value']; } elseif ($total['total_type'] == 'shipping') { $order_shipping += $total['value']; } } $this->registry->set('google_analytics_data', array('transaction_id' => (int) $this->session->data['order_id'], 'store_name' => $this->config->get('store_name'), 'currency_code' => $order_data['currency'], 'total' => $order_total, 'tax' => $order_tax, 'shipping' => $order_shipping, 'city' => $order_data['shipping_city'], 'state' => $order_data['shipping_zone'], 'country' => $order_data['shipping_country'])); $this->cart->clear(); unset($this->session->data['shipping_method'], $this->session->data['shipping_methods'], $this->session->data['payment_method'], $this->session->data['payment_methods'], $this->session->data['guest'], $this->session->data['comment'], $this->session->data['order_id'], $this->session->data['coupon'], $this->session->data['used_balance'], $this->session->data['used_balance_full']); //Redirect back. Fix for clearing shopping cart content $this->redirect($this->html->getSecureURL('checkout/success')); } $this->document->setTitle($this->language->get('heading_title')); $this->document->resetBreadcrumbs(); $this->document->addBreadcrumb(array('href' => $this->html->getURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE)); $this->document->addBreadcrumb(array('href' => $this->html->getURL('checkout/cart'), 'text' => $this->language->get('text_basket'), 'separator' => $this->language->get('text_separator'))); if ($this->customer->isLogged()) { $this->document->addBreadcrumb(array('href' => $this->html->getURL('checkout/shipping'), 'text' => $this->language->get('text_shipping'), 'separator' => $this->language->get('text_separator'))); $this->document->addBreadcrumb(array('href' => $this->html->getURL('checkout/payment'), 'text' => $this->language->get('text_payment'), 'separator' => $this->language->get('text_separator'))); $this->document->addBreadcrumb(array('href' => $this->html->getURL('checkout/confirm'), 'text' => $this->language->get('text_confirm'), 'separator' => $this->language->get('text_separator'))); } else { $this->document->addBreadcrumb(array('href' => $this->html->getURL('checkout/guest'), 'text' => $this->language->get('text_guest'), 'separator' => $this->language->get('text_separator'))); $this->document->addBreadcrumb(array('href' => $this->html->getURL('checkout/guest/confirm'), 'text' => $this->language->get('text_confirm'), 'separator' => $this->language->get('text_separator'))); } $this->document->addBreadcrumb(array('href' => $this->html->getURL('checkout/success'), 'text' => $this->language->get('text_success'), 'separator' => $this->language->get('text_separator'))); $this->view->assign('heading_title', $this->language->get('heading_title')); if ($this->session->data['account'] == 'guest') { $this->view->assign('text_message', sprintf($this->language->get('text_message_guest'), $this->html->getURL('content/contact'))); } else { $this->view->assign('text_message', sprintf($this->language->get('text_message'), $this->html->getSecureURL('account/account'), $this->html->getSecureURL('account/history'), $this->html->getURL('content/contact'))); } $this->view->assign('button_continue', $this->language->get('button_continue')); $this->view->assign('continue', $this->html->getURL('index/home')); $continue = HtmlElementFactory::create(array('type' => 'button', 'name' => 'continue_button', 'text' => $this->language->get('button_continue'), 'style' => 'button')); $this->view->assign('continue_button', $continue); $this->processTemplate('common/success.tpl'); //init controller data $this->extensions->hk_UpdateData($this, __FUNCTION__); }
/** * constructor with arguments */ public function __construct($orderId, $userId) { parent::__construct(); $this->orderId = $orderId; $this->encryptedOrderId = Yii::app()->getSecurityManager()->hashData($orderId); $selectedOrders = null; //if order id belongs to current user and is in 'order_start' status //(other status mean order has already crossed the checkout process once) //as order id's input has been added to checkout action to facilitate the //order resumption. Note: As order is being modified or created in this function //do check before any POST or GET if order can be modified. Order can be modified //only and only if it is in 'order-start' status. $selectedOrders = AOrder::model()->findAll(array('order' => 'id', 'condition' => 'is_deleted = "no" AND ordered_by2user_details = ' . $userId . ' AND order_unique_id = "' . $orderId . '" ' . ' AND status = "order_start" ')); if (!isset($selectedOrders) || count($selectedOrders) < 1) { $this->render('cart_error', array('errorMessage' => "Either this page does not exists or has expired or you are not allowed to view this page.", 'link' => CHtml::normalizeUrl(array('cart/checkout')))); Yii::app()->end(); } $this->totalItemsInOrder = 0; foreach ($selectedOrders as $row) { $this->tiffinPriceTimeSelectionArr[] = new TiffinPriceTimeSelectionForm($row, $this->encryptedOrderId); $this->destinationLocality = $row->destination_locality; $this->totalItemsInOrder = $this->totalItemsInOrder + $row->num_of_units; } $this->totalAmountInWallet = AppCommonWallet::getTotalAmountInWalletForUser($userId); $this->amountUsedFromWallet = 0; $this->userId = $userId; }
/** * @param string $order_id * @throws AException */ public function __construct($order_id = '') { $this->registry = Registry::getInstance(); if ((int) $order_id) { $this->order_id = (int) $order_id; } parent::__construct($this->registry, $this->order_id); if (!IS_ADMIN) { // forbid for non admin calls throw new AException(AC_ERR_LOAD, 'Error: permission denied to access package manager'); } }
public function main() { //init controller data $this->extensions->hk_InitData($this, __FUNCTION__); //is this an embed mode $cart_rt = 'checkout/cart'; if ($this->config->get('embed_mode') == true) { $cart_rt = 'r/checkout/cart/embed'; } if (!$this->cart->hasProducts() || !$this->cart->hasStock() && !$this->config->get('config_stock_checkout')) { $this->redirect($this->html->getSecureURL($cart_rt)); } //validate if order min/max are met if (!$this->cart->hasMinRequirement() || !$this->cart->hasMaxRequirement()) { $this->redirect($this->html->getSecureURL($cart_rt)); } if ($this->customer->isLogged()) { $this->redirect($this->html->getSecureURL('checkout/shipping')); } if (!isset($this->session->data['guest'])) { $this->redirect($this->html->getSecureURL('checkout/guest_step_1')); } if ($this->cart->hasShipping()) { if (!isset($this->session->data['shipping_method'])) { $this->redirect($this->html->getSecureURL('checkout/guest_step_2')); } } else { unset($this->session->data['shipping_method']); unset($this->session->data['shipping_methods']); //$this->tax->setZone($this->config->get('config_country_id'), $this->config->get('config_zone_id')); $this->tax->setZone($this->session->data['country_id'], $this->session->data['zone_id']); } if (!isset($this->session->data['payment_method'])) { $this->redirect($this->html->getSecureURL('checkout/guest_step_2')); } $this->loadLanguage('checkout/confirm'); $this->document->setTitle($this->language->get('heading_title')); //build and save order $this->data = array(); $order = new AOrder($this->registry); $this->data = $order->buildOrderData($this->session->data); $this->session->data['order_id'] = $order->saveOrder(); $this->document->resetBreadcrumbs(); $this->document->addBreadcrumb(array('href' => $this->html->getURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE)); $this->document->addBreadcrumb(array('href' => $this->html->getURL($cart_rt), 'text' => $this->language->get('text_basket'), 'separator' => $this->language->get('text_separator'))); $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('checkout/guest_step_1'), 'text' => $this->language->get('text_guest_step_1'), 'separator' => $this->language->get('text_separator'))); $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('checkout/guest_step_2'), 'text' => $this->language->get('text_guest_step_2'), 'separator' => $this->language->get('text_separator'))); $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('checkout/guest_step_3'), 'text' => $this->language->get('text_confirm'), 'separator' => $this->language->get('text_separator'))); $this->view->assign('error_warning', $this->error['warning']); $this->view->assign('success', $this->session->data['success']); if (isset($this->session->data['success'])) { unset($this->session->data['success']); } if ($this->cart->hasShipping()) { if (isset($this->session->data['guest']['shipping'])) { $shipping_address = $this->session->data['guest']['shipping']; } else { $shipping_address = $this->session->data['guest']; } $this->data['shipping_address'] = $this->customer->getFormatedAdress($shipping_address, $shipping_address['address_format']); } else { $this->data['shipping_address'] = ''; } if (isset($this->session->data['shipping_method']['title'])) { $this->data['shipping_method'] = $this->session->data['shipping_method']['title']; } else { $this->data['shipping_method'] = ''; } $this->data['checkout_shipping'] = $this->html->getSecureURL('checkout/guest_step_2'); $this->data['checkout_shipping_edit'] = $this->html->getSecureURL('checkout/guest_step_2', '&mode=edit', true); $this->data['checkout_shipping_address'] = $this->html->getSecureURL('checkout/guest_step_1'); $payment_address = $this->session->data['guest']; if ($payment_address) { $this->data['payment_address'] = $this->customer->getFormatedAdress($payment_address, $payment_address['address_format']); } else { $this->data['payment_address'] = ''; } if ($this->session->data['payment_method']['id'] != 'no_payment_required') { $this->data['payment_method'] = $this->session->data['payment_method']['title']; } else { $this->data['payment_method'] = ''; } $this->data['checkout_payment'] = $this->html->getSecureURL('checkout/guest_step_2'); $this->data['checkout_payment_edit'] = $this->html->getSecureURL('checkout/guest_step_2', '&mode=edit', true); $this->data['cart'] = $this->html->getSecureURL($cart_rt); $this->data['checkout_payment_address'] = $this->html->getSecureURL('checkout/guest_step_1'); $this->loadModel('tool/seo_url'); $this->loadModel('tool/image'); //Format product data specific for confirmation page $resource = new AResource('image'); for ($i = 0; $i < sizeof($this->data['products']); $i++) { $product_id = $this->data['products'][$i]['product_id']; $thumbnail = $resource->getMainThumb('products', $product_id, $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_height'), true); $tax = $this->tax->calcTotalTaxAmount($this->data['products'][$i]['total'], $this->data['products'][$i]['tax_class_id']); $this->data['products'][$i] = array_merge($this->data['products'][$i], array('thumb' => $thumbnail, 'tax' => $this->currency->format($tax), 'price' => $this->currency->format($this->data['products'][$i]['price']), 'total' => $this->currency->format($this->data['products'][$i]['total']), 'href' => $this->html->getSEOURL('product/product', '&product_id=' . $product_id, true))); } if ($this->config->get('config_checkout_id')) { $this->loadModel('catalog/content'); $content_info = $this->model_catalog_content->getContent($this->config->get('config_checkout_id')); if ($content_info) { $this->data['text_accept_agree'] = $this->language->get('text_accept_agree'); $this->data['text_accept_agree_href'] = $this->html->getSEOURL('r/content/content/loadInfo', '&content_id=' . $this->config->get('config_checkout_id'), true); $this->data['text_accept_agree_href_link'] = $content_info['title']; } else { $this->data['text_accept_agree'] = ''; } } else { $this->data['text_accept_agree'] = ''; } if ($this->session->data['payment_method']['id'] != 'no_payment_required') { $this->addChild('responses/extension/' . $this->session->data['payment_method']['id'], 'payment'); } else { $this->addChild('responses/checkout/no_payment', 'payment'); } $this->view->batchAssign($this->data); $this->processTemplate('pages/checkout/confirm.tpl'); //init controller data $this->extensions->hk_UpdateData($this, __FUNCTION__); }
public function onControllerPagesCheckoutGuestStep2_InitData() { $error = false; $that = $this->baseObject; if (isset($that->request->post['shipping_method'])) { $shipping = explode('.', $that->request->post['shipping_method']); $that->session->data['shipping_method'] = $that->session->data['shipping_methods'][$shipping[0]]['quote'][$shipping[1]]; } if ($that->request->get['mode'] == 'edit') { unset($that->session->data['pp_express_checkout']); } // if coupon code was submited if (has_value($that->request->post['coupon'])) { $promotion = new APromotion(); $coupon = $promotion->getCouponData($that->request->post['coupon']); // rebuild order data if coupon applied $order = new AOrder(Registry::getInstance()); $this->data = $order->buildOrderData($that->session->data); $order->saveOrder(); if ($coupon) { $that->session->data['coupon'] = $that->request->post['coupon']; } else { $error = true; } } if (!$error && $that->request->server['REQUEST_METHOD'] == 'POST' && ($that->request->post['payment_method'] == 'default_pp_express' || $that->session->data['payment_method']['id'] == 'default_pp_express')) { if (!has_value($that->session->data['pp_express_checkout']['token']) || !has_value($that->session->data['pp_express_checkout']['PayerID'])) { // rebuild order data if coupon applied $order = new AOrder(Registry::getInstance()); $this->data = $order->buildOrderData($that->session->data); $order->saveOrder(); $redirect_url = $that->html->getSecureURL('checkout/guest_step_3'); header('Location: ' . $that->html->getSecureURL('r/extension/default_pp_express/set_pp', '&to_confirm=1&redirect_to=' . urlencode($redirect_url))); exit; } } }
public function post() { //init controller data $this->extensions->hk_InitData($this, __FUNCTION__); $request = $this->rest->getRequestParams(); if (!$this->customer->isLoggedWithToken($request['token'])) { $this->rest->sendResponse(401, array('error' => 'Not logged in or Login attempt failed!')); return null; } if (!$this->cart->hasProducts()) { //No products in the cart. $this->rest->sendResponse(200, array('status' => 2, 'error' => 'Nothing in the cart!')); return null; } if (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout')) { //No stock for products in the cart if tracked. $this->rest->sendResponse(200, array('status' => 3, 'error' => 'No stock for product!')); return null; } if ($this->cart->hasShipping()) { if (!isset($this->session->data['shipping_address_id']) || !$this->session->data['shipping_address_id']) { //Problem. Missing shipping address $this->rest->sendResponse(200, array('status' => 4, 'error' => 'Missing shipping address!')); return null; } if (!isset($this->session->data['shipping_method'])) { //Problem. Missing shipping address $this->rest->sendResponse(200, array('status' => 5, 'error' => 'Missing shipping method!')); return null; } } else { unset($this->session->data['shipping_address_id']); unset($this->session->data['shipping_method']); unset($this->session->data['shipping_methods']); $this->tax->setZone($this->session->data['country_id'], $this->session->data['zone_id']); } if (!isset($this->session->data['payment_address_id']) || !$this->session->data['payment_address_id']) { $this->rest->sendResponse(200, array('status' => 6, 'error' => 'Missing payment (billing) address!')); return null; } if (!isset($this->session->data['payment_method'])) { $this->rest->sendResponse(200, array('status' => 5, 'error' => 'Missing payment (billing) method!')); return null; } //build order and pre-save $order = new AOrder($this->registry); $this->data = $order->buildOrderData($this->session->data); $this->session->data['order_id'] = $order->saveOrder(); //build confirmation data $this->loadModel('account/address'); $shipping_address = $this->model_account_address->getAddress($this->session->data['shipping_address_id']); if ($this->cart->hasShipping()) { $this->data['shipping_address'] = $this->customer->getFormattedAddress($shipping_address, $shipping_address['address_format']); } else { $this->data['shipping_address'] = ''; } $this->data['shipping_method'] = $this->session->data['shipping_method']['title']; $payment_address = $this->model_account_address->getAddress($this->session->data['payment_address_id']); if ($payment_address) { $this->data['payment_address'] = $this->customer->getFormattedAddress($payment_address, $payment_address['address_format']); } else { $this->data['payment_address'] = ''; } if ($this->session->data['payment_method']['id'] != 'no_payment_required') { $this->data['payment_method'] = $this->session->data['payment_method']['title']; } else { $this->data['payment_method'] = ''; } $this->loadModel('tool/seo_url'); $this->loadModel('tool/image'); $product_ids = array(); foreach ($this->data['products'] as $result) { $product_ids[] = (int) $result['product_id']; } $resource = new AResource('image'); $thumbnails = $resource->getMainThumbList('products', $product_ids, $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_height')); //Format product data specific for confirmation response for ($i = 0; $i < sizeof($this->data['products']); $i++) { $product_id = $this->data['products'][$i]['product_id']; $thumbnail = $thumbnails[$product_id]; $tax = $this->tax->calcTotalTaxAmount($this->data['products'][$i]['total'], $this->data['products'][$i]['tax_class_id']); $this->data['products'][$i] = array_merge($this->data['products'][$i], array('thumb' => $thumbnail['thumb_url'], 'tax' => $this->currency->format($tax), 'price' => $this->currency->format($this->data['products'][$i]['price']), 'total' => $this->currency->format($this->data['products'][$i]['total']))); } if ($this->config->get('config_checkout_id')) { $this->loadModel('catalog/content'); $content_info = $this->model_catalog_content->getContent($this->config->get('config_checkout_id')); if ($content_info) { $this->data['text_accept_agree'] = sprintf($this->language->get('text_accept_agree'), '', $content_info['title']); } else { $this->data['text_accept_agree'] = ''; } } else { $this->data['text_accept_agree'] = ''; } // Load selected paymnet required data from payment extension if ($this->session->data['payment_method']['id'] != 'no_payment_required') { $payment_controller = $this->dispatch('responses/extension/' . $this->session->data['payment_method']['id'] . '/api'); } else { $payment_controller = $this->dispatch('responses/checkout/no_payment/api'); } $this->load->library('json'); $this->data['payment'] = AJson::decode($payment_controller->dispatchGetOutput(), TRUE); //set process_rt for process step to run the payment $this->session->data['process_rt'] = $this->data['payment']['process_rt']; //mark confirmation viewed $this->session->data['confirmed'] = TRUE; $this->extensions->hk_UpdateData($this, __FUNCTION__); $this->rest->setResponseData($this->data); $this->rest->sendResponse(200); }
public function main() { //init controller data $this->extensions->hk_InitData($this, __FUNCTION__); if (!$this->cart->hasProducts() || !$this->cart->hasStock() && !$this->config->get('config_stock_checkout')) { $this->redirect($this->html->getSecureURL('checkout/cart')); } //validate if order min/max are met if (!$this->cart->hasMinRequirement() || !$this->cart->hasMaxRequirement()) { $this->redirect($this->html->getSecureURL('checkout/cart')); } if (!$this->customer->isLogged()) { $this->session->data['redirect'] = $this->html->getSecureURL('checkout/shipping'); $this->redirect($this->html->getSecureURL('account/login')); } if ($this->cart->hasShipping()) { if (!isset($this->session->data['shipping_address_id']) || !$this->session->data['shipping_address_id']) { $this->redirect($this->html->getSecureURL('checkout/shipping')); } if (!isset($this->session->data['shipping_method'])) { $this->redirect($this->html->getSecureURL('checkout/shipping')); } } else { unset($this->session->data['shipping_address_id']); unset($this->session->data['shipping_method']); unset($this->session->data['shipping_methods']); $this->tax->setZone($this->session->data['country_id'], $this->session->data['zone_id']); } if (!isset($this->session->data['payment_address_id']) || !$this->session->data['payment_address_id']) { $this->redirect($this->html->getSecureURL('checkout/payment')); } if (!isset($this->session->data['payment_method'])) { $this->redirect($this->html->getSecureURL('checkout/payment')); } if ($this->request->get['balance'] == 'disapply') { unset($this->session->data['used_balance'], $this->request->get['balance'], $this->session->data['used_balance_full']); } $this->data = array(); $order = new AOrder($this->registry); $this->data = $order->buildOrderData($this->session->data); $order_id = $order->saveOrder(); if ($order_id === false) { // preventing rebuilding order of already processed orders //(by "back" button via browser history from external payment page(paypal, google_checkout etc)) $this->redirect($this->html->getSecureURL('checkout/success')); } $this->session->data['order_id'] = $order_id; $this->document->setTitle($this->language->get('heading_title')); $this->document->resetBreadcrumbs(); $this->document->addBreadcrumb(array('href' => $this->html->getURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE)); $this->document->addBreadcrumb(array('href' => $this->html->getURL('checkout/cart'), 'text' => $this->language->get('text_basket'), 'separator' => $this->language->get('text_separator'))); if ($this->cart->hasShipping()) { $this->document->addBreadcrumb(array('href' => $this->html->getURL('checkout/shipping'), 'text' => $this->language->get('text_shipping'), 'separator' => $this->language->get('text_separator'))); } $this->document->addBreadcrumb(array('href' => $this->html->getURL('checkout/payment', '&mode=edit', true), 'text' => $this->language->get('text_payment'), 'separator' => $this->language->get('text_separator'))); $this->document->addBreadcrumb(array('href' => $this->html->getURL('checkout/confirm'), 'text' => $this->language->get('text_confirm'), 'separator' => $this->language->get('text_separator'))); $this->data['error_warning'] = $this->error['warning']; $this->data['success'] = $this->session->data['success']; if (isset($this->session->data['success'])) { unset($this->session->data['success']); } //balance $balance_def_currency = $this->customer->getBalance(); $balance = $this->currency->convert($balance_def_currency, $this->config->get('config_currency'), $this->session->data['currency']); if ($balance != 0 || $balance == 0 && $this->config->get('config_zero_customer_balance') && (double) $this->session->data['used_balance'] != 0) { $this->data['balance'] = $this->language->get('text_balance_checkout') . ' ' . $this->currency->format($balance, $this->session->data['currency'], 1); if ((double) $this->session->data['used_balance'] > 0) { $this->data['disapply_balance'] = array('href' => $this->html->getSecureURL('checkout/payment', '&mode=edit&balance=disapply', true), 'text' => $this->language->get('button_disapply_balance')); $this->data['balance'] .= ' (' . $this->currency->format($balance_def_currency - (double) $this->session->data['used_balance']) . ')'; $this->data['balance'] .= ' ' . $this->currency->format((double) $this->session->data['used_balance']) . ' ' . $this->language->get('text_applied_balance'); } elseif ((double) $this->session->data['used_balance'] == 0 && $balance > 0) { $this->data['disapply_balance'] = array('href' => $this->html->getSecureURL('checkout/payment', '&mode=edit&balance=apply', true), 'text' => $this->language->get('button_apply_balance')); } } $this->loadModel('account/address'); $shipping_address = $this->model_account_address->getAddress($this->session->data['shipping_address_id']); if ($this->cart->hasShipping()) { $this->data['shipping_address'] = $this->customer->getFormatedAdress($shipping_address, $shipping_address['address_format']); } else { $this->data['shipping_address'] = ''; } $this->data['shipping_method'] = $this->session->data['shipping_method']['title']; $this->data['shipping_method_price'] = $this->session->data['shipping_method']['title']; $this->data['checkout_shipping_edit'] = $this->html->getSecureURL('checkout/shipping', '&mode=edit', true); $this->data['checkout_shipping_address'] = $this->html->getSecureURL('checkout/address/shipping'); $payment_address = $this->model_account_address->getAddress($this->session->data['payment_address_id']); if ($payment_address) { $this->data['payment_address'] = $this->customer->getFormatedAdress($payment_address, $payment_address['address_format']); } else { $this->data['payment_address'] = ''; } if ($this->session->data['payment_method']['id'] != 'no_payment_required') { $this->data['payment_method'] = $this->session->data['payment_method']['title']; } else { $this->data['payment_method'] = ''; } $this->data['checkout_payment_edit'] = $this->html->getSecureURL('checkout/payment', '&mode=edit', true); $this->data['checkout_payment_address'] = $this->html->getSecureURL('checkout/address/payment'); $this->loadModel('tool/seo_url'); $this->loadModel('tool/image'); //Format product data specific for confirmation page $resource = new AResource('image'); for ($i = 0; $i < sizeof($this->data['products']); $i++) { $product_id = $this->data['products'][$i]['product_id']; $opts = $this->data['products'][$i]['option']; $options = array(); foreach ($opts as $option) { if ($option['element_type'] == 'H') { continue; } //hide hidden options $value = $option['value']; // hide binary value for checkbox if ($option['element_type'] == 'C' && in_array($value, array(0, 1))) { $value = ''; } $options[] = array('name' => $option['name'], 'value' => $value); } $this->data['products'][$i]['option'] = $options; $thumbnail = $resource->getMainThumb('products', $product_id, (int) $this->config->get('config_image_cart_width'), (int) $this->config->get('config_image_cart_height'), true); $tax = $this->tax->calcTotalTaxAmount($this->data['products'][$i]['total'], $this->data['products'][$i]['tax_class_id']); $this->data['products'][$i] = array_merge($this->data['products'][$i], array('thumb' => $thumbnail, 'tax' => $this->currency->format($tax), 'price' => $this->currency->format($this->data['products'][$i]['price']), 'total' => $this->currency->format($this->data['products'][$i]['total']), 'href' => $this->html->getSEOURL('product/product', '&product_id=' . $product_id, true))); } $display_totals = $this->cart->buildTotalDisplay(); $this->data['totals'] = $display_totals['total_data']; $this->data['cart'] = $this->html->getSecureURL('checkout/cart'); if ($this->config->get('config_checkout_id')) { $this->loadModel('catalog/content'); $content_info = $this->model_catalog_content->getContent($this->config->get('config_checkout_id')); if ($content_info) { $this->data['text_accept_agree'] = $this->language->get('text_accept_agree'); $this->data['text_accept_agree_href'] = $this->html->getSEOURL('r/content/content/loadInfo', '&content_id=' . $this->config->get('config_checkout_id'), true); $this->data['text_accept_agree_href_link'] = $content_info['title']; } else { $this->data['text_accept_agree'] = ''; } } else { $this->data['text_accept_agree'] = ''; } if ($this->session->data['payment_method']['id'] != 'no_payment_required') { $this->addChild('responses/extension/' . $this->session->data['payment_method']['id'], 'payment'); } else { $this->addChild('responses/checkout/no_payment', 'payment'); } $this->view->batchAssign($this->data); $this->processTemplate('pages/checkout/confirm.tpl'); //update data before render $this->extensions->hk_UpdateData($this, __FUNCTION__); }
public function post() { $request = $this->rest->getRequestParams(); if (!$this->customer->isLoggedWithToken($request['token'])) { $this->rest->sendResponse(401, array('error' => 'Not logged in or Login attempt failed!')); return; } //Check if confirmation details were reviewed. if (!$this->session->data['confirmed']) { $this->rest->sendResponse(400, array('status' => 0, 'error' => 'Need to review confirmation details first!')); return; } $this->session->data['confirmed'] = FALSE; //Check if order is created and process payment if (!isset($this->session->data['order_id'])) { $this->rest->sendResponse(500, array('status' => 2, 'error' => 'Not order data available!')); return; } $order = new AOrder($this->registry); $order_data = $order->loadOrderData($this->session->data['order_id'], 'any'); //Check if order is present and not processed yet if (!isset($order_data)) { $this->rest->sendResponse(500, array('status' => 3, 'error' => 'No order available. Something went wrong!')); return; } if ($order_data['order_status_id'] > 0) { $this->rest->sendResponse(200, array('status' => 4, 'error' => 'Order was already processed!')); return; } //Dispatch the payment send controller process and capture the result if (!$this->session->data['process_rt']) { $this->rest->sendResponse(500, array('status' => 5, 'error' => 'Something went wrong. Incomplete request!')); return; } //we process only responce type payment extensions $payment_controller = $this->dispatch('responses/extension/' . $this->session->data['process_rt']); $this->load->library('json'); $this->data = AJson::decode($payment_controller->dispatchGetOutput(), TRUE); if ($this->data['error']) { $this->data['status'] = 6; $this->rest->sendResponse(200, $this->data); return; } else { if ($this->data['success']) { $this->data['status'] = 1; //order completed clean up if (isset($this->session->data['order_id'])) { $this->cart->clear(); unset($this->session->data['shipping_method']); unset($this->session->data['shipping_methods']); unset($this->session->data['payment_method']); unset($this->session->data['payment_methods']); unset($this->session->data['guest']); unset($this->session->data['comment']); unset($this->session->data['order_id']); unset($this->session->data['coupon']); } $this->rest->setResponseData($this->data); $this->rest->sendResponse(200); } else { $this->data['status'] = 0; $this->data['error'] = "Unexpected Error"; $this->rest->sendResponse(500, $this->data); } } }
/** * $id is order unique id * * TODO::add comments */ public function actionCheckout($id = null) { $sm = Yii::app()->getSecurityManager(); $orderId = $id; $selectedOrders = null; if (isset($orderId)) { if (($orderId = $sm->validateData($orderId)) == false) { $this->render('cart_error', array('errorMessage' => "Either this page does not exists or has expired.", 'link' => CHtml::normalizeUrl(array('site/index')))); Yii::app()->end(); } //if order id exists and belongs to current user and is in 'order_start' status //(other status mean order has already crossed the checkout process once) //as order id's input has been added to checkout action to facilitate the //order resumption. Note: As order is being modified or created in this function //do check before any POST or GET if order can be modified. Order can be modified //only and only if it is in 'order-start' status. $selectedOrders = AOrder::model()->findAll(array('condition' => 'is_deleted = "no" AND ordered_by2user_details = ' . AppCommon::getUserDetailsId() . ' AND order_unique_id = "' . $orderId . '" ' . ' AND status = "order_start" ')); if (!isset($selectedOrders) || count($selectedOrders) < 1) { $this->render('cart_error', array('errorMessage' => "Either this page does not exists or has expired or you are not allowed to view this page.", 'link' => CHtml::normalizeUrl(array('cart/checkout')))); Yii::app()->end(); } } $model = new CheckoutFirstStageForm(); if (Yii::app()->getRequest()->getRequestType() == 'GET' || isset($_POST['CheckoutFirstStageForm'])) { if (isset($orderId) && Yii::app()->getRequest()->getRequestType() == 'GET') { //first add the items retreived from $orderId to cart if (isset($selectedOrders)) { foreach ($selectedOrders as $row) { $this->actionAddToCart($row->order2tiffin, $row->num_of_units, 0); $model->address = $row->order2address; $model->phone = $row->destination_phone; $model->customerLocality = $row->destination_locality; } } } if (AppCommon::cartItemCount() < 1) { $this->render('cart_error', array('errorMessage' => "Cart is empty.", 'link' => CHtml::normalizeUrl(array('site/index')))); Yii::app()->end(); } //handling POST method here if (isset($_POST['CheckoutFirstStageForm'])) { $model->attributes = $_POST['CheckoutFirstStageForm']; if ($model->validate()) { //get a order id if not there create new //after this if we will have a order id for sure :) if (!isset($orderId) && ($orderId = AppCommon::getUniqueOrderNumForUser(AppCommon::getUserDetailsId())) == false) { $this->render('cart_error', array('errorMessage' => "Order number could not be created.", 'link' => CHtml::normalizeUrl(array('site/index')))); Yii::app()->end(); } //Yii::ankFileSave( $orderId ); //create order rows in table $transaction = Yii::app()->db->beginTransaction(); try { //remove all old records if any with supplied orderId if (isset($selectedOrders) && count($selectedOrders) > 0) { foreach ($selectedOrders as $row) { $row->is_deleted = AppCommon::getUserDetailsId(); $row->save(); } } $currDateTime = new DateTime(); $currDateTime = $currDateTime->format('Y-m-d H:i:s'); //Yii::ankFileSave( var_export( $model->getCartArray, true ) ); //save orders rows for item in current locality foreach ($model->getCartArray as $key => $value) { if (is_array($value)) { if ($value["is_available_at_current_locality"]) { //saved order record $orderRecord = new AOrder(); $orderRecord->order_unique_id = $orderId; $orderRecord->num_of_units = $value["quantity"]; $orderRecord->ordered_by2user_details = AppCommon::getUserDetailsId(); $orderRecord->order2tiffin = $value["id"]; $orderRecord->order2address = $model->address; $orderRecord->status = 'order_start'; $orderRecord->last_status_update = $currDateTime; $orderRecord->destination_phone = $model->phone; $orderRecord->destination_address = $model->getAddressData[$model->address][1]; $orderRecord->destination_locality = $model->getAddressData[$model->address][0]; if ($emailPhoneArr = AppCommon::getEmailAndBasePhoneNumForUser($value["chef_id"])) { if (isset($emailPhoneArr['phone'])) { $orderRecord->source_phone = $emailPhoneArr['phone']; } } if ($AddressDataArrForChef = AppCommon::getBaseAddressDataForUser($value["chef_id"])) { foreach ($AddressDataArrForChef as $key1 => $value1) { $orderRecord->source_address = $value1[1]; $orderRecord->source_locality = $value1[0]; } } $orderRecord->save(); //saved order history record AppCommon::createOrderHistoryRecord($orderRecord->id, 'order_start', $currDateTime, $orderId); //TODO save phone number with user id in phone table if not exists already } } } $transaction->commit(); } catch (Exception $e) { //Yii::ankFileSave($e->getMessage()); $transaction->rollback(); $this->render('cart_error', array('errorMessage' => "Order could not be created.", 'link' => CHtml::normalizeUrl(array('site/index')))); Yii::app()->end(); } $secStage = new CheckoutSecondStageForm($orderId, AppCommon::getUserDetailsId()); $secStage->validate(); $secStage->clearErrors(); //clear error as it the first time display of form //Yii::ankFileSave( var_export( $secStage, true ) ); $this->render('checkout_second_stage', array('model' => $secStage)); Yii::app()->end(); //stop here after displaying checkout second stage } } //datastructure format : array( addrId => array( locality, addrText ) ) $addressArray = AAddress::getAllowedAddressForUser(AppCommon::getUserDetailsId()); $this->render('checkout_first_stage', array('model' => $model, 'addressArray' => $addressArray)); } else { if (isset($_POST['CheckoutSecondStageForm']) && isset($orderId) && isset($orderId) && isset($selectedOrders) && count($selectedOrders) > 0) { $secStage1 = new CheckoutSecondStageForm($orderId, AppCommon::getUserDetailsId()); $secStage1->attributes = $_POST['CheckoutSecondStageForm']; foreach ($secStage1->tiffinPriceTimeSelectionArr as $key1 => $value1) { if (isset($_POST['TiffinPriceTimeSelectionForm'][$key1])) { $value1->attributes = $_POST['TiffinPriceTimeSelectionForm'][$key1]; } } //validation passed finishing orders if ($secStage1->validate()) { //TODO: javascript thing also //TODO: before displaying make sure pament method is set accoding to wallet money and total value //TODO: and discount and cash back value should be rest user should press verify to set them. //TODO: things to make order confirmed $transaction1 = Yii::app()->db->beginTransaction(); try { $currDateTime1 = new DateTime(); $currDateTime1 = $currDateTime1->format('Y-m-d H:i:s'); foreach ($secStage1->tiffinPriceTimeSelectionArr as $key3 => $value3) { /* @var $value3 TiffinPriceTimeSelectionForm */ /* @var $aOrderObj $currOrder */ $currOrder = $value3->aOrderObj; $currOrder->total_price = $value3->totalPrice; $currOrder->per_unit_price = $value3->perUnitPrice; $currOrder->order2price_time = $value3->selectedPriceTimeId; if (!AppCommon::isEmpty($secStage1->couponCode)) { $currOrder->applied_offer_id = $secStage1->couponCode; if ($secStage1->billArray[1] != 0) { $currOrder->applied_order_amount = $secStage1->billArray[1]; } else { if ($secStage1->billArray[2] != 0) { $currOrder->applied_order_amount = $secStage1->billArray[2]; } } } $currOrder->order_pickup_time = $value3->selectedAPriceTimeObj->order_pickup_time; $currOrder->order_delivery_time = $value3->selectedAPriceTimeObj->order_delivery_time; $currOrder->wallet_amount_used = $secStage1->amountUsedFromWallet; if ($secStage1->paymentMethod == 1) { //order_start -> wallet -> order_confirmed $currOrder->payment_mode = 'wallet'; AppCommon::createOrderHistoryRecord($currOrder->id, 'wallet', $currDateTime1, $currOrder->order_unique_id); AppCommon::createOrderHistoryRecord($currOrder->id, 'order_confirmed', $currDateTime1, $currOrder->order_unique_id); $currOrder->status = 'order_confirmed'; $currOrder->last_status_update = $currDateTime1; } else { if ($secStage1->paymentMethod == 2) { throw new Exception(); //order_start -> online_payment -> awaiting_payment_confirmation -> payment_received -> order_confirmed/ order_failed $currOrder->payment_mode = 'online_payment'; AppCommon::createOrderHistoryRecord($currOrder->id, 'online_payment', $currDateTime1, $currOrder->order_unique_id); AppCommon::createOrderHistoryRecord($currOrder->id, 'awaiting_payment_confirmation', $currDateTime1, $currOrder->order_unique_id); } else { if ($secStage1->paymentMethod == 3) { //order_start -> cod -> awaiting_order_verification -> order_confirmed $currOrder->payment_mode = 'cod'; AppCommon::createOrderHistoryRecord($currOrder->id, 'cod', $currDateTime1, $currOrder->order_unique_id); AppCommon::createOrderHistoryRecord($currOrder->id, 'awaiting_order_verification', $currDateTime1, $currOrder->order_unique_id); AppCommon::createOrderHistoryRecord($currOrder->id, 'order_confirmed', $currDateTime1, $currOrder->order_unique_id); $currOrder->status = 'order_confirmed'; $currOrder->last_status_update = $currDateTime1; } } } $currOrder->save(); } if ($secStage1->paymentMethod == 1) { //deduct money from wallet if wallet used AppCommonWallet::debitAmountFromWallet($secStage1->amountUsedFromWallet, 'order_creation', $currDateTime1, $secStage1->orderId, 'wallet', $secStage1->userId); } else { if ($secStage1->paymentMethod == 3) { //deduct money from wallet if wallet used AppCommonWallet::debitAmountFromWallet($secStage1->amountUsedFromWallet, 'order_creation', $currDateTime1, $secStage1->orderId, 'wallet', $secStage1->userId); } } $transaction1->commit(); } catch (Exception $e) { Yii::ankFileSave($e->getMessage()); $transaction1->rollback(); $this->render('cart_error', array('errorMessage' => "Order could not be created.", 'link' => CHtml::normalizeUrl(array('cart/checkout', 'id' => $secStage1->encryptedOrderId)))); Yii::app()->end(); } $orderViewLink = Yii::app()->getRequest()->getHostInfo() . Yii::app()->getRequest()->getScriptUrl() . '/order/view/id/' . $secStage1->encryptedOrderId; Yii::ankFileSave("order links"); Yii::ankFileSave($orderViewLink); $subject_email = "tw.in Order Confirmation order no. " . $secStage1->orderId; $content_user = "******" . Yii::app()->user->name . ",\n" . "Your order no. " . $secStage1->orderId . " has been accepted. The url containing details of your order is \n\n\n" . $orderViewLink . "\n\n\n We will deliver the order by as per your selected time. We may call you for asking directions, if needed." . " Kindly receive the calls to make us deliver quickly. \nThanks and regards, \nTiffinwale.in team "; //notify customer AppCommon::sendEmail(AppCommon::getEmail(), Yii::app()->user->name, $subject_email, $content_user, array("order_notification_customer")); //notify tw team AppCommon::sendEmail(Yii::app()->params['adminEmail'], Yii::app()->user->name, $subject_email, $content_user, array("order_notification_tiffinwale.in_team")); $content_sms = "Dear Customer, we have received your order no. " . $secStage1->orderId . ". For more details click " . CHtml::encode($orderViewLink) . " or view email" . " Thanks! tw.in"; /*$content_sms = "Dear Customer, we have received your order from". " and it will be delivered between 12:30 PM to 2:00 PM. Thank You! tw.in";*/ //sms customer AppCommon::sendSmsOnTime($secStage1->tiffinPriceTimeSelectionArr[0]->aOrderObj->destination_phone, $content_sms, "null", true); AppCommon::sendSmsOnTime('9999999999', $content_sms, "null", true); //redirect to view order details Yii::app()->getRequest()->redirect($orderViewLink); //TODO: price time and cart value decrease Yii::app()->end(); //stop here } $this->render('checkout_second_stage', array('model' => $secStage1)); } else { $this->render('cart_error', array('errorMessage' => "Few security issues has been detected with this request.", 'link' => CHtml::normalizeUrl(array('site/index')))); Yii::app()->end(); } } }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return AOrder the loaded model * @throws CHttpException */ public function loadModel($id) { $model = AOrder::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }