Guest User

Untitled

a guest
Jun 23rd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.52 KB | None | 0 0
  1. <?php
  2. lmb_require('limb/cms/src/controller/lmbAdminObjectController.class.php');
  3. lmb_require('limb/util/system/lmbFs.class.php');
  4.  
  5. class AdminProductController extends lmbAdminObjectController
  6. {
  7.   protected $_object_class_name = 'Product';
  8.  
  9.   protected function _onAfterImport()
  10.   {
  11.     return $this->_uploadImage($this->item, $this->request->get('image'));
  12.   }
  13.  
  14.   protected function _uploadImage($item, $uploaded_image)
  15.   {
  16.     if(!$uploaded_image)
  17.       return;
  18.  
  19.     if(!$uploaded_image['name'] || !$uploaded_image['tmp_name'])
  20.       return;
  21.  
  22.     $file_name = $uploaded_image['name'];
  23.     $file_path = $uploaded_image['tmp_name'];
  24.  
  25.     $dest_path = lmb_env_get('PRODUCT_IMAGES_DIR') . $file_name;
  26.     lmbFs :: cp($file_path, $dest_path);
  27.  
  28.     unlink($file_path);
  29.  
  30.     $item->setImageName($file_name);
  31.   }
  32.  
  33.   function doSetAvailable()
  34.   {
  35.     return $this->_changeAvailability(true);
  36.   }
  37.  
  38.   function doSetUnavailable()
  39.   {
  40.     return $this->_changeAvailability(false);
  41.   }
  42.  
  43.   protected function _changeAvailability($is_available)
  44.   {
  45.     if(!$ids = $this->request->getArray('ids'))
  46.     {
  47.       $this->_endDialog();
  48.       return;
  49.     }
  50.  
  51.     $products = lmbActiveRecord :: findByIds('Product', $ids);
  52.     foreach($products as $product)
  53.     {
  54.       $product->setIsAvailable((int) $is_available);
  55.       $product->save();
  56.     }
  57.  
  58.     $this->_endDialog();
  59.   }
  60.  
  61.     function doCreateprod()
  62.     {
  63.  
  64.    
  65.     $this->useForm($this->_form_name);
  66.     $this->setFormDatasource($this->request);
  67.         if(!$this->request->hasPost())
  68.         {
  69.         return;
  70.         }
  71.     $prod_param = $this->request->getPost(array('title', 'description', 'is_available', 'price', 'image_name'));
  72.     $cat_name = $this->request->getPost('category');
  73.  
  74.     $product = new Product($prod_param);
  75.     $category = new Category();
  76.     $category->title = $cat_name;
  77.    
  78.     $product->category = $category;
  79.    
  80.     $category->save();
  81.    
  82.    
  83.         $product->trySave($this->error_list);
  84.        
  85.         if($this->error_list->isValid())
  86.        {
  87.         $this->flashMessage('New product has been added!');
  88.         $this->toolkit->redirect('/admin_product');
  89.        }
  90.        
  91.     }  
  92.     function doAddcat()
  93.     {
  94.     $this->useForm('cat_form');
  95.     $this->setFormDatasource($this->request);
  96.  
  97.     if($this->request->hasPost())
  98.         {
  99.         $cat_param = $this->request->getPost(array('title'));
  100.        
  101.         $cat = new Category($cat_param);
  102.         $cat->trySave($this->error_list);
  103.         if($this->error_list->isValid())
  104.        {
  105.         $this->flashMessage('New category has been added!');
  106.         $this->toolkit->redirect('/admin_product');
  107.        }
  108.     }
  109.     }
  110. }
Add Comment
Please, Sign In to add comment