Guest User

PHP File

a guest
Jan 26th, 2022
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.72 KB | None | 0 0
  1. <?php
  2.  
  3. if (!defined('_PS_VERSION_'))
  4. exit;
  5.  
  6. use PrestaShop\PrestaShop\Core\Module\WidgetInterface;
  7. use PrestaShop\PrestaShop\Adapter\Category\CategoryProductSearchProvider;
  8. use PrestaShop\PrestaShop\Adapter\Image\ImageRetriever;
  9. use PrestaShop\PrestaShop\Adapter\Product\PriceFormatter;
  10. use PrestaShop\PrestaShop\Core\Product\ProductListingPresenter;
  11. use PrestaShop\PrestaShop\Adapter\Product\ProductColorsRetriever;
  12. use PrestaShop\PrestaShop\Adapter\Translator;
  13. use PrestaShop\PrestaShop\Adapter\LegacyContext;
  14. use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchContext;
  15. use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
  16. use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
  17.  
  18. class postabcateslider extends Module implements WidgetInterface
  19. {
  20.  
  21. private $templateFile;
  22.  
  23. public static $sort_by = array(
  24. 1 => array('id' => 1, 'name' => 'Product Name'),
  25. 2 => array('id' => 2, 'name' => 'Price'),
  26. 3 => array('id' => 3, 'name' => 'Product ID'),
  27. 4 => array('id' => 4, 'name' => 'Position'),
  28. 5 => array('id' => 5, 'name' => 'Date updated'),
  29. 6 => array('id' => 6, 'name' => 'Date added'),
  30. 7 => array('id' => 7, 'name' => 'Po iloĊ›ci produktu'),
  31. 8 => array('id' => 8, 'name' => 'Random'),
  32. );
  33.  
  34. public static $order_by = array(
  35. 1 => array('id' => 1, 'name' => 'Descending'),
  36. 2 => array('id' => 2, 'name' => 'Ascending'),
  37. );
  38. public function __construct()
  39. {
  40. $this->name = 'postabcateslider';
  41. $this->tab = 'front_office_features';
  42. $this->version = '1.5';
  43. $this->author = 'posthemes';
  44. $this->bootstrap = true;
  45. $this->_html = '';
  46. $this->displayName = $this->l('Category Tab Slider');
  47. $this->description = $this->l('Show tab products from categories on homepage');
  48. parent::__construct();
  49.  
  50. $this->ps_versions_compliancy = array('min' => '1.7.0.0', 'max' => _PS_VERSION_);
  51. $this->templateFile = 'module:postabcateslider/views/templates/hook/postabcateslider.tpl';
  52. }
  53.  
  54. public function install()
  55. {
  56. Configuration::updateValue($this->name . '_row', 2);
  57. Configuration::updateValue($this->name . '_number_item', 4);
  58. Configuration::updateValue($this->name . '_speed_slide', 1000);
  59. Configuration::updateValue($this->name . '_auto_play', 0);
  60. Configuration::updateValue($this->name . '_pause_time', 3000);
  61. Configuration::updateValue($this->name . '_show_arrow', 1);
  62. Configuration::updateValue($this->name . '_show_ctr', 0);
  63. Configuration::updateValue($this->name . '_limit', 8);
  64. Configuration::updateValue($this->name . '_sort', 1);
  65. Configuration::updateValue($this->name . '_order', 1);
  66. Configuration::updateValue($this->name . '_move', 1);
  67. Configuration::updateValue($this->name . '_pausehover', 0);
  68. Configuration::updateValue($this->name . '_per_md', 4);
  69. Configuration::updateValue($this->name . '_per_sm', 3);
  70. Configuration::updateValue($this->name . '_per_xs', 2);
  71. Configuration::updateValue($this->name . '_per_xxs', 1);
  72. $arrayDefault = array('3', '4', '5');
  73. $cateDefault = implode(',', $arrayDefault);
  74. Configuration::updateGlobalValue($this->name . '_list_cate', $cateDefault);
  75.  
  76. return parent::install()
  77. && $this->registerHook('displayBlockPosition1')
  78. && $this->registerHook('header')
  79. && $this->installFixtures();
  80. }
  81. protected function installFixtures()
  82. {
  83. $languages = Language::getLanguages(false);
  84. foreach ($languages as $lang) {
  85. $this->installFixture((int)$lang['id_lang'], 'cms.jpg');
  86. }
  87.  
  88. return true;
  89. }
  90.  
  91. protected function installFixture($id_lang, $image = null)
  92. {
  93. $values['postabcateslider_img'][(int)$id_lang] = $image;
  94. $values['postabcateslider_link'][(int)$id_lang] = '#';
  95. $values['postabcateslider_title'][(int)$id_lang] = 'Our Products';
  96. Configuration::updateValue($this->name . '_title', $values['postabcateslider_title']);
  97. Configuration::updateValue($this->name . '_img', $values['postabcateslider_img']);
  98. Configuration::updateValue($this->name . '_link', $values['postabcateslider_link']);
  99. }
  100.  
  101. public function uninstall()
  102. {
  103. $this->_clearCache('postabcateslider.tpl');
  104. Configuration::deleteByName($this->name . '_row');
  105. Configuration::deleteByName($this->name . '_number_item');
  106. Configuration::deleteByName($this->name . '_speed_slide');
  107. Configuration::deleteByName($this->name . '_auto_play');
  108. Configuration::deleteByName($this->name . '_pause_time');
  109. Configuration::deleteByName($this->name . '_show_arrow');
  110. Configuration::deleteByName($this->name . '_show_ctr');
  111. Configuration::deleteByName($this->name . '_limit');
  112. Configuration::deleteByName($this->name . '_list_cate');
  113. Configuration::deleteByName($this->name . '_title');
  114. Configuration::deleteByName($this->name . '_img');
  115. Configuration::deleteByName($this->name . '_link');
  116. Configuration::deleteByName($this->name . '_sort');
  117. Configuration::deleteByName($this->name . '_order');
  118. Configuration::deleteByName($this->name . '_move');
  119. Configuration::deleteByName($this->name . '_pausehover');
  120. Configuration::deleteByName($this->name . '_per_md');
  121. Configuration::deleteByName($this->name . '_per_sm');
  122. Configuration::deleteByName($this->name . '_per_xs');
  123. Configuration::deleteByName($this->name . '_per_xxs');
  124. $arrayDefault = array('3', '4', '5');
  125.  
  126. return parent::uninstall();
  127. }
  128.  
  129.  
  130. public function psversion()
  131. {
  132. $version = _PS_VERSION_;
  133. $exp = $explode = explode(".", $version);
  134. return $exp[1];
  135. }
  136.  
  137.  
  138. public function hookHeader($params)
  139. {
  140. $this->context->controller->addCSS($this->_path . '/postabcateslider.css');
  141. $this->context->controller->addJS($this->_path . 'js/postabcateslider.js');
  142. }
  143.  
  144. public function renderWidget($hookName = null, array $configuration = [])
  145. {
  146. if (!$this->isCached($this->templateFile, $this->getCacheId('postabcateslider'))) {
  147. $variables = $this->getWidgetVariables($hookName, $configuration);
  148. if (empty($variables)) {
  149. return false;
  150. }
  151.  
  152. $this->smarty->assign($variables);
  153. }
  154.  
  155. return $this->fetch($this->templateFile, $this->getCacheId('postabcateslider'));
  156. }
  157.  
  158. public function getWidgetVariables($hookName = null, array $configuration = [])
  159. {
  160. $catSelected = Configuration::get($this->name . '_list_cate');
  161. $cateArray = explode(',', $catSelected);
  162. $id_lang = (int) Context::getContext()->language->id;
  163. $id_shop = (int) Context::getContext()->shop->id;
  164. $arrayProductCate = array();
  165.  
  166. foreach ($cateArray as $id_category) {
  167. $category = new Category((int) $id_category, (int) $id_lang, (int) $id_shop);
  168. $categoryProducts = $this->getProducts((int) $id_category);
  169. $files = scandir(_PS_CAT_IMG_DIR_);
  170. $categorythumb = '';
  171. if (count($files) > 0) {
  172. foreach ($files as $file) {
  173. if (preg_match('/^' . $id_category . '-([0-9])?_thumb.jpg/i', $file) === 1) {
  174. $categorythumb = $this->context->link->getMediaLink(_THEME_CAT_DIR_ . $file);
  175. }
  176. }
  177. }
  178. if ($categoryProducts) {
  179. $arrayProductCate[] = array('id' => $id_category, 'name' => $category->name, 'products' => $categoryProducts, 'categorythumbs' => $categorythumb,);
  180. }
  181. }
  182. $title = Configuration::get($this->name . '_title', $this->context->language->id);
  183. $slider_options = array(
  184. 'rows' => (int)Configuration::get($this->name . '_row'),
  185. 'number_item' => (int)Configuration::get($this->name . '_number_item'),
  186. 'speed_slide' => (int)Configuration::get($this->name . '_speed_slide'),
  187. 'auto_play' => (int)Configuration::get($this->name . '_auto_play'),
  188. 'auto_time' => (int)Configuration::get($this->name . '_pause_time'),
  189. 'show_arrow' => (int)Configuration::get($this->name . '_show_arrow'),
  190. 'show_pagination' => (int)Configuration::get($this->name . '_show_ctr'),
  191. 'limit' => (int)Configuration::get($this->name . '_limit'),
  192. 'move' => (int)Configuration::get($this->name . '_move'),
  193. 'pausehover' => (int)Configuration::get($this->name . '_pausehover'),
  194. 'items_md' => (int)Configuration::get($this->name . '_per_md'),
  195. 'items_sm' => (int)Configuration::get($this->name . '_per_sm'),
  196. 'items_xs' => (int)Configuration::get($this->name . '_per_xs'),
  197. 'items_xxs' => (int)Configuration::get($this->name . '_per_xxs'),
  198. );
  199.  
  200. $imgname = Configuration::get($this->name . '_img', $this->context->language->id);
  201.  
  202. if ($imgname && file_exists(_PS_MODULE_DIR_ . $this->name . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . $imgname))
  203. $this->smarty->assign('banner_img', $this->context->link->protocol_content . Tools::getMediaServer($imgname) . $this->_path . 'img/' . $imgname);
  204.  
  205. if (!empty($arrayProductCate)) {
  206. return array(
  207. 'productCates' => $arrayProductCate,
  208. 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
  209. 'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
  210. 'tab_effect' => Configuration::get($this->name . '_tab_effect'),
  211. 'title' => Configuration::get($this->name . '_title', $this->context->language->id),
  212. 'image_link' => Configuration::get($this->name . '_link', $this->context->language->id),
  213. 'slider_options' => $slider_options
  214. );
  215. }
  216.  
  217. return false;
  218. }
  219. protected function getProducts($category_id)
  220. {
  221.  
  222.  
  223. $random = false;
  224. $sortby = Configuration::get($this->name . '_sort');
  225. switch ($sortby) {
  226. case 1:
  227. $sortby = 'name';
  228. break;
  229. case 2:
  230. $sortby = 'price';
  231. break;
  232. case 3:
  233. $sortby = 'id_product';
  234. break;
  235. case 4:
  236. $sortby = 'position';
  237. break;
  238. case 5:
  239. $sortby = 'date_upd';
  240. break;
  241. case 6:
  242. $sortby = 'date_add';
  243. break;
  244. case 7:
  245. $sortby = 'quantity';
  246. break;
  247. case 8:
  248. $sortby = null;
  249. $random = true;
  250. break;
  251. }
  252. $orderby = Configuration::get($this->name . '_order');
  253. if ($orderby == 1) {
  254. $orderby = 'DESC';
  255. } else {
  256. $orderby = 'ASC';
  257. };
  258.  
  259. $category = new Category($category_id);
  260.  
  261. $searchProvider = new CategoryProductSearchProvider(
  262. $this->context->getTranslator(),
  263. $category
  264. );
  265.  
  266. $context = new ProductSearchContext($this->context);
  267.  
  268. $query = new ProductSearchQuery();
  269.  
  270. $nProducts = Configuration::get($this->name . '_limit');
  271. if ($nProducts < 0) {
  272. $nProducts = 12;
  273. }
  274.  
  275. $query
  276. ->setResultsPerPage($nProducts)
  277. ->setPage(1);
  278.  
  279. if ($random) {
  280. $query->setSortOrder(SortOrder::random());
  281. } else {
  282. $query->setSortOrder(new SortOrder('product', $sortby, $orderby,));
  283. }
  284.  
  285. $result = $searchProvider->runQuery(
  286. $context,
  287. $query
  288. );
  289.  
  290. $assembler = new ProductAssembler($this->context);
  291.  
  292. $presenterFactory = new ProductPresenterFactory($this->context);
  293. $presentationSettings = $presenterFactory->getPresentationSettings();
  294. $presenter = new ProductListingPresenter(
  295. new ImageRetriever(
  296. $this->context->link
  297. ),
  298. $this->context->link,
  299. new PriceFormatter(),
  300. new ProductColorsRetriever(),
  301. $this->context->getTranslator()
  302. );
  303.  
  304. $products_for_template = [];
  305.  
  306.  
  307.  
  308.  
  309. foreach ($result->getProducts() as $rawProduct) {
  310.  
  311. $products_for_template[] = $presenter->present(
  312. $presentationSettings,
  313. $assembler->assembleProduct($rawProduct),
  314. $this->context->language
  315. );
  316. }
  317.  
  318.  
  319. return $products_for_template;
  320. }
  321. private function postProcess()
  322. {
  323. if (Tools::isSubmit('submitpostabcateslider')) {
  324. $languages = Language::getLanguages(false);
  325. $values = array();
  326. $update_images_values = false;
  327.  
  328.  
  329. foreach ($languages as $lang) {
  330. if (
  331. isset($_FILES['postabcateslider_img_' . $lang['id_lang']])
  332. && isset($_FILES['postabcateslider_img_' . $lang['id_lang']]['tmp_name'])
  333. && !empty($_FILES['postabcateslider_img_' . $lang['id_lang']]['tmp_name'])
  334. ) {
  335. if ($error = ImageManager::validateUpload($_FILES['postabcateslider_img_' . $lang['id_lang']], 4000000))
  336. return $error;
  337. else {
  338. $ext = substr($_FILES['postabcateslider_img_' . $lang['id_lang']]['name'], strrpos($_FILES['postabcateslider_img_' . $lang['id_lang']]['name'], '.') + 1);
  339. $file_name = md5($_FILES['postabcateslider_img_' . $lang['id_lang']]['name']) . '.' . $ext;
  340.  
  341. if (!move_uploaded_file($_FILES['postabcateslider_img_' . $lang['id_lang']]['tmp_name'], dirname(__FILE__) . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . $file_name))
  342. return $this->displayError($this->l('An error occurred while attempting to upload the file.'));
  343. else {
  344. if (
  345. Configuration::hasContext('postabcateslider_img', $lang['id_lang'], Shop::getContext())
  346. && Configuration::get('postabcateslider_img', $lang['id_lang']) != $file_name
  347. )
  348. @unlink(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . Configuration::get('postabcateslider_img', $lang['id_lang']));
  349.  
  350. $values['postabcateslider_img'][$lang['id_lang']] = $file_name;
  351. }
  352. }
  353.  
  354. $update_images_values = true;
  355. }
  356. $values['postabcateslider_link'][$lang['id_lang']] = Tools::getValue('postabcateslider_link_' . $lang['id_lang']);
  357. $values['postabcateslider_title'][$lang['id_lang']] = Tools::getValue('postabcateslider_title_' . $lang['id_lang']);
  358. }
  359.  
  360. if ($update_images_values)
  361. Configuration::updateValue($this->name . '_img', $values['postabcateslider_img']);
  362.  
  363. Configuration::updateValue($this->name . '_link', $values['postabcateslider_link']);
  364. Configuration::updateValue($this->name . '_title', $values['postabcateslider_title']);
  365.  
  366. Configuration::updateValue($this->name . '_list_cate', implode(',', Tools::getValue('postabcateslider_list_cate')));
  367.  
  368. Configuration::updateValue($this->name . '_limit', Tools::getValue('postabcateslider_limit'));
  369. Configuration::updateValue($this->name . '_row', Tools::getValue('postabcateslider_row'));
  370. Configuration::updateValue($this->name . '_speed_slide', Tools::getValue('postabcateslider_speed_slide'));
  371. Configuration::updateValue($this->name . '_pause_time', Tools::getValue('postabcateslider_pause_time'));
  372. Configuration::updateValue($this->name . '_auto_play', Tools::getValue('postabcateslider_auto_play'));
  373. Configuration::updateValue($this->name . '_show_arrow', Tools::getValue('postabcateslider_show_arrow'));
  374. Configuration::updateValue($this->name . '_show_ctr', Tools::getValue('postabcateslider_show_ctr'));
  375. Configuration::updateValue($this->name . '_number_item', Tools::getValue('postabcateslider_number_item'));
  376.  
  377. Configuration::updateValue($this->name . '_sort', Tools::getValue('postabcateslider_sort'));
  378. Configuration::updateValue($this->name . '_order', Tools::getValue('postabcateslider_order'));
  379. Configuration::updateValue($this->name . '_move', Tools::getValue('postabcateslider_move'));
  380. Configuration::updateValue($this->name . '_pausehover', Tools::getValue('postabcateslider_pausehover'));
  381. Configuration::updateValue($this->name . '_per_md', Tools::getValue('postabcateslider_per_md'));
  382. Configuration::updateValue($this->name . '_per_sm', Tools::getValue('postabcateslider_per_sm'));
  383. Configuration::updateValue($this->name . '_per_xs', Tools::getValue('postabcateslider_per_xs'));
  384. Configuration::updateValue($this->name . '_per_xxs', Tools::getValue('postabcateslider_per_xxs'));
  385. return $this->displayConfirmation($this->l('The settings have been updated.'));
  386. }
  387.  
  388. return '';
  389. }
  390.  
  391. public function getContent()
  392. {
  393. return $this->postProcess() . $this->renderForm();
  394. }
  395. public function renderForm()
  396. {
  397. $cateCurrent = Configuration::get($this->name . '_list_cate');
  398. $cateCurrent = explode(',', $cateCurrent);
  399.  
  400. $id_lang = (int) Context::getContext()->language->id;
  401. $options = $this->getCategoryOption(1, (int)$id_lang, (int)Shop::getContextShopID());
  402. $fields_form[0]['form'] = array(
  403. 'legend' => array(
  404. 'title' => $this->l('Module Settings'),
  405. 'icon' => 'icon-cogs'
  406. ),
  407. 'input' => array(
  408. array(
  409. 'type' => 'text',
  410. 'lang' => true,
  411. 'label' => $this->l('Module title'),
  412. 'name' => 'postabcateslider_title',
  413. 'desc' => $this->l('This title will be displayed on front-office.')
  414. ),
  415. array(
  416. 'type' => 'select',
  417. 'label' => $this->l('Sort by:'),
  418. 'name' => 'postabcateslider_sort',
  419. 'options' => array(
  420. 'query' => self::$sort_by,
  421. 'id' => 'id',
  422. 'name' => 'name',
  423. ),
  424. 'validation' => 'isUnsignedInt',
  425. ),
  426. array(
  427. 'type' => 'select',
  428. 'label' => $this->l('Order by:'),
  429. 'name' => 'postabcateslider_order',
  430. 'options' => array(
  431. 'query' => self::$order_by,
  432. 'id' => 'id',
  433. 'name' => 'name',
  434. ),
  435. 'validation' => 'isUnsignedInt',
  436. ),
  437. array(
  438. 'type' => 'text',
  439. 'label' => $this->l('Products limit :'),
  440. 'name' => 'postabcateslider_limit',
  441. 'class' => 'fixed-width-sm',
  442. 'desc' => $this->l('Set the number of products which you would like to see displayed in this module')
  443. ),
  444. array(
  445. 'type' => 'file_lang',
  446. 'label' => $this->l('Banner image'),
  447. 'name' => 'postabcateslider_img',
  448. 'desc' => $this->l('Upload an image for your banner. The recommended dimensions are 1170 x 65px.'),
  449. 'lang' => true,
  450. ),
  451. array(
  452. 'type' => 'text',
  453. 'lang' => true,
  454. 'label' => $this->l('Banner Link'),
  455. 'name' => 'postabcateslider_link',
  456. 'desc' => $this->l('Enter the link associated to your banner. When clicking on the banner, the link opens in the same window.')
  457. ),
  458. array(
  459. 'type' => 'selectlist',
  460. 'label' => 'Choose the categories:',
  461. 'name' => 'postabcateslider_list_cate',
  462. 'multiple' => true,
  463. 'size' => 500
  464. ),
  465.  
  466. ),
  467. 'submit' => array(
  468. 'title' => $this->l('Save'),
  469. )
  470. );
  471. $fields_form[1]['form'] = array(
  472. 'legend' => array(
  473. 'title' => $this->l('Slider configurations'),
  474. 'icon' => 'icon-cogs'
  475. ),
  476. 'input' => array(
  477. array(
  478. 'type' => 'text',
  479. 'label' => $this->l('Rows'),
  480. 'name' => 'postabcateslider_row',
  481. 'class' => 'fixed-width-sm',
  482. 'desc' => $this->l('Number rows of module')
  483. ),
  484. array(
  485. 'type' => 'text',
  486. 'label' => $this->l('Number of Items:'),
  487. 'name' => 'postabcateslider_number_item',
  488. 'class' => 'fixed-width-sm',
  489. 'desc' => $this->l('Show number of product visible.')
  490. ),
  491. array(
  492. 'type' => 'text',
  493. 'label' => $this->l('Slide speed:'),
  494. 'name' => 'postabcateslider_speed_slide',
  495. 'class' => 'fixed-width-sm',
  496. 'desc' => $this->l('')
  497. ),
  498.  
  499. array(
  500. 'type' => 'switch',
  501. 'label' => $this->l('Auto play'),
  502. 'name' => 'postabcateslider_auto_play',
  503. 'class' => 'fixed-width-xs',
  504. 'desc' => $this->l(''),
  505. 'values' => array(
  506. array(
  507. 'id' => 'active_on',
  508. 'value' => 1,
  509. 'label' => $this->l('Enabled')
  510. ),
  511. array(
  512. 'id' => 'active_off',
  513. 'value' => 0,
  514. 'label' => $this->l('Disabled')
  515. )
  516. )
  517. ),
  518. array(
  519. 'type' => 'text',
  520. 'label' => $this->l('Time auto'),
  521. 'name' => 'postabcateslider_pause_time',
  522. 'class' => 'fixed-width-sm',
  523. 'desc' => $this->l('This field only is value when auto play function is enable. Default is 3000ms.')
  524. ),
  525. array(
  526. 'type' => 'switch',
  527. 'label' => $this->l('Show Next/Back control:'),
  528. 'name' => 'postabcateslider_show_arrow',
  529. 'class' => 'fixed-width-xs',
  530. 'desc' => $this->l(''),
  531. 'values' => array(
  532. array(
  533. 'id' => 'active_on',
  534. 'value' => 1,
  535. 'label' => $this->l('Enabled')
  536. ),
  537. array(
  538. 'id' => 'active_off',
  539. 'value' => 0,
  540. 'label' => $this->l('Disabled')
  541. )
  542. )
  543. ),
  544. array(
  545. 'type' => 'switch',
  546. 'label' => $this->l('Show navigation control:'),
  547. 'name' => 'postabcateslider_show_ctr',
  548. 'class' => 'fixed-width-xs',
  549. 'desc' => $this->l(''),
  550. 'values' => array(
  551. array(
  552. 'id' => 'active_on',
  553. 'value' => 1,
  554. 'label' => $this->l('Enabled')
  555. ),
  556. array(
  557. 'id' => 'active_off',
  558. 'value' => 0,
  559. 'label' => $this->l('Disabled')
  560. )
  561. )
  562. ),
  563. array(
  564. 'type' => 'radio',
  565. 'label' => $this->l('Scroll number:'),
  566. 'name' => 'postabcateslider_move',
  567. 'default_value' => 0,
  568. 'values' => array(
  569. array(
  570. 'id' => 'postabcateslider_move_on',
  571. 'value' => 1,
  572. 'label' => $this->l('1 item')
  573. ),
  574. array(
  575. 'id' => 'postabcateslider_move_off',
  576. 'value' => 0,
  577. 'label' => $this->l('All visible items')
  578. ),
  579. ),
  580. 'validation' => 'isBool',
  581. ),
  582. array(
  583. 'type' => 'switch',
  584. 'label' => $this->l('Pause On Hover:'),
  585. 'name' => 'postabcateslider_pausehover',
  586. 'default_value' => 1,
  587. 'is_bool' => true,
  588. 'values' => array(
  589. array(
  590. 'id' => 'postabcateslider_pausehover_on',
  591. 'value' => 1,
  592. 'label' => $this->l('Yes')
  593. ),
  594. array(
  595. 'id' => 'postabcateslider_pausehover_off',
  596. 'value' => 0,
  597. 'label' => $this->l('No')
  598. ),
  599. ),
  600. 'validation' => 'isBool',
  601. ),
  602. 'pos_tabcate_pro' => array(
  603. 'type' => 'html',
  604. 'id' => 'pos_tabcate_pro',
  605. 'label' => $this->l('Responsive:'),
  606. 'name' => '',
  607. ),
  608. ),
  609. 'submit' => array(
  610. 'title' => $this->l('Save'),
  611. )
  612. );
  613. $fields_form[1]['form']['input']['pos_tabcate_pro']['name'] = $this->BuildDropListGroup($this->findCateProPer());
  614.  
  615. $helper = new HelperForm();
  616. $helper->show_toolbar = true;
  617. $helper->table = $this->table;
  618. $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
  619. $helper->module = $this;
  620. $helper->options = $options;
  621. $helper->default_form_language = $lang->id;
  622. $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
  623. $helper->identifier = $this->identifier;
  624. $helper->submit_action = 'submitpostabcateslider';
  625. $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name;
  626. $helper->token = Tools::getAdminTokenLite('AdminModules');
  627. $module = _PS_MODULE_DIR_;
  628. $helper->tpl_vars = array(
  629. 'module' => $module,
  630. 'uri' => $this->getPathUri(),
  631. 'fields_value' => $this->getConfigFieldsValues(),
  632. 'languages' => $this->context->controller->getLanguages(),
  633. 'id_language' => $this->context->language->id,
  634. 'options' => $options,
  635. 'cateCurrent' => $cateCurrent,
  636. );
  637.  
  638. return $helper->generateForm($fields_form);
  639. }
  640.  
  641. public function getConfigFieldsValues()
  642. {
  643. $languages = Language::getLanguages(false);
  644. $fields = array();
  645. $fields['postabcateslider_number_item'] = Tools::getValue('postabcateslider_number_item', (int)Configuration::get($this->name . '_number_item'));
  646. $fields['postabcateslider_speed_slide'] = Tools::getValue('postabcateslider_speed_slide', (int)Configuration::get($this->name . '_speed_slide'));
  647. $fields['postabcateslider_pause_time'] = Tools::getValue('postabcateslider_pause_time', (int)Configuration::get($this->name . '_pause_time'));
  648. $fields['postabcateslider_auto_play'] = Tools::getValue('postabcateslider_auto_play', (int)Configuration::get($this->name . '_auto_play'));
  649. $fields['postabcateslider_show_arrow'] = Tools::getValue('postabcateslider_show_arrow', (int)Configuration::get($this->name . '_show_arrow'));
  650. $fields['postabcateslider_show_ctr'] = Tools::getValue('postabcateslider_show_ctr', (int)Configuration::get($this->name . '_show_ctr'));
  651. $fields['postabcateslider_limit'] = Tools::getValue('postabcateslider_limit', (int)Configuration::get($this->name . '_limit'));
  652. $fields['postabcateslider_row'] = Tools::getValue('postabcateslider_row', (int)Configuration::get($this->name . '_row'));
  653. $fields['postabcateslider_list_cate'] = Tools::getValue('postabcateslider_list_cate', Configuration::get($this->name . '_list_cate'));
  654.  
  655. $fields['postabcateslider_move'] = Tools::getValue('postabcateslider_move', Configuration::get($this->name . '_move'));
  656. $fields['postabcateslider_pausehover'] = Tools::getValue('postabcateslider_pausehover', Configuration::get($this->name . '_pausehover'));
  657. $fields['postabcateslider_sort'] = Tools::getValue('postabcateslider_sort', Configuration::get($this->name . '_sort'));
  658. $fields['postabcateslider_order'] = Tools::getValue('postabcateslider_order', Configuration::get($this->name . '_order'));
  659.  
  660. foreach ($languages as $lang) {
  661. $fields['postabcateslider_title'][$lang['id_lang']] = Tools::getValue('postabcateslider_title_' . $lang['id_lang'], Configuration::get($this->name . '_title', $lang['id_lang']));
  662. $fields['postabcateslider_img'][$lang['id_lang']] = Tools::getValue('postabcateslider_img_' . $lang['id_lang'], Configuration::get($this->name . '_img', $lang['id_lang']));
  663. $fields['postabcateslider_link'][$lang['id_lang']] = Tools::getValue('postabcateslider_link_' . $lang['id_lang'], Configuration::get($this->name . '_link', $lang['id_lang']));
  664. }
  665.  
  666. return $fields;
  667. }
  668.  
  669. public function getCategoryOption($id_category = 1, $id_lang = false, $id_shop = false, $recursive = true)
  670. {
  671. $cateCurrent = Configuration::get($this->name . '_list_cate');
  672. $cateCurrent = explode(',', $cateCurrent);
  673. $id_lang = $id_lang ? (int)$id_lang : (int)Context::getContext()->language->id;
  674. $category = new Category((int)$id_category, (int)$id_lang, (int)$id_shop);
  675. if (is_null($category->id))
  676. return;
  677. if ($recursive) {
  678. $children = Category::getChildren((int)$id_category, (int)$id_lang, true, (int)$id_shop); // array
  679. }
  680.  
  681. if (isset($children) && count($children)) {
  682. if ($category->id != 1) {
  683. $this->_html .= '<li class="tree-folder">';
  684. $this->_html .= '<span class="tree-folder-name"><input type="checkbox" name="postabcateslider_list_cate[]" value="' . $category->id . '"/><i class="icon-folder-close" style="padding-right: 3px;"></i><label>' . $category->name . '</label></span>';
  685. $this->_html .= '<ul class="tree">';
  686. }
  687. foreach ($children as $child) {
  688. $this->getCategoryOption((int)$child['id_category'], (int)$id_lang, (int)$child['id_shop']);
  689. }
  690. if ($category->id != 1) {
  691. $this->_html .= '</ul>';
  692. $this->_html .= '</li>';
  693. }
  694. } else {
  695. $this->_html .= '<li class="tree-item">';
  696. $this->_html .= '<span class="tree-item-name"><input type="checkbox" name="postabcateslider_list_cate[]" value="' . $category->id . '"/><i class="tree-dot"></i><label>' . $category->name . '</label></span>';
  697. $this->_html .= '</li>';
  698. }
  699.  
  700. $shop = (object) Shop::getShop((int)$category->getShopID());
  701. return $this->_html;
  702. }
  703. public function BuildDropListGroup($group)
  704. {
  705. if (!is_array($group) || !count($group))
  706. return false;
  707.  
  708. $html = '<div class="row">';
  709. foreach ($group as $key => $k) {
  710. if ($key == 4)
  711. $html .= '</div><div class="row">';
  712.  
  713. $html .= '<div class="col-xs-4 col-sm-3">' . $k['label'] . '</label>' .
  714. '<select name="' . $k['id'] . '"
  715. id="' . $k['id'] . '"
  716. class="' . (isset($k['class']) ? $k['class'] : 'fixed-width-md') . '"' .
  717. (isset($k['onchange']) ? ' onchange="' . $k['onchange'] . '"' : '') . ' >';
  718.  
  719. for ($i = 1; $i < 7; $i++) {
  720. $html .= '<option value="' . $i . '" ' . (Configuration::get($k['id']) == $i ? ' selected="selected"' : '') . '>' . $i . '</option>';
  721. }
  722.  
  723. $html .= '</select></div>';
  724. }
  725.  
  726. return $html . '</div>';
  727. }
  728. public function findCateProPer()
  729. {
  730. return array(
  731. array(
  732. 'id' => 'postabcateslider_per_md',
  733. 'label' => $this->l('Desktops (>991 pixels)'),
  734. ),
  735. array(
  736. 'id' => 'postabcateslider_per_sm',
  737. 'label' => $this->l('Tablets (>767 pixels)'),
  738. ),
  739. array(
  740. 'id' => 'postabcateslider_per_xs',
  741. 'label' => $this->l('Phones (>479 pixels)'),
  742. ),
  743. array(
  744. 'id' => 'postabcateslider_per_xxs',
  745. 'label' => $this->l('Small phones (>320 pixels)'),
  746. ),
  747. );
  748. }
  749. }
  750.  
Advertisement
Add Comment
Please, Sign In to add comment