Пример #1
0
 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')));
 }
Пример #2
0
 public function execute()
 {
     $id = waRequest::get('id', null, waRequest::TYPE_INT);
     // null             - don't add/edit contact info
     // not zero numeric - edit existing contact
     // zero numeric     - add contact
     $customer_id = waRequest::post('customer_id', null, waRequest::TYPE_INT);
     if ($customer_id && !shopHelper::getContactRights($customer_id)) {
         $customer_id = null;
     }
     if ($customer_id === null && !$id) {
         $customer_id = 0;
     }
     if ($customer_id !== null) {
         $contact = new waContact($customer_id);
         $form = shopHelper::getCustomerForm($customer_id);
         $customer_validation_disabled = wa()->getSetting('disable_backend_customer_form_validation');
         if (!$customer_validation_disabled) {
             if (!$form->isValid($contact)) {
                 $this->errors['customer']['html'] = $form->html();
             }
         }
     }
     if ($data = $this->getData($id)) {
         $this->validate($data, $id);
     }
     if ($this->errors) {
         return;
     }
     $params_model = new shopOrderParamsModel();
     $params = $params_model->get($id);
     if ($customer_id !== null) {
         foreach ((array) $form->post() as $fld_id => $fld_data) {
             if (!$fld_data) {
                 continue;
             }
             if ($fld_id == 'address.shipping') {
                 $this->shipping_address = $fld_data;
                 $this->setAddress($contact, $params, 'shipping');
                 continue;
             } elseif ($fld_id == 'address.billing') {
                 $this->billing_address = $fld_data;
                 $this->setAddress($contact, $params, 'billing');
                 continue;
             }
             if (is_array($fld_data) && !empty($fld_data[0])) {
                 $contact[$fld_id] = array();
                 foreach ($fld_data as $v) {
                     $contact->set($fld_id, $v, true);
                 }
             } else {
                 $contact[$fld_id] = $fld_data;
             }
         }
         if ($customer_validation_disabled) {
             $contact->save();
         } else {
             $errors = $contact->save(array(), true);
             if ($errors) {
                 // Only consider errors from visible fields
                 $errors = array_intersect_key($errors, $form->fields);
                 if ($errors) {
                     $this->errors['customer'] = $errors;
                     return;
                 } else {
                     // No errors from visible fields: save anyway
                     $contact->save();
                 }
             }
         }
         $data['contact'] = $contact;
     }
     $workflow = new shopWorkflow();
     $this->getParams($data, $id);
     if (!$id) {
         $id = $workflow->getActionById('create')->run($data);
     } else {
         $data['id'] = $id;
         $workflow->getActionById('edit')->run($data);
     }
     $this->response['order'] = $this->workupOrder($this->getModel()->getOrder($id));
 }