public function index($product)
 {
     // Get the product
     $product = $this->products_m->get_product($product);
     // Check it exists
     if ($product) {
         // General information
         $this->data->product = $product;
         $this->data->category = $this->products_m->get_category($product);
         $this->data->folder = '/' . UPLOAD_PATH . 'products/' . $this->data->product['id'] . '/';
         // Fire event
         Events::trigger('product_viewed', array('id' => $product['id']));
         // Images
         $folder = $this->products_m->get_file_folder_by_slug($product['slug']);
         $images = Files::folder_contents($folder->id);
         $this->data->images = $images['data']['file'];
         // Add key for easy limits, main, etc.
         foreach ($this->data->images as $key => $image) {
             $this->data->images[$key]->position = $key;
         }
         // Breadcrumbs
         $cat_tree = $this->products_m->get_cat_path($this->data->category, true);
         $this->template->set_breadcrumb('Home', '/home');
         foreach ($cat_tree as $key => $cat) {
             if ($key == 0) {
                 $this->data->parent = $cat['id'];
             }
             $this->template->set_breadcrumb($cat['title'], '/category/' . $cat['slug']);
         }
         // Build Page
         $this->template->set_breadcrumb($this->data->product['title'], '/product/' . $this->data->product['slug'])->title($this->data->product['title'])->set($this->data);
         // Fire events
         Events::trigger('page_build', $this->template);
         // Build page
         $this->template->build('product');
     } else {
         set_status_header(404);
         echo Modules::run('pages/_remap', '404');
     }
 }
示例#2
0
 /**
  * Get all files and folders within a folder
  *
  * Grabs the parent id from the POST data.
  */
 public function folder_contents()
 {
     $parent = $this->input->post('parent');
     echo json_encode(Files::folder_contents($parent));
 }
示例#3
0
 /**
  * Deletes a product, the images and Files folder related to it.
  *
  * @param integer $id The Product ID to delete
  * @return boolean TRUE or FALSE on success of failure
  * @access public
  */
 public function delete_product($id)
 {
     $product = $this->get_product($id);
     if ($this->db->delete('firesale_products', array('id' => $id))) {
         // Remove files folder
         if ($product !== FALSE) {
             $folder = $this->get_file_folder_by_slug($product->slug);
             if ($folder != FALSE) {
                 $images = Files::folder_contents($folder->id);
                 $images = $images['data']['file'];
                 foreach ($images as $image) {
                     Files::delete_file($image->id);
                 }
                 Files::delete_folder($folder->id);
             }
         }
         return TRUE;
     } else {
         return FALSE;
     }
 }
 public function create($id = NULL, $row = NULL)
 {
     // Check for post data
     if (substr($this->input->post('btnAction'), 0, 4) == 'save') {
         // Variables
         $input = $this->input->post();
         $skip = array('btnAction');
         $extra = array('return' => '/admin/firesale/products/edit/-id-', 'success_message' => lang('firesale:prod_' . ($id == NULL ? 'add' : 'edit') . '_success'), 'error_message' => lang('firesale:prod_' . ($id == NULL ? 'add' : 'edit') . '_error'));
         // Check button action for return location
         if ($this->input->post('btnAction') == 'save_exit') {
             $extra['return'] = '/admin/firesale/products';
         }
         // Manually update categories
         // Multiple tends not to do it
         if ($id !== NULL) {
             $this->products_m->update_categories($id, $this->stream->id, $input['category']);
             unset($_POST['category']);
         }
         // Added to seperate if since above will be removed for 2.2
         if ($id !== NULL) {
             $data = array_merge(array('id' => $id, 'stream' => 'firesale_products'), $input);
             Events::trigger('product_updated', $data);
         }
     } else {
         $input = FALSE;
         $skip = array();
         $extra = array();
     }
     // Get the stream fields
     $fields = $this->fields->build_form($this->stream, $id == NULL ? 'new' : 'edit', $id == NULL ? $input : $row, FALSE, FALSE, $skip, $extra);
     // Assign variables
     if ($row !== NULL) {
         $this->data = $row;
     }
     $this->data->id = $id;
     $this->data->fields = fields_to_tabs($fields, $this->tabs);
     $this->data->tabs = array_keys($this->data->fields);
     // Get current images
     if ($row != FALSE) {
         $folder = $this->products_m->get_file_folder_by_slug($row->slug);
         $images = Files::folder_contents($folder->id);
         $this->data->images = $images['data']['file'];
     }
     // Add metadata
     $this->template->append_js('module::jquery.filedrop.js')->append_js('module::upload.js')->append_metadata($this->load->view('fragments/wysiwyg', NULL, TRUE));
     // Add page data
     $this->template->title(lang('firesale:title') . ' ' . lang('firesale:prod_title_' . ($id == NULL ? 'create' : 'edit')))->set($this->data)->enable_parser(true);
     // Fire events
     Events::trigger('page_build', $this->template);
     // Build page
     $this->template->build('admin/products/create');
 }