public function execute() { if (!$this->getUser()->getRights('shop', 'settings')) { throw new waRightsException(_w('Access denied')); } $model = new shopPluginModel(); $this->view->assign('instances', $model->listPlugins(shopPluginModel::TYPE_PAYMENT, array('all' => true))); $this->view->assign('plugins', waPayment::enumerate()); $this->view->assign('installer', $this->getUser()->getRights('installer', 'backend')); }
public function backendOrders() { $view = wa()->getView(); $plugin_model = new shopPluginModel(); $workflow = new shopWorkflow(); $view->assign('states', $workflow->getAvailableStates()); $view->assign('payments', $plugin_model->listPlugins(shopPluginModel::TYPE_PAYMENT)); $view->assign('shippings', $plugin_model->listPlugins(shopPluginModel::TYPE_SHIPPING)); return array('sidebar_section' => $view->fetch($this->path . '/templates/actions/backend/BackendOrders.html')); }
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() { if (!$this->getUser()->getRights('shop', 'settings')) { throw new waRightsException(_w('Access denied')); } $model = new shopPluginModel(); $this->view->assign('instances', $model->listPlugins(shopPluginModel::TYPE_SHIPPING, array('all' => true))); $this->view->assign('plugins', shopShipping::getList()); $feature_model = new shopFeatureModel(); $this->view->assign('no_weight', $feature_model->getByCode('weight') ? false : true); $this->view->assign('installer', $this->getUser()->getRights('installer', 'backend')); }
public function execute() { if (!$this->getUser()->getRights('shop', 'settings')) { throw new waRightsException(_w('Access denied')); } $id = waRequest::post('module_id', 0, waRequest::TYPE_INT); $after_id = waRequest::post('after_id', 0, waRequest::TYPE_INT); $model = new shopPluginModel(); try { $model->move($id, $after_id, shopPluginModel::TYPE_SHIPPING); } catch (waException $e) { $this->setError($e->getMessage()); } }
public function execute() { if (!$this->getUser()->getRights('shop', 'settings')) { throw new waRightsException(_w('Access denied')); } if ($plugin_id = waRequest::post('plugin_id')) { $model = new shopPluginModel(); if ($plugin = $model->getByField(array('id' => $plugin_id, 'type' => 'shipping'))) { $model->deleteById($plugin['id']); } else { throw new waException("Shipping plugin {$plugin_id} not found", 404); } } }
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))); }
/** * Get custom params of order * @param array|int $ids order ID * @return array params in key=>value format */ public function get($ids, $full = false) { if (!$ids) { return array(); } $params = array(); $payment = $shipping = array(); $plugin_model = new shopPluginModel(); foreach ($this->getByField('order_id', $ids, true) as $p) { $params[$p['order_id']][$p['name']] = $p['value']; if ($full) { if ($p['name'] == 'shipping_id' && $p['value']) { if (!isset($shipping[$p['value']])) { $shipping[$p['value']] = $plugin_model->getById($p['value']); } if (!empty($shipping[$p['value']])) { $params[$p['order_id']]['shipping_description'] = $shipping[$p['value']]['description']; } else { $params[$p['order_id']]['shipping_description'] = ''; } } if ($p['name'] == 'payment_id' && $p['value']) { if (!isset($payment[$p['value']])) { $payment[$p['value']] = $plugin_model->getById($p['value']); } if (!empty($payment[$p['value']])) { $params[$p['order_id']]['payment_description'] = $payment[$p['value']]['description']; } else { $params[$p['order_id']]['payment_description'] = ''; } } } } if (is_numeric($ids)) { $params = isset($params[$ids]) ? $params[$ids] : array(); } else { foreach ($ids as $id) { if (!isset($params[$id])) { $params[$id] = array(); } } } return $params; }
public static function savePlugin($plugin) { $default = array('status' => 0); $plugin = array_merge($default, $plugin); if (!intval(ifempty($plugin['id'])) && isset($plugin['settings'])) { $instance = waShipping::factory($plugin['plugin'], null, self::getInstance()); $instance->saveSettings($plugin['settings']); } $model = new shopPluginModel(); if (!empty($plugin['id']) && ($id = max(0, intval($plugin['id']))) && ($row = $model->getByField(array('id' => $id, 'type' => shopPluginModel::TYPE_SHIPPING)))) { $plugin['plugin'] = $row['plugin']; $model->updateById($plugin['id'], $plugin); } elseif (!empty($plugin['plugin'])) { $plugin['type'] = shopPluginModel::TYPE_SHIPPING; $plugin['id'] = $model->insert($plugin); } if (!empty($plugin['id']) && isset($plugin['settings'])) { $instance = waShipping::factory($plugin['plugin'], $plugin['id'], self::getInstance()); $instance->saveSettings($plugin['settings']); } return $plugin; }
public function display() { $settings = wa('shop')->getConfig()->getCheckoutSettings(); if (!empty($settings['confirmation']['terms']) && waRequest::get('terms')) { echo $settings['confirmation']['terms']; exit; } $cart = new shopCart(); $items = $cart->items(false); $subtotal = $cart->total(false); $order = array('contact' => $this->getContact(), 'total' => $subtotal, 'items' => $items); $order['discount'] = shopDiscounts::calculate($order); $contact = $this->getContact(); $view = wa()->getView(); if (!$contact) { $view->assign('error', _w('Not enough data in the contact information to place the order.')); return; } $shipping_address = $contact->getFirst('address.shipping'); if (!$shipping_address) { $shipping_address = array('data' => array(), 'value' => ''); } $billing_address = $contact->getFirst('address.billing'); if (!$billing_address) { $billing_address = array('data' => array(), 'value' => ''); } $discount_rate = (double) $subtotal ? $order['discount'] / $subtotal : 0; $taxes = shopTaxes::apply($items, array('shipping' => $shipping_address['data'], 'billing' => $billing_address['data'], 'discount_rate' => $discount_rate)); $tax = 0; $tax_included = 0; foreach ($taxes as $t) { if (isset($t['sum'])) { $tax += $t['sum']; } if (isset($t['sum_included'])) { $tax_included += $t['sum_included']; } } if (!isset($order['shipping'])) { $shipping_step = new shopOnestepCheckoutShipping(); $rate = $shipping_step->getRate(); if ($rate) { $order['shipping'] = $rate['rate']; } else { $order['shipping'] = 0; } } $plugin_model = new shopPluginModel(); $params = array(); if ($shipping = $this->getSessionData('shipping')) { $params['shipping_id'] = $shipping['id']; if ($shipping['id']) { $plugin_info = $plugin_model->getById($shipping['id']); $params['shipping_rate_id'] = $shipping['rate_id']; $params['shipping_name'] = $shipping['name']; $params['shipping_description'] = $plugin_info['description']; } } if ($payment_id = $this->getSessionData('payment')) { $params['payment_id'] = $payment_id; $plugin_info = $plugin_model->getById($payment_id); $params['payment_name'] = $plugin_info['name']; $params['payment_plugin'] = $plugin_info['plugin']; $params['payment_description'] = $plugin_info['description']; } $view->assign(array('params' => $params, 'contact' => $contact, 'items' => $items, 'shipping' => $order['shipping'], 'discount' => $order['discount'], 'total' => $subtotal - $order['discount'] + $order['shipping'] + $tax, 'tax' => $tax_included + $tax, 'subtotal' => $subtotal, 'shipping_address' => $shipping_address, 'billing_address' => !empty($settings['contactinfo']['fields']['address.billing']) ? $billing_address : false, 'terms' => !empty($settings['confirmation']['terms']) ? $settings['confirmation']['terms'] : false)); $checkout_flow = new shopCheckoutFlowModel(); $step_number = shopOnestepCheckout::getStepNumber('confirmation'); // IF no errors $checkout_flow->add(array('step' => $step_number)); // ELSE // $checkout_flow->add(array( // 'step' => $step_number, // 'description' => ERROR MESSAGE HERE // )); }
<?php $model = new waModel(); $plugin_model = new shopPluginModel(); $plugings = $plugin_model->getByField('plugin', 'invoicejur', true); if ($plugings) { foreach ($plugings as $p) { $settings = $model->query("SELECT name, value FROM shop_plugin_settings WHERE id = i:0", $p['id'])->fetchAll('name', true); $company = !empty($settings['cust_company']) ? $settings['cust_company'] : 'company'; $inn = !empty($settings['cust_inn']) ? $settings['cust_inn'] : 'inn'; $model->exec("UPDATE shop_order_params SET name = 'payment_params_" . $company . "' WHERE name = 'billing_" . $company . "'"); $model->exec("UPDATE shop_order_params SET name = 'payment_params_" . $inn . "' WHERE name = 'billing_" . $inn . "'"); } }
protected function createOrder() { $checkout_data = wa()->getStorage()->get('shop/checkout'); if (wa()->getUser()->isAuth()) { $contact = wa()->getUser(); } else { if (!empty($checkout_data['contact']) && $checkout_data['contact'] instanceof waContact) { $contact = $checkout_data['contact']; } else { $contact = new waContact(); } } $cart = new shopCart(); $items = $cart->items(false); // remove id from item foreach ($items as &$item) { unset($item['id']); unset($item['parent_id']); } unset($item); $order = array('contact' => $contact, 'items' => $items, 'total' => $cart->total(false), 'params' => isset($checkout_data['params']) ? $checkout_data['params'] : array()); $order['discount_description'] = null; $order['discount'] = shopDiscounts::apply($order, $order['discount_description']); if (isset($checkout_data['shipping'])) { $order['params']['shipping_id'] = $checkout_data['shipping']['id']; $order['params']['shipping_rate_id'] = $checkout_data['shipping']['rate_id']; $shipping_step = new shopOnestepCheckoutShipping(); $rate = $shipping_step->getRate($order['params']['shipping_id'], $order['params']['shipping_rate_id']); $order['params']['shipping_plugin'] = $rate['plugin']; $order['params']['shipping_name'] = $rate['name']; if (isset($rate['est_delivery'])) { $order['params']['shipping_est_delivery'] = $rate['est_delivery']; } if (!isset($order['shipping'])) { $order['shipping'] = $rate['rate']; } if (!empty($order['params']['shipping'])) { foreach ($order['params']['shipping'] as $k => $v) { $order['params']['shipping_params_' . $k] = $v; } unset($order['params']['shipping']); } } else { $order['shipping'] = 0; } if (isset($checkout_data['payment'])) { $order['params']['payment_id'] = $checkout_data['payment']; $plugin_model = new shopPluginModel(); $plugin_info = $plugin_model->getById($checkout_data['payment']); $order['params']['payment_name'] = $plugin_info['name']; $order['params']['payment_plugin'] = $plugin_info['plugin']; if (!empty($order['params']['payment'])) { foreach ($order['params']['payment'] as $k => $v) { $order['params']['payment_params_' . $k] = $v; } unset($order['params']['payment']); } } if ($skock_id = waRequest::post('stock_id')) { $order['params']['stock_id'] = $skock_id; } $routing_url = wa()->getRouting()->getRootUrl(); $order['params']['storefront'] = wa()->getConfig()->getDomain() . ($routing_url ? '/' . $routing_url : ''); if ($ref = waRequest::cookie('referer')) { $order['params']['referer'] = $ref; $ref_parts = @parse_url($ref); $order['params']['referer_host'] = $ref_parts['host']; // try get search keywords if (!empty($ref_parts['query'])) { $search_engines = array('text' => 'yandex\\.|rambler\\.', 'q' => 'bing\\.com|mail\\.|google\\.', 's' => 'nigma\\.ru', 'p' => 'yahoo\\.com'); $q_var = false; foreach ($search_engines as $q => $pattern) { if (preg_match('/(' . $pattern . ')/si', $ref_parts['host'])) { $q_var = $q; break; } } // default query var name if (!$q_var) { $q_var = 'q'; } parse_str($ref_parts['query'], $query); if (!empty($query[$q_var])) { $order['params']['keyword'] = $query[$q_var]; } } } if ($utm = waRequest::cookie('utm')) { $utm = json_decode($utm, true); if ($utm && is_array($utm)) { foreach ($utm as $k => $v) { $order['params']['utm_' . $k] = $v; } } } if (($landing = waRequest::cookie('landing')) && ($landing = @parse_url($landing))) { if (!empty($landing['query'])) { @parse_str($landing['query'], $arr); if (!empty($arr['gclid']) && !empty($order['params']['referer_host']) && strpos($order['params']['referer_host'], 'google') !== false) { $order['params']['referer_host'] .= ' (cpc)'; $order['params']['cpc'] = 1; } else { if (!empty($arr['_openstat']) && !empty($order['params']['referer_host']) && strpos($order['params']['referer_host'], 'yandex') !== false) { $order['params']['referer_host'] .= ' (cpc)'; $order['params']['openstat'] = $arr['_openstat']; $order['params']['cpc'] = 1; } } } $order['params']['landing'] = $landing['path']; } // A/B tests /* $abtest_variants_model = new shopAbtestVariantsModel(); foreach (waRequest::cookie() as $k => $v) { if (substr($k, 0, 5) == 'waabt') { $variant_id = $v; $abtest_id = substr($k, 5); if (wa_is_int($abtest_id) && wa_is_int($variant_id)) { $row = $abtest_variants_model->getById($variant_id); if ($row && $row['abtest_id'] == $abtest_id) { $order['params']['abt' . $abtest_id] = $variant_id; } } } } */ $order['params']['ip'] = waRequest::getIp(); $order['params']['user_agent'] = waRequest::getUserAgent(); foreach (array('shipping', 'billing') as $ext) { $address = $contact->getFirst('address.' . $ext); if ($address) { foreach ($address['data'] as $k => $v) { $order['params'][$ext . '_address.' . $k] = $v; } } } if (isset($checkout_data['comment'])) { $order['comment'] = $checkout_data['comment']; } $workflow = new shopWorkflow(); if ($order_id = $workflow->getActionById('create')->run($order)) { $step_number = shopOnestepCheckout::getStepNumber(); $checkout_flow = new shopCheckoutFlowModel(); $checkout_flow->add(array('step' => $step_number)); $cart->clear(); wa()->getStorage()->remove('shop/checkout'); wa()->getStorage()->set('shop/order_id', $order_id); return $order_id; } else { return false; } }
/** * Returns available shipping methods and rates for specified address. * * @param array $address Address data * @param array $items Order items * @param array $params Optional extra parameters: * 'payment' => [int] payment method id for which available shipping methods must be returned * 'currency' => [string] currency code to convert shipping rates to * 'total_price' => [float] arbitrary total order items cost to be taken into account for obtaining shipping rates * @return array */ public static function getShippingMethods($address = null, $items = array(), $params = array()) { $plugin_model = new shopPluginModel(); $options = array(); if (!empty($params[shopPluginModel::TYPE_PAYMENT])) { $options[shopPluginModel::TYPE_PAYMENT] = $params[shopPluginModel::TYPE_PAYMENT]; } $methods = $plugin_model->listPlugins(shopPluginModel::TYPE_SHIPPING, $options); if ($address !== null) { $config = wa('shop')->getConfig(); /** * @var $config shopConfig */ $result = array(); $currency = isset($params['currency']) ? $params['currency'] : $config->getCurrency(); $dimensions = shopDimension::getInstance(); foreach ($methods as $m) { if ($m['available']) { $plugin = shopShipping::getPlugin($m['plugin'], $m['id']); $plugin_info = $plugin->info($m['plugin']); $plugin_currency = (array) $plugin->allowedCurrency(); $total = null; if ($plugin_currency != $currency) { if (!$config->getCurrencies($plugin_currency)) { $result[$m['id']] = array('plugin' => $m['plugin'], 'logo' => $m['logo'], 'icon' => $plugin_info['icon'], 'img' => $plugin_info['img'], 'name' => $m['name'], 'error' => sprintf(_w('Shipping rate was not calculated because required currency %s is not defined in your store settings.'), implode(', ', $plugin_currency)), 'rate' => '', 'currency' => $currency); continue; } } if (isset($params['total_price'])) { if (!in_array($currency, $plugin_currency)) { $total = shop_currency($params['total_price'], $currency, reset($plugin_currency), false); } else { $total = $params['total_price']; } } else { foreach ($items as $item) { if (!empty($item['price'])) { $total += $item['price'] * (isset($item['quantity']) ? $item['quantity'] : 1); } if ($total && !in_array($currency, $plugin_currency)) { $total = shop_currency($total, $currency, reset($plugin_currency), false); } } } $weight_unit = $plugin->allowedWeightUnit(); foreach ($items as &$item) { if (!empty($item['weight'])) { $item['weight'] = $dimensions->convert($item['weight'], 'weight', $weight_unit); } } unset($item); $rates = $plugin->getRates($items, $address ? $address : array(), $total ? array('total_price' => $total) : array()); if (is_array($rates)) { foreach ($rates as $rate_id => $info) { if (is_array($info)) { $rate = is_array($info['rate']) ? max($info['rate']) : $info['rate']; $rate = (double) shop_currency($rate, reset($plugin_currency), $currency, false); $result[$m['id'] . '.' . $rate_id] = array('plugin' => $m['plugin'], 'logo' => $m['logo'], 'icon' => $plugin_info['icon'], 'img' => $plugin_info['img'], 'name' => $m['name'] . (!empty($info['name']) ? ' (' . $info['name'] . ')' : ''), 'rate' => $rate, 'currency' => $currency); } } } elseif (is_string($rates)) { $result[$m['id']] = array('plugin' => $m['plugin'], 'logo' => $m['logo'], 'icon' => $plugin_info['icon'], 'img' => $plugin_info['img'], 'name' => $m['name'], 'error' => $rates, 'rate' => '', 'currency' => $currency); } } } return $result; } else { return $methods; } }
/** * Verify that the plugin is suitable for payment of the order * @param int $order_id * @return bool|string */ private function isSuitable($order_id) { $order_params_model = new shopOrderParamsModel(); if (!$this->merchant_id) { return 'Invalid plugin id'; } else { if ($this->merchant_id != $order_params_model->getOne($order_id, 'payment_id')) { return 'Plugin does not suitable to payment of the order'; } $shop_plugin_model = new shopPluginModel(); if ($plugin = $shop_plugin_model->getById($this->merchant_id)) { if (!$plugin['status']) { return 'Plugin status is disabled'; } } else { return 'Plugin deleted'; } } return true; }
public function shipping() { $plugin_model = new shopPluginModel(); return $plugin_model->listPlugins('shipping'); }
private function getParams(&$data, $id) { $model = new shopPluginModel(); $shipping_address = array(); if (!empty($data['contact'])) { $address = $data['contact']->getFirst('address.shipping'); if (!$address) { $address = $data['contact']->getFirst('address'); } if (!empty($address['data'])) { $shipping_address = $address['data']; } } $empty_address = false; // shipping if ($shipping_id = waRequest::post('shipping_id')) { $shipping_parts = explode('.', $shipping_id); $shipping_id = $shipping_parts[0]; $rate_id = isset($shipping_parts[1]) ? $shipping_parts[1] : ''; $data['params']['shipping_id'] = $shipping_id; $data['params']['shipping_rate_id'] = $rate_id; $plugin_info = $model->getById($shipping_id); $plugin = shopShipping::getPlugin($plugin_info['plugin'], $shipping_id); $rates = $plugin->getRates($this->getOrderItems($data['items'], $plugin->allowedWeightUnit()), $shipping_address); // save address if ($plugin->allowedAddress() === false) { $empty_address = true; } if (!$rates) { $this->errors['order']['common'] = _w('Unknown region for delivery'); return; } if (!$rate_id) { $rate = reset($rates); $data['params']['shipping_rate_id'] = key($rates); } else { $rate = $rates[$rate_id]; } $data['params']['shipping_plugin'] = $plugin->getId(); $data['params']['shipping_name'] = $plugin_info['name'] . (!empty($rate['name']) ? ' (' . $rate['name'] . ')' : ''); $data['params']['shipping_est_delivery'] = $rate['est_delivery']; if (waRequest::post('shipping' . $shipping_id)) { foreach (waRequest::post('shipping_' . $shipping_id) as $k => $v) { $data['params']['shipping_params_' . $k] = $v; } } } else { foreach (array('id', 'rate_id', 'plugin', 'name', 'est_delivery') as $k) { $data['params']['shipping_' . $k] = null; } } // payment if ($payment_id = waRequest::post('payment_id')) { $data['params']['payment_id'] = $payment_id; $plugin_info = $model->getById($payment_id); $data['params']['payment_plugin'] = $plugin_info['plugin']; $data['params']['payment_name'] = $plugin_info['name']; if (waRequest::post('payment_' . $payment_id)) { foreach (waRequest::post('payment_' . $payment_id) as $k => $v) { $data['params']['payment_params_' . $k] = $v; } } } // shipping and billing addreses if (!empty($data['contact'])) { // Make sure all old address data is removed if ($id) { $opm = new shopOrderParamsModel(); foreach ($opm->get($id) as $k => $v) { if (preg_match('~^(billing|shipping)_address\\.~', $k)) { $data['params'][$k] = null; } } } if (!$empty_address && $this->shipping_address) { foreach ($this->shipping_address as $k => $v) { $data['params']['shipping_address.' . $k] = $v; } } if ($this->billing_address) { foreach ($this->billing_address as $k => $v) { $data['params']['billing_address.' . $k] = $v; } } } }
public function getRate($id = null, $rate_id = null, $contact = null) { if (!$id) { $shipping = $this->getSessionData('shipping'); if (!$shipping) { return array(); } $id = $shipping['id']; $rate_id = $shipping['rate_id']; } if (!$contact) { $contact = $this->getContact(); } $plugin_model = new shopPluginModel(); $plugin_info = $plugin_model->getById($id); $plugin = shopShipping::getPlugin($plugin_info['plugin'], $id); $cart = new shopCart(); $total = $cart->total(); $currency = $plugin->allowedCurrency(); $currrent_currency = wa()->getConfig()->getCurrency(false); if ($currency != $currrent_currency) { $total = shop_currency($total, $currrent_currency, $currency, false); } $rates = $plugin->getRates($this->getItems($plugin->allowedWeightUnit()), $this->getAddress($contact), array('total_price' => $total)); if (!$rates) { return false; } if (is_string($rates)) { return $rates; } if ($rate_id) { $result = $rates[$rate_id]; } else { $result = array('rate' => 0); } if (is_array($result['rate'])) { $result['rate'] = max($result['rate']); } if ($currency != $currrent_currency) { $result['rate'] = shop_currency($result['rate'], $currency, $currrent_currency, false); } $result['plugin'] = $plugin->getId(); $result['name'] = $plugin_info['name'] . (!empty($result['name']) ? ' (' . $result['name'] . ')' : ''); return $result; }
protected function createOrder() { $checkout_data = $this->getStorage()->get('shop/checkout'); $contact = $this->getUser()->isAuth() ? $this->getUser() : $checkout_data['contact']; $cart = new shopCart(); $items = $cart->items(false); // remove id from item foreach ($items as &$item) { unset($item['id']); unset($item['parent_id']); } unset($item); $order = array('contact' => $contact, 'items' => $items, 'total' => $cart->total(false), 'params' => isset($checkout_data['params']) ? $checkout_data['params'] : array()); $order['discount'] = shopDiscounts::apply($order); if (isset($checkout_data['shipping'])) { $order['params']['shipping_id'] = $checkout_data['shipping']['id']; $order['params']['shipping_rate_id'] = $checkout_data['shipping']['rate_id']; $shipping_step = new shopCheckoutShipping(); $rate = $shipping_step->getRate($order['params']['shipping_id'], $order['params']['shipping_rate_id']); $order['params']['shipping_plugin'] = $rate['plugin']; $order['params']['shipping_name'] = $rate['name']; if (isset($rate['est_delivery'])) { $order['params']['shipping_est_delivery'] = $rate['est_delivery']; } if (!isset($order['shipping'])) { $order['shipping'] = $rate['rate']; } if (!empty($order['params']['shipping'])) { foreach ($order['params']['shipping'] as $k => $v) { $order['params']['shipping_params_' . $k] = $v; } unset($order['params']['shipping']); } } else { $order['shipping'] = 0; } if (isset($checkout_data['payment'])) { $order['params']['payment_id'] = $checkout_data['payment']; $plugin_model = new shopPluginModel(); $plugin_info = $plugin_model->getById($checkout_data['payment']); $order['params']['payment_name'] = $plugin_info['name']; $order['params']['payment_plugin'] = $plugin_info['plugin']; if (!empty($order['params']['payment'])) { foreach ($order['params']['payment'] as $k => $v) { $order['params']['payment_params_' . $k] = $v; } unset($order['params']['payment']); } } if ($skock_id = waRequest::post('stock_id')) { $order['params']['stock_id'] = $skock_id; } $routing_url = wa()->getRouting()->getRootUrl(); $order['params']['storefront'] = wa()->getConfig()->getDomain() . ($routing_url ? '/' . $routing_url : ''); if (($ref = wa()->getStorage()->get('shop/referer')) || ($ref = waRequest::cookie('referer'))) { $order['params']['referer'] = $ref; $ref_parts = parse_url($ref); $order['params']['referer_host'] = $ref_parts['host']; // try get search keywords if (!empty($ref_parts['query'])) { $search_engines = array('text' => 'yandex\\.|rambler\\.', 'q' => 'bing\\.com|mail\\.|google\\.', 's' => 'nigma\\.ru', 'p' => 'yahoo\\.com'); $q_var = false; foreach ($search_engines as $q => $pattern) { if (preg_match('/(' . $pattern . ')/si', $ref_parts['host'])) { $q_var = $q; break; } } // default query var name if (!$q_var) { $q_var = 'q'; } parse_str($ref_parts['query'], $query); if (!empty($query[$q_var])) { $order['params']['keyword'] = $query[$q_var]; } } } if ($utm = waRequest::cookie('utm')) { $utm = json_decode($utm, true); if ($utm && is_array($utm)) { foreach ($utm as $k => $v) { $order['params']['utm_' . $k] = $v; } } } $order['params']['ip'] = waRequest::getIp(); $order['params']['user_agent'] = waRequest::getUserAgent(); foreach (array('shipping', 'billing') as $ext) { $address = $contact->getFirst('address.' . $ext); if ($address) { foreach ($address['data'] as $k => $v) { $order['params'][$ext . '_address.' . $k] = $v; } } } if (isset($checkout_data['comment'])) { $order['comment'] = $checkout_data['comment']; } $workflow = new shopWorkflow(); if ($order_id = $workflow->getActionById('create')->run($order)) { $step_number = shopCheckout::getStepNumber(); $checkout_flow = new shopCheckoutFlowModel(); $checkout_flow->add(array('step' => $step_number)); $cart->clear(); wa()->getStorage()->remove('shop/checkout'); wa()->getStorage()->set('shop/order_id', $order_id); return true; } }
/** * @param bool $all - return all available or only enabled steps * @return array */ public function getCheckoutSettings($all = false) { $all_steps = (include wa('shop')->getConfig()->getAppPath('lib/config/data/checkout.php')); // @todo: event to get all available steps from plugins if ($all) { return $all_steps; } $file = wa('shop')->getConfig()->getConfigPath('checkout.php', true, 'shop'); if (file_exists($file) && is_array($steps = (include $file))) { foreach ($steps as $step_id => &$step) { if (is_array($step)) { $step = $step + $all_steps[$step_id]; } elseif ($step) { $step = $all_steps[$step_id]; } else { unset($steps[$step_id]); } } } else { $steps = $all_steps; } $plugin_model = new shopPluginModel(); if (!$plugin_model->countByField('type', 'shipping') && isset($steps['shipping'])) { unset($steps['shipping']); } if (!$plugin_model->countByField('type', 'payment') && isset($steps['payment'])) { unset($steps['payment']); } reset($steps); return $steps; }