steve07 Posted August 22, 2023 at 08:32 AM Share Posted August 22, 2023 at 08:32 AM как получить отфильтрованный массив товаров? Делаю со страницы категории экспорт товаров в PDF формат, в pdf попадают все товары if ($category_info) { /*// OCFilter start if (isset($this->request->get['filter_ocfilter'])) { $filter_ocfilter = $this->request->get['filter_ocfilter']; } else { $filter_ocfilter = ''; } // OCFilter end*/ if (isset($this->request->get['filter'])) { $filter = $this->request->get['filter']; } else { $filter = ''; } if (isset($this->request->get['sort'])) { $sort = $this->request->get['sort']; } else { $sort = 'p.sort_order'; } if (isset($this->request->get['order'])) { $order = $this->request->get['order']; } else { $order = 'ASC'; } if (isset($this->request->get['page'])) { $page = $this->request->get['page']; } else { $page = 1; } if (isset($this->request->get['limit'])) { $limit = (int)$this->request->get['limit']; } else { $limit = $this->config->get($this->config->get('config_theme') . '_product_limit'); } require('system/library/mpdf/mpdf.php'); $data['heading_title'] = $category_info['name']; $data['text_refine'] = $this->language->get('text_refine'); $data['text_empty'] = $this->language->get('text_empty'); $data['text_quantity'] = $this->language->get('text_quantity'); $data['text_manufacturer'] = $this->language->get('text_manufacturer'); $data['text_model'] = $this->language->get('text_model'); $data['text_price'] = $this->language->get('text_price'); $data['products'] = array(); $filter_data = array( 'filter_category_id' => $category_id, 'filter_filter' => $filter, 'sort' => $sort, 'order' => $order, 'start' => ($page - 1) * $limit, 'limit' => 10000 ); /*// OCFilter start $filter_data['filter_ocfilter'] = $filter_ocfilter; // OCFilter end*/ // OCFilter start if ($this->registry->get('ocfilter') && $this->ocfilter->startup() && $this->ocfilter->api->useSubCategory() && $this->ocfilter->api->isSelected() && empty($filter_data['filter_sub_category'])) { $filter_data['filter_sub_category'] = true; } // OCFilter end $product_total = $this->model_catalog_product->getTotalProducts($filter_data); $results = $this->model_catalog_product->getProducts($filter_data); // Unit of measure → $this->load->model('extension/module/unit_of_measure'); $product_ids = array(); foreach ($results as $result) { $product_ids[] = $result['product_id']; } $units_result = $this->model_extension_module_unit_of_measure->getUnits($product_ids); // ← Unit of measure foreach ($results as $result) { if ($result['image']) { $image = $this->model_tool_image->resize($result['image'], $this->config->get($this->config->get('config_theme') . '_image_product_width'), $this->config->get($this->config->get('config_theme') . '_image_product_height')); } else { $image = $this->model_tool_image->resize('placeholder.png', $this->config->get($this->config->get('config_theme') . '_image_product_width'), $this->config->get($this->config->get('config_theme') . '_image_product_height')); } if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) { $price = $result['price']; } else { $price = false; } if ((float)$result['special']) { $special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']); if ($this->currency->has($this->config->get('config_currency2')) && ($this->config->get('config_currency2') != $this->session->data['currency'])) { $special .= ' (' . $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->config->get('config_currency2')) . ')'; } } else { $special = false; } $data['products'][] = array( 'unit_of_measure' => isset($units_result[$result['product_id']]) ? html_entity_decode($units_result[$result['product_id']], ENT_QUOTES, 'UTF-8') : '', 'product_id' => $result['product_id'], 'thumb' => $image, 'name' => $result['name'], 'model' => $result['model'], 'collection' => $result['collection'], 'attribute_groups' => $this->model_catalog_product->getProductAttributes($result['product_id']), 'price' => (int)$price . ' руб', 'special' => $special, 'href' => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url) ); } // $template = 'product/category'; //$this->load->library('mpdf/mpdf'); $headerHTML = ' <div style="float: left; width: 340px; text-align: left"> <a target="_blank" href="' . HTTPS_SERVER . '"><img style="max-width:100%;max-height:180px" src="/image/'.$this->config->get('config_logo').'" /></a> </div> <div style="float: right; width: 340px; text-align: right; color: #808180"> ' . nl2br($this->config->get('config_address')) . '<br/> ' . $this->config->get('config_telephone') . '<br/> ' . $this->config->get('config_email') . '<br/> <a style="color:blue; text-decoration:none;" target="_blank" href="' . HTTPS_SERVER . '">' . HTTPS_SERVER . '</a> </div> <div class="clear"></div> <hr> '; //print_r($this->config); if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/category_price.tpl')) { $this->template = $this->config->get('config_template') . '/template/product/category_price.tpl'; } else { $this->template = 'default/template/product/category_price.tpl'; } $today = date("d.m.Y"); $mpdf = new mPDF('utf-8', 'A4', 7, 'Helvetica', 20, 5, 35, 5); $mpdf->name = $category_info['name'] . '.pdf'; $mpdf->SetHTMLHeader($headerHTML); $mpdf->WriteHTML($this->load->view('product/category_price.tpl', $data)); $mpdf->Output('Прайс_' . $today . '.pdf', 'D'); } 0 Quote Link to comment Share on other sites More sharing options...
AlexDW Posted August 22, 2023 at 09:19 AM Share Posted August 22, 2023 at 09:19 AM вероятно раскомментировать части кода с $filter_ocfilter 0 Quote модули для удобной работы с Opencart Link to comment Share on other sites More sharing options...
steve07 Posted August 22, 2023 at 10:16 AM Author Share Posted August 22, 2023 at 10:16 AM В 22.08.2023 в 14:19, AlexDW сказал: вероятно раскомментировать части кода с $filter_ocfilter не помогает, это при старой версии фильтра было... и все ок работало. С новой не работает 0 Quote Link to comment Share on other sites More sharing options...
AlexDW Posted August 22, 2023 at 11:29 AM Share Posted August 22, 2023 at 11:29 AM отслеживайте что у вас в $filter_data передается 0 Quote модули для удобной работы с Opencart Link to comment Share on other sites More sharing options...
steve07 Posted November 28, 2023 at 01:22 PM Author Share Posted November 28, 2023 at 01:22 PM В 22.08.2023 в 16:29, AlexDW сказал: отслеживайте что у вас в $filter_data передается тут все ок Array ( [filter_category_id] => 61 [filter_filter] => [sort] => p.sort_order [order] => ASC [start] => 0 [limit] => 10000 ) в results соответственно попадают все товары из категории id=61. А как получить массив с отфильтрованным списком никак не пойму. Помогите, пожалуйста. функция экспорта в PDF Спойлер public function pdf() { $this->load->model('catalog/category'); $this->load->model('catalog/product'); $this->load->model('tool/image'); if (isset($this->request->get['path'])) { $url = ''; if (isset($this->request->get['sort'])) { $url .= '&sort=' . $this->request->get['sort']; } if (isset($this->request->get['order'])) { $url .= '&order=' . $this->request->get['order']; } if (isset($this->request->get['limit'])) { $url .= '&limit=' . $this->request->get['limit']; } $path = ''; $parts = explode('_', (string)$this->request->get['path']); $category_id = (int)array_pop($parts); foreach ($parts as $path_id) { if (!$path) { $path = (int)$path_id; } else { $path .= '_' . (int)$path_id; } $category_info = $this->model_catalog_category->getCategory($path_id); if ($category_info) { $data['breadcrumbs'][] = array( 'text' => $category_info['name'], 'href' => $this->url->link('product/category', 'path=' . $path . $url) ); } } } else { $category_id = 0; } $category_info = $this->model_catalog_category->getCategory($category_id); if ($category_info) { if (isset($this->request->get['filter'])) { $filter = $this->request->get['filter']; } else { $filter = ''; } if (isset($this->request->get['sort'])) { $sort = $this->request->get['sort']; } else { $sort = 'p.sort_order'; } if (isset($this->request->get['order'])) { $order = $this->request->get['order']; } else { $order = 'ASC'; } if (isset($this->request->get['page'])) { $page = $this->request->get['page']; } else { $page = 1; } if (isset($this->request->get['limit'])) { $limit = (int)$this->request->get['limit']; } else { $limit = $this->config->get($this->config->get('config_theme') . '_product_limit'); } require('system/library/mpdf/mpdf.php'); $data['heading_title'] = $category_info['name']; $data['text_refine'] = $this->language->get('text_refine'); $data['text_empty'] = $this->language->get('text_empty'); $data['text_quantity'] = $this->language->get('text_quantity'); $data['text_manufacturer'] = $this->language->get('text_manufacturer'); $data['text_model'] = $this->language->get('text_model'); $data['text_price'] = $this->language->get('text_price'); $data['products'] = array(); $filter_data = array( 'filter_category_id' => $category_id, 'filter_filter' => $filter, 'sort' => $sort, 'order' => $order, 'start' => ($page - 1) * $limit, 'limit' => 10000 ); // OCFilter start if ($this->registry->get('ocfilter') && $this->ocfilter->startup() && $this->ocfilter->api->useSubCategory() && $this->ocfilter->api->isSelected() && empty($filter_data['filter_sub_category'])) { $filter_data['filter_sub_category'] = true; } // OCFilter end $product_total = $this->model_catalog_product->getTotalProducts($filter_data); $results = $this->model_catalog_product->getProducts($filter_data); //print_r($results); foreach ($results as $result) { if ($result['image']) { $image = $this->model_tool_image->resize($result['image'], $this->config->get($this->config->get('config_theme') . '_image_product_width'), $this->config->get($this->config->get('config_theme') . '_image_product_height')); } else { $image = $this->model_tool_image->resize('placeholder.png', $this->config->get($this->config->get('config_theme') . '_image_product_width'), $this->config->get($this->config->get('config_theme') . '_image_product_height')); } if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) { $price = $result['price']; } else { $price = false; } if ((float)$result['special']) { $special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']); } else { $special = false; } $data['products'][] = array( 'product_id' => $result['product_id'], 'thumb' => $image, 'name' => $result['name'], 'model' => $result['model'], 'collection' => $result['collection'], 'attribute_groups' => $this->model_catalog_product->getProductAttributes($result['product_id']), 'price' => (int)$price, 'special' => $special, 'href' => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url) ); } $headerHTML = ' <div style="float: left; width: 340px; text-align: left"> <a target="_blank" href="' . HTTPS_SERVER . '"><img style="max-width:100%;max-height:180px" src="/image/'.$this->config->get('config_logo').'" /></a> </div> <div style="float: right; width: 340px; text-align: right; color: #808180"> ' . nl2br($this->config->get('config_address')) . '<br/> ' . $this->config->get('config_telephone') . '<br/> ' . $this->config->get('config_email') . '<br/> <a style="color:blue; text-decoration:none;" target="_blank" href="' . HTTPS_SERVER . '">' . HTTPS_SERVER . '</a> </div> <div class="clear"></div> <hr> '; if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/price_to_pdf.tpl')) { $this->template = $this->config->get('config_template') . '/template/product/price_to_pdf.tpl'; } else { $this->template = 'default/template/product/price_to_pdf.tpl'; } $today = date("d.m.Y"); $mpdf = new mPDF('utf-8', 'A4', 7, 'Helvetica', 20, 5, 35, 5); $mpdf->name = $category_info['name'] . '.pdf'; $mpdf->SetHTMLHeader($headerHTML); $mpdf->WriteHTML($this->load->view('product/price_to_pdf.tpl', $data)); $mpdf->Output('Прайс_' . $today . '.pdf', 'D'); } } 0 Quote Link to comment Share on other sites More sharing options...
AlexDW Posted November 28, 2023 at 02:32 PM Share Posted November 28, 2023 at 02:32 PM отслеживать какие входные данные идут в запрос выборки и что там происходит $product_total = $this->model_catalog_product->getTotalProducts($filter_data); $results = $this->model_catalog_product->getProducts($filter_data); 0 Quote модули для удобной работы с Opencart Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.