public function execute()
 {
     $id = waRequest::post('id', null, waRequest::TYPE_STRING_TRIM);
     if (!$id) {
         $this->errors[] = _w("Unknown state");
         return;
     }
     $before_id = waRequest::post('before_id', null, waRequest::TYPE_STRING_TRIM);
     $config = shopWorkflow::getConfig();
     $item = $config['states'][$id];
     if (!isset($config['states'][$id])) {
         $this->errors[] = _w("Unknown state");
         return;
     }
     unset($config['states'][$id]);
     if (!$before_id) {
         $config['states'][$id] = $item;
     } else {
         if (!isset($config['states'][$before_id])) {
             $this->errors[] = _w("Unknown state");
             return;
         }
         $states = array();
         foreach ($config['states'] as $state_id => $state) {
             if ($state_id == $before_id) {
                 $states[$id] = $item;
             }
             $states[$state_id] = $state;
         }
         $config['states'] = $states;
     }
     if (!shopWorkflow::setConfig($config)) {
         $this->errors[] = _w("Error when save config");
     }
 }
 public function execute()
 {
     $this->config = shopWorkflow::getConfig();
     $add = waRequest::get('id', 'new_state', waRequest::TYPE_STRING_TRIM) == 'new_state';
     $data = $this->getData($add);
     if (!$this->validate($data, $add)) {
         return;
     }
     $this->save($data);
     $id = $data['state']['id'];
     $this->response = array('id' => $id);
 }
 public function execute()
 {
     $id = waRequest::post('id');
     if (!$id) {
         $this->errors = _w("Unknown state");
         return;
     }
     $order_model = new shopOrderModel();
     if ($order_model->countByField('state_id', $id)) {
         $this->errors = _w("Cannot delete order status while there are active orders in this status");
         return;
     }
     $config = shopWorkflow::getConfig();
     if (isset($config['states'][$id])) {
         unset($config['states'][$id]);
     }
     shopWorkflow::setConfig($config);
 }