Author: Your name here
Inheritance: extends BaseProductForm
Exemplo n.º 1
0
 public function actionDelete($id)
 {
     $productForm = ProductForm::model()->findByPk($id);
     if (!empty($productForm)) {
         $productForm->delete();
     }
     $this->redirect($this->createUrl('product/index'));
 }
Exemplo n.º 2
0
 public function actionUpdate($id)
 {
     $model = new ProductForm();
     if (isset($_POST['ProductForm'])) {
         $model->attributes = $_POST['ProductForm'];
         if ($model->validate()) {
             $model->save();
             $this->redirect(array('index'));
         }
     } else {
         $model->loadDataFromProduct($id);
     }
     $statuses = array(0 => Yii::t('common', 'Disabled'), 1 => Yii::t('common', 'Enabled'));
     $yes_no = array(0 => Yii::t('common', 'No'), 1 => Yii::t('common', 'Yes'));
     $taxClasses = TaxClass::model()->findAll();
     $taxClassesList = array();
     foreach ($taxClasses as $taxClass) {
         $taxClassesList[$taxClass->tax_class_id] = $taxClass->title;
     }
     // TODO: add language
     $stockStatuses = StockStatus::model()->findAll();
     $stockStatusesList = array();
     foreach ($stockStatuses as $stockStatus) {
         $stockStatusesList[$stockStatus->stock_status_id] = $stockStatus->name;
     }
     // TODO: add language
     $weightClasses = WeightClass::model()->findAll();
     $weightClassesList = array();
     foreach ($weightClasses as $weightClass) {
         $weightClassesList[$weightClass->weight_class_id] = $weightClass->description->title;
     }
     // TODO: add language
     $lengthClasses = LengthClass::model()->findAll();
     $lengthClassesList = array();
     foreach ($lengthClasses as $lengthClass) {
         $lengthClassesList[$lengthClass->length_class_id] = $lengthClass->description->title;
     }
     $this->render('update', array('model' => $model, 'statuses' => $statuses, 'taxClasses' => $taxClassesList, 'yes_no' => $yes_no, 'stockStatuses' => $stockStatusesList, 'weightClasses' => $weightClassesList, 'lengthClasses' => $lengthClassesList));
 }
Exemplo n.º 3
0
 public function ProductForm($quantity = null, $redirectURL = null)
 {
     return ProductForm::create($this, 'ProductForm', $quantity, $redirectURL)->disableSecurityToken();
 }
Exemplo n.º 4
0
 function editAction()
 {
     $this->view->title = "Product";
     $form = new ProductForm();
     $form->submit->setLabel('Save');
     $this->view->form = $form;
     if ($this->_request->isPost()) {
         $formData = $this->_request->getPost();
         //removed validation on edit
         $form->getElement('product_id')->removeValidator('Db_NoRecordExists');
         if ($form->isValid($formData)) {
             $products = new Product();
             $id = (int) $form->getValue('id');
             $row = $products->fetchRow('id=' . $id);
             $row->product_name = $form->getValue('product_name');
             $row->product_id = $form->getValue('product_id');
             $row->product_desc = $form->getValue('product_desc');
             $row->product_desc = $form->getValue('product_desc');
             $row->product_image = $form->getValue('product_image');
             $row->category_id = $form->getValue('category_id');
             $row->product_image = $form->getValue('product_image');
             $row->save();
             $this->_redirect('/');
         } else {
             $form->populate($formData);
         }
     } else {
         $id = (int) $this->_request->getParam('id', 0);
         if ($id > 0) {
             $products = new Product();
             $product = $products->fetchRow('id=' . $id);
             $form->populate($product->toArray());
         }
     }
 }