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