PageRenderTime 43ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/shop/classes/controller/goods.php

https://bitbucket.org/seyar/kinda.local
PHP | 317 lines | 223 code | 66 blank | 28 comment | 10 complexity | f258d5d9b4b76b83ea24783bd57f4d9f MD5 | raw file
  1. <?php
  2. defined( 'SYSPATH' ) OR die( 'No direct access allowed.' );
  3. class Controller_Goods extends Controller_Shop
  4. {
  5. public $template = 'shop_products';
  6. public $module_title = 'Goods';
  7. // public $module_name = 'goods';
  8. public $module_desc_short = 'Shop Descr Short';
  9. public $module_desc_full = 'Shop Descr Full';
  10. static $goods_status_list = array( 'active', 'archive', 'out_of_store', 'unverified', 'from1c' );
  11. static $images_folder;
  12. static $image_width;
  13. static $image_height;
  14. static $image_prev_width;
  15. static $image_prev_height;
  16. static $max_images_count;
  17. public function before()
  18. {
  19. parent::before();
  20. $this->model = new Model_Goods();
  21. // $this->request->controller .= ':'.MODULE_SUBCONTROLLER;
  22. Controller_Goods::$images_folder = self::$images_folder = Kohana_Config::instance()->load('shop')->images_folder;
  23. Controller_Goods::$image_width = self::$image_width = Kohana_Config::instance()->load('shop')->image_width;
  24. Controller_Goods::$image_height = self::$image_height = Kohana_Config::instance()->load('shop')->image_height;
  25. Controller_Goods::$image_prev_width = self::$image_prev_width = Kohana_Config::instance()->load('shop')->image_prev_width;
  26. Controller_Goods::$image_prev_height = self::$image_prev_height = Kohana_Config::instance()->load('shop')->image_prev_height;
  27. Controller_Goods::$max_images_count = self::$max_images_count = Kohana_Config::instance()->load('shop')->max_images_count;
  28. $this->template->current_lang = $this->lang;
  29. }
  30. public function action_index()
  31. {
  32. $where = array();
  33. // $this->template = View::factory( 'shop_products' );
  34. list($where, $filter) = Model_Goods::getFilter($this->lang);
  35. $rows = array();
  36. $page_links = '';
  37. $total_pages = 0;
  38. $this->template->publ_types = Model_Categories::getAllGoods();
  39. $this->template->filter = $filter;
  40. $cookie = Arr::get($_COOKIE,'stat', 'yes');
  41. if( $cookie == 'yes' )
  42. {
  43. $this->template->style_panel = 'display:block';
  44. $this->template->style_content='margin-left: 249px;';
  45. $this->template->style_but='display:none;';
  46. }else
  47. {
  48. $this->template->style_panel = 'display:none';
  49. $this->template->style_content='margin-left: 0px;';
  50. $this->template->style_but='display:block;';
  51. }
  52. $priceCategories = array(-1 => array('id' => '', 'name'=> ''))+Model_Currencies::getPriceCategories();
  53. $this->template->priceCategories = $priceCategories;
  54. //die(Kohana::debug($this->template->filter));
  55. $shop_goods_prices = DB::select( 'shop_goods.id', 'shop_goods.name', 'alter_name', 'quantity', 'shop_goods.status', 'default_photo', 'is_bestseller', 'is_new', 'show_on_startpage', array('shop_prices.price', 'shop_prices'), 'shop_goods.seo_url', 'shop_goods.seo_description', 'shop_goods.seo_keywords', 'shop_goods.categories_id' )
  56. ->from('shop_goods')
  57. ->join('shop_categories','left')
  58. ->on( 'shop_categories.id', '=','shop_goods.categories_id')
  59. ->join('shop_prices','left')
  60. ->on( 'shop_prices.good_id', '=','shop_goods.id')
  61. ;
  62. list($this->template->pagination, $this->template->rows) = Admin::highload_model_pagination(
  63. $this->lang,
  64. $shop_goods_prices,
  65. $where
  66. );
  67. }
  68. public function action_apply()
  69. {
  70. die('Hello world');
  71. //die(Kohana::debug($_POST));
  72. if( $id = $this->model->save( $this->lang, $this->request->param( 'id' ) ) )
  73. {
  74. $this->redirect_to_controller( $this->request->controller . '/' . $id . '/edit' . '#' . $_POST['actTab'] );
  75. }else
  76. {
  77. // $this->view->assign( 'errors', $this->model->errors );
  78. $this->action_edit();
  79. }
  80. }
  81. public function action_edit()
  82. {
  83. $this->model = new Model_Goods();
  84. if( $good = Model_Goods::itemExists($this->request->param('id')) ) $this->redirect_to_controller( $this->request->controller . '/' . $good . '/edit' );
  85. $this->template = View::factory( 'shop_products_edit' );
  86. $this->template->edit_categories_list = Model_Categories::categories_folders( $this->lang, 1 );
  87. $this->template->edit_price_categories = Model_Shop::shop_price_categories();
  88. $this->template->edit_currencies_list = Model_Shop::shop_currencies();
  89. $this->template->defaultCurrency = Kohana::config('shop')->default_currency;
  90. //die(Kohana::debug($this->template->edit_categories_list));
  91. $this->template->obj = $this->model->load( $this->request->param('id') );
  92. $this->template->brands = array(-1 => array('id' => '', 'name'=> ''))+Model_Brands::getItems();
  93. $this->template->goodGroups = $this->model->getGoodsGroups($this->request->param('id'));
  94. $addGoodsModel = Kohana::config('shop')->addGoodsModel;
  95. $addGoodsMethod = Kohana::config('shop')->addGoodsMethGet;
  96. if( class_exists($addGoodsModel) && $this->request->param('id') )
  97. $this->template->recGoods = call_user_func(array($addGoodsModel, $addGoodsMethod),'goodId = '.$this->request->param('id'));
  98. }
  99. public function action_update()
  100. {
  101. // if( $this->request->param( 'id' ) == 0 )
  102. // {
  103. // $id = $this->model->product_create();
  104. // $this->redirect_to_controller( $this->request->controller . '/' . $id . '/edit' );
  105. // }
  106. if( $res = $this->model->save( $this->lang, $this->request->param( 'id' ) ) )
  107. {
  108. $this->redirect_to_controller( $this->request->controller . '/' . $res . '/edit' . '#' . $_POST['actTab'] );
  109. }else
  110. {
  111. // $this->template->errors = $this->model->errors;
  112. $this->action_edit();
  113. }
  114. }
  115. public function action_save()
  116. {
  117. // if( $this->request->param( 'id' ) == 0 )
  118. // {
  119. // $id = $this->model->product_create();
  120. //
  121. // $this->redirect_to_controller( $this->request->controller . '/products' );
  122. // }
  123. if( $this->model->save( $this->lang, $this->request->param( 'id' ) ) )
  124. {
  125. $this->redirect_to_controller( $this->request->controller );
  126. }
  127. else
  128. {
  129. // $this->template->errors = $this->model->errors;
  130. $this->action_edit();
  131. }
  132. }
  133. public function action_delete()
  134. {
  135. if( $this->request->param( 'id' ) )
  136. $this->model->delete( $this->request->param( 'id' ) );
  137. elseif( count( $_POST['chk'] ) )
  138. $this->model->delete_list( $_POST['chk'] );
  139. $this->redirect_to_controller( $this->request->controller );
  140. }
  141. // Images Actions
  142. public function action_image_preview()
  143. {
  144. $this->show_image_preview( MEDIAPATH . self::$images_folder . '/' . $this->request->param('id') . '/' . basename( $_GET['name'] ),$this->request->param('id') );
  145. }
  146. public function action_images_default()
  147. {
  148. $this->model->images_default( MEDIAPATH . self::$images_folder . '/' . $this->request->param('id') . '/' . basename( $_GET['name'] ),$this->request->param('id') );
  149. die();
  150. }
  151. public function action_images_delete()
  152. {
  153. $this->model->images_delete( self::$images_folder, $this->request->param('id') );
  154. die();
  155. }
  156. public function action_images_show()
  157. {
  158. echo json_encode(
  159. $this->model->images_show(
  160. self::$images_folder
  161. , strtolower($this->admin_path . Request::instance()->controller . "/" . MODULE_NAME . ':' . MODULE_SUBCONTROLLER . "/" . $this->request->param('id'))
  162. , strtolower(MEDIAWEBPATH . MODULE_NAME . "/" . $this->request->param('id').'/')
  163. , $this->request->param('id')
  164. )
  165. );
  166. die();
  167. }
  168. // Images Upload Actions
  169. public function action_images_upload()
  170. {
  171. $watermark = Kohana::config( 'shop.watermark' );
  172. // Kohana_log::instance()->add('d', Kohana::debug(self::$images_folder, self::$image_width, self::$image_height, self::$image_prev_width, self::$image_prev_height, $this->request->param('id')));
  173. $this->model->images_upload( self::$images_folder, self::$image_width, self::$image_height, self::$image_prev_width, self::$image_prev_height, $this->request->param('id'), NULL );
  174. }
  175. public function action_images_check()
  176. {
  177. $this->model->images_check( self::$images_folder, $this->request->param('id') );
  178. }
  179. public function action_copy2otherlang()
  180. {
  181. if( $this->model->copy2otherlang( $_POST['copy_for_lang'], $this->request->param( 'id' ), $this->lang ) )
  182. {
  183. $this->redirect_to_controller( $this->request->controller . '/' . $this->request->param( 'id' ) . '/edit' );
  184. }else
  185. {
  186. // $this->view->assign( 'errors', $this->model->errors );
  187. $this->action_edit();
  188. }
  189. }
  190. public function action_reprice()
  191. {
  192. $this->model->reprice();
  193. }
  194. public function action_statusUpdate()
  195. {
  196. // print_r($_POST);
  197. DB::update( 'shop_goods' )
  198. ->set(
  199. array(
  200. 'status' => $_POST['status']
  201. )
  202. )
  203. ->where( 'id', '=', $this->request->param( 'id' ) )
  204. ->execute();
  205. die( '1' );
  206. }
  207. public function action_statusUpdateBest()
  208. {
  209. $var = $this->request->param( 'id' );
  210. ;
  211. DB::update( 'shop_goods' )
  212. ->set( array( 'is_bestseller' => DB::expr( '! is_bestseller' ) ) )
  213. ->where( 'id', '=', $var )
  214. ->execute();
  215. //die(Kohana::debug($this));
  216. die( '1' );
  217. }
  218. public function action_statusUpdateNews()
  219. {
  220. $var = $this->request->param( 'id' );
  221. ;
  222. DB::update( 'shop_goods' )
  223. ->set( array( 'is_new' => DB::expr( '! is_new' ) ) )
  224. ->where( 'id', '=', $var )
  225. ->execute();
  226. //die(Kohana::debug($this));
  227. die( '1' );
  228. }
  229. public function action_statusUpdatePage()
  230. {
  231. $var = $this->request->param( 'id' );
  232. ;
  233. DB::update( 'shop_goods' )
  234. ->set( array( 'show_on_startpage' => DB::expr( '! show_on_startpage' ) ) )
  235. ->where( 'id', '=', $var )
  236. ->execute()
  237. ;
  238. //die(Kohana::debug($this));
  239. die( '1' );
  240. }
  241. public function action_toparentsMode()
  242. {
  243. $res = $this->model->toParentsMode( 1 );
  244. die( Kohana::debug( $res ) );
  245. }
  246. public function action_cancel_default_image()
  247. {
  248. $res = Model_Goods::update( $this->request->param('id'), array('default_photo' => '') );
  249. die( print($res) );
  250. }
  251. }