Example #1
0
 /** 
  * Edit product
  * @param integer id of product
  * @return void
  */
 public function edit($id)
 {
     // Check user permission
     if (user::is_got()) {
         // Model
         $manufacturer = new Manufacturer_Model();
         // Settings
         $this->set_title(Kohana::lang('eshop.edit_product'));
         $this->add_breadcrumb(Kohana::lang('eshop.edit_product'), url::current());
         // Load tinymce
         $this->add_javascript('/libs/tinymce/tiny_mce.js');
         $this->add_javascript('/libs/tinymce/poorEditor.js');
         $this->add_javascript('/libs/tinymce/richEditor.js');
         // Fetch default values
         $row = $this->products->get_one($id);
         $form = array('name' => $row['name'], 'cat' => $this->products->get_product_cat($id), 'short_description' => $row['short_description'], 'manufacturer' => $row['manufacturer'], 'description' => $row['description'], 'price' => $row['price'], 'discount' => $row['discount'], 'tip' => $row['tip'], 'news' => $row['news']);
         $errors = array();
         // validation
         if ($_POST) {
             $post = new Validation($_POST);
             // Some filters
             $post->pre_filter('trim', TRUE);
             // Rules
             $post->add_rules('name', 'required');
             $post->add_rules('cat', 'required');
             if ($post->validate()) {
                 // Everything seems to be ok, insert to db
                 $this->products->change_data($post, $id);
                 url::redirect('/product/' . $id . '/' . string::to_url(product::get_name($id)));
             } else {
                 // Repopulate form with error and original values
                 $form = arr::overwrite($form, $post->as_array());
                 $errors = $post->errors('products_errors');
             }
         }
         // View
         $this->template->content = new View('admin/product_edit');
         $selection = $this->cats->add_names($this->cats->get_all_cats());
         $this->template->content->selection = $selection;
         $selection2 = $manufacturer->get_selection();
         $this->template->content->selection2 = $selection2;
         $this->template->content->form = $form;
         $this->template->content->errors = $errors;
     } else {
         url::redirect('/denied');
     }
 }
Example #2
0
 /**
  * Return human readable name of manufacturer
  * @return string 
  * @param integer id of manufacturer
  */
 public function get_name($id)
 {
     $manufacturer = new Manufacturer_Model();
     return $manufacturer->get_name($id);
 }