public function execute() { $order_id = waRequest::post('order_id', null, waRequest::TYPE_INT); if ($order_id) { $order_model = new shopOrderModel(); $order = $order_model->getOrder($order_id); $customer_model = new shopCustomerModel(); $customer = $customer_model->getById($order['contact_id']); $customer_model->updateById($order['contact_id'], array('is_spamer' => 1)); $plugin = waSystem::getInstance()->getPlugin('orderantispam'); $action_id = $plugin->getSettings('action_id'); $workflow = new shopWorkflow(); $action = $workflow->getActionById($action_id); $action->run($order_id); // counters $state_counters = $order_model->getStateCounters(); $pending_counters = (!empty($state_counters['new']) ? $state_counters['new'] : 0) + (!empty($state_counters['processing']) ? $state_counters['processing'] : 0) + (!empty($state_counters['paid']) ? $state_counters['paid'] : 0); // update app coutner wa('shop')->getConfig()->setCount($state_counters['new']); $script = "<script>"; $script .= "\$.order_list.updateCounters(" . json_encode(array('state_counters' => $state_counters, 'common_counters' => array('pending_counters' => $pending_counters))) . ");"; $script .= "\$.order.reload();</script>"; $this->response['script'] = $script; } }
public function execute() { $lazy = waRequest::get('lazy', 0, waRequest::TYPE_INT); $offset = waRequest::get('offset', 0, waRequest::TYPE_INT); $limit = 30; $model = new shopDiscountcardsPluginOrderModel(); $sql = "SELECT count(*) " . $this->getSql(); $total_count = (int) $model->query($sql)->fetchField(); $sql = "SELECT * " . $this->getSql() . " LIMIT {$offset}, {$limit}"; $discountcards_orders = $model->query($sql)->fetchAll(); $discountcards_model = new shopDiscountcardsPluginModel(); $order_model = new shopOrderModel(); $workflow = new shopWorkflow(); foreach ($discountcards_orders as &$discountcards_order) { $order = $order_model->getOrder($discountcards_order['order_id']); $discountcards_order['order'] = $order; $discountcards_order['order_id_encode'] = shopHelper::encodeOrderId($order['id']); if ($discountcard = $discountcards_model->getByField('discountcard', $discountcards_order['discountcard'])) { $discountcards_order['_discountcard'] = $discountcard; } $discountcards_order['state'] = $workflow->getStateById($order['state_id']); } unset($discountcards_order); $this->view->assign(array('discountcards_orders' => $discountcards_orders, 'offset' => $offset, 'limit' => $limit, 'count' => count($discountcards_orders), 'total_count' => $total_count, 'lazy' => $lazy)); }
private function getOrder($order_id) { $order = $this->order_model->getOrder($order_id, true, true); if (!$order) { throw new waException("Unknow order", 404); } $order['shipping_id'] = ifset($order['params']['shipping_id'], '') . '.' . ifset($order['params']['shipping_rate_id'], ''); $sku_ids = array(); foreach ($order['items'] as $item) { foreach ($item['skus'] as $sku) { if (empty($sku['fake'])) { $sku_ids[] = $sku['id']; } } } $sku_stocks = $this->getSkuStocks(array_unique($sku_ids)); $subtotal = 0; $product_ids = array(); foreach ($order['items'] as $i) { $product_ids[] = $i['id']; $subtotal += $i['item']['price'] * $i['item']['quantity']; } $order['subtotal'] = $subtotal; $product_ids = array_unique($product_ids); $feature_model = new shopFeatureModel(); $f = $feature_model->getByCode('weight'); if (!$f) { $values = array(); } else { $values_model = $feature_model->getValuesModel($f['type']); $values = $values_model->getProductValues($product_ids, $f['id']); } foreach ($order['items'] as &$item) { if (isset($values['skus'][$item['item']['sku_id']])) { $w = $values['skus'][$item['item']['sku_id']]; } else { $w = isset($values[$item['id']]) ? $values[$item['id']] : 0; } $this->workupItems($item, $sku_stocks); $item['quantity'] = $item['item']['quantity']; $item['weight'] = $w; } unset($item); return $order; }
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() { $id = waRequest::get('id', null, waRequest::TYPE_INT); if ($id) { $model = new shopOrderModel(); if ($model->delete($id)) { $this->response = shopHelper::workupOrders($model->getOrder($id), 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() { $order_id = waRequest::get('order_id', null, waRequest::TYPE_INT); $customer_id = waRequest::get('customer_id', null, waRequest::TYPE_INT); $order_id = $order_id ? $order_id : null; $currency = waRequest::get('currency'); if (!$currency && $order_id) { $order_model = new shopOrderModel(); $order = $order_model->getOrder($order_id); $currency = $order['currency']; } $product_id = waRequest::get('product_id', 0, waRequest::TYPE_INT); if (!$product_id) { $this->errors[] = _w("Unknown product"); return; } $sku_id = waRequest::get('sku_id', 0, waRequest::TYPE_INT); if ($sku_id) { $sku = $this->getSku($sku_id, $order_id); $skus = shopPricePlugin::prepareSkus(array($sku_id => $sku), $customer_id); if (!empty($skus[$sku_id])) { $sku = $skus[$sku_id]; } $this->response['sku'] = $sku; $this->response['service_ids'] = array_keys($sku['services']); } else { $product = $this->getProduct($product_id, $order_id); $products = shopPricePlugin::prepareProducts(array($product_id => $product), $customer_id, $currency); if (!empty($products[$product_id])) { $product = $products[$product_id]; } $product['skus'] = shopPricePlugin::prepareSkus($product['skus'], $customer_id, $currency); foreach ($product['skus'] as &$sku) { if (isset($sku['price'])) { $sku['price_str'] = wa_currency($sku['price'], $currency); $sku['price_html'] = wa_currency_html($sku['price'], $currency); } } unset($sku); $this->response['product'] = $product; $this->response['sku_ids'] = array_keys($product['skus']); $this->response['service_ids'] = array_keys($product['services']); } }
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); } }
protected function additionalSum($order_id, $refund = false) { $discountcard_order_model = new shopDiscountcardsPluginOrderModel(); if ($discountcard_order = $discountcard_order_model->getByField('order_id', $order_id)) { $discountcard_model = new shopDiscountcardsPluginModel(); if ($discountcard = $discountcard_model->getByField('discountcard', $discountcard_order['discountcard'])) { $order_model = new shopOrderModel(); $order = $order_model->getOrder($order_id); $total = $order['total']; if ($this->getSettings('without_delivery') && !empty($order['shipping'])) { $total -= $order['shipping']; } $def_currency = wa('shop')->getConfig()->getCurrency(true); $total = shop_currency($total, $order['currency'], $def_currency, false); if ($refund) { $amount = $discountcard['amount'] - $total; } else { $amount = $discountcard['amount'] + $total; } $data = array('amount' => $amount); if ($this->getSettings('recalculation')) { $discount = $this->defineDiscount($amount); $data['discount'] = $discount; } $discountcard_model->updateById($discountcard['id'], $data); } } }
public function execute() { $id = waRequest::request('id', 0, 'int'); if (!$id || !wa()->getUser()->getRights('shop', 'orders')) { $this->redirect(wa()->getAppUrl()); } // Order $om = new shopOrderModel(); $order = $om->getOrder($id); shopHelper::workupOrders($order, true); $order['tax'] = (double) $order['tax']; $order['discount'] = (double) $order['discount']; // Order params $opm = new shopOrderParamsModel(); $order['params'] = $opm->get($order['id']); // Order subtotal $order_subtotal = 0; foreach ($order['items'] as $i) { $order_subtotal += $i['price'] * $i['quantity']; } // Format addresses $settings = wa('shop')->getConfig()->getCheckoutSettings(); $form_fields = ifset($settings['contactinfo']['fields'], array()); $formatter = new waContactAddressSeveralLinesFormatter(); $shipping_address = shopHelper::getOrderAddress($order['params'], 'shipping'); $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']; if ($billing_address === $shipping_address) { $billing_address = null; } } else { $billing_address = null; } // Order history $log_model = new shopOrderLogModel(); $log = $log_model->getLog($order['id']); // Customer $contact = $customer = self::getCustomer($order); $top = array(); foreach (array('email', 'phone') as $f) { if ($v = $contact->get($f, 'top,html')) { $top[] = array('id' => $f, 'name' => waContactFields::get($f)->getName(), 'value' => is_array($v) ? implode(', ', $v) : $v); } } // Workflow stuff: actions and state $workflow = new shopWorkflow(); $workflow_state = $workflow->getStateById($order['state_id']); $workflow_buttons = array(); foreach ($workflow_state->getActions() as $a_id => $action) { if ($a_id === 'edit' || $a_id === 'delete') { continue; } $workflow_buttons[] = $action->getButton(); } $this->view->assign('top', $top); $this->view->assign('log', $log); $this->view->assign('order', $order); $this->view->assign('uniqid', uniqid('f')); $this->view->assign('customer', $customer); $this->view->assign('workflow_state', $workflow_state); $this->view->assign('workflow_buttons', $workflow_buttons); $this->view->assign('shipping_address', $shipping_address); $this->view->assign('billing_address', $billing_address); $this->view->assign('order_subtotal', $order_subtotal); $this->view->assign('currency', ifempty($order['currency'], wa()->getConfig()->getCurrency())); wa()->getResponse()->setTitle(_w('Order') . ' ' . $order['id_str']); parent::execute(); }
public static function cancelBonus($order_or_id) { if (wa_is_int($order_or_id)) { $order_id = $order_or_id; $om = new shopOrderModel(); $order = $om->getOrder($order_id); } else { $order = $order_or_id; $order_id = $order['id']; } if (!$order['contact_id']) { return; } $cm = new shopCustomerModel(); $customer = $cm->getById($order['contact_id']); if (!$customer) { return; } $atm = new shopAffiliateTransactionModel(); $atm->applyBonus($order['contact_id'], -self::calculateBonus($order), $order_id, '', shopAffiliateTransactionModel::TYPE_ORDER_CANCEL); }
/** * * 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); } }