PageRenderTime 52ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/leotempcp/classes/widget/carousel.php

https://gitlab.com/ptisky/API_prestashop
PHP | 434 lines | 386 code | 29 blank | 19 comment | 18 complexity | 86f01fc6096aae2e3d03edc535d3d3c2 MD5 | raw file
  1. <?php
  2. /**
  3. * Leo Theme for Prestashop 1.6.x
  4. *
  5. * @author http://www.leotheme.com
  6. * @copyright Copyright (C) October 2013 LeoThemes.com <@emai:leotheme@gmail.com>
  7. * <info@leotheme.com>.All rights reserved.
  8. * @license GNU General Public License version 2
  9. */
  10. class LeoWidgetCarousel extends LeoWidgetBase
  11. {
  12. public $name = 'Carousel';
  13. public $for_module = 'manage';
  14. public function getWidgetInfo()
  15. {
  16. return array('label' => $this->l('Product List Carousel'), 'explain' => $this->l('Create Products List Carousel !'));
  17. }
  18. public function renderForm($args, $data)
  19. {
  20. # validate module
  21. unset($args);
  22. $helper = $this->getFormHelper();
  23. $types = array();
  24. $types[] = array(
  25. 'value' => 'newest',
  26. 'text' => $this->l('Products Newest')
  27. );
  28. $types[] = array(
  29. 'value' => 'bestseller',
  30. 'text' => $this->l('Products Bestseller')
  31. );
  32. $types[] = array(
  33. 'value' => 'special',
  34. 'text' => $this->l('Products Special')
  35. );
  36. $types[] = array(
  37. 'value' => 'featured',
  38. 'text' => $this->l('Products Featured')
  39. );
  40. $types[] = array(
  41. 'value' => 'random',
  42. 'text' => $this->l('Products Random')
  43. );
  44. $source = array(
  45. array(
  46. 'value' => 'pcategories', // The value of the 'value' attribute of the <option> tag.
  47. 'name' => $this->l('Category') // The value of the text content of the <option> tag.
  48. ),
  49. array(
  50. 'value' => 'ptype',
  51. 'name' => $this->l('Product')
  52. ),
  53. array(
  54. 'value' => 'pmanufacturers',
  55. 'name' => $this->l('Manufacturers')
  56. ),
  57. array(
  58. 'value' => 'pproductids',
  59. 'name' => $this->l('Product Ids')
  60. ));
  61. $orderby = array(
  62. array(
  63. 'order' => 'date_add', // The value of the 'value' attribute of the <option> tag.
  64. 'name' => $this->l('Date Add') // The value of the text content of the <option> tag.
  65. ),
  66. array(
  67. 'order' => 'date_upd', // The value of the 'value' attribute of the <option> tag.
  68. 'name' => $this->l('Date Update') // The value of the text content of the <option> tag.
  69. ),
  70. array(
  71. 'order' => 'name',
  72. 'name' => $this->l('Name')
  73. ),
  74. array(
  75. 'order' => 'id_product',
  76. 'name' => $this->l('Product Id')
  77. ),
  78. array(
  79. 'order' => 'price',
  80. 'name' => $this->l('Price')
  81. ),
  82. );
  83. $orderway = array(
  84. array(
  85. 'orderway' => 'ASC', // The value of the 'value' attribute of the <option> tag.
  86. 'name' => $this->l('Ascending') // The value of the text content of the <option> tag.
  87. ),
  88. array(
  89. 'orderway' => 'DESC', // The value of the 'value' attribute of the <option> tag.
  90. 'name' => $this->l('Descending') // The value of the text content of the <option> tag.
  91. ),
  92. );
  93. $pmanufacturers = $this->getManufacturers(Context::getContext()->shop->id);
  94. $selected_cat = array();
  95. if ($data)
  96. {
  97. if ($data['params'] && isset($data['params']['categories']) && $data['params']['categories'])
  98. $selected_cat = $data['params']['categories'];
  99. if ($data['params'] && isset($data['params']['pmanufacturer']) && $data['params']['pmanufacturer'])
  100. $data['params']['pmanufacturer[]'] = $data['params']['pmanufacturer'];
  101. }
  102. $this->fields_form[1]['form'] = array(
  103. 'legend' => array(
  104. 'title' => $this->l('Carousel Form.'),
  105. ),
  106. 'input' => array(
  107. array(
  108. 'type' => 'select',
  109. 'label' => $this->l('Source'),
  110. //'desc' => $this->l('The maximum number of products in each page Carousel (default: 3).'),
  111. 'name' => 'source',
  112. 'class' => 'group',
  113. 'default' => 'date_add',
  114. 'options' => array(
  115. 'query' => $source,
  116. 'id' => 'value',
  117. 'name' => 'name'
  118. )
  119. ),
  120. array(
  121. 'type' => 'categories',
  122. 'label' => $this->l('Categories'),
  123. 'name' => 'categories',
  124. 'default' => '',
  125. 'tree' => array(
  126. 'id' => 'pcategories',
  127. 'title' => 'Categories',
  128. 'selected_categories' => $selected_cat,
  129. 'use_search' => true,
  130. 'use_checkbox' => true
  131. )
  132. ),
  133. array(
  134. 'type' => 'select',
  135. 'label' => $this->l('Products List Type'),
  136. 'name' => 'ptype',
  137. 'options' => array('query' => $types,
  138. 'id' => 'value',
  139. 'name' => 'text'),
  140. 'default' => 'newest',
  141. 'desc' => $this->l('Select a Product List Type')
  142. ),
  143. array(
  144. 'type' => 'text',
  145. 'label' => $this->l('Product Ids'),
  146. 'name' => 'pproductids',
  147. 'default' => '',
  148. ),
  149. array(
  150. 'type' => 'select',
  151. 'label' => $this->l('Manufacturer'),
  152. 'name' => 'pmanufacturer[]',
  153. 'id' => 'pmanufacturers',
  154. 'default' => '',
  155. 'multiple' => true,
  156. 'options' => array(
  157. 'query' => $pmanufacturers,
  158. 'id' => 'id_manufacturer',
  159. 'name' => 'name'
  160. )
  161. ),
  162. array(
  163. 'type' => 'select',
  164. 'label' => $this->l('Order By'),
  165. 'desc' => $this->l('The maximum number of products in each page Carousel (default: 3).'),
  166. 'name' => 'orderby',
  167. 'default' => 'date_add',
  168. 'options' => array(
  169. 'query' => $orderby,
  170. 'id' => 'order',
  171. 'name' => 'name'
  172. )
  173. ),
  174. array(
  175. 'type' => 'select',
  176. 'label' => $this->l('Order Way'),
  177. 'desc' => $this->l('The maximum number of products in each page Carousel (default: 3).'),
  178. 'name' => 'orderway',
  179. 'default' => 'date_add',
  180. 'options' => array(
  181. 'query' => $orderway,
  182. 'id' => 'orderway',
  183. 'name' => 'name'
  184. )
  185. ),
  186. array(
  187. 'type' => 'text',
  188. 'label' => $this->l('Limit'),
  189. 'name' => 'itemstab',
  190. 'default' => 6,
  191. 'desc' => $this->l('The maximum number of products in each Carousel (default: 6).')
  192. ),
  193. array(
  194. 'type' => 'select',
  195. 'label' => $this->l('Carousel type'),
  196. 'name' => 'carousel_type',
  197. 'default' => LeomanagewidgetsOwlCarousel::CAROUSEL_BOOTSTRAP,
  198. 'class' => 'form-action',
  199. 'options' => array(
  200. 'query' => LeomanagewidgetsOwlCarousel::getCaroulseOptions(),
  201. 'id' => 'value',
  202. 'name' => 'name'
  203. )
  204. ),
  205. # config for Bootstrap Carousel - BEGIN
  206. array(
  207. 'type' => 'text',
  208. 'label' => $this->l('Items Per Page'),
  209. 'name' => 'itemspage',
  210. 'default' => 3,
  211. 'form_group_class' => 'carousel_type_sub carousel_type-'.LeomanagewidgetsOwlCarousel::CAROUSEL_BOOTSTRAP,
  212. 'desc' => $this->l('The maximum number of products in each page Carousel (default: 3).')
  213. ),
  214. array(
  215. 'type' => 'text',
  216. 'label' => $this->l('Colums In Tab'),
  217. 'name' => 'columns',
  218. 'default' => 3,
  219. 'form_group_class' => 'carousel_type_sub carousel_type-'.LeomanagewidgetsOwlCarousel::CAROUSEL_BOOTSTRAP,
  220. 'desc' => 'The maximum column products in each page Carousel (default: 3).'
  221. ),
  222. array(
  223. 'type' => 'text',
  224. 'label' => $this->l('Interval'),
  225. 'name' => 'interval',
  226. 'default' => 8000,
  227. 'form_group_class' => 'carousel_type_sub carousel_type-'.LeomanagewidgetsOwlCarousel::CAROUSEL_BOOTSTRAP,
  228. 'desc' => $this->l('Enter Time(miniseconds) to play carousel. Value 0 to stop.')
  229. ),
  230. ),
  231. 'buttons' => array(
  232. array(
  233. 'title' => $this->l('Save And Stay'),
  234. 'icon' => 'process-icon-save',
  235. 'class' => 'pull-right',
  236. 'type' => 'submit',
  237. 'name' => 'saveandstayleotempcp'
  238. ),
  239. array(
  240. 'title' => $this->l('Save'),
  241. 'icon' => 'process-icon-save',
  242. 'class' => 'pull-right',
  243. 'type' => 'submit',
  244. 'name' => 'saveleotempcp'
  245. ),
  246. )
  247. );
  248. // Add library owl carousel
  249. $owl_carousel = new LeomanagewidgetsOwlCarousel();
  250. $arrays = $owl_carousel->getOwlCarouselAdminFormOptions();
  251. foreach ($arrays as $key => $array)
  252. {
  253. # validate module
  254. unset($key);
  255. $this->fields_form[1]['form']['input'][] = $array;
  256. }
  257. $default_lang = (int)Configuration::get('PS_LANG_DEFAULT');
  258. $helper->tpl_vars = array(
  259. 'fields_value' => $this->getConfigFieldsValues($data),
  260. 'languages' => Context::getContext()->controller->getLanguages(),
  261. 'id_language' => $default_lang
  262. );
  263. return $helper->generateForm($this->fields_form);
  264. }
  265. public function renderContent($args, $setting)
  266. {
  267. # validate module
  268. unset($args);
  269. $t = array(
  270. 'name' => '',
  271. 'html' => '',
  272. );
  273. $setting = array_merge($t, $setting);
  274. $nb = ($setting['itemstab']) ? (int)($setting['itemstab']) : 6;
  275. $orderby = ($setting['orderby']) ? ($setting['orderby']) : 'date_add';
  276. $orderway = ($setting['orderway']) ? ($setting['orderway']) : 'ASC';
  277. $items_page = ($setting['itemspage']) ? (int)($setting['itemspage']) : 3;
  278. $columns_page = ($setting['columns']) ? (int)($setting['columns']) : 3;
  279. $interval = (isset($setting['interval'])) ? (int)($setting['interval']) : 8000;
  280. switch ($setting['source'])
  281. {
  282. case 'ptype':
  283. switch ($setting['ptype'])
  284. {
  285. case 'newest':
  286. $products = Product::getNewProducts($this->langID, 0, $nb, false, $orderby, $orderway);
  287. break;
  288. case 'featured':
  289. $category = new Category(Context::getContext()->shop->getCategory(), $this->langID);
  290. $products = $category->getProducts((int)$this->langID, 1, $nb, $orderby, $orderway);
  291. break;
  292. case 'bestseller':
  293. $products = ProductSale::getBestSalesLight((int)$this->langID, 0, $nb);
  294. break;
  295. case 'special':
  296. $products = Product::getPricesDrop($this->langID, 0, $nb, false, $orderby, $orderway);
  297. break;
  298. case 'random':
  299. $random = true;
  300. $products = $this->getProducts('WHERE p.id_product > 0', (int)Context::getContext()->language->id, 1, $nb, $orderby, $orderway, false, true, $random, $nb);
  301. Configuration::updateValue('LEO_CURRENT_RANDOM_CACHE', '1');
  302. break;
  303. }
  304. break;
  305. case 'pproductids':
  306. $where = '';
  307. if (empty($setting['pproductids']))
  308. return false;
  309. if ($pproductids = $setting['pproductids'])
  310. $where = 'WHERE p.id_product IN ('.pSQL($pproductids).')';
  311. $products = $this->getProducts($where, (int)Context::getContext()->language->id, 1, $nb, $orderby, $orderway);
  312. break;
  313. case 'pcategories':
  314. $where = '';
  315. $catids = (isset($setting['categories']) && $setting['categories']) ? ($setting['categories']) : array();
  316. $products = array();
  317. if ($catids)
  318. {
  319. $categorys = implode(',', $catids);
  320. $where = 'WHERE cp.id_category IN ('.pSQL($categorys).')';
  321. $products = $this->getProducts($where, (int)Context::getContext()->language->id, 1, $nb, $orderby, $orderway);
  322. }
  323. break;
  324. case 'pmanufacturers':
  325. $where = '';
  326. $manufacturers = ($setting['pmanufacturer']) ? ($setting['pmanufacturer']) : array();
  327. if ($manufacturers)
  328. {
  329. $manufacturers = implode(',', $manufacturers);
  330. $where = 'WHERE p.id_manufacturer IN ('.pSQL($manufacturers).')';
  331. }
  332. $products = $this->getProducts($where, (int)Context::getContext()->language->id, 1, $nb, $orderby, $orderway);
  333. break;
  334. }
  335. Context::getContext()->controller->addColorsToProductList($products);
  336. $setting['products'] = $products;
  337. $setting['itemsperpage'] = $items_page;
  338. $setting['columnspage'] = $columns_page;
  339. $setting['scolumn'] = 12 / $columns_page;
  340. $setting['interval'] = $interval;
  341. $setting['homeSize'] = Image::getSize(ImageType::getFormatedName('home'));
  342. $setting['tab'] = 'leoproductcarousel'.rand(20, rand());
  343. $output = array('type' => 'carousel', 'data' => $setting);
  344. return $output;
  345. }
  346. /**
  347. * 0 no multi_lang
  348. * 1 multi_lang follow id_lang
  349. * 2 multi_lnag follow code_lang
  350. */
  351. public function getConfigKey($multi_lang = 0)
  352. {
  353. if ($multi_lang == 0)
  354. {
  355. return array(
  356. 'source',
  357. 'categories',
  358. 'ptype',
  359. 'pproductids',
  360. 'orderby',
  361. 'orderway',
  362. 'itemstab',
  363. 'carousel_type',
  364. 'itemspage',
  365. 'columns',
  366. 'interval',
  367. 'owl_items',
  368. 'owl_rows',
  369. 'owl_autoPlay',
  370. 'owl_stopOnHover',
  371. 'owl_autoHeight',
  372. 'owl_responsive',
  373. 'owl_mouseDrag',
  374. 'owl_touchDrag',
  375. 'owl_navigation',
  376. 'owl_slideSpeed',
  377. 'owl_itemsDesktop',
  378. 'owl_itemsDesktopSmall',
  379. 'owl_itemsTablet',
  380. 'owl_itemsTabletSmall',
  381. 'owl_itemsMobile',
  382. 'owl_itemsCustom',
  383. 'owl_lazyLoad',
  384. 'owl_lazyEffect',
  385. 'owl_lazyFollow',
  386. 'owl_pagination',
  387. 'owl_paginationNumbers',
  388. 'owl_paginationSpeed',
  389. 'owl_rewindNav',
  390. 'owl_rewindSpeed',
  391. 'owl_scrollPerPage',
  392. );
  393. }
  394. elseif ($multi_lang == 1)
  395. {
  396. return array(
  397. );
  398. }
  399. elseif ($multi_lang == 2)
  400. {
  401. return array(
  402. );
  403. }
  404. }
  405. }