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