/** * @return shopNotificationModel */ protected static function getModel() { if (!self::$model) { self::$model = new shopNotificationModel(); } return self::$model; }
public function execute() { $order_id = waRequest::request('order_id', 0, 'int'); $id = waRequest::request('id', 0, 'int'); $to = waRequest::request('to'); $nm = new shopNotificationModel(); $n = $nm->getById($id); if (!$n) { $this->errors = sprintf_wp('%s entry not found', _w('Notification')); return; } $om = new shopOrderModel(); $o = $om->getById($order_id); if (!$o) { $this->errors = _w('Order not found'); return; } shopHelper::workupOrders($o, true); $opm = new shopOrderParamsModel(); $o['params'] = $opm->get($order_id); try { $contact = $o['contact_id'] ? new shopCustomer($o['contact_id']) : wa()->getUser(); $contact->getName(); } catch (Exception $e) { $contact = new shopCustomer(wa()->getUser()->getId()); } $cm = new shopCustomerModel(); $customer = $cm->getById($contact->getId()); if (!$customer) { $customer = $cm->getEmptyRow(); } $workflow = new shopWorkflow(); // send notifications shopNotifications::sendOne($id, array('order' => $o, 'customer' => $contact, 'status' => $workflow->getStateById($o['state_id'])->getName()), $to); }
public function postExecute($order_id = null, $result = null) { $order_id = $result['order_id']; $data = is_array($result) ? $result : array(); $data['order_id'] = $order_id; $data['action_id'] = $this->getId(); $data['before_state_id'] = ''; $data['after_state_id'] = 'new'; $order_log_model = new shopOrderLogModel(); $order_log_model->add($data); /** * @event order_action.create */ wa('shop')->event('order_action.create', $data); $order_model = new shopOrderModel(); $order = $order_model->getById($order_id); $params_model = new shopOrderParamsModel(); $order['params'] = $params_model->get($order_id); // send notifications shopNotifications::send('order.' . $this->getId(), array('order' => $order, 'customer' => new waContact($order['contact_id']), 'status' => $this->getWorkflow()->getStateById($data['after_state_id'])->getName(), 'action_data' => $data)); // Update stock count, but take into account 'update_stock_count_on_create_order'-setting $app_settings_model = new waAppSettingsModel(); if ($app_settings_model->get('shop', 'update_stock_count_on_create_order')) { // for logging changes in stocks shopProductStocksLogModel::setContext(shopProductStocksLogModel::TYPE_ORDER, 'Order %s was placed', array('order_id' => $order_id)); $order_model->reduceProductsFromStocks($order_id); shopProductStocksLogModel::clearContext(); } return $order_id; }
public function postExecute($order_id = null, $result = null) { if (!$result) { return; } $order_model = new shopOrderModel(); if (is_array($order_id)) { $order = $order_id; $order_id = $order['id']; } else { $order = $order_model->getById($order_id); } $data = is_array($result) ? $result : array(); $data['order_id'] = $order_id; $data['action_id'] = $this->getId(); $data['before_state_id'] = $order['state_id']; if ($this->state_id) { $data['after_state_id'] = $this->state_id; } else { $data['after_state_id'] = $order['state_id']; } $order_log_model = new shopOrderLogModel(); $data['id'] = $order_log_model->add($data); $update = isset($result['update']) ? $result['update'] : array(); $update['update_datetime'] = date('Y-m-d H:i:s'); $data['update'] = $update; if ($this->state_id) { $update['state_id'] = $this->state_id; } $order_model->updateById($order['id'], $update); $order_params_model = new shopOrderParamsModel(); if (isset($update['params'])) { $order_params_model->set($order['id'], $update['params'], false); } $order['params'] = $order_params_model->get($order_id); // send notifications shopNotifications::send('order.' . $this->getId(), array('order' => $order, 'customer' => new waContact($order['contact_id']), 'status' => $this->getWorkflow()->getStateById($data['after_state_id'])->getName(), 'action_data' => $data)); /** * @event order_action.callback * @event order_action.pay * @event order_action.ship * @event order_action.process * @event order_action.delete * @event order_action.restore * @event order_action.complete * @event order_action.comment * * @param array[string]mixed $data * @param array[string]int $data['order_id'] * @param array[string]int $data['action_id'] * @param array[string]int $data['before_state_id'] * @param array[string]int $data['after_state_id'] * @param array[string]int $data['id'] Order log record id */ wa('shop')->event('order_action.' . $this->getId(), $data); return $data; }