shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

special.php (9320B)


      1 <?php
      2 class ControllerProductSpecial extends Controller {
      3 	public function index() {
      4 		$this->load->language('product/special');
      5 
      6 		$this->load->model('catalog/product');
      7 
      8 		$this->load->model('tool/image');
      9 
     10 		if (isset($this->request->get['sort'])) {
     11 			$sort = $this->request->get['sort'];
     12 		} else {
     13 			$sort = 'p.sort_order';
     14 		}
     15 
     16 		if (isset($this->request->get['order'])) {
     17 			$order = $this->request->get['order'];
     18 		} else {
     19 			$order = 'ASC';
     20 		}
     21 
     22 		if (isset($this->request->get['page'])) {
     23 			$page = $this->request->get['page'];
     24 		} else {
     25 			$page = 1;
     26 		}
     27 
     28 		if (isset($this->request->get['limit'])) {
     29 			$limit = (int)$this->request->get['limit'];
     30 		} else {
     31 			$limit = $this->config->get('theme_' . $this->config->get('config_theme') . '_product_limit');
     32 		}
     33 
     34 		$this->document->setTitle($this->language->get('heading_title'));
     35 
     36 		$data['breadcrumbs'] = array();
     37 
     38 		$data['breadcrumbs'][] = array(
     39 			'text' => $this->language->get('text_home'),
     40 			'href' => $this->url->link('common/home')
     41 		);
     42 
     43 		$url = '';
     44 
     45 		if (isset($this->request->get['sort'])) {
     46 			$url .= '&sort=' . $this->request->get['sort'];
     47 		}
     48 
     49 		if (isset($this->request->get['order'])) {
     50 			$url .= '&order=' . $this->request->get['order'];
     51 		}
     52 
     53 		if (isset($this->request->get['page'])) {
     54 			$url .= '&page=' . $this->request->get['page'];
     55 		}
     56 
     57 		if (isset($this->request->get['limit'])) {
     58 			$url .= '&limit=' . $this->request->get['limit'];
     59 		}
     60 
     61 		$data['breadcrumbs'][] = array(
     62 			'text' => $this->language->get('heading_title'),
     63 			'href' => $this->url->link('product/special', $url)
     64 		);
     65 
     66 		$data['text_compare'] = sprintf($this->language->get('text_compare'), (isset($this->session->data['compare']) ? count($this->session->data['compare']) : 0));
     67 
     68 		$data['compare'] = $this->url->link('product/compare');
     69 
     70 		$data['products'] = array();
     71 
     72 		$filter_data = array(
     73 			'sort'  => $sort,
     74 			'order' => $order,
     75 			'start' => ($page - 1) * $limit,
     76 			'limit' => $limit
     77 		);
     78 
     79 		$product_total = $this->model_catalog_product->getTotalProductSpecials();
     80 
     81 		$results = $this->model_catalog_product->getProductSpecials($filter_data);
     82 
     83 		foreach ($results as $result) {
     84 			if ($result['image']) {
     85 				$image = $this->model_tool_image->resize($result['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_height'));
     86 			} else {
     87 				$image = $this->model_tool_image->resize('placeholder.png', $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_height'));
     88 			}
     89 
     90 			if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
     91 				$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
     92 			} else {
     93 				$price = false;
     94 			}
     95 
     96 			if ((float)$result['special']) {
     97 				$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
     98 			} else {
     99 				$special = false;
    100 			}
    101 
    102 			if ($this->config->get('config_tax')) {
    103 				$tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']);
    104 			} else {
    105 				$tax = false;
    106 			}
    107 
    108 			if ($this->config->get('config_review_status')) {
    109 				$rating = (int)$result['rating'];
    110 			} else {
    111 				$rating = false;
    112 			}
    113 
    114 			$data['products'][] = array(
    115 				'product_id'  => $result['product_id'],
    116 				'thumb'       => $image,
    117 				'name'        => $result['name'],
    118 				'description' => utf8_substr(trim(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('theme_' . $this->config->get('config_theme') . '_product_description_length')) . '..',
    119 				'price'       => $price,
    120 				'special'     => $special,
    121 				'tax'         => $tax,
    122 				'minimum'     => $result['minimum'] > 0 ? $result['minimum'] : 1,
    123 				'rating'      => $result['rating'],
    124 				'href'        => $this->url->link('product/product', 'product_id=' . $result['product_id'] . $url)
    125 			);
    126 		}
    127 
    128 		$url = '';
    129 
    130 		if (isset($this->request->get['limit'])) {
    131 			$url .= '&limit=' . $this->request->get['limit'];
    132 		}
    133 
    134 		$data['sorts'] = array();
    135 
    136 		$data['sorts'][] = array(
    137 			'text'  => $this->language->get('text_default'),
    138 			'value' => 'p.sort_order-ASC',
    139 			'href'  => $this->url->link('product/special', 'sort=p.sort_order&order=ASC' . $url)
    140 		);
    141 
    142 		$data['sorts'][] = array(
    143 			'text'  => $this->language->get('text_name_asc'),
    144 			'value' => 'pd.name-ASC',
    145 			'href'  => $this->url->link('product/special', 'sort=pd.name&order=ASC' . $url)
    146 		);
    147 
    148 		$data['sorts'][] = array(
    149 			'text'  => $this->language->get('text_name_desc'),
    150 			'value' => 'pd.name-DESC',
    151 			'href'  => $this->url->link('product/special', 'sort=pd.name&order=DESC' . $url)
    152 		);
    153 
    154 		$data['sorts'][] = array(
    155 			'text'  => $this->language->get('text_price_asc'),
    156 			'value' => 'ps.price-ASC',
    157 			'href'  => $this->url->link('product/special', 'sort=ps.price&order=ASC' . $url)
    158 		);
    159 
    160 		$data['sorts'][] = array(
    161 			'text'  => $this->language->get('text_price_desc'),
    162 			'value' => 'ps.price-DESC',
    163 			'href'  => $this->url->link('product/special', 'sort=ps.price&order=DESC' . $url)
    164 		);
    165 
    166 		if ($this->config->get('config_review_status')) {
    167 			$data['sorts'][] = array(
    168 				'text'  => $this->language->get('text_rating_desc'),
    169 				'value' => 'rating-DESC',
    170 				'href'  => $this->url->link('product/special', 'sort=rating&order=DESC' . $url)
    171 			);
    172 
    173 			$data['sorts'][] = array(
    174 				'text'  => $this->language->get('text_rating_asc'),
    175 				'value' => 'rating-ASC',
    176 				'href'  => $this->url->link('product/special', 'sort=rating&order=ASC' . $url)
    177 			);
    178 		}
    179 
    180 		$data['sorts'][] = array(
    181 				'text'  => $this->language->get('text_model_asc'),
    182 				'value' => 'p.model-ASC',
    183 				'href'  => $this->url->link('product/special', 'sort=p.model&order=ASC' . $url)
    184 		);
    185 
    186 		$data['sorts'][] = array(
    187 			'text'  => $this->language->get('text_model_desc'),
    188 			'value' => 'p.model-DESC',
    189 			'href'  => $this->url->link('product/special', 'sort=p.model&order=DESC' . $url)
    190 		);
    191 
    192 		$url = '';
    193 
    194 		if (isset($this->request->get['sort'])) {
    195 			$url .= '&sort=' . $this->request->get['sort'];
    196 		}
    197 
    198 		if (isset($this->request->get['order'])) {
    199 			$url .= '&order=' . $this->request->get['order'];
    200 		}
    201 
    202 		$data['limits'] = array();
    203 
    204 		$limits = array_unique(array($this->config->get('theme_' . $this->config->get('config_theme') . '_product_limit'), 25, 50, 75, 100));
    205 
    206 		sort($limits);
    207 
    208 		foreach($limits as $value) {
    209 			$data['limits'][] = array(
    210 				'text'  => $value,
    211 				'value' => $value,
    212 				'href'  => $this->url->link('product/special', $url . '&limit=' . $value)
    213 			);
    214 		}
    215 
    216 		$url = '';
    217 
    218 		if (isset($this->request->get['sort'])) {
    219 			$url .= '&sort=' . $this->request->get['sort'];
    220 		}
    221 
    222 		if (isset($this->request->get['order'])) {
    223 			$url .= '&order=' . $this->request->get['order'];
    224 		}
    225 
    226 		if (isset($this->request->get['limit'])) {
    227 			$url .= '&limit=' . $this->request->get['limit'];
    228 		}
    229 
    230 		$pagination = new Pagination();
    231 		$pagination->total = $product_total;
    232 		$pagination->page = $page;
    233 		$pagination->limit = $limit;
    234 		$pagination->url = $this->url->link('product/special', $url . '&page={page}');
    235 
    236 		$data['pagination'] = $pagination->render();
    237 
    238 		$data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($product_total - $limit)) ? $product_total : ((($page - 1) * $limit) + $limit), $product_total, ceil($product_total / $limit));
    239 
    240 		// http://googlewebmastercentral.blogspot.com/2011/09/pagination-with-relnext-and-relprev.html
    241 		if ($page == 1) {
    242 		    $this->document->addLink($this->url->link('product/special', '', true), 'canonical');
    243 		} else {
    244 		    $this->document->addLink($this->url->link('product/special', 'page='. $page , true), 'canonical');
    245 		}		
    246 		
    247 		if ($page > 1) {
    248 			$this->document->addLink($this->url->link('product/special', (($page - 2) ? '&page='. ($page - 1) : ''), true), 'prev');
    249 		}
    250 
    251 		if ($limit && ceil($product_total / $limit) > $page) {
    252 		    $this->document->addLink($this->url->link('product/special', 'page='. ($page + 1), true), 'next');
    253 		}
    254 
    255 		$data['sort'] = $sort;
    256 		$data['order'] = $order;
    257 		$data['limit'] = $limit;
    258 
    259 		$data['continue'] = $this->url->link('common/home');
    260 
    261 		$data['column_left'] = $this->load->controller('common/column_left');
    262 		$data['column_right'] = $this->load->controller('common/column_right');
    263 		$data['content_top'] = $this->load->controller('common/content_top');
    264 		$data['content_bottom'] = $this->load->controller('common/content_bottom');
    265 		$data['footer'] = $this->load->controller('common/footer');
    266 		$data['header'] = $this->load->controller('common/header');
    267 
    268 		$this->response->setOutput($this->load->view('product/special', $data));
    269 	}
    270 }