Пример #1
0
 public function validateProductOption()
 {
     if (isset($_POST['ProductOption'])) {
         $valid = true;
         $this->_productoption = array();
         /*Yii::log( "ProductCreateAction: ".CVarDumper::dumpAsString( $_POST['ProductOption'] ),
         			CLogger::LEVEL_ERROR, "product.actions.create" 
         		);*/
         foreach ($_POST['ProductOption'] as $i => $item) {
             if (isset($_POST['ProductOption'][$i])) {
                 $option = new ProductOption();
                 $option->product_id = 0;
                 if (isset($_POST['ProductOption'][$i]['option_id'])) {
                     $option->option_id = $_POST['ProductOption'][$i]['option_id'];
                 }
                 if (isset($_POST['ProductOption'][$i]['option_value'])) {
                     $option->option_value = $_POST['ProductOption'][$i]['option_value'];
                 }
                 $option->required = $_POST['ProductOption'][$i]['required'];
                 $valid = $option->validate() && $valid;
                 $optionvalue = array();
                 if (isset($_POST['ProductOption'][$i]['ProductOptionValue'])) {
                     foreach ($_POST['ProductOption'][$i]['ProductOptionValue'] as $j => $item) {
                         if (isset($_POST['ProductOption'][$i]['ProductOptionValue'][$j])) {
                             $model = new ProductOptionValue();
                             $model->attributes = $_POST['ProductOption'][$i]['ProductOptionValue'][$j];
                             $model->product_option_id = 0;
                             $model->product_id = 0;
                             $model->option_id = 0;
                             $valid = $model->validate() && $valid;
                             $optionvalue[] = $model;
                         }
                     }
                 }
                 $this->_productoption[] = array($option, $optionvalue);
             }
         }
         if (!$valid) {
             return false;
         }
     }
     return true;
 }