├── upload ├── catalog │ ├── view │ │ ├── javascript │ │ │ └── pdf_catalog.js │ │ └── theme │ │ │ └── default │ │ │ ├── stylesheet │ │ │ └── pdf_catalog.css │ │ │ └── template │ │ │ └── module │ │ │ └── pdf_catalog.tpl │ ├── language │ │ ├── english │ │ │ └── module │ │ │ │ └── pdf_catalog.php │ │ └── spanish │ │ │ └── module │ │ │ └── pdf_catalog.php │ ├── controller │ │ ├── module │ │ │ └── pdf_catalog.php │ │ └── product │ │ │ └── pdf_catalog.php │ └── model │ │ └── catalog │ │ └── pdf_catalog.php ├── image │ └── data │ │ ├── pdf.png │ │ └── pdf_catalog_default_logo.png ├── system │ ├── cache │ │ └── pdf_catalog_default_logo.png │ └── config │ │ └── pdf_catalog.php └── admin │ ├── language │ ├── spanish │ │ └── module │ │ │ └── pdf_catalog.php │ └── english │ │ └── module │ │ └── pdf_catalog.php │ ├── view │ └── template │ │ └── module │ │ └── pdf_catalog.tpl │ └── controller │ └── module │ └── pdf_catalog.php ├── .gitignore ├── nbproject ├── project.properties └── project.xml └── README.md /upload/catalog/view/javascript/pdf_catalog.js: -------------------------------------------------------------------------------- 1 | category=getURLVar('path') -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | install-opencart-plugin.sh 2 | /nbproject/private/ 3 | .projdir 4 | -------------------------------------------------------------------------------- /upload/catalog/view/theme/default/stylesheet/pdf_catalog.css: -------------------------------------------------------------------------------- 1 | #pdf_button{ 2 | height:3em; 3 | } 4 | -------------------------------------------------------------------------------- /upload/image/data/pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mithereal/opencart-pdf-catalog/HEAD/upload/image/data/pdf.png -------------------------------------------------------------------------------- /upload/image/data/pdf_catalog_default_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mithereal/opencart-pdf-catalog/HEAD/upload/image/data/pdf_catalog_default_logo.png -------------------------------------------------------------------------------- /upload/system/cache/pdf_catalog_default_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mithereal/opencart-pdf-catalog/HEAD/upload/system/cache/pdf_catalog_default_logo.png -------------------------------------------------------------------------------- /nbproject/project.properties: -------------------------------------------------------------------------------- 1 | include.path=${php.global.include.path} 2 | php.version=PHP_53 3 | source.encoding=UTF-8 4 | src.dir=. 5 | tags.asp=false 6 | tags.short=false 7 | web.root=. 8 | -------------------------------------------------------------------------------- /nbproject/project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.netbeans.modules.php.project 4 | 5 | 6 | opencart-pdf-catalog 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | pdf-catalog 2 | =========== 3 | 4 | pdf catalog gives your users a pdf catalog of your entire opencart store or just the category. 5 | This is for a small scale store, pdf generation is limited based on the timeout your hosting provider has configured generally ~30 sec. 6 | One can configure the product options included in the pdf such as limit of products per category, description, image size, status 7 | -------------------------------------------------------------------------------- /upload/catalog/language/english/module/pdf_catalog.php: -------------------------------------------------------------------------------- 1 | 18 | -------------------------------------------------------------------------------- /upload/catalog/language/spanish/module/pdf_catalog.php: -------------------------------------------------------------------------------- 1 | 19 | -------------------------------------------------------------------------------- /upload/catalog/view/theme/default/template/module/pdf_catalog.tpl: -------------------------------------------------------------------------------- 1 |
2 | 3 |
4 | 5 | 6 |
7 | 8 |
9 | 10 | 11 | 15 | 16 | 32 | 33 | 34 | 35 | 38 | 40 | 41 | 42 | 45 | 46 | 47 |
48 | 57 |
58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /upload/catalog/controller/module/pdf_catalog.php: -------------------------------------------------------------------------------- 1 | language->load('module/pdf_catalog'); 5 | 6 | $this->data['heading_title'] = $this->language->get('heading_title'); 7 | $this->data['text_select'] = $this->language->get('text_select'); 8 | $this->data['text_all_categories'] = $this->language->get('text_all_categories'); 9 | 10 | $this->load->model('catalog/manufacturer'); 11 | $this->load->model('catalog/pdf_catalog'); 12 | $this->document->addStyle('catalog/view/theme/' . $this->config->get('config_template') . '/stylesheet/pdf_catalog.css'); 13 | 14 | //$this->load->model('tool/seo_url'); 15 | 16 | //$this->data['pdf_catalog_href'] = $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/pdf_catalog&category_id='); 17 | $this->data['pdf_catalog_href'] = HTTP_SERVER . 'index.php?route=product/pdf_catalog&category_id='; 18 | 19 | if($this->config->get('pdf_catalog_display_categories') == 1){ 20 | 21 | if($this->config->get('pdf_catalog_display_subcategories') == 0){ 22 | $categories = $this->model_catalog_pdf_catalog->getMaincategories(); 23 | }else{ 24 | $categories = $this->model_catalog_pdf_catalog->getCategories(0); 25 | } 26 | }else{ 27 | $categories = null; 28 | } 29 | $this->data['categories']= $categories; 30 | 31 | 32 | $this->id = 'pdf_catalog'; 33 | 34 | if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/pdf_catalog.tpl')) { 35 | $this->template = $this->config->get('config_template') . '/template/module/pdf_catalog.tpl'; 36 | } else { 37 | $this->template = 'default/template/module/pdf_catalog.tpl'; 38 | } 39 | //var_dump($this); 40 | $this->render(); 41 | } 42 | } 43 | ?> 44 | -------------------------------------------------------------------------------- /upload/admin/language/spanish/module/pdf_catalog.php: -------------------------------------------------------------------------------- 1 | 51 | -------------------------------------------------------------------------------- /upload/system/config/pdf_catalog.php: -------------------------------------------------------------------------------- 1 | 4 | 5 | h2 { 6 | font-size: 140%; 7 | } 8 | h3 { 9 | font-size: 120%; 10 | } 11 | table.pdf_table { 12 | width:100%; 13 | } 14 | 15 | table.pdf_table td.pdf_category{ 16 | font-size:17pt; 17 | background-color:#EFEFEF; 18 | padding:20px; 19 | } 20 | 21 | tr.pdf_product{ 22 | page-break-inside:avoid; 23 | page-break-after:auto; 24 | height: {::image_height}px; 25 | } 26 | 27 | td.pdf_product_image{ 28 | width:30%; 29 | text-align:center; 30 | padding: 0; 31 | margin: 0; 32 | vertical-align: middle; 33 | border-bottom: 1px solid #EFEFEF; 34 | } 35 | 36 | td.pdf_product_desc{ 37 | width:70%; 38 | padding:10px; 39 | border-left: 1px solid #EFEFEF; 40 | border-bottom: 1px solid #EFEFEF; 41 | } 42 | 43 | ul.pdf_product_ul{ 44 | list-style-type:none; 45 | margin:0; 46 | padding:0; 47 | } 48 | 49 | .page_break{ 50 | page-break-before: always; 51 | } 52 | 53 | 54 | '); 55 | 56 | define('PDF_TOC_TITLE', ' 57 |

{::category_title}


58 | '); 59 | 60 | define('PDF_TOC_CATEGORY', ' 61 |

{::category_name} ({::product_cnt})


62 | '); 63 | 64 | define('PDF_CATALOG_TEMPLATE_CATEGORY', ' 65 | 66 | 67 | 68 | 69 | {::products} 70 |
{::category_name}
71 | '); 72 | 73 | define('PDF_CATALOG_TEMPLATE_PRODUCT', ' 74 | 75 | 76 | 77 | 85 | 86 | 87 | '); 88 | ?> 89 | -------------------------------------------------------------------------------- /upload/admin/language/english/module/pdf_catalog.php: -------------------------------------------------------------------------------- 1 | 60 | -------------------------------------------------------------------------------- /upload/catalog/model/catalog/pdf_catalog.php: -------------------------------------------------------------------------------- 1 | db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "category c LEFT JOIN " . DB_PREFIX . "category_description cd ON (c.category_id = cd.category_id) LEFT JOIN " . DB_PREFIX . "category_to_store c2s ON (c.category_id = c2s.category_id) WHERE c.category_id = '" . (int)$category_id . "' AND cd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND c2s.store_id = '" . (int)$this->config->get('config_store_id') . "' "); 5 | 6 | return $query->row; 7 | } 8 | 9 | public function getPath($category_id) { 10 | $query = $this->db->query("SELECT name, parent_id FROM " . DB_PREFIX . "category c LEFT JOIN " . DB_PREFIX . "category_description cd ON (c.category_id = cd.category_id) WHERE c.category_id = '" . (int)$category_id . "' AND cd.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY c.sort_order, cd.name ASC"); 11 | 12 | $category_info = $query->row; 13 | 14 | if ($category_info['parent_id']) { 15 | return $this->getPath($category_info['parent_id'], $this->config->get('config_language_id')) . $this->language->get('text_separator') . $category_info['name']; 16 | } else { 17 | return $category_info['name']; 18 | } 19 | } 20 | 21 | public function getCategories($category_id, $include_parent = true) { 22 | $category_data = $this->cache->get('category.' . $this->config->get('config_language_id') . '.' . $category_id); 23 | 24 | if (!$category_data) { 25 | $category_data = array(); 26 | if ($include_parent) { 27 | $query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "category c LEFT JOIN " . DB_PREFIX . "category_description cd ON (c.category_id = cd.category_id) LEFT JOIN " . DB_PREFIX . "category_to_store c2s ON (c.category_id = c2s.category_id) WHERE c.category_id = '" . (int)$category_id . "' AND cd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND c2s.store_id = '" . (int)$this->config->get('config_store_id') . "' "); 28 | if ($query->row) { 29 | $category_data[] = $this->parseCategory($query->row); 30 | } 31 | } 32 | $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "category c LEFT JOIN " . DB_PREFIX . "category_description cd ON (c.category_id = cd.category_id) WHERE c.status = '1' AND c.parent_id = '" . (int)$category_id . "' AND cd.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY c.sort_order, cd.name ASC"); 33 | foreach ($query->rows as $result) { 34 | $category_data[] = $this->parseCategory($result); 35 | $category_data = array_merge($category_data, $this->getCategories($result['category_id'], false)); 36 | } 37 | $this->cache->set('category.' . $this->config->get('config_language_id') . '.' . $category_id, $category_data); 38 | } 39 | 40 | return $category_data; 41 | } 42 | private function parseCategory($result) { 43 | return array( 44 | 'category_id' => $result['category_id'], 45 | 'name' => $this->getPath($result['category_id'], $this->config->get('config_language_id')), 46 | 'status' => $result['status'], 47 | 'sort_order' => $result['sort_order'], 48 | 'parent_id' => $result['parent_id'] 49 | ); 50 | } 51 | public function getMaincategories() { 52 | $category_data = $this->cache->get('category.0' . $this->config->get('config_language_id') ); 53 | 54 | if (!$category_data) { 55 | $category_data = array(); 56 | 57 | $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "category c LEFT JOIN " . DB_PREFIX . "category_description cd ON (c.category_id = cd.category_id) WHERE c.status = '1' AND c.parent_id = '0' AND cd.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY c.sort_order, cd.name ASC"); 58 | 59 | foreach ($query->rows as $result) { 60 | $category_data[] = array( 61 | 'category_id' => $result['category_id'], 62 | 'name' => $this->getPath($result['category_id'], $this->config->get('config_language_id')), 63 | 'status' => $result['status'], 64 | 'sort_order' => $result['sort_order'], 65 | 66 | ); 67 | 68 | 69 | } 70 | 71 | $this->cache->set('category.0' . $this->config->get('config_language_id') , $category_data); 72 | } 73 | 74 | return $category_data; 75 | } 76 | 77 | public function getProductsByCategoryId($category_id, $data) { 78 | 79 | $sql = " 80 | SELECT 81 | * 82 | FROM " . DB_PREFIX . "product p 83 | LEFT JOIN " . DB_PREFIX . "product_description pd 84 | ON (p.product_id = pd.product_id) 85 | LEFT JOIN " . DB_PREFIX . "product_to_category p2c 86 | ON (p.product_id = p2c.product_id) 87 | WHERE 88 | pd.language_id = '" . (int)$this->config->get('config_language_id') . "' 89 | AND p2c.category_id = '" . (int)$category_id . "' 90 | "; 91 | 92 | if (isset($data['filter_name']) && !is_null($data['filter_name'])) { 93 | $sql .= " AND LCASE(pd.name) LIKE '%" . $this->db->escape(strtolower($data['filter_name'])) . "%'"; 94 | } 95 | 96 | if (isset($data['filter_model']) && !is_null($data['filter_model'])) { 97 | $sql .= " AND LCASE(p.model) LIKE '%" . $this->db->escape(strtolower($data['filter_model'])) . "%'"; 98 | } 99 | 100 | if (isset($data['filter_quantity']) && !is_null($data['filter_quantity'])) { 101 | $sql .= " AND p.quantity >= '" . $this->db->escape($data['filter_quantity']) . "'"; 102 | } 103 | 104 | if (isset($data['filter_status']) && !is_null($data['filter_status'])) { 105 | $sql .= " AND p.status = '" . (int)$data['filter_status'] . "'"; 106 | } 107 | 108 | $sort_data = array( 109 | 'pd.name', 110 | 'p.model', 111 | 'p.quantity', 112 | 'p.status', 113 | 'p.sort_order' 114 | ); 115 | 116 | if (isset($data['sort']) && in_array($data['sort'], $sort_data)) { 117 | $sql .= " ORDER BY " . $data['sort']; 118 | } else { 119 | $sql .= " ORDER BY pd.name"; 120 | } 121 | 122 | if (isset($data['order']) && ($data['order'] == 'DESC')) { 123 | $sql .= " DESC"; 124 | } else { 125 | $sql .= " ASC"; 126 | } 127 | 128 | 129 | 130 | if(isset($data['limit'])){ 131 | if ($data['limit'] < 1) { 132 | $data['limit'] = 20; 133 | } 134 | 135 | $sql .= " LIMIT " . 0 . "," . (int)$data['limit']; 136 | } 137 | 138 | //var_dump($sql); 139 | $query = $this->db->query($sql); 140 | 141 | return $query->rows; 142 | } 143 | 144 | public function getLatestProducts($limit) { 145 | $product_data = $this->cache->get('product.latest.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit); 146 | 147 | if (!$product_data) { 148 | $query = $this->db->query("SELECT p.product_id FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' ORDER BY p.date_added DESC LIMIT " . (int)$limit); 149 | 150 | foreach ($query->rows as $result) { 151 | $product_data[$result['product_id']] = $this->getProduct($result['product_id']); 152 | } 153 | 154 | $this->cache->set('product.latest.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit, $product_data); 155 | } 156 | 157 | return $product_data; 158 | } 159 | 160 | public function getPopularProducts($limit) { 161 | $product_data = array(); 162 | 163 | $query = $this->db->query("SELECT p.product_id FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' ORDER BY p.viewed, p.date_added DESC LIMIT " . (int)$limit); 164 | 165 | foreach ($query->rows as $result) { 166 | $product_data[$result['product_id']] = $this->getProduct($result['product_id']); 167 | } 168 | 169 | return $product_data; 170 | } 171 | 172 | public function getBestSellerProducts($limit) { 173 | $product_data = $this->cache->get('product.bestseller.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit); 174 | 175 | if (!$product_data) { 176 | $product_data = array(); 177 | 178 | $query = $this->db->query("SELECT op.product_id, COUNT(*) AS total FROM " . DB_PREFIX . "order_product op LEFT JOIN `" . DB_PREFIX . "order` o ON (op.order_id = o.order_id) LEFT JOIN `" . DB_PREFIX . "product` p ON (op.product_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE o.order_status_id > '0' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' GROUP BY op.product_id ORDER BY total DESC LIMIT " . (int)$limit); 179 | 180 | foreach ($query->rows as $result) { 181 | $product_data[$result['product_id']] = $this->getProduct($result['product_id']); 182 | } 183 | 184 | $this->cache->set('product.bestseller.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit, $product_data); 185 | } 186 | 187 | return $product_data; 188 | } 189 | 190 | } 191 | -------------------------------------------------------------------------------- /upload/admin/view/template/module/pdf_catalog.tpl: -------------------------------------------------------------------------------- 1 | 2 |
3 | 8 | 9 |
10 | 11 |
12 |
13 |

14 |
15 |
16 |
17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 31 | 32 | 33 | 34 | 43 | 65 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 |
87 | 88 | 89 | 90 | 93 | 94 | 95 | 96 | 97 |
98 | 99 |
100 | 103 | 104 | 105 | 106 | 107 | 108 | 117 | 118 | 119 | 120 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 145 | 146 | 147 | 148 | 157 | 158 | 159 | 160 | 169 | 170 | 171 | 172 | 173 | 184 | 185 | 186 | 187 | 188 | 199 | 200 | 201 | 202 | 216 | 217 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 282 | 283 | 284 | 285 | - 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 313 | 315 | 316 | 317 | 318 | 319 | 322 | 323 | 324 |

Frontend

PDF

174 | 183 |
189 | 198 |
314 |
320 | 321 |
325 |
326 |
327 |
328 |
329 | 330 | 331 | 341 | 342 | 383 | 384 | 385 | -------------------------------------------------------------------------------- /upload/admin/controller/module/pdf_catalog.php: -------------------------------------------------------------------------------- 1 | load->language('module/pdf_catalog'); 19 | 20 | $this->document->setTitle = $this->language->get('heading_title'); 21 | 22 | 23 | $this->load->model('setting/setting'); 24 | $this->load->model('design/layout'); 25 | 26 | if (($this->request->server['REQUEST_METHOD'] == 'POST') && ($this->validate())) { 27 | $this->model_setting_setting->editSetting('pdf_catalog', $this->request->post); 28 | 29 | $this->session->data['success'] = $this->language->get('text_success'); 30 | 31 | } 32 | $this->data['heading_title'] = $this->language->get('heading_title'); 33 | 34 | $this->data['text_enabled'] = $this->language->get('text_enabled'); 35 | $this->data['text_disabled'] = $this->language->get('text_disabled'); 36 | $this->data['text_content_top'] = $this->language->get('text_content_top'); 37 | $this->data['text_content_bottom'] = $this->language->get('text_content_bottom'); 38 | $this->data['text_column_left'] = $this->language->get('text_column_left'); 39 | $this->data['text_column_right'] = $this->language->get('text_column_right'); 40 | $this->data['text_hide'] = $this->language->get('text_hide'); 41 | $this->data['text_yes'] = $this->language->get('text_yes'); 42 | $this->data['text_no'] = $this->language->get('text_no'); 43 | $this->data['text_native'] = $this->language->get('text_native'); 44 | $this->data['text_product_name'] = $this->language->get('text_product_name'); 45 | $this->data['text_product_popular'] = $this->language->get('text_product_popular'); 46 | 47 | $this->data['entry_display_categories'] = $this->language->get('entry_display_categories'); 48 | $this->data['entry_pdf_creator'] = $this->language->get('entry_pdf_creator'); 49 | $this->data['entry_display_toc'] = $this->language->get('entry_display_toc'); 50 | $this->data['entry_pdf_author'] = $this->language->get('entry_pdf_author'); 51 | $this->data['entry_pdf_max_products'] = $this->language->get('entry_pdf_max_products'); 52 | $this->data['entry_pdf_title'] = $this->language->get('entry_pdf_title'); 53 | $this->data['entry_pdf_subject'] = $this->language->get('entry_pdf_subject'); 54 | $this->data['entry_pdf_keywords'] = $this->language->get('entry_pdf_keywords'); 55 | $this->data['entry_pdf_catalog_display_description'] = $this->language->get('entry_pdf_catalog_display_description'); 56 | $this->data['entry_pdf_catalog_item_per_page'] = $this->language->get('entry_pdf_catalog_item_per_page'); 57 | $this->data['entry_pdf_catalog_image_width'] = $this->language->get('entry_pdf_catalog_image_width'); 58 | $this->data['entry_pdf_catalog_image_height'] = $this->language->get('entry_pdf_catalog_image_height'); 59 | $this->data['entry_pdf_catalog_description_chars'] = $this->language->get('entry_pdf_catalog_description_chars'); 60 | $this->data['entry_pdf_catalog_template_type'] = $this->language->get('entry_pdf_catalog_template_type'); 61 | $this->data['entry_pdf_catalog_max_options'] = $this->language->get('entry_pdf_catalog_max_options'); 62 | $this->data['entry_pdf_catalog_max_per_options'] = $this->language->get('entry_pdf_catalog_max_per_options'); 63 | $this->data['entry_pdf_max_options'] = $this->language->get('entry_pdf_max_options'); 64 | $this->data['entry_pdf_max_per_options'] = $this->language->get('entry_pdf_max_per_options'); 65 | $this->data['entry_pdf_catalog_text_orientation'] = $this->language->get('entry_pdf_catalog_text_orientation'); 66 | $this->data['entry_pdf_catalog_remove_empty_tags'] = $this->language->get('entry_pdf_catalog_remove_empty_tags'); 67 | $this->data['text_rtl'] = $this->language->get('text_rtl'); 68 | $this->data['text_ltr'] = $this->language->get('text_ltr'); 69 | 70 | 71 | 72 | $this->data['entry_layout'] = $this->language->get('entry_layout'); 73 | $this->data['entry_position'] = $this->language->get('entry_position'); 74 | $this->data['entry_status'] = $this->language->get('entry_status'); 75 | $this->data['entry_sort_order'] = $this->language->get('entry_sort_order'); 76 | $this->data['entry_description'] = $this->language->get('entry_description'); 77 | $this->data['entry_display_out_of_stock'] = $this->language->get('entry_display_out_of_stock'); 78 | $this->data['entry_display_disabled'] = $this->language->get('entry_display_disabled'); 79 | $this->data['entry_display_subcategories'] = $this->language->get('entry_display_subcategories'); 80 | $this->data['entry_sort_products'] = $this->language->get('entry_sort_products'); 81 | $this->data['entry_display_manufacturer_logo'] = $this->language->get('entry_display_manufacturer_logo'); 82 | $this->data['entry_display_manufacturer_name'] = $this->language->get('entry_display_manufacturer_name'); 83 | 84 | $this->data['button_install_tcpdf'] = $this->language->get('button_install_tcpdf'); 85 | $this->data['button_save'] = $this->language->get('button_save'); 86 | $this->data['button_cancel'] = $this->language->get('button_cancel'); 87 | $this->data['button_add_module'] = $this->language->get('button_add_module'); 88 | $this->data['button_remove'] = $this->language->get('button_remove'); 89 | 90 | if (isset($this->error['warning'])) { 91 | $this->data['error_warning'] = $this->error['warning']; 92 | } else { 93 | $this->data['error_warning'] = ''; 94 | } 95 | 96 | $this->data['breadcrumbs'] = array(); 97 | 98 | $this->data['breadcrumbs'][] = array( 99 | 'text' => $this->language->get('text_home'), 100 | 'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'), 101 | 'separator' => false 102 | ); 103 | 104 | $this->data['breadcrumbs'][] = array( 105 | 'text' => $this->language->get('text_module'), 106 | 'href' => $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'), 107 | 'separator' => ' :: ' 108 | ); 109 | 110 | $this->data['breadcrumbs'][] = array( 111 | 'text' => $this->language->get('heading_title'), 112 | 'href' => $this->url->link('module/pdf_catalog', 'token=' . $this->session->data['token'], 'SSL'), 113 | 'separator' => ' :: ' 114 | ); 115 | 116 | $this->data['action'] = $this->url->link('module/pdf_catalog', 'token=' . $this->session->data['token'], 'SSL'); 117 | $this->data['cancel'] = $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'); 118 | $this->data['modules'] = array(); 119 | 120 | if (isset($this->request->post['pdf_catalog_display_description'])) { 121 | $this->data['pdf_catalog_display_description'] = $this->request->post['pdf_catalog_display_description']; 122 | } else { 123 | $this->data['pdf_catalog_display_description'] = $this->config->get('pdf_catalog_display_description'); 124 | } 125 | 126 | if (isset($this->request->post['pdf_catalog_module'])) { 127 | $this->data['modules'] = $this->request->post['pdf_catalog_module']; 128 | } elseif ($this->config->get('pdf_catalog_module')) { 129 | $this->data['modules'] = $this->config->get('pdf_catalog_module'); 130 | } 131 | 132 | if (isset($this->request->post['pdf_catalog_position'])) { 133 | $this->data['pdf_catalog_position'] = $this->request->post['pdf_catalog_position']; 134 | } else { 135 | $this->data['pdf_catalog_position'] = $this->config->get('pdf_catalog_position'); 136 | } 137 | 138 | if (isset($this->request->post['pdf_catalog_item_per_page'])) { 139 | $this->data['pdf_catalog_item_per_page'] = $this->request->post['pdf_catalog_item_per_page']; 140 | } else { 141 | $this->data['pdf_catalog_item_per_page'] = $this->config->get('pdf_catalog_item_per_page'); 142 | } 143 | 144 | if (isset($this->request->post['pdf_catalog_image_width'])) { 145 | $this->data['pdf_catalog_image_width'] = $this->request->post['pdf_catalog_image_width']; 146 | } else { 147 | $this->data['pdf_catalog_image_width'] = $this->config->get('pdf_catalog_image_width'); 148 | } 149 | 150 | if (isset($this->request->post['pdf_catalog_display_toc'])) { 151 | $this->data['pdf_catalog_display_toc'] = $this->request->post['pdf_catalog_display_toc']; 152 | } else { 153 | $this->data['pdf_catalog_display_toc'] = $this->config->get('pdf_catalog_display_toc'); 154 | } 155 | 156 | if (isset($this->request->post['pdf_catalog_max_products'])) { 157 | $this->data['pdf_catalog_max_products'] = $this->request->post['pdf_catalog_max_products']; 158 | } else { 159 | $this->data['pdf_catalog_max_products'] = $this->config->get('pdf_catalog_max_products'); 160 | } 161 | 162 | if (isset($this->request->post['pdf_catalog_image_height'])) { 163 | $this->data['pdf_catalog_image_height'] = $this->request->post['pdf_catalog_image_height']; 164 | } else { 165 | $this->data['pdf_catalog_image_height'] = $this->config->get('pdf_catalog_image_height'); 166 | } 167 | 168 | if (isset($this->request->post['pdf_catalog_status'])) { 169 | $this->data['pdf_catalog_status'] = $this->request->post['pdf_catalog_status']; 170 | } else { 171 | $this->data['pdf_catalog_status'] = $this->config->get('pdf_catalog_status'); 172 | } 173 | 174 | if (isset($this->request->post['pdf_catalog_sort_order'])) { 175 | $this->data['pdf_catalog_sort_order'] = $this->request->post['pdf_catalog_sort_order']; 176 | } else { 177 | $this->data['pdf_catalog_sort_order'] = $this->config->get('pdf_catalog_sort_order'); 178 | } 179 | 180 | if (isset($this->request->post['pdf_catalog_description'])) { 181 | $this->data['pdf_catalog_description'] = $this->request->post['pdf_catalog_description']; 182 | } else { 183 | $this->data['pdf_catalog_description'] = $this->config->get('pdf_catalog_description'); 184 | } 185 | 186 | if (isset($this->request->post['pdf_catalog_display_categories'])) { 187 | $this->data['pdf_catalog_display_categories'] = $this->request->post['pdf_catalog_display_categories']; 188 | } else { 189 | $this->data['pdf_catalog_display_categories'] = $this->config->get('pdf_catalog_display_categories'); 190 | } 191 | 192 | if (isset($this->request->post['pdf_catalog_author'])) { 193 | $this->data['pdf_catalog_author'] = $this->request->post['pdf_catalog_author']; 194 | } else { 195 | $this->data['pdf_catalog_author'] = $this->config->get('pdf_catalog_author'); 196 | } 197 | 198 | if (isset($this->request->post['pdf_catalog_title'])) { 199 | $this->data['pdf_catalog_title'] = $this->request->post['pdf_catalog_title']; 200 | } else { 201 | $this->data['pdf_catalog_title'] = $this->config->get('pdf_catalog_title'); 202 | } 203 | 204 | if (isset($this->request->post['pdf_catalog_subject'])) { 205 | $this->data['pdf_catalog_subject'] = $this->request->post['pdf_catalog_subject']; 206 | } else { 207 | $this->data['pdf_catalog_subject'] = $this->config->get('pdf_catalog_subject'); 208 | } 209 | 210 | if (isset($this->request->post['pdf_catalog_keywords'])) { 211 | $this->data['pdf_catalog_keywords'] = $this->request->post['pdf_catalog_keywords']; 212 | } else { 213 | $this->data['pdf_catalog_keywords'] = $this->config->get('pdf_catalog_keywords'); 214 | } 215 | 216 | if (isset($this->request->post['pdf_catalog_description_chars'])) { 217 | $this->data['pdf_catalog_description_chars'] = $this->request->post['pdf_catalog_description_chars']; 218 | } else { 219 | $this->data['pdf_catalog_description_chars'] = $this->config->get('pdf_catalog_description_chars'); 220 | } 221 | 222 | if (isset($this->request->post['pdf_catalog_template_type'])) { 223 | $this->data['pdf_catalog_template_type'] = $this->request->post['pdf_catalog_template_type']; 224 | } else { 225 | $this->data['pdf_catalog_template_type'] = $this->config->get('pdf_catalog_template_type'); 226 | } 227 | 228 | if (isset($this->request->post['pdf_catalog_display_out_of_stock'])) { 229 | $this->data['pdf_catalog_display_out_of_stock'] = $this->request->post['pdf_catalog_display_out_of_stock']; 230 | } else { 231 | $this->data['pdf_catalog_display_out_of_stock'] = $this->config->get('pdf_catalog_display_out_of_stock'); 232 | } 233 | 234 | if (isset($this->request->post['pdf_catalog_display_disabled'])) { 235 | $this->data['pdf_catalog_display_disabled'] = $this->request->post['pdf_catalog_display_disabled']; 236 | } else { 237 | $this->data['pdf_catalog_display_disabled'] = $this->config->get('pdf_catalog_display_disabled'); 238 | } 239 | 240 | if (isset($this->request->post['pdf_catalog_display_subcategories'])) { 241 | $this->data['pdf_catalog_display_subcategories'] = $this->request->post['pdf_catalog_display_subcategories']; 242 | } else { 243 | $this->data['pdf_catalog_display_subcategories'] = $this->config->get('pdf_catalog_display_subcategories'); 244 | } 245 | if (isset($this->request->post['pdf_catalog_sort_products'])) { 246 | $this->data['pdf_catalog_sort_products'] = $this->request->post['pdf_catalog_sort_products']; 247 | } else { 248 | $this->data['pdf_catalog_sort_products'] = $this->config->get('pdf_catalog_sort_products'); 249 | } 250 | 251 | if (isset($this->request->post['pdf_catalog_max_options'])) { 252 | $this->data['pdf_catalog_max_options'] = $this->request->post['pdf_catalog_max_options']; 253 | } else { 254 | $this->data['pdf_catalog_max_options'] = $this->config->get('pdf_catalog_max_options'); 255 | } 256 | 257 | if (isset($this->request->post['pdf_catalog_max_per_options'])) { 258 | $this->data['pdf_catalog_max_per_options'] = $this->request->post['pdf_catalog_max_per_options']; 259 | } else { 260 | $this->data['pdf_catalog_max_per_options'] = $this->config->get('pdf_catalog_max_per_options'); 261 | } 262 | 263 | if (isset($this->request->post['pdf_catalog_display_manufacturer_name'])) { 264 | $this->data['pdf_catalog_display_manufacturer_name'] = $this->request->post['pdf_catalog_display_manufacturer_name']; 265 | } else { 266 | $this->data['pdf_catalog_display_manufacturer_name'] = $this->config->get('pdf_catalog_display_manufacturer_name'); 267 | } 268 | 269 | if (isset($this->request->post['pdf_catalog_display_manufacturer_logo'])) { 270 | $this->data['pdf_catalog_display_manufacturer_logo'] = $this->request->post['pdf_catalog_display_manufacturer_logo']; 271 | } else { 272 | $this->data['pdf_catalog_display_manufacturer_logo'] = $this->config->get('pdf_catalog_display_manufacturer_logo'); 273 | } 274 | 275 | if (isset($this->request->post['pdf_catalog_remove_empty_tags'])) { 276 | $this->data['pdf_catalog_remove_empty_tags'] = $this->request->post['pdf_catalog_remove_empty_tags']; 277 | } else { 278 | $this->data['pdf_catalog_remove_empty_tags'] = $this->config->get('pdf_catalog_remove_empty_tags'); 279 | } 280 | if (isset($this->request->post['pdf_catalog_text_orientation'])) { 281 | $this->data['pdf_catalog_text_orientation'] = $this->request->post['pdf_catalog_text_orientation']; 282 | } else { 283 | $this->data['pdf_catalog_text_orientation'] = $this->config->get('pdf_catalog_text_orientation'); 284 | } 285 | $this->data['modules'] = array(); 286 | if (isset($this->request->post['pdf_catalog_module'])) { 287 | $this->data['modules'] = $this->request->post['pdf_catalog_module']; 288 | } elseif ($this->config->get('pdf_catalog_module')) { 289 | $this->data['modules'] = $this->config->get('pdf_catalog_module'); 290 | } 291 | $this->data['token'] = $this->session->data['token']; 292 | $this->data['layouts'] = $this->model_design_layout->getLayouts(); 293 | $this->data['tcpdf'] = file_exists(DIR_SYSTEM.'helper/tcpdf/tcpdf.php'); 294 | 295 | $this->template = 'module/pdf_catalog.tpl'; 296 | $this->children = array( 297 | 'common/header', 298 | 'common/footer' 299 | ); 300 | 301 | $this->response->setOutput($this->render(TRUE), $this->config->get('config_compression')); 302 | } 303 | 304 | 305 | public function install() { 306 | $this->load->model('setting/setting'); 307 | $this->db->query(" 308 | INSERT INTO " . DB_PREFIX . "setting ( 309 | `setting_id` , 310 | `store_id` , 311 | `group` , 312 | `key` , 313 | `value` , 314 | `serialized` 315 | ) 316 | VALUES ( 317 | NULL , '0', 'pdf_catalog', 'pdf_catalog_image_height', '100', '0' 318 | ),( 319 | NULL , '0', 'pdf_catalog', 'pdf_catalog_image_width', '100', '0' 320 | ),( 321 | NULL , '0', 'pdf_catalog', 'pdf_catalog_display_toc', '1', '0' 322 | ),( 323 | NULL , '0', 'pdf_catalog', 'pdf_catalog_display_subcategories', '1', '0' 324 | ),( 325 | NULL , '0', 'pdf_catalog', 'pdf_catalog_item_per_page', '6', '0' 326 | ),( 327 | NULL , '0', 'pdf_catalog', 'pdf_catalog_max_products', '200', '0' 328 | ),( 329 | NULL , '0', 'pdf_catalog', 'pdf_catalog_description_chars', '75', '0' 330 | ),( 331 | NULL , '0', 'pdf_catalog', 'pdf_catalog_template_type', 'html', '0' 332 | ),( 333 | NULL , '0', 'pdf_catalog', 'pdf_catalog_display_disabled', '0', '0' 334 | ),( 335 | NULL , '0', 'pdf_catalog', 'pdf_catalog_display_out_of_stock', '0', '0' 336 | ),( 337 | NULL , '0', 'pdf_catalog', 'pdf_catalog_display_subcategories', '1', '0' 338 | ),( 339 | NULL , '0', 'pdf_catalog', 'pdf_catalog_sort_products', 'pd.name', '0' 340 | ),( 341 | NULL , '0', 'pdf_catalog', 'pdf_catalog_max_options', '1', '0' 342 | ),( 343 | NULL , '0', 'pdf_catalog', 'pdf_catalog_max_per_options', '1', '0' 344 | ),( 345 | NULL , '0', 'pdf_catalog', 'pdf_catalog_text_orientation', 'ltr', '0' 346 | ),( 347 | NULL , '0', 'pdf_catalog', 'pdf_catalog_display_manufacturer_name', '0', '0' 348 | ),( 349 | NULL , '0', 'pdf_catalog', 'pdf_catalog_display_manufacturer_logo', '0', '0' 350 | ),( 351 | NULL , '0', 'pdf_catalog', 'pdf_catalog_remove_empty_tags', '1', '0' 352 | ),( 353 | NULL , '0', 'pdf_catalog', 'pdf_catalog_display_description', '0', '0' 354 | ); 355 | "); 356 | } 357 | 358 | public function fetch_api() { 359 | $this->load->model('setting/setting'); 360 | 361 | $config_error_display = $this->config->get('config_error_display'); 362 | $config_error_log = $this->config->get('config_error_log'); 363 | 364 | if ( $config_error_display > 0 || $config_error_log > 0) { 365 | $this->model_setting_setting->editSettingValue('config', 'config_error_display', 0); 366 | $this->model_setting_setting->editSettingValue('config', 'config_error_log', 0); 367 | 368 | } 369 | 370 | $this->load->language('module/pdf_catalog'); 371 | 372 | $url = $this->language->get('tcpdf_url'); 373 | $cache = DIR_SYSTEM . 'cache/tcpdf.zip'; 374 | $unzip_path = DIR_SYSTEM . 'helper/'; 375 | 376 | if (!$fp = fopen($cache, 'w')) { 377 | echo "Error:
"; 378 | echo "You may need to change permissions for the directory $cache"; 379 | echo '
'; 380 | return; 381 | } 382 | 383 | $ch = curl_init($url); 384 | curl_setopt($ch, CURLOPT_FILE, $fp); 385 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 386 | $data = curl_exec($ch); 387 | curl_close($ch); 388 | fclose($fp); 389 | 390 | echo 'Download Complete....' . '
'; 391 | 392 | $this->model_setting_setting->editSettingValue('config', 'config_error_display', $config_error_display); 393 | $this->model_setting_setting->editSettingValue('config', 'config_error_log', $config_error_log); 394 | 395 | if (!$fp = fopen($unzip_path.'test', 'w')) { 396 | echo "Error:
"; 397 | echo "You may need to change permissions for the directory $unzip_path"; 398 | echo '
'; 399 | }else{ 400 | $this->unzip($cache, $unzip_path); 401 | fclose($fp); 402 | } 403 | unlink($unzip_path.'test'); 404 | //$this->rrmdir($unzip_path.'tcpdf'); 405 | $renamed=rename(DIR_SYSTEM . 'helper/tcpdf-6.0.086',DIR_SYSTEM . 'helper/tcpdf'); 406 | if(!$renamed == false) 407 | { 408 | copy(DIR_SYSTEM . 'cache/pdf_catalog_default_logo.png', DIR_SYSTEM . 'helper/tcpdf/examples/images/pdf_catalog_default_logo.png'); 409 | //unlink($cache); 410 | echo 'Api Installed...'; 411 | echo '
'; 412 | }else{ 413 | echo '
'; 414 | echo '
'; 415 | echo "Error: Check if Tcpdf directory exists, if it does remove it (unless you need for specific purpose)."; 416 | echo '
'; 417 | } 418 | } 419 | 420 | public function rrmdir($dir) { 421 | if (is_dir($dir)) { 422 | $objects = scandir($dir); 423 | foreach ($objects as $object) { 424 | if ($object != "." && $object != "..") { 425 | if (filetype($dir."/".$object) == "dir") $this->rrmdir($dir."/".$object); else unlink($dir."/".$object); 426 | } 427 | } 428 | reset($objects); 429 | rmdir($dir); 430 | } 431 | } 432 | 433 | public function unzip($path,$unzip_path) { 434 | 435 | $zip = new ZipArchive; 436 | $res = $zip->open($path); 437 | if ($res === TRUE) { 438 | $zip->extractTo($unzip_path); 439 | $zip->close(); 440 | echo "$path successfully unzipped at location:.$unzip_path"; 441 | echo '
'; 442 | } else { 443 | echo "Error: $path failed to unzip at location:$unzip_path"; 444 | echo '
'; 445 | } 446 | 447 | } 448 | 449 | public function uninstall() { 450 | $this->db->query(" 451 | DELETE FROM " . DB_PREFIX . "setting 452 | WHERE `group` = 'pdf_catalog' 453 | "); 454 | } 455 | 456 | private function validate() { 457 | if (!$this->user->hasPermission('modify', 'module/pdf_catalog')) { 458 | $this->error['warning'] = $this->language->get('error_permission'); 459 | } 460 | 461 | if (!$this->error) { 462 | return TRUE; 463 | } else { 464 | return FALSE; 465 | } 466 | } 467 | 468 | } 469 | 470 | -------------------------------------------------------------------------------- /upload/catalog/controller/product/pdf_catalog.php: -------------------------------------------------------------------------------- 1 | load->config('pdf_catalog'); 7 | $this->load->model('catalog/pdf_catalog'); 8 | $this->load->model('catalog/product'); 9 | $this->load->model('catalog/manufacturer'); 10 | $this->load->language('module/pdf_catalog'); 11 | $this->document->addStyle('catalog/view/theme/' . $this->config->get('config_template') . '/stylesheet/pdf_catalog.css'); 12 | 13 | $this->data['entry_position'] = $this->language->get('entry_position'); 14 | $this->data['text_description'] = $this->language->get('text_description'); 15 | 16 | $this->load->model('tool/image'); 17 | $limit = $this->config->get('pdf_catalog_max_products'); 18 | $sort = $this->config->get('pdf_catalog_sort_products'); 19 | $data = array( 20 | 'status' => 1, 21 | 'sort' => 'pd.name', 22 | // 'sort' => $sort, 23 | 'limit' => $limit 24 | ); 25 | 26 | if($this->config->get('pdf_catalog_display_disabled') == 0){ 27 | $data['filter_status'] = 1; 28 | } 29 | if($this->config->get('pdf_catalog_display_out_of_stock') == 0){ 30 | $data['filter_quantity'] = 1; 31 | } 32 | 33 | if (isset($this->request->get['category_id'])) { 34 | $parentCategory = $this->request->get['category_id']; 35 | } else { 36 | $parentCategory = 0; 37 | } 38 | $categories = $this->model_catalog_pdf_catalog->getCategories($parentCategory); 39 | foreach ($categories as $key => $category) { 40 | $products = $this->model_catalog_pdf_catalog->getProductsByCategoryId($category['category_id'], $data); 41 | if (!empty($products)) { 42 | foreach ($products as $key2 => $product) { 43 | $products[$key2]['price'] = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax'))); 44 | $options = $this->model_catalog_product->getProductOptions($products[$key2]['product_id']); 45 | $attributes = $this->model_catalog_product->getProductAttributes($products[$key2]['product_id']); 46 | $discounts = $this->model_catalog_product->getProductDiscounts($products[$key2]['product_id']); 47 | $specials = $this->model_catalog_product->getProductSpecials($products[$key2]['product_id']); 48 | $products[$key2]['options'] = $options; 49 | if($this->config->get('pdf_catalog_display_manufacturer_logo') == 1 || $this->config->get('pdf_catalog_display_manufacturer_name') == 1){ 50 | 51 | $manufacturer = $this->model_catalog_manufacturer->getManufacturer($products[$key2]['manufacturer_id']); 52 | if(isset($manufacturer['image']) && isset($manufacturer['name'])){ 53 | //var_dump($manufacturer); 54 | $products[$key2]['manufacturer_logo_url'] = $manufacturer['image']; 55 | $products[$key2]['manufacturer_name'] = $manufacturer['name']; 56 | } 57 | 58 | } 59 | 60 | if ($this->config->get('pdf_catalog_description') && strlen(trim($this->config->get('pdf_catalog_description'))) > 1) { 61 | $products[$key2]['description'] = $product['description']; 62 | } 63 | 64 | } 65 | } 66 | $categories[$key]['products'] = $products; 67 | } 68 | 69 | $totalproducts = 0; 70 | foreach ($categories as $k => $categori) { 71 | $totalproducts = $totalproducts + count($categori['products']); 72 | $productsizes[$k] = count($categori['products']); 73 | } 74 | 75 | while ($totalproducts > $limit) { 76 | $categories = $this->removeProduct($categories, $productsizes); 77 | $totalproducts--; 78 | foreach ($categories as $k => $categori) { 79 | $productsizes[$k] = count($categori['products']); 80 | } 81 | } 82 | 83 | $this->createPdf($categories); 84 | } 85 | 86 | public function removeProduct($categories, $sizes) { 87 | 88 | $flipped = array_flip($sizes); 89 | array_multisort($flipped, SORT_DESC); 90 | 91 | $highest_value = $flipped[0]; 92 | 93 | foreach ($sizes as $k => $size) { 94 | 95 | if ($size == $highest_value) { 96 | array_pop($categories[$k]['products']); 97 | } 98 | } 99 | 100 | 101 | return $categories; 102 | } 103 | 104 | public function createPdf($pdf_data) { 105 | $datacount = count($pdf_data[0]); 106 | 107 | if ($datacount > 1) { 108 | 109 | $image_width = (int) $this->config->get('pdf_catalog_image_width'); 110 | $image_height = (int) $this->config->get('pdf_catalog_image_height'); 111 | $item_per_page = (int) $this->config->get('pdf_catalog_item_per_page'); 112 | 113 | 114 | $this->load->helper('tcpdf/config/tcpdf_config'); 115 | $this->load->helper('tcpdf/tcpdf'); 116 | 117 | $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); 118 | $author = $this->config->get('pdf_catalog_author'); 119 | $title = $this->config->get('pdf_catalog_title'); 120 | $subject = $this->config->get('pdf_catalog_subject'); 121 | $keywords = $this->config->get('pdf_catalog_description'); 122 | 123 | // set document information 124 | $pdf->SetCreator(PDF_CREATOR); 125 | $pdf->SetAuthor($author); 126 | $pdf->SetTitle($title); 127 | $pdf->SetSubject($subject); 128 | $pdf->SetKeywords($keywords); 129 | 130 | // set default header data 131 | $pdf_logo = "../../../../image/pdf_catalog_default_logo.png"; 132 | 133 | if (file_exists($pdf_logo) == false) { 134 | $pdf_logo = "pdf_catalog_default_logo.png"; 135 | } 136 | $pdf_title = $this->config->get('config_name'); 137 | $pdf_string = $this->config->get('config_url'); 138 | $pdf->SetHeaderData($pdf_logo, PDF_HEADER_LOGO_WIDTH, $pdf_title, $pdf_string); 139 | 140 | // set header and footer fonts 141 | $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); 142 | $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); 143 | 144 | // set default monospaced font 145 | $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); 146 | 147 | //set margins 148 | $pdf->SetMargins(PDF_MARGIN_LEFT, 20, PDF_MARGIN_RIGHT); 149 | $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); 150 | $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); 151 | 152 | //set auto page breaks 153 | $pdf->SetAutoPageBreak(TRUE, 20); 154 | 155 | // set font 156 | $pdf->SetFont('helvetica', '', 10); 157 | 158 | if($this->config->get('pdf_catalog_text_orientation') == 'rtl') 159 | { 160 | $pdf->setRTL($enable = true, $resetx = true); 161 | } 162 | 163 | // add a page 164 | $pdf->AddPage(); 165 | 166 | if ($this->config->get('pdf_catalog_template_type') == 'native') { 167 | $pdf = $this->native_template($pdf, $pdf_data); 168 | 169 | } else { 170 | $pdf = $this->html_template($pdf, $pdf_data, $image_height, $image_width, $item_per_page); 171 | } 172 | 173 | // reset pointer to the last page and remove it 174 | $pdf->lastPage(); 175 | $lastpage = $pdf->getPage(); 176 | $pdf->deletePage($lastpage); 177 | 178 | //Close and output PDF document 179 | $pdf->Output('catalog.pdf', 'I'); 180 | die; 181 | } else { 182 | echo "Category # " . $this->request->get['category_id'] . " Not Found"; 183 | } 184 | } 185 | 186 | //@TODO: fix native template 187 | public function native_template($pdf, $pdf_data) { 188 | $margins = array(1, 1, 1, 1); 189 | $padding = array(1, 1, 1, 1); 190 | $bgcolor = array(255, 255, 127); 191 | $products = $pdf_data; 192 | $pdf->setCellPaddings($padding[0], $padding[1], $padding[2], $padding[3]); 193 | $pdf->setCellMargins($margins[0], $margins[1], $margins[2], $margins[3]); 194 | $pdf->SetFillColor($bgcolor[0], $bgcolor[1], $bgcolor[2]); 195 | 196 | // MultiCell($w, $h, $txt, $border=0, $align='J', $fill=0, $ln=1, $x='', $y='', $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0) 197 | // set some text for example 198 | $txt = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'; 199 | $pdf->MultiCell(100, 5, '[price] ' . $txt, 1, 'L', 1, 1, '', '', true); 200 | 201 | //loop through products and build pdf 202 | // foreach($data as $prod){ 203 | // $pdf->MultiCell(100, 5, '[price] ' .$prod[price], 1, 'L', 1, 1, '', '', true); 204 | // $pdf->Ln(4); 205 | // or 206 | // $pdf->MultiRow('Row '.($i), $prod[price]."\n"); 207 | // } 208 | return $pdf; 209 | } 210 | 211 | public function html_template($pdf, $pdf_data, $image_height, $image_width, $item_per_page) { 212 | 213 | $html_template_css = PDF_CATALOG_TEMPLATE_CSS; 214 | $html_template_category = PDF_CATALOG_TEMPLATE_CATEGORY; 215 | $html_template_product = PDF_CATALOG_TEMPLATE_PRODUCT; 216 | 217 | $html_template_css = str_replace("{::image_height}", $image_height, $html_template_css); 218 | $html = $html_template_css; 219 | 220 | if ($this->config->get('pdf_catalog_description') && strlen(trim($this->config->get('pdf_catalog_description'))) > 1) { 221 | $html_description = '
' . html_entity_decode($this->config->get('pdf_catalog_description')) . '
'; 222 | $html .= $html_description; 223 | } 224 | 225 | $no_of_category = 0; 226 | if ($this->config->get('pdf_catalog_display_toc') == 1 && $this->request->get['category_id'] == 0) { 227 | if (!empty($pdf_data)) { 228 | $html_catalog_toc = PDF_TOC_CATEGORY; 229 | $catalog_toc = PDF_TOC_TITLE; 230 | $catalog_toc = str_replace("{::category_title}", $this->language->get('text_category_title'), $catalog_toc); 231 | foreach ($pdf_data as $key => $category) { 232 | $tmp_catalog_toc = str_replace("{::category_name}", $category['name'], $html_catalog_toc); 233 | $tmp_catalog_toc = str_replace("{::product_cnt}", count($category['products']), $tmp_catalog_toc); 234 | $catalog_toc .= $tmp_catalog_toc; 235 | $no_of_category++; 236 | } 237 | } 238 | 239 | if ($no_of_category > 1) { 240 | $catalog_toc .= '
'; 241 | $html .= $catalog_toc; 242 | } 243 | } 244 | 245 | $pdf_content = ""; 246 | if (!empty($pdf_data)) { 247 | foreach ($pdf_data as $key => $category) { 248 | if (!empty($category['products'])) { 249 | 250 | $tmp_category = str_replace("{::category_name}", $category['name'], $html_template_category); 251 | 252 | $tmp_products = ""; 253 | $no_of_item = 0; 254 | foreach ($category['products'] as $key2 => $product) { 255 | if ($product['image']) { 256 | $image = $product['image']; 257 | } else { 258 | $image = 'no_image.jpg'; 259 | } 260 | 261 | $thumb = $this->model_tool_image->resize($image, $image_width, $image_height); 262 | $thumb = str_replace(HTTP_SERVER, "", $thumb); 263 | $tmp_product = str_replace("{::product_image}", $thumb, $html_template_product); 264 | $tmp_product = str_replace("{::txt_product_name}", $this->language->get('text_category'), $tmp_product); 265 | $tmp_product = str_replace("{::product_name}", $product['name'], $tmp_product); 266 | $tmp_product = str_replace("{::txt_product_model}", $this->language->get('text_model'), $tmp_product); 267 | $tmp_product = str_replace("{::product_model}", $product['model'], $tmp_product); 268 | $tmp_product = str_replace("{::txt_product_price}", $this->language->get('text_price'), $tmp_product); 269 | 270 | $tmp_product = str_replace("{::txt_product_attributes}", $this->language->get('txt_product_attributes'), $tmp_product); 271 | $tmp_product = str_replace("{::txt_product_discounts}", $this->language->get('txt_product_discounts'), $tmp_product); 272 | $tmp_product = str_replace("{::txt_product_specials}", $this->language->get('txt_product_specials'), $tmp_product); 273 | 274 | $description = ""; 275 | if ($this->config->get('pdf_catalog_display_description') == "1") { 276 | $description = html_entity_decode($product['description']); 277 | $description = $this->fixfontsize($description); 278 | $description = trim($description); 279 | if (0>(int)$this->config->get('pdf_catalog_description_chars')) { 280 | $description = $this->truncate($description, $this->config->get('pdf_catalog_description_chars'), $ending = '...', $exact = false, $considerHtml = true); 281 | } 282 | } 283 | if (strlen($description) > 0){ 284 | $tmp_product = str_replace("{::txt_product_description}", $this->language->get('text_description'), $tmp_product); 285 | $tmp_product = str_replace("{::product_description}", $description, $tmp_product); 286 | } else { 287 | $tmp_product = str_replace("{::txt_product_description}", '', $tmp_product); 288 | $tmp_product = str_replace("{::product_description}", '', $tmp_product); 289 | } 290 | 291 | $max_options=(int)$this->config->get('pdf_catalog_max_options'); 292 | $max_per_options=(int)$this->config->get('pdf_catalog_max_per_options'); 293 | 294 | if(isset($product['options']) && is_array($product['options']) && count($product['options'])>0 && $max_options > 0){ 295 | $product_options=''; 319 | $tmp_product = str_replace("{::product_options}", $product_options, $tmp_product); 320 | $tmp_product = str_replace("{::txt_product_options}", $this->language->get('text_product_options'), $tmp_product); 321 | }else { 322 | $tmp_product = str_replace("{::product_options}", '', $tmp_product); 323 | $tmp_product = str_replace("{::txt_product_options}", '', $tmp_product); 324 | } 325 | 326 | $tmp_product = str_replace("{::txt_manufacturer}}", '', $tmp_product); 327 | 328 | if ($this->config->get('pdf_catalog_display_manufacturer_logo') == 1 && isset($product['manufacturer_logo_url'])) { 329 | $mlogo = $this->model_tool_image->resize($product['manufacturer_logo_url'], $image_width, $image_height); 330 | $mlogo = str_replace(HTTP_SERVER, "", $mlogo); 331 | $tmp_product = str_replace("{::manufacturer_logo}", $mlogo, $tmp_product); 332 | 333 | 334 | }else{ 335 | $tmp_product = str_replace("{::txt_manufacturer}}", '', $tmp_product); 336 | $tmp_product = str_replace("{::manufacturer_logo}", '', $tmp_product); 337 | } 338 | 339 | if ($this->config->get('pdf_catalog_display_manufacturer_name') == 1 && isset($product['manufacturer_name']) ) { 340 | $tmp_product = str_replace("{::txt_manufacturer}}", '', $tmp_product); 341 | $tmp_product = str_replace("{::txt_manufacturer_name}", $product['manufacturer_name'], $tmp_product); 342 | 343 | }else{ 344 | $tmp_product = str_replace("{::txt_manufacturer}}", '', $tmp_product); 345 | $tmp_product = str_replace("{::txt_manufacturer_name}", '', $tmp_product); 346 | } 347 | 348 | 349 | $tmp_product = str_replace("{::product_price}", $product['price'], $tmp_product); 350 | 351 | $tmp_products .= $tmp_product; 352 | $no_of_item++; 353 | } 354 | 355 | if ($no_of_item > 0) { 356 | $pdf_content .= str_replace("{::products}", $tmp_products, $tmp_category) . '
'; 357 | $tmp_products = ""; 358 | $no_of_item = 0; 359 | } 360 | } 361 | } 362 | } 363 | 364 | $html .= $pdf_content; 365 | 366 | if($this->config->get('pdf_catalog_remove_empty_tags') == 1){ 367 | $html = $this->remove_empty_tags_recursive($html); 368 | } 369 | 370 | $pdf->writeHTML($html, true, false, true, false, ''); 371 | return $pdf; 372 | } 373 | 374 | function remove_empty_tags_recursive ($str, $repto = NULL) 375 | { 376 | if (!is_string ($str)|| trim ($str) == '') 377 | return $str; 378 | 379 | $start_len = 0; 380 | do { 381 | $start_len = strlen($str); 382 | $str = preg_replace('/<(.*?)\s*>(\s| )*<\/\1\s*>/ims','',$str); 383 | } while (strlen($str) != $start_len); 384 | return $str; 385 | } 386 | 387 | function fixfontsize($text) { 388 | $text= preg_replace ('/size=".*?"/' , '' , $text ); 389 | $text= preg_replace ('/font-size:.*?;/' , '' , $text ); 390 | $text= preg_replace ('/style="\s*"/' , '' , $text ); 391 | return $text; 392 | } 393 | 394 | function truncate($text, $length = 100, $ending = '...', $exact = false, $considerHtml = true) { 395 | if ($considerHtml) { 396 | // if the plain text is shorter than the maximum length, return the whole text 397 | if (strlen(preg_replace('/<.*?>/', '', $text)) <= $length) { 398 | return $text; 399 | } 400 | // splits all html-tags to scanable lines 401 | preg_match_all('/(<.+?>)?([^<>]*)/s', $text, $lines, PREG_SET_ORDER); 402 | $total_length = strlen($ending); 403 | $open_tags = array(); 404 | $truncate = ''; 405 | foreach ($lines as $line_matchings) { 406 | // if there is any html-tag in this line, handle it and add it (uncounted) to the output 407 | if (!empty($line_matchings[1])) { 408 | // if it's an "empty element" with or without xhtml-conform closing slash 409 | if (preg_match('/^<(\s*.+?\/\s*|\s*(img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param)(\s.+?)?)>$/is', $line_matchings[1])) { 410 | // do nothing 411 | // if tag is a closing tag 412 | } else if (preg_match('/^<\s*\/([^\s]+?)\s*>$/s', $line_matchings[1], $tag_matchings)) { 413 | // delete tag from $open_tags list 414 | $pos = array_search($tag_matchings[1], $open_tags); 415 | if ($pos !== false) { 416 | unset($open_tags[$pos]); 417 | } 418 | // if tag is an opening tag 419 | } else if (preg_match('/^<\s*([^\s>!]+).*?>$/s', $line_matchings[1], $tag_matchings)) { 420 | // add tag to the beginning of $open_tags list 421 | array_unshift($open_tags, strtolower($tag_matchings[1])); 422 | } 423 | // add html-tag to $truncate'd text 424 | $truncate .= $line_matchings[1]; 425 | } 426 | // calculate the length of the plain text part of the line; handle entities as one character 427 | $content_length = strlen(preg_replace('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|[0-9a-f]{1,6};/i', ' ', $line_matchings[2])); 428 | if ($total_length+$content_length> $length) { 429 | // the number of characters which are left 430 | $left = $length - $total_length; 431 | $entities_length = 0; 432 | // search for html entities 433 | if (preg_match_all('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|[0-9a-f]{1,6};/i', $line_matchings[2], $entities, PREG_OFFSET_CAPTURE)) { 434 | // calculate the real length of all entities in the legal range 435 | foreach ($entities[0] as $entity) { 436 | if ($entity[1]+1-$entities_length <= $left) { 437 | $left--; 438 | $entities_length += strlen($entity[0]); 439 | } else { 440 | // no more characters left 441 | break; 442 | } 443 | } 444 | } 445 | $truncate .= substr($line_matchings[2], 0, $left+$entities_length); 446 | // maximum lenght is reached, so get off the loop 447 | break; 448 | } else { 449 | $truncate .= $line_matchings[2]; 450 | $total_length += $content_length; 451 | } 452 | // if the maximum length is reached, get off the loop 453 | if($total_length>= $length) { 454 | break; 455 | } 456 | } 457 | } else { 458 | if (strlen($text) <= $length) { 459 | return $text; 460 | } else { 461 | $truncate = substr($text, 0, $length - strlen($ending)); 462 | } 463 | } 464 | // if the words shouldn't be cut in the middle... 465 | if (!$exact) { 466 | // ...search the last occurance of a space... 467 | $spacepos = strrpos($truncate, ' '); 468 | if (isset($spacepos)) { 469 | // ...and cut the text in this position 470 | $truncate = substr($truncate, 0, $spacepos); 471 | } 472 | } 473 | // add the defined ending to the text 474 | $truncate .= $ending; 475 | if($considerHtml) { 476 | // close all unclosed html-tags 477 | foreach ($open_tags as $tag) { 478 | $truncate .= ''; 479 | } 480 | } 481 | return $truncate; 482 | } 483 | 484 | 485 | } 486 | --------------------------------------------------------------------------------