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()
 {
     if (!($order_id = waRequest::post('id', 0, 'int'))) {
         throw new waException('No order id given.');
     }
     if (!($action_id = waRequest::post('action_id'))) {
         throw new waException('No action id given.');
     }
     $workflow = new shopWorkflow();
     // @todo: check action availablity in state
     $action = $workflow->getActionById($action_id);
     if ($html = $action->getHTML($order_id)) {
         // display html
         echo $html;
     } else {
         // perform action and reload
         $result = $action->run($order_id);
         // counters
         $order_model = new shopOrderModel();
         $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']);
         echo "<script>";
         echo "\$.order_list.updateCounters(" . json_encode(array('state_counters' => $state_counters, 'common_counters' => array('pending_counters' => $pending_counters))) . ");";
         echo "\$.order.reload();</script>";
     }
 }
 public function execute()
 {
     $order_id = waRequest::get('id', null, waRequest::TYPE_INT);
     $form = null;
     $order = array();
     $shipping_address = array();
     // Existing order?
     if ($order_id) {
         $order = $this->getOrder($order_id);
         $currency = $order['currency'];
         if ($order['contact_id']) {
             $has_contacts_rights = shopHelper::getContactRights($order['contact_id']);
             $shipping_address = shopHelper::getOrderAddress($order['params'], 'shipping');
             if (!empty($order['contact_id'])) {
                 try {
                     $c = new waContact($order['contact_id']);
                     if ($shipping_address) {
                         $c['address.shipping'] = $shipping_address;
                     }
                     $form = shopHelper::getCustomerForm($c);
                 } catch (waException $e) {
                     // Contact does not exist; ignore. When $form is null, customer data saved in order is shown.
                 }
             }
         } else {
             $has_contacts_rights = shopHelper::getContactRights();
         }
     } else {
         $currency = $this->getConfig()->getCurrency();
         $has_contacts_rights = shopHelper::getContactRights();
         $form = shopHelper::getCustomerForm();
     }
     $stock_model = new shopStockModel();
     $stocks = $stock_model->getAll('id');
     $tax_model = new shopTaxModel();
     $taxes_count = $tax_model->countAll();
     $count_new = $this->order_model->getStateCounters('new');
     /**
      * Backend order edit page
      * @event backend_order_edit
      * @param array $order
      * @return array[string][string] $return[%plugin_id%] html output
      */
     $this->view->assign('backend_order_edit', wa()->event('backend_order_edit', $order));
     $this->view->assign(array('form' => $form, 'order' => $order, 'stocks' => $stocks, 'currency' => $currency, 'count_new' => $count_new, 'taxes_count' => $taxes_count, 'shipping_address' => $shipping_address, 'has_contacts_rights' => $has_contacts_rights, 'customer_validation_disabled' => wa()->getSetting('disable_backend_customer_form_validation'), 'ignore_stock_count' => wa()->getSetting('ignore_stock_count')));
 }
Beispiel #4
0
 public function onCount()
 {
     if (!wa()->getUser()->getRights('shop', 'orders')) {
         return null;
     }
     $order_model = new shopOrderModel();
     return $order_model->getStateCounters('new');
 }
Beispiel #5
0
 public function execute()
 {
     $curm = new shopCurrencyModel();
     $currencies = $curm->getAll('code');
     $coupm = new shopCouponModel();
     $coupons = $coupm->order('id DESC')->fetchAll('code');
     foreach ($coupons as &$c) {
         $c['enabled'] = self::isEnabled($c);
         $c['hint'] = self::formatValue($c, $currencies);
     }
     unset($c);
     $order_model = new shopOrderModel();
     $count_new = $order_model->getStateCounters('new');
     $this->view->assign(array('coupons' => $coupons, 'order_count_new' => $count_new));
 }
 public function execute()
 {
     $action_id = waRequest::get('id', null, waRequest::TYPE_STRING_TRIM);
     if (!$action_id) {
         throw new waException('No action id given.');
     }
     $chunk_size = 100;
     $offset = (int) waRequest::get('offset');
     $workflow = new shopWorkflow();
     $order_model = new shopOrderModel();
     // collect orders under which has performed actions
     $updated_orders_ids = array();
     $hash = $this->getHash();
     if ($hash === null) {
         return;
     }
     $collection = new shopOrdersCollection($hash);
     $total_count = $collection->count();
     $orders = $collection->getOrders('*', $offset, $chunk_size);
     foreach ($orders as $order) {
         $actions = $workflow->getStateById($order['state_id'])->getActions();
         if (isset($actions[$action_id])) {
             $actions[$action_id]->run($order['id']);
             $updated_orders_ids[] = $order['id'];
         }
     }
     if (!$updated_orders_ids) {
         return;
     }
     $this->response = array('offset' => $offset + count($orders), 'total_count' => $total_count);
     // sidebar counters
     if ($this->response['offset'] >= $this->response['total_count']) {
         $order_model = new shopOrderModel();
         $state_counters = $order_model->getStateCounters();
         $pending_count = (!empty($state_counters['new']) ? $state_counters['new'] : 0) + (!empty($state_counters['processing']) ? $state_counters['processing'] : 0) + (!empty($state_counters['paid']) ? $state_counters['paid'] : 0);
         $this->response['state_counters'] = $state_counters;
         $this->response['pending_count'] = $pending_count;
     }
     $collection = new shopOrdersCollection('id/' . implode(',', $updated_orders_ids));
     $total_count = $collection->count();
     $orders = $collection->getOrders('*,contact', 0, $total_count);
     // orders for update items in table
     shopHelper::workupOrders($orders);
     $this->response['orders'] = array_values($orders);
 }
 public function execute()
 {
     if (!wa()->getUser()->getRights('shop', 'orders')) {
         throw new waException(_w("Access denied"));
     }
     $this->setLayout(new shopBackendLayout());
     $this->getResponse()->setTitle(_w('Orders'));
     $config = $this->getConfig();
     $order_model = new shopOrderModel();
     $state_counters = $order_model->getStateCounters();
     $pending_count = (!empty($state_counters['new']) ? $state_counters['new'] : 0) + (!empty($state_counters['processing']) ? $state_counters['processing'] : 0) + (!empty($state_counters['paid']) ? $state_counters['paid'] : 0);
     $cm = new shopCouponModel();
     /*
      * @event backend_orders
      * @return array[string]array $return[%plugin_id%] array of html output
      * @return array[string][string]string $return[%plugin_id%]['sidebar_top_li'] html output
      * @return array[string][string]string $return[%plugin_id%]['sidebar_bottom_li'] html output
      * @return array[string][string]string $return[%plugin_id%]['sidebar_section'] html output
      */
     $backend_orders = wa()->event('backend_orders');
     $this->getLayout()->assign('backend_orders', $backend_orders);
     $this->view->assign(array('states' => $this->getStates(), 'user_id' => $this->getUser()->getId(), 'contacts' => array(), 'default_view' => $config->getOption('orders_default_view'), 'coupons_count' => $cm->countActive(), 'state_counters' => $state_counters, 'pending_count' => $pending_count, 'all_count' => $order_model->countAll(), 'storefronts' => $order_model->getStorefrontCounters(), 'backend_orders' => $backend_orders));
 }