Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.79 KB | None | 0 0
  1. public function index() {
  2. if ($this->journal2->page->getType() !== 'product' && $this->journal2->page->getType() !== 'quickview') return;
  3.  
  4. Journal2::startTimer('ProductTabs');
  5.  
  6. $product_id = (int)$this->journal2->page->getId();
  7.  
  8. /* recently viewed */
  9. $recently_viewed = isset($this->request->cookie['jrv']) && $this->request->cookie['jrv'] ? explode(',', $this->request->cookie['jrv']) : array();
  10. $recently_viewed = array_diff($recently_viewed, array($product_id));
  11. array_unshift($recently_viewed, $product_id);
  12. $limit = (int)$this->config->get(version_compare(VERSION, '2', '>=') ? 'config_product_limit' : 'config_catalog_limit');
  13. if (!$limit) {
  14. $limit = 50;
  15. }
  16. $recently_viewed = array_splice($recently_viewed, 0, $limit);
  17. setcookie('jrv', implode(',', $recently_viewed), time() + 60 * 60 * 24 * 30, '/', $this->request->server['HTTP_HOST']);
  18.  
  19. $product_info = $this->model_catalog_product->getProduct($product_id);
  20.  
  21. $tabs = $this->model_journal2_module->getProductTabs($product_id, $product_info);
  22. $tabs = Journal2Utils::sortArray($tabs);
  23.  
  24. $tab_tab = array();
  25. $tab_desc_top = array();
  26. $tab_desc_bottom = array();
  27. $tab_image = array();
  28. $tab_enquiry = array();
  29.  
  30. foreach ($tabs as $tab) {
  31. if (!$tab['status']) continue;
  32.  
  33. if ($this->journal2->settings->get('responsive_design')) {
  34. $device = Journal2Utils::getDevice();
  35.  
  36. if (Journal2Utils::getProperty($tab, 'enable_on_phone', '1') == '0') {
  37. if ($device === 'phone') {
  38. continue;
  39. }
  40. }
  41.  
  42. if (Journal2Utils::getProperty($tab, 'enable_on_tablet', '1') == '0') {
  43. if ($device === 'tablet') {
  44. continue;
  45. }
  46. }
  47.  
  48. if (Journal2Utils::getProperty($tab, 'enable_on_desktop', '1') == '0') {
  49. if ($device === 'desktop') {
  50. continue;
  51. }
  52. }
  53. }
  54.  
  55. $css = array();
  56.  
  57. if (Journal2Utils::getColor(Journal2Utils::getProperty($tab, 'icon_bg_color.value.color'))) {
  58. $css[] = 'background-color: ' . Journal2Utils::getColor(Journal2Utils::getProperty($tab, 'icon_bg_color.value.color'));
  59. }
  60. if (Journal2Utils::getProperty($tab, 'icon_width')) {
  61. $css[] = 'width: ' . Journal2Utils::getProperty($tab, 'icon_width') . 'px';
  62. }
  63. if (Journal2Utils::getProperty($tab, 'icon_height')) {
  64. $css[] = 'height: ' . Journal2Utils::getProperty($tab, 'icon_height') . 'px';
  65. $css[] = 'line-height: ' . Journal2Utils::getProperty($tab, 'icon_height') . 'px';
  66. }
  67. if (Journal2Utils::getProperty($tab, 'icon_border')) {
  68. $css = array_merge($css, Journal2Utils::getBorderCssProperties(Journal2Utils::getProperty($tab, 'icon_border')));
  69. }
  70.  
  71. $position = Journal2Utils::getProperty($tab, 'position');
  72. $name = Journal2Utils::getProperty($tab, 'name.value.' . $this->config->get('config_language_id'));
  73. $has_icon = Journal2Utils::getProperty($tab, 'icon_status');
  74. $icon = Journal2Utils::getIconOptions2(Journal2Utils::getProperty($tab, 'icon'));
  75. $icon_css = implode('; ', $css);
  76.  
  77. switch (Journal2Utils::getProperty($tab, 'content_type', 'custom')) {
  78. case 'custom':
  79. $content = Journal2Utils::getProperty($tab, 'content.' . $this->config->get('config_language_id'));
  80. break;
  81. case 'description':
  82. $content = html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8');
  83. $this->journal2->settings->set('hide_product_description', true);
  84. break;
  85. case 'enquiry':
  86. $position = 'enquiry';
  87. $this->journal2->settings->set('hide_add_to_cart_button', true);
  88. $href = "javascript:Journal.openPopup('" . (int)Journal2Utils::getProperty($tab, 'popup') . "', '" . $product_id . "')";
  89. $content = "<a class=\"button enquiry-button\" href=\"{$href}\">{$icon}{$name}</a>";
  90. break;
  91. }
  92.  
  93. $position_desc = $position === 'desc' ? '_' . Journal2Utils::getProperty($tab, 'option_position') : '';
  94. $names[] = $name;
  95. if($name == 'PDF') {
  96. $qq = $this->db->query('SELECT pdf FROM oc_product WHERE product_id = "'. $product_id .'"');
  97. if(isset($qq->row['pdf']) && !empty($qq->row)) {
  98. $content = str_replace('data="image/pdf/sample.pdf"','data="image/'.$qq->row['pdf'] .'"',$content);
  99. } else {
  100. continue;
  101. }
  102. } elseif($name == 'Полезни съвети') {
  103. $q3 = $this->db->query('
  104. SELECT oc_category_advice.title, oc_category_advice.text
  105. FROM oc_category_advice
  106. JOIN oc_product_to_category ON oc_product_to_category.category_id = oc_category_advice.cat_id
  107. WHERE oc_product_to_category.product_id = "'. $product_id .'"
  108. ');
  109.  
  110. if(isset($q3->rows) && !empty($q3->rows)) {
  111. $content = '';
  112. $tabn = 1;
  113. foreach ($q3->rows as $r) {
  114. $content .= "<h3>". $r['title'] ."</h3><p>". $r['text'] ."</p><br><br>";
  115. }
  116. } else {
  117. $catq = $this->db->query('
  118. SELECT oc_category.*
  119. FROM oc_category
  120. JOIN oc_product_to_category ON oc_product_to_category.category_id = oc_category.category_id
  121. WHERE oc_product_to_category.product_id = "'. $product_id .'"
  122. ');
  123. if(isset($catq->row) && !empty($catq->row) && $catq->row['parent_id'] != 0) {
  124. $q4 = $this->db->query('
  125. SELECT * FROM oc_category_advice WHERE cat_id = "'. $catq->row['parent_id'] .'"
  126. ');
  127. if(isset($q4->rows) && !empty($q4->rows)) {
  128. $content = '';
  129. foreach ($q4->rows as $r) {
  130. $content .= "<h3>". $r['title'] ."</h3><p>". $r['text'] ."</p><br><br>";
  131. }
  132. } else {
  133. continue;
  134. }
  135. } else {
  136. continue;
  137. }
  138. }
  139. }
  140. $data = array (
  141. 'name' => $name,
  142. 'has_icon' => $has_icon,
  143. 'icon' => $icon,
  144. 'icon_css' => $icon_css,
  145. 'content' => $content
  146. );
  147.  
  148. $var = 'tab_' . $position . $position_desc;
  149. array_push($$var, $data);
  150. }
  151.  
  152. $this->journal2->settings->set('additional_product_tabs', $tab_tab);
  153. $this->journal2->settings->set('additional_product_description_top', $tab_desc_top);
  154. $this->journal2->settings->set('additional_product_description_bottom', $tab_desc_bottom);
  155. $this->journal2->settings->set('additional_product_description_image', $tab_image);
  156. $this->journal2->settings->set('additional_product_enquiry', $tab_enquiry);
  157.  
  158. Journal2::stopTimer('ProductTabs');
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement