Beispiel #1
0
 /**
  * Initialize the products form
  */
 public function initialize($entity = null, $options = array())
 {
     /*======================= usuario_id ================================*/
     if (!isset($options['edit'])) {
         $element = new Text("usuario_id");
         $this->add($element->setLabel("Id"));
     } else {
         $this->add(new Hidden("usuario_id"));
     }
     /*======================= usuario_nick ================================*/
     $name = new Text("name");
     $name->setLabel("Name");
     $name->setFilters(array('striptags', 'string'));
     $name->addValidators(array(new PresenceOf(array('message' => 'Name is required'))));
     $this->add($name);
     /*======================= usuario_nombreCompleto ================================*/
     $type = new Select('product_types_id', ProductTypes::find(), array('using' => array('id', 'name'), 'useEmpty' => true, 'emptyText' => '...', 'emptyValue' => ''));
     $type->setLabel('Type');
     $this->add($type);
     /*======================= usuario_contrasenia ================================*/
     $price = new Text("price");
     $price->setLabel("Price");
     $price->setFilters(array('float'));
     $price->addValidators(array(new PresenceOf(array('message' => 'Price is required')), new Numericality(array('message' => 'Price is required'))));
     $this->add($price);
     /*======================= usuario_sector ================================*/
     /*======================= usuario_email ================================*/
     /*======================= usuario_activo ================================*/
     /*======================= usuario_fechaCreacion ================================*/
     /*======================= usuario_imagen ================================*/
 }
 public function createtypeAction()
 {
     $request = $this->request;
     if (!$request->isPost()) {
         return $this->forward("products/addtype");
     }
     $request = $request->getPost();
     $producttypes = new ProductTypes();
     $producttypes->name = $request['name'];
     if ($producttypes->save()) {
         $this->flash->notice("保存成功!");
         return $this->forward('products/addtype');
     } else {
         foreach ($products->getMessages() as $message) {
             $this->flash->error((string) $message);
         }
     }
 }
Beispiel #3
0
 public function editAction($id)
 {
     $request = $this->request;
     if (!$request->isPost()) {
         $id = $this->filter->sanitize($id, array("int"));
         $products = Products::findFirst('id="' . $id . '"');
         if (!$products) {
             $this->flash->error("products was not found");
             return $this->forward("products/index");
         }
         $this->view->setVar("id", $products->id);
         Tag::displayTo("id", $products->id);
         Tag::displayTo("product_types_id", $products->product_types_id);
         Tag::displayTo("name", $products->name);
         Tag::displayTo("price", $products->price);
         Tag::displayTo("active", $products->active);
         $this->view->setVar("productTypes", ProductTypes::find());
     }
 }
Beispiel #4
0
 /**
  * Initialize the products form
  */
 public function initialize($entity = null, $options = array())
 {
     if (!isset($options['edit'])) {
         $element = new Text("id");
         $this->add($element->setLabel("Id"));
     } else {
         $this->add(new Hidden("id"));
     }
     $name = new Text("name");
     $name->setLabel("Name");
     $name->setFilters(array('striptags', 'string'));
     $name->addValidators(array(new PresenceOf(array('message' => 'Name is required'))));
     $this->add($name);
     $type = new Select('product_types_id', ProductTypes::find(), array('using' => array('id', 'name'), 'useEmpty' => true, 'emptyText' => '...', 'emptyValue' => ''));
     $type->setLabel('Type');
     $this->add($type);
     $price = new Text("price");
     $price->setLabel("Price");
     $price->setFilters(array('float'));
     $price->addValidators(array(new PresenceOf(array('message' => 'Price is required')), new Numericality(array('message' => 'Price is required'))));
     $this->add($price);
 }
Beispiel #5
0
 public function addXLS($file_path)
 {
     //$file_path = './upload_dir/test.xls';
     $sheet_array = Yii::app()->yexcel->readActiveSheet($file_path);
     $current_product = null;
     foreach ($sheet_array as $row) {
         if ($this->isRowEmpty($row)) {
             continue;
         }
         if ($row['A'] != null && $row['B'] != null) {
             continue;
         }
         if ($row['A'] != null) {
             $current_product = ProductTypes::model()->findByAttributes(array('name' => $row['A']));
             if (!$current_product) {
                 $current_product = new ProductTypes();
             }
             $current_product->name = $row['A'];
             $properties = '[';
             foreach ($row as $cell) {
                 if ($cell != null && $cell != $row['A']) {
                     $properties = "{$properties}\"{$cell}\",";
                 }
             }
             $properties[strlen($properties) - 1] = ']';
             $current_product->properties = $properties;
             $objValues = json_decode($current_product->values_);
             if (!$objValues) {
                 $objValues = array();
                 $propCount = substr_count($current_product->properties, '","') + 1;
                 for ($i = 0; $i < $propCount; $i++) {
                     $objValues[$i] = array();
                 }
             }
             $current_product->values_ = json_encode($objValues);
             $current_product->save();
             continue;
         }
         if (!$current_product) {
             continue;
         }
         //$cell = $row['B'];
         $product = Products::model()->findByAttributes(array('article' => $row['B']));
         if (!$product) {
             $product = new Products();
         }
         $product->type_id = $current_product->id;
         $product->article = $row['B'];
         //$cell = next($row);
         $product->description = $row['C'];
         //$cell = next($row);
         $product->prices = "[\"{$row['D']}\";\"{$row['E']}\";\"{$row['F']}\"]";
         $values = '[';
         //$cell = $row['F'];
         //while ($cell = next($row))
         $objValues = json_decode($current_product->values_, true);
         $i = 'H';
         $nProp = 0;
         $isChanged = false;
         while ($row[$i]) {
             $values = "{$values}\"{$row[$i]}\",";
             if (is_array($objValues[$nProp]) && !in_array(strtolower($row[$i]), array_map('strtolower', $objValues[$nProp])) || !is_array($objValues[$nProp]) && $row[$i] != $objValues[$nProp]) {
                 $objValues[$nProp][] = $row[$i];
                 $isChanged = true;
             }
             $i++;
             $nProp++;
         }
         $values[strlen($values) - 1] = ']';
         $product->values_ = $values;
         if ($isChanged) {
             $current_product->values_ = json_encode($objValues, JSON_UNESCAPED_UNICODE);
             $current_product->save();
         }
         $product->save();
     }
     //$this->actionIndex();
 }
Beispiel #6
0
 public function actionShowProduct($id = 1)
 {
     $productType = ProductTypes::model()->with('products')->findByPk($id);
     $productType->products[0]->getPriceString();
     Yii::app()->clientScript->registerCoreScript('jquery');
     Yii::app()->clientScript->registerCoreScript('ajaxupload');
     Yii::app()->clientScript->registerCoreScript('datatables');
     Yii::app()->clientScript->registerCoreScript('datatablesColumnFilter');
     Yii::app()->clientScript->registerCoreScript('jTruncate');
     Yii::app()->clientScript->registerCssFile('/css/jquery.dataTables.min.css');
     $stringVariableColumns = '';
     for ($i = 0; $i < count(json_decode($productType->properties)); $i++) {
         $stringVariableColumns = $stringVariableColumns . "{ type: \"select\" }, \n";
     }
     $this->render('showProduct', array('productType' => $productType, 'stringVariableColumns' => $stringVariableColumns));
 }
 public function deleteAction($id)
 {
     $id = $this->filter->sanitize($id, array("int"));
     $producttypes = ProductTypes::findFirst('id="' . $id . '"');
     if (!$producttypes) {
         Flash::error("product types was not found", "alert alert-error");
         return $this->_forward("producttypes/index");
     }
     if (!$producttypes->delete()) {
         foreach ($producttypes->getMessages() as $message) {
             Flash::error((string) $message, "alert alert-error");
         }
         return $this->_forward("producttypes/search");
     } else {
         Flash::success("product types was deleted", "alert alert-success");
         return $this->_forward("producttypes/index");
     }
 }
 /**
  * Deletes a producttypes
  *
  * @param string $id
  */
 public function deleteAction($id)
 {
     $productTypes = ProductTypes::findFirstById($id);
     if (!$productTypes) {
         $this->flash->error("Product types was not found");
         return $this->forward("producttypes/index");
     }
     if (!$productTypes->delete()) {
         foreach ($productTypes->getMessages() as $message) {
             $this->flash->error($message);
         }
         return $this->forward("producttypes/search");
     }
     $this->flash->success("product types was deleted");
     return $this->forward("producttypes/index");
 }
 public function indexAction()
 {
     $this->persistent->searchParams = null;
     $types = Types::find();
     $this->view->setVar("productTypes", ProductTypes::find());
 }
 public function newAction()
 {
     $this->view->setVar("productTypes", ProductTypes::find());
 }