public function beforeValidate($options = array())
 {
     parent::beforeValidate($options);
     //get type config
     if (isset($this->data['type_config'])) {
         $this->type_config = array_merge($this->type_config, $this->data['type_config']);
         unset($this->data['type_config']);
     }
     // check for price as required
     if ($this->type_config['price']['required']) {
         $this->validate['price']['It can not be empty'] = array('rule' => 'notEmpty');
     }
     // check for parent_lookup as required
     if ($this->type_config['parent_lookup']['required']) {
         $this->validate['parent_lookup']['It can not be empty'] = array('rule' => 'notEmpty');
     }
     // check for value as required
     if ($this->type_config['value']['required']) {
         $this->validate['value']['It can not be empty'] = array('rule' => 'notEmpty');
     }
     // check for value as unique
     if ($this->type_config['value']['unique']) {
         //debug($this->id);exit;
         $this->validate['value']['It is already exist'] = array('rule' => array('uniqueValue', 'lookup_type'));
     }
     $this->data['InventoryLookup']['department_id'] = $this->createSearchCache($this->data['InventoryLookup']['department_id']);
 }
Пример #2
0
 public function beforeValidate($options = array())
 {
     parent::beforeValidate($options);
     if (isset($this->data['Cabinet']['product_type'])) {
         $this->data['Cabinet']['product_type'] = $this->createSearchCache($this->data['Cabinet']['product_type']);
     }
 }
Пример #3
0
 public function beforeValidate($options = array())
 {
     parent::beforeValidate($options);
     if (!$this->id) {
         if (isset($this->data['Item']['base_item'])) {
             $item = $this->data;
             $this->read(null, $this->data['Item']['base_item']);
             array_merge($this->data['Item'], $item['Item']);
             $item['Item']['item_group'] = $this->data['Item']['item_group'];
             $this->data = $item;
         }
         App::import('Model', 'Inventory.InventoryLookup');
         $inventorylookup = new InventoryLookup();
         $number = $inventorylookup->find("first", array("conditions" => array("InventoryLookup.id" => $this->data['Item']['item_group'])));
         $items = $this->find('first', array('limit' => 1, 'order' => array('Item.id DESC')));
         $item_id = $items['Item']['id'] + 1;
         $number['InventoryLookup']['num'] = str_pad($item_id, 6, '0', STR_PAD_LEFT);
         if ($this->data['Item']['base_item'] != 0) {
             $this->data['Item']['number'] = $number['InventoryLookup']['value'] . $number['InventoryLookup']['num'];
         }
     }
 }