public function display() { $plugin_model = new shopPluginModel(); if (waRequest::param('payment_id') && is_array(waRequest::param('payment_id'))) { $methods = $plugin_model->getById(waRequest::param('payment_id')); } else { $methods = $plugin_model->listPlugins('payment'); } $shipping = $this->getSessionData('shipping'); if ($shipping) { $disabled = shopHelper::getDisabledMethods('payment', $shipping['id']); } else { $disabled = array(); } $currencies = wa('shop')->getConfig()->getCurrencies(); $selected = null; foreach ($methods as $key => $m) { $method_id = $m['id']; if (in_array($method_id, $disabled)) { unset($methods[$key]); continue; } $plugin = shopPayment::getPlugin($m['plugin'], $m['id']); $plugin_info = $plugin->info($m['plugin']); $methods[$key]['icon'] = $plugin_info['icon']; $custom_fields = $this->getCustomFields($method_id, $plugin); $custom_html = ''; foreach ($custom_fields as $c) { $custom_html .= '<div class="wa-field">' . $c . '</div>'; } $methods[$key]['custom_html'] = $custom_html; $allowed_currencies = $plugin->allowedCurrency(); if ($allowed_currencies !== true) { $allowed_currencies = (array) $allowed_currencies; if (!array_intersect($allowed_currencies, array_keys($currencies))) { $methods[$key]['error'] = sprintf(_w('Payment procedure cannot be processed because required currency %s is not defined in your store settings.'), implode(', ', $allowed_currencies)); } } if (!$selected && empty($methods[$key]['error'])) { $selected = $method_id; } } $view = wa()->getView(); $view->assign('checkout_payment_methods', $methods); $view->assign('payment_id', $this->getSessionData('payment', $selected)); $checkout_flow = new shopCheckoutFlowModel(); $step_number = shopCheckout::getStepNumber('payment'); // IF no errors $checkout_flow->add(array('step' => $step_number)); // ELSE // $checkout_flow->add(array( // 'step' => $step_number, // 'description' => ERROR MESSAGE HERE // )); }
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() { if (!$this->getUser()->getRights('shop', 'settings')) { throw new waRightsException(_w('Access denied')); } $this->view->assign('plugin_id', $plugin_id = waRequest::get('plugin_id')); $this->view->assign('plugin', $info = shopPayment::getPluginInfo($plugin_id)); $plugin = shopPayment::getPlugin($info['plugin'], $plugin_id); $params = array('namespace' => "payment[settings]", 'value' => waRequest::post('shipping[settings]')); $this->view->assign('settings_html', $plugin->getSettingsHTML($params)); $this->view->assign('guide_html', $plugin->getGuide($params)); $model = new shopPluginModel(); $this->view->assign('shipping', $model->listPlugins(shopPluginModel::TYPE_SHIPPING, array('payment' => $plugin_id, 'all' => true))); }
/** * Returns array of print forms available for specified order. * * @param array|null $order Order data; if not specified, print forms applicable to any orders are returned * @return array */ public static function getPrintForms($order = null) { $plugins = wa('shop')->getConfig()->getPlugins(); foreach ($plugins as $id => $plugin) { if (empty($plugin['printform'])) { unset($plugins[$id]); } } if ($order) { $type = 'payment'; $key = ifempty($order['params'][$type . '_id']); try { if (!empty($key) && ($plugin = shopPayment::getPlugin(null, $key)) && method_exists($plugin, 'getPrintForms')) { $forms = $plugin->getPrintForms(shopPayment::getOrderData($order)); foreach ($forms as $id => $form) { $plugins["{$type}.{$id}"] = $form; } } } catch (waException $e) { } $type = 'shipping'; $key = ifempty($order['params'][$type . '_id']); try { if (!empty($key) && ($plugin = shopShipping::getPlugin(null, $key)) && method_exists($plugin, 'getPrintForms')) { $forms = $plugin->getPrintForms(shopPayment::getOrderData($order)); foreach ($forms as $id => $form) { $plugins["{$type}.{$id}"] = $form; } } } catch (waException $e) { } foreach ($plugins as $plugin_id => &$plugin) { if (strpos($plugin_id, '.')) { $plugin['url'] = "?module=order&action=printform&form_id={$plugin_id}&order_id={$order['id']}"; } else { $plugin['url'] = "?plugin={$plugin_id}&module=printform&action=display&order_id={$order['id']}"; } } unset($plugin); } //TODO separate backend & frontend return $plugins; }
public function execute() { $steps = $this->getConfig()->getCheckoutSettings(); $current_step = waRequest::param('step', waRequest::request('step')); if (!$current_step) { $current_step = key($steps); } $title = _w('Checkout'); if ($current_step == 'success') { $order_id = waRequest::get('order_id'); if (!$order_id) { $order_id = wa()->getStorage()->get('shop/order_id'); $payment_success = false; } else { $payment_success = true; $this->view->assign('payment_success', true); } if (!$order_id) { wa()->getResponse()->redirect(wa()->getRouteUrl('shop/frontend')); } $order_model = new shopOrderModel(); $order = $order_model->getById($order_id); if ($order) { $order['_id'] = $order['id']; } if (!$payment_success) { $order_params_model = new shopOrderParamsModel(); $order['params'] = $order_params_model->get($order_id); $order_items_model = new shopOrderItemsModel(); $order['items'] = $order_items_model->getByField('order_id', $order_id, true); $payment = ''; if (!empty($order['params']['payment_id'])) { try { /** * @var waPayment $plugin */ $plugin = shopPayment::getPlugin(null, $order['params']['payment_id']); $payment = $plugin->payment(waRequest::post(), shopPayment::getOrderData($order, $plugin), true); } catch (waException $ex) { $payment = $ex->getMessage(); } } $order['id'] = shopHelper::encodeOrderId($order_id); $this->getResponse()->addGoogleAnalytics($this->getGoogleAnalytics($order)); } else { $order['id'] = shopHelper::encodeOrderId($order_id); } $this->view->assign('order', $order); if (isset($payment)) { $this->view->assign('payment', $payment); } } else { $cart = new shopCart(); if (!$cart->count() && $current_step != 'error') { $current_step = 'error'; $this->view->assign('error', _w('Your shopping cart is empty. Please add some products to cart, and then proceed to checkout.')); } if ($current_step != 'error') { if (waRequest::method() == 'post') { if (waRequest::post('wa_auth_login')) { $login_action = new shopLoginAction(); $login_action->run(); } else { $redirect = false; foreach ($steps as $step_id => $step) { if ($step_id == $current_step) { $step_instance = $this->getStep($step_id); if ($step_instance->execute()) { $redirect = true; } } elseif ($redirect) { $this->redirect(wa()->getRouteUrl('/frontend/checkout', array('step' => $step_id))); } } // last step if ($redirect) { if ($this->createOrder()) { $this->redirect(wa()->getRouteUrl('/frontend/checkout', array('step' => 'success'))); } } } } else { $this->view->assign('error', ''); } $title .= ' - ' . $steps[$current_step]['name']; $steps[$current_step]['content'] = $this->getStep($current_step)->display(); $this->view->assign('checkout_steps', $steps); } } $this->getResponse()->setTitle($title); $this->view->assign('checkout_current_step', $current_step); /** * @event frontend_checkout * @return array[string]string $return[%plugin_id%] html output */ $event_params = array('step' => $current_step); $this->view->assign('frontend_checkout', wa()->event('frontend_checkout', $event_params)); if (waRequest::isXMLHttpRequest()) { $this->setThemeTemplate('checkout.' . $current_step . '.html'); } else { $this->setLayout(new shopFrontendLayout()); $this->setThemeTemplate('checkout.html'); } }
/** * * @param string $type * @param int $key * @return waSystemPlugin */ private static function getPlugin($type, $key) { $plugin = null; if ($key) { switch ($type) { case 'payment': $plugin = shopPayment::getPlugin(null, $key); break; case 'shipping': $plugin = shopShipping::getPlugin(null, $key); break; } } return $plugin; }
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); } }