public function execute() { $code = waRequest::param('code'); $encoded_order_id = waRequest::param('id'); $order_id = shopHelper::decodeOrderId($encoded_order_id); if (!$order_id) { // fall back to non-encoded id $order_id = $encoded_order_id; $encoded_order_id = shopHelper::encodeOrderId($order_id); } if (!$order_id || $order_id != substr($code, 16, -16)) { throw new waException(_w('Order not found'), 404); } // When user is authorized, check if order belongs to him. // When it does, redirect to plain order page. if (wa()->getUser()->isAuth()) { $om = new shopOrderModel(); $order = $om->getOrder($order_id); if (!$order) { throw new waException(_w('Order not found'), 404); } if ($order['contact_id'] == wa()->getUser()->getId()) { $this->redirect(wa()->getRouteUrl('/frontend/myOrder', array('id' => $order_id))); } } // Check auth code $opm = new shopOrderParamsModel(); $params = $opm->get($order_id); if (ifset($params['auth_code']) !== $code || empty($params['auth_pin'])) { throw new waException(_w('Order not found'), 404); } // Check auth pin and show order page if pin is correct $pin = waRequest::request('pin', wa()->getStorage()->get('shop/pin/' . $order_id)); if ($pin && $pin == $params['auth_pin']) { wa()->getStorage()->set('shop/pin/' . $order_id, $pin); parent::execute(); if (!waRequest::isXMLHttpRequest()) { $this->layout->assign('breadcrumbs', self::getBreadcrumbs()); } return; } // // No pin or pin is incorrect: show form to enter pin // $this->view->assign('wrong_pin', !!$pin); $this->view->assign('pin_required', true); $this->view->assign('encoded_order_id', $encoded_order_id); $this->view->assign('my_nav_selected', 'orders'); // Set up layout and template from theme $this->setThemeTemplate('my.order.html'); if (!waRequest::isXMLHttpRequest()) { $this->setLayout(new shopFrontendLayout()); $this->getResponse()->setTitle(_w('Order') . ' ' . $encoded_order_id); $this->view->assign('breadcrumbs', self::getBreadcrumbs()); $this->layout->assign('nofollow', true); } }
public function execute() { $om = new shopOrderModel(); $encoded_order_id = waRequest::param('id'); $code = waRequest::param('code'); $order_id = shopHelper::decodeOrderId($encoded_order_id); if (!$order_id) { // fall back to non-encoded id $order_id = $encoded_order_id; $encoded_order_id = shopHelper::encodeOrderId($order_id); } $order = $om->getOrder($order_id); if (!$order) { throw new waException(_w('Order not found'), 404); } elseif (!$this->isAuth($order, $code)) { if ($code && $order_id != substr($code, 16, -16)) { throw new waException(_w('Order not found'), 404); } else { $redirect = array('id' => $order_id); if (!empty($code)) { $redirect['code'] = $code; } $url = $code ? '/frontend/myOrderByCode' : '/frontend/myOrder'; $this->redirect(wa()->getRouteUrl($url, $redirect)); } } elseif ($code && $order['contact_id'] == wa()->getUser()->getId()) { $redirect = array('id' => $order_id, 'form_type' => waRequest::param('form_type'), 'form_id' => waRequest::param('form_id')); $this->redirect(wa()->getRouteUrl('/frontend/myOrderPrintform', $redirect)); } $order_params_model = new shopOrderParamsModel(); $order['params'] = $order_params_model->get($order['id']); $order['id_str'] = $encoded_order_id; switch (waRequest::param('form_type')) { case 'payment': if (empty($order['params']['payment_id']) || !($payment = shopPayment::getPlugin(null, $order['params']['payment_id']))) { throw new waException(_w('Printform not found'), 404); } $form_id = waRequest::param('form_id'); $params = null; if (strpos($form_id, '.')) { $form = explode('.', $form_id, 2); $form_id = array_shift($form); $params = array_shift($form); } print $payment->displayPrintForm(ifempty($form_id, $payment->getId()), shopPayment::getOrderData($order, $payment), intval($params)); exit; break; default: throw new waException(_w('Printform not found'), 404); break; } }
public function execute() { $encoded_order_id = waRequest::param('id'); $order_id = shopHelper::decodeOrderId($encoded_order_id); if (!$order_id) { // fall back to non-encoded id $order_id = $encoded_order_id; $encoded_order_id = shopHelper::encodeOrderId($order_id); } $om = new shopOrderModel(); $order = $om->getOrder($order_id); if (!$order) { throw new waException(_w('Order not found'), 404); } if (!$this->isAuth($order)) { throw new waException(_w('The file will be available for download after the order is paid and processed.'), 404); } // Check auth code $opm = new shopOrderParamsModel(); $params = $opm->get($order_id); $code = waRequest::param('code'); if (ifset($params['auth_code']) !== $code) { throw new waException(_w('Order not found'), 404); } if ($item = ifempty($order['items'][waRequest::param('item')])) { $skus_model = new shopProductSkusModel(); $sku = $skus_model->getById(ifempty($item['sku_id'])); if ($sku['file_name'] && $sku['file_size']) { $file_path = shopProductSkusModel::getPath($sku); waFiles::readFile($file_path, $sku['file_name']); } else { throw new waException(_w('File not found'), 404); } } else { throw new waException(_w('Order item not found'), 404); } }
public function getOrder() { $id = (int) waRequest::get('id'); if (!$id) { return array(); } $order = $this->_getOrder($id); if (!$order) { $id = shopHelper::decodeOrderId($id); $order = $this->_getOrder($id); if (!$order) { return array(); } } return $order; }
public function ordersAutocomplete($q) { // search by: // 1. order_id, // 2. email, phone, firstname, lastname, name // 3. product, sku $limit = 3; // first, assume $q is encoded $order_id, so decode $dq = shopHelper::decodeOrderId($q); if (!$dq) { $dq = self::decodeOrderId($q); } if ($dq) { $orders = $this->getOrders($dq, $limit); } else { $orders = array(); } $cnt = count($orders); if ($cnt < $limit) { $orders = array_merge($orders, $this->getOrders($q, $limit - $cnt)); } foreach ($orders as &$o) { $o['autocomplete_item_type'] = 'order'; } unset($o); $contacts = $this->contactsAutocomplete($q, $limit); foreach ($contacts as &$c) { $c['autocomplete_item_type'] = 'contact'; $c['value'] = $c['name']; } unset($c); $products = $this->productsAutocomplete($q, $limit); foreach ($products as &$p) { $p['autocomplete_item_type'] = 'product'; if (empty($p['label'])) { $p['label'] = htmlspecialchars($p['value']); } $p['label'] .= ' ' . shopHelper::getStockCountIcon($p['count'], null, true); } $data = array_merge($orders, $contacts, $products); return $data; }
public function execute() { $id = waRequest::get('order_id'); if (!$id) { throw new waException("Unknown order", 404); } $order = $this->getOrder($id); if (!$order) { $id = shopHelper::decodeOrderId($id); $order = $this->getOrder($id); if (!$order) { throw new waException("Unkown order", 404); } } $product_ids = array(); foreach ($order['items'] as $item) { if ($item['type'] == 'product') { $product_ids[] = $item['product_id']; } } $product_ids = array_unique($product_ids); $form_id = waRequest::get('form_id'); if (strpos($form_id, '.')) { list($type, $form) = explode('.', $form_id, 2); } else { $form = null; $type = $form_id; } $order_params_model = new shopOrderParamsModel(); $params = $order_params_model->get($order['id']); $plugin = self::getPlugin($type, ifempty($params[$type . '_id'])); if ($type == 'shipping') { /* add weight info only for shipping modules */ $feature_model = new shopFeatureModel(); $f = $feature_model->getByCode('weight'); if (!$f) { $weights = array(); } else { $values_model = $feature_model->getValuesModel($f['type']); $weights = $values_model->getProductValues($product_ids, $f['id']); } if ($weights) { $dimension = shopDimension::getInstance()->getDimension('weight'); $weight_unit = $plugin->allowedWeightUnit(); $m = null; if ($weight_unit != $dimension['base_unit']) { $m = $dimension['units'][$weight_unit]['multiplier']; } foreach ($order['items'] as &$item) { if ($item['type'] == 'product') { if (isset($weights['skus'][$item['sku_id']])) { $w = $weights['skus'][$item['sku_id']]; } else { $w = isset($weights[$item['product_id']]) ? $weights[$item['product_id']] : 0; } if ($m !== null) { $w = $w / $m; } $item['weight'] = $w; } } unset($item); } } if (!$plugin) { throw new waException(_w('Printform not found'), 404); } print $plugin->displayPrintForm(ifempty($form, $plugin->getId()), shopPayment::getOrderData($order, $plugin)); exit; }
/** * * formalize order data * @param string|array $order order ID or order data * @param waPayment $payment_plugin * @return waOrder */ public static function getOrderData($order, $payment_plugin = null) { if (!is_array($order)) { $order_id = shopHelper::decodeOrderId($encoded_order_id = $order); if (!$order_id) { $order_id = $encoded_order_id; $encoded_order_id = shopHelper::encodeOrderId($order_id); } $om = new shopOrderModel(); $order = $om->getOrder($order_id); if (!$order) { return null; } $order['id_str'] = $encoded_order_id; } if (!isset($order['id_str'])) { $order['id_str'] = shopHelper::encodeOrderId($order['id']); } if (!isset($order['params'])) { $order_params_model = new shopOrderParamsModel(); $order['params'] = $order_params_model->get($order['id']); } $convert = false; if ($payment_plugin && method_exists($payment_plugin, 'allowedCurrency')) { $currency = $payment_plugin->allowedCurrency(); $total = $order['total']; $currency_id = $order['currency']; if ($currency !== true) { $currency = (array) $currency; if (!in_array($order['currency'], $currency)) { $convert = true; $total = shop_currency($total, $order['currency'], $currency_id = reset($currency), false); } } } else { $currency_id = $order['currency']; $total = $order['total']; } $items = array(); if (!empty($order['items'])) { foreach ($order['items'] as $item) { ifempty($item['price'], 0.0); if ($convert) { $item['price'] = shop_currency($item['price'], $order['currency'], $currency_id, false); } $items[] = array('id' => ifset($item['id']), 'name' => ifset($item['name']), 'sku' => ifset($item['sku_code']), 'description' => '', 'price' => $item['price'], 'quantity' => ifset($item['quantity'], 0), 'total' => $item['price'] * $item['quantity'], 'type' => ifset($item['type'], 'product'), 'product_id' => ifset($item['product_id'])); if (isset($item['weight'])) { $items[count($items) - 1]['weight'] = $item['weight']; } } } $empty_address = array('firstname' => '', 'lastname' => '', 'country' => '', 'region' => '', 'city' => '', 'street' => '', 'zip' => ''); $shipping_address = array_merge($empty_address, shopHelper::getOrderAddress($order['params'], 'shipping')); $billing_address = array_merge($empty_address, shopHelper::getOrderAddress($order['params'], 'billing')); if (!count(array_filter($billing_address, 'strlen'))) { $billing_address = $shipping_address; } ifset($order['shipping'], 0.0); ifset($order['discount'], 0.0); ifset($order['tax'], 0.0); if ($convert) { $order['tax'] = shop_currency($order['tax'], $order['currency'], $currency_id, false); $order['shipping'] = shop_currency($order['shipping'], $order['currency'], $currency_id, false); $order['discount'] = shop_currency($order['discount'], $order['currency'], $currency_id, false); } $order_data = array('id_str' => ifempty($order['id_str'], $order['id']), 'id' => $order['id'], 'contact_id' => $order['contact_id'], 'datetime' => ifempty($order['create_datetime']), 'description' => sprintf(_w('Payment for order %s'), ifempty($order['id_str'], $order['id'])), 'update_datetime' => ifempty($order['update_datetime']), 'paid_datetime' => empty($order['paid_date']) ? null : $order['paid_date'] . ' 00:00:00', 'total' => ifempty($total, $order['total']), 'currency' => ifempty($currency_id, $order['currency']), 'discount' => $order['discount'], 'tax' => $order['tax'], 'payment_name' => ifset($order['params']['payment_name'], ''), 'billing_address' => $billing_address, 'shipping' => $order['shipping'], 'shipping_name' => ifset($order['params']['shipping_name'], ''), 'shipping_address' => $shipping_address, 'items' => $items, 'comment' => ifempty($order['comment'], ''), 'params' => $order['params']); return waOrder::factory($order_data); }
public function execute() { $encoded_order_id = waRequest::param('id'); $order_id = shopHelper::decodeOrderId($encoded_order_id); if (!$order_id) { // fall back to non-encoded id $order_id = $encoded_order_id; $encoded_order_id = shopHelper::encodeOrderId($order_id); } // Check that order exists and belongs to this user $om = new shopOrderModel(); $order = $om->getOrder($order_id); if (!$order || !$this->isAuth($order)) { throw new waException(_w('Order not found'), 404); } if ($order['paid_date']) { foreach ($order['items'] as &$i) { if (!empty($i['file_name'])) { $i['download_link'] = wa()->getRouteUrl('/frontend/myOrderDownload', array('id' => $order['id'], 'code' => $order['params']['auth_code'], 'item' => $i['id']), true); } } unset($i); } $workflow = new shopWorkflow(); $order_params_model = new shopOrderParamsModel(); $order['params'] = $order_params_model->get($order['id']); $order['id_str'] = $encoded_order_id; $order['state'] = $workflow->getStateById($order['state_id']); // Order subtotal $subtotal = 0; foreach ($order['items'] as $item) { $subtotal += $item['price'] * $item['quantity']; } // Order comment $lm = new shopOrderLogModel(); $l = $lm->getByField(array('action_id' => 'create', 'order_id' => $order['id'])); $order['comment'] = ifempty($l['text']); $order['payment_name'] = ifset($order['params']['payment_name'], ''); $order['shipping_name'] = ifset($order['params']['shipping_name'], ''); // Shipping and billing addresses $settings = wa('shop')->getConfig()->getCheckoutSettings(); $form_fields = ifset($settings['contactinfo']['fields'], array()); $formatter = new waContactAddressSeveralLinesFormatter(); $shipping_address = shopHelper::getOrderAddress($order['params'], 'shipping'); if ($shipping_address) { $shipping_address = $formatter->format(array('data' => $shipping_address)); $shipping_address = $shipping_address['value']; } if (isset($form_fields['address.billing'])) { $billing_address = shopHelper::getOrderAddress($order['params'], 'billing'); $billing_address = $formatter->format(array('data' => $billing_address)); $billing_address = $billing_address['value']; } else { $billing_address = null; } if (wa()->getUser()->getId() == $order['contact_id']) { $contact = wa()->getUser(); } else { $contact = new waContact($order['contact_id']); } $payment = ''; if (!empty($order['params']['payment_id']) && !$order['paid_date']) { try { $plugin = shopPayment::getPlugin(null, $order['params']['payment_id']); $payment = $plugin->payment(waRequest::post(), shopPayment::getOrderData($order, $plugin), false); } catch (waException $ex) { $payment = $ex->getMessage(); } } $this->view->assign('payment', $payment); $tracking = ''; if (!empty($order['params']['shipping_id']) && !empty($order['params']['tracking_number'])) { try { $plugin = shopShipping::getPlugin(null, $order['params']['shipping_id']); $tracking = $plugin->tracking($order['params']['tracking_number']); } catch (waException $ex) { $tracking = $ex->getMessage(); } } $this->view->assign('tracking', $tracking); $this->view->assign('order', $order); $this->view->assign('contact', $contact); $this->view->assign('shipping_address', $shipping_address); $this->view->assign('billing_address', $billing_address); $this->view->assign('subtotal', $subtotal); // Set up layout and template from theme $this->setThemeTemplate('my.order.html'); $this->view->assign('my_nav_selected', 'orders'); if (!waRequest::isXMLHttpRequest()) { $this->setLayout(new shopFrontendLayout()); $this->getResponse()->setTitle(_w('Order') . ' ' . $encoded_order_id); $this->view->assign('breadcrumbs', self::getBreadcrumbs()); $this->layout->assign('nofollow', true); } }