PageRenderTime 57ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/seyar/ari100krat.local
PHP | 314 lines | 224 code | 65 blank | 25 comment | 9 complexity | f8bb2a54e3b035638ac1f1b115d97074 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  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. $this->template = View::factory( 'shop_products_edit' );
  85. $this->template->edit_categories_list = Model_Categories::categories_folders( $this->lang, 1 );
  86. $this->template->edit_price_categories = Model_Shop::shop_price_categories();
  87. $this->template->edit_currencies_list = Model_Shop::shop_currencies();
  88. $this->template->defaultCurrency = Kohana::config('shop')->default_currency;
  89. //die(Kohana::debug($this->template->edit_categories_list));
  90. $this->template->obj = $this->model->load( $this->request->param('id') );
  91. $this->template->brands = array(-1 => array('id' => '', 'name'=> ''))+Model_Brands::getItems();
  92. $addGoodsModel = Kohana::config('shop')->addGoodsModel;
  93. $addGoodsMethod = Kohana::config('shop')->addGoodsMethGet;
  94. if( class_exists($addGoodsModel) && $this->request->param('id') )
  95. $this->template->recGoods = call_user_func(array($addGoodsModel, $addGoodsMethod),'goodId = '.$this->request->param('id'));
  96. }
  97. public function action_update()
  98. {
  99. // if( $this->request->param( 'id' ) == 0 )
  100. // {
  101. // $id = $this->model->product_create();
  102. // $this->redirect_to_controller( $this->request->controller . '/' . $id . '/edit' );
  103. // }
  104. if( $res = $this->model->save( $this->lang, $this->request->param( 'id' ) ) )
  105. {
  106. $this->redirect_to_controller( $this->request->controller . '/' . $res . '/edit' . '#' . $_POST['actTab'] );
  107. }else
  108. {
  109. // $this->template->errors = $this->model->errors;
  110. $this->action_edit();
  111. }
  112. }
  113. public function action_save()
  114. {
  115. // if( $this->request->param( 'id' ) == 0 )
  116. // {
  117. // $id = $this->model->product_create();
  118. //
  119. // $this->redirect_to_controller( $this->request->controller . '/products' );
  120. // }
  121. if( $this->model->save( $this->lang, $this->request->param( 'id' ) ) )
  122. {
  123. $this->redirect_to_controller( $this->request->controller );
  124. }
  125. else
  126. {
  127. $this->template->errors = $this->model->errors;
  128. $this->action_edit();
  129. }
  130. }
  131. public function action_delete()
  132. {
  133. if( $this->request->param( 'id' ) )
  134. $this->model->delete( $this->request->param( 'id' ) );
  135. elseif( count( $_POST['chk'] ) )
  136. $this->model->delete_list( $_POST['chk'] );
  137. $this->redirect_to_controller( $this->request->controller );
  138. }
  139. // Images Actions
  140. public function action_image_preview()
  141. {
  142. $this->show_image_preview( MEDIAPATH . self::$images_folder . '/' . $this->request->param('id') . '/' . basename( $_GET['name'] ),$this->request->param('id') );
  143. }
  144. public function action_images_default()
  145. {
  146. $this->model->images_default( MEDIAPATH . self::$images_folder . '/' . $this->request->param('id') . '/' . basename( $_GET['name'] ),$this->request->param('id') );
  147. die();
  148. }
  149. public function action_images_delete()
  150. {
  151. $this->model->images_delete( self::$images_folder, $this->request->param('id') );
  152. die();
  153. }
  154. public function action_images_show()
  155. {
  156. echo json_encode(
  157. $this->model->images_show(
  158. self::$images_folder
  159. , strtolower($this->admin_path . Request::instance()->controller . "/" . MODULE_NAME . ':' . MODULE_SUBCONTROLLER . "/" . $this->request->param('id'))
  160. , strtolower(MEDIAWEBPATH . MODULE_NAME . "/" . $this->request->param('id').'/')
  161. , $this->request->param('id')
  162. )
  163. );
  164. die();
  165. }
  166. // Images Upload Actions
  167. public function action_images_upload()
  168. {
  169. $watermark = Kohana::config( 'shop.watermark' );
  170. // 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'), $watermark));
  171. $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'), $watermark );
  172. }
  173. public function action_images_check()
  174. {
  175. $this->model->images_check( self::$images_folder, $this->request->param('id') );
  176. }
  177. public function action_copy2otherlang()
  178. {
  179. if( $this->model->copy2otherlang( $_POST['copy_for_lang'], $this->request->param( 'id' ), $this->lang ) )
  180. {
  181. $this->redirect_to_controller( $this->request->controller . '/' . $this->request->param( 'id' ) . '/edit' );
  182. }else
  183. {
  184. $this->view->assign( 'errors', $this->model->errors );
  185. $this->action_edit();
  186. }
  187. }
  188. public function action_reprice()
  189. {
  190. $this->model->reprice();
  191. }
  192. public function action_statusUpdate()
  193. {
  194. // print_r($_POST);
  195. DB::update( 'shop_goods' )
  196. ->set(
  197. array(
  198. 'status' => $_POST['status']
  199. )
  200. )
  201. ->where( 'id', '=', $this->request->param( 'id' ) )
  202. ->execute();
  203. die( '1' );
  204. }
  205. public function action_statusUpdateBest()
  206. {
  207. $var = $this->request->param( 'id' );
  208. ;
  209. DB::update( 'shop_goods' )
  210. ->set( array( 'is_bestseller' => DB::expr( '! is_bestseller' ) ) )
  211. ->where( 'id', '=', $var )
  212. ->execute();
  213. //die(Kohana::debug($this));
  214. die( '1' );
  215. }
  216. public function action_statusUpdateNews()
  217. {
  218. $var = $this->request->param( 'id' );
  219. ;
  220. DB::update( 'shop_goods' )
  221. ->set( array( 'is_new' => DB::expr( '! is_new' ) ) )
  222. ->where( 'id', '=', $var )
  223. ->execute();
  224. //die(Kohana::debug($this));
  225. die( '1' );
  226. }
  227. public function action_statusUpdatePage()
  228. {
  229. $var = $this->request->param( 'id' );
  230. ;
  231. DB::update( 'shop_goods' )
  232. ->set( array( 'show_on_startpage' => DB::expr( '! show_on_startpage' ) ) )
  233. ->where( 'id', '=', $var )
  234. ->execute()
  235. ;
  236. //die(Kohana::debug($this));
  237. die( '1' );
  238. }
  239. public function action_toparentsMode()
  240. {
  241. $res = $this->model->toParentsMode( 1 );
  242. die( Kohana::debug( $res ) );
  243. }
  244. public function action_cancel_default_image()
  245. {
  246. $res = Model_Goods::update( $this->request->param('id'), array('default_photo' => '') );
  247. die( print($res) );
  248. }
  249. }