| 1: | <?php
|
| 2: | namespace Opencart\Catalog\Controller\Extension\Opencart\Module;
|
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: |
|
| 8: | class Special extends \Opencart\System\Engine\Controller {
|
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: |
|
| 16: | public function index(array $setting): string {
|
| 17: | $this->load->language('extension/opencart/module/special');
|
| 18: |
|
| 19: | $data['axis'] = $setting['axis'];
|
| 20: |
|
| 21: | $data['products'] = [];
|
| 22: |
|
| 23: | $filter_data = [
|
| 24: | 'sort' => 'pd.name',
|
| 25: | 'order' => 'ASC',
|
| 26: | 'start' => 0,
|
| 27: | 'limit' => $setting['limit']
|
| 28: | ];
|
| 29: |
|
| 30: | $this->load->model('catalog/product');
|
| 31: | $this->load->model('tool/image');
|
| 32: |
|
| 33: | $results = $this->model_catalog_product->getSpecials($filter_data);
|
| 34: |
|
| 35: | if ($results) {
|
| 36: | foreach ($results as $result) {
|
| 37: | if ($result['image']) {
|
| 38: | $image = $this->model_tool_image->resize(html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'), $setting['width'], $setting['height']);
|
| 39: | } else {
|
| 40: | $image = $this->model_tool_image->resize('placeholder.png', $setting['width'], $setting['height']);
|
| 41: | }
|
| 42: |
|
| 43: | if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
|
| 44: | $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
|
| 45: | } else {
|
| 46: | $price = false;
|
| 47: | }
|
| 48: |
|
| 49: | if ((float)$result['special']) {
|
| 50: | $special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
|
| 51: | } else {
|
| 52: | $special = false;
|
| 53: | }
|
| 54: |
|
| 55: | if ($this->config->get('config_tax')) {
|
| 56: | $tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']);
|
| 57: | } else {
|
| 58: | $tax = false;
|
| 59: | }
|
| 60: |
|
| 61: | $product_data = [
|
| 62: | 'product_id' => $result['product_id'],
|
| 63: | 'thumb' => $image,
|
| 64: | 'name' => $result['name'],
|
| 65: | 'description' => oc_substr(trim(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('config_product_description_length')) . '..',
|
| 66: | 'price' => $price,
|
| 67: | 'special' => $special,
|
| 68: | 'tax' => $tax,
|
| 69: | 'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
|
| 70: | 'rating' => $result['rating'],
|
| 71: | 'href' => $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . $result['product_id'])
|
| 72: | ];
|
| 73: |
|
| 74: | $data['products'][] = $this->load->controller('product/thumb', $product_data);
|
| 75: | }
|
| 76: |
|
| 77: | return $this->load->view('extension/opencart/module/special', $data);
|
| 78: | } else {
|
| 79: | return '';
|
| 80: | }
|
| 81: | }
|
| 82: | }
|
| 83: | |