//Latest Products
$this->data['latest_products'] = array();
$latest_results = $this->model_catalog_product->getLatestProducts($setting['limit']);
foreach ($latest_results as $result) {
if ($result['image']) {
$results_img = $this->model_catalog_product->getProductImages($result['product_id']);
$dop_img = array();
foreach ($results_img as $result_img) {
if ($result_img['image']) {
$image_dop = $this->model_tool_image->resize($result_img['image'], $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
} else {
$image_dop = false;
}
$dop_img[] = $image_dop;
}
$image = $this->model_tool_image->resize($result['image'], $setting['image_width'], $setting['image_height']);
} else {
$image = $this->model_tool_image->resize('no_image.jpg', $setting['image_width'], $setting['image_height']);
}
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
} 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')));
} else {
$special = false;
}
if ($this->config->get('config_review_status')) {
$rating = $result['rating'];
} else {
$rating = false;
}
$mylabels = new Label($this->registry);
$mylabels->labels = $config_labels;
$mylabels->product_info = stripos($current_layout,'ControllerModuleFeatured') !== false ||
stripos($current_layout,'ControllerModuleFakelatest') !== false ||
stripos($current_layout,'ControllerModuleFakemostviewed') !== false ||
stripos($current_layout,'ControllerModuleFakebestseller')!== false ||
stripos($current_layout,'ControllerModuleBookoftheweek')!== false ||
stripos($current_layout,'ControllerModuledealoftheday')!== false ||
stripos($current_layout,'ControllerModulePreorders')!== false ? $product_info : $result;
$mylabels->current_layout = $current_layout;
$mylabels->current_layout_position = $setting['position'];
$mylabels->products_featured = $products_featured;
$mylabels->bestsellers = $bestsellers;
$labels = $mylabels->RenderLabels();
$this->data['latest_products'][] = array(
'quantity' => $result['quantity'],
'labels' => $labels,
'product_id' => $result['product_id'],
'dop_img' => $dop_img,
'thumb' => $image,
'name' => $result['name'],
'price' => $price,
'special' => $special,
'saving' => ((float)$result['price'] ? round((($result['price'] - $result['special'])/$result['price'])*100, 0) : 0),
'rating' => $rating,
'reviews' => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
'href' => $this->url->link('product/product', 'product_id=' . $result['product_id']),
);
}
//Featured
$this->data['featured_products'] = array();
$products = explode(',', $this->config->get('featured_product'));
if (empty($setting['limit'])) {
$setting['limit'] = 5;
}
$products = array_slice($products, 0, (int)$setting['limit']);
foreach ($products as $product_id) {
$product_info = $this->model_catalog_product->getProduct($product_id);
if ($product_info) {
$results_img = $this->model_catalog_product->getProductImages($product_info['product_id']);
$dop_img = array();
foreach ($results_img as $result_img) {
if ($result_img['image']) {
$image_dop = $this->model_tool_image->resize($result_img['image'], $setting['image_width'], $setting['image_height']);
} else {
$image_dop = false;
}
$dop_img[] = $image_dop;
}
if ($product_info['image']) {
$image = $this->model_tool_image->resize($product_info['image'], $setting['image_width'], $setting['image_height']);
} else {
$image = $this->model_tool_image->resize('no_image.jpg', $setting['image_width'], $setting['image_height']);
}
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));
} else {
$price = false;
}
if ((float)$product_info['special']) {
$special = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')));
} else {
$special = false;
}
if ($this->config->get('config_review_status')) {
$rating = $product_info['rating'];
} else {
$rating = false;
}
$mylabels = new Label($this->registry);
$mylabels->labels = $config_labels;
$mylabels->product_info = stripos($current_layout,'ControllerModuleFeatured') !== false ||
stripos($current_layout,'ControllerModuleFakelatest') !== false ||
stripos($current_layout,'ControllerModuleFakemostviewed') !== false ||
stripos($current_layout,'ControllerModuleFakebestseller')!== false ||
stripos($current_layout,'ControllerModuleBookoftheweek')!== false ||
stripos($current_layout,'ControllerModuledealoftheday')!== false ||
stripos($current_layout,'ControllerModulePreorders')!== false ? $product_info : $result;
$mylabels->current_layout = $current_layout;
$mylabels->current_layout_position = $setting['position'];
$mylabels->products_featured = $products_featured;
$mylabels->bestsellers = $bestsellers;
$labels = $mylabels->RenderLabels();
$this->data['featured_products'][] = array(
'quantity' => $result['quantity'],
'labels' => $labels,
'product_id' => $product_info['product_id'],
'dop_img' => $dop_img,
'thumb' => $image,
'name' => $product_info['name'],
'price' => $price,
'special' => $special,
'saving' => ((float)$product_info['price'] ? round((($product_info['price'] - $product_info['special'])/$product_info['price'])*100, 0) : 0),
'rating' => $rating,
'reviews' => sprintf($this->language->get('text_reviews'), (int)$product_info['reviews']),
'href' => $this->url->link('product/product', 'product_id=' . $product_info['product_id']),
);
}
}
}