everybody
Need to add label to discouted products.
When i add the discount price to product(admin - product - discount -add) it ok - the price become to that valuet. But i can't add the label, the $discount array is empty.
So my product.tpl:
<span><?php echo $price; ?></span><?php } ?></b>
<?php print_r($discounts);?>
and my conteroller/product.php
$discounts = $this->model_catalog_product->getProductDiscounts($product_id);
$this->data['discounts'] = array();
foreach ($discounts as $discount) {
$this->data['discounts'][] = array(
'quantity' => $discount['quantity'],
'price' => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax')))
);
}
$this->data['options'] = array();
foreach ($this->model_catalog_product->getProductOptions($product_id) as $option) {
if ($option['type'] == 'select' || $option['type'] == 'radio' || $option['type'] == 'checkbox' || $option['type'] == 'image') {
$option_value_data = array();
foreach ($option['option_value'] as $option_value) {
if (!$option_value['subtract'] || ($option_value['quantity'] > 0)) {
if ((($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) && (float)$option_value['price']) {
$price = $this->currency->format($this->tax->calculate($option_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));
} else {
$price = false;
}
$option_value_data[] = array(
'product_option_value_id' => $option_value['product_option_value_id'],
'option_value_id' => $option_value['option_value_id'],
'name' => $option_value['name'],
'image' => $this->model_tool_image->resize($option_value['image'], 50, 50),
'price' => $price,
'price_prefix' => $option_value['price_prefix']
);
}
}
$this->data['options'][] = array(
'product_option_id' => $option['product_option_id'],
'option_id' => $option['option_id'],
'name' => $option['name'],
'type' => $option['type'],
'option_value' => $option_value_data,
'required' => $option['required']
);
} elseif ($option['type'] == 'text' || $option['type'] == 'textarea' || $option['type'] == 'file' || $option['type'] == 'date' || $option['type'] == 'datetime' || $option['type'] == 'time') {
$this->data['options'][] = array(
'product_option_id' => $option['product_option_id'],
'option_id' => $option['option_id'],
'name' => $option['name'],
'type' => $option['type'],
'option_value' => $option['option_value'],
'required' => $option['required']
);
}
}
if ($product_info['minimum']) {
$this->data['minimum'] = $product_info['minimum'];
} else {
$this->data['minimum'] = 1;
}
$this->data['review_status'] = $this->config->get('config_review_status');
$this->data['reviews'] = sprintf($this->language->get('text_reviews'), (int)$product_info['reviews']);
$this->data['rating'] = (int)$product_info['rating'];
$this->data['description'] = html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8');
$this->data['attribute_groups'] = $this->model_catalog_product->getProductAttributes($product_id);
$this->data['products'] = array();
$results = $this->model_catalog_product->getProductRelated($product_id);
foreach ($results as $result) {
if ($result['image']) {
$image = $this->model_tool_image->resize($result['image'], $this->config->get('config_image_related_width'), $this->config->get('config_image_related_height'));
} else {
$image = false;
}
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 = (int)$result['rating'];
} else {
$rating = false;
}
$this->data['products'][] = array(
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'price' => $price,
'special' => $special,
'rating' => $rating,
'reviews' => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
'href' => $this->url->link('product/product', 'product_id=' . $result['product_id'])
);
}
Mayby i need to look somewere else, can some body help?
Related
By the default Ajax live search module can search by product name and SKU. I want to make it so that the search also takes place by manufacturer. I was able to add a manufacturer to the controller so that it appears in the search results, but it does not search for this criterion.
I've looked at the controller and Java Script code in the template, but I don't see a place anywhere that would be responsible for the search parameters. Maybe someone came across and knows where to look?
This is catalog/controller file:
<?php
class ControllerExtensionModuleLiveSearch extends Controller {
public function index() {
$json = array();
if (isset($this->request->get['filter_name'])) {
$search = $this->request->get['filter_name'];
} else {
$search = '';
}
if (isset($this->request->get['cat_id'])) {
$cat_id = (int)$this->request->get['cat_id'];
} else {
$cat_id = 0;
}
$tag = $search;
$description = '';
$category_id = $cat_id;
$sub_category = '';
$sort = 'p.sort_order';
$order = 'ASC';
$page = 1;
$limit = $this->config->get('module_live_search_limit');
$search_result = 0;
$error = false;
if( version_compare(VERSION, '3.0.0.0', '>=') ){
$currency_code = $this->session->data['currency'];
}
else{
$error = true;
$json[] = array(
'product_id' => 0,
'image' => null,
'name' => 'Version Error: '.VERSION,
'extra_info' => null,
'price' => 0,
'special' => 0,
'url' => '#'
);
}
if(!$error){
if (isset($this->request->get['filter_name'])) {
$this->load->model('catalog/product');
$this->load->model('tool/image');
$filter_data = array(
'filter_name' => $search,
'filter_tag' => $tag,
'filter_description' => $description,
'filter_category_id' => $category_id,
'filter_sub_category' => $sub_category,
'sort' => $sort,
'order' => $order,
'start' => ($page - 1) * $limit,
'limit' => $limit
);
$results = $this->model_catalog_product->getProducts($filter_data);
$search_result = $this->model_catalog_product->getTotalProducts($filter_data);
$image_width = $this->config->get('module_live_search_image_width') ? $this->config->get('module_live_search_image_width') : 0;
$image_height = $this->config->get('module_live_search_image_height') ? $this->config->get('module_live_search_image_height') : 0;
$title_length = $this->config->get('module_live_search_title_length');
$description_length = $this->config->get('module_live_search_description_length');
foreach ($results as $result) {
if ($result['image']) {
$image = $this->model_tool_image->resize($result['image'], $image_width, $image_height);
} else {
$image = $this->model_tool_image->resize('placeholder.png', $image_width, $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')), $currency_code);
} 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')), $currency_code);
} else {
$special = false;
}
if ($this->config->get('config_tax')) {
$tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price'], $currency_code);
} else {
$tax = false;
}
if ($this->config->get('config_review_status')) {
$rating = (int)$result['rating'];
} else {
$rating = false;
}
$json['total'] = (int)$search_result;
$json['products'][] = array(
'product_id' => $result['product_id'],
'image' => $image,
'name' => utf8_substr(strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8')), 0, $title_length) . '..',
'extra_info' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $description_length) . '..',
'price' => $price,
'special' => $special,
'url' => $this->url->link('product/product', 'product_id=' . $result['product_id'])
);
}
}
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}
This is JS code in the template:
var live_search = {
selector: '#search input[name=\'search\']',
text_no_matches: '{{ text_empty }}',
height: '50px'
}
$(document).ready(function() {
var html = '';
html += '<div class="live-search">';
html += ' <ul>';
html += ' </ul>';
html += '<div class="result-text"></div>';
html += '</div>';
//$(live_search.selector).parent().closest('div').after(html);
$(live_search.selector).after(html);
$(live_search.selector).autocomplete({
'source': function(request, response) {
var filter_name = $(live_search.selector).val();
var cat_id = 0;
var module_live_search_min_length = '{{ module_live_search_min_length|abs }}';
if (filter_name.length < module_live_search_min_length) {
$('.live-search').css('display','none');
}
else{
var html = '';
html += '<li style="text-align: center;height:10px;">';
html += '<img class="loading" src="catalog/view/theme/default/image/loading.gif" />';
html += '</li>';
$('.live-search ul').html(html);
$('.live-search').css('display','block');
$.ajax({
url: 'index.php?route=extension/module/live_search&filter_name=' + encodeURIComponent(filter_name),
dataType: 'json',
success: function(result) {
var products = result.products;
$('.live-search ul li').remove();
$('.result-text').html('');
if (!$.isEmptyObject(products)) {
var show_image = {{ module_live_search_show_image|abs }};
var show_price = {{ module_live_search_show_price|abs }};
var show_description = {{ module_live_search_show_description|abs }};
$('.result-text').html('{{ text_view_all_results|e }} ('+result.total+')');
$.each(products, function(index,product) {
var html = '';
html += '<li>';
html += '<a href="' + product.url + '" title="' + product.name + '">';
if(product.image && show_image){
html += ' <div class="product-image"><img alt="' + product.name + '" src="' + product.image + '"></div>';
}
html += ' <div class="product-name">' + product.name ;
if(show_description){
html += '<p>' + product.extra_info + '</p>';
}
html += '</div>';
if(show_price){
if (product.special) {
html += '<div class="product-price"><span class="price">' + product.special + '</span></div>';
} else {
html += ' <div class="product-price"><span class="price">' + product.price + '</span></div>';
}
}
html += '<span style="clear:both"></span>';
html += '</a>';
html += '</li>';
$('.live-search ul').append(html);
});
} else {
var html = '';
html += '<li style="text-align: center;height:10px;">';
html += live_search.text_no_matches;
html += '</li>';
$('.live-search ul').html(html);
}
$('.live-search').css('display','block');
return false;
}
});
}
},
'select': function(product) {
$(live_search.selector).val(product.name);
}
});
$(document).bind( "mouseup touchend", function(e){
var container = $('.live-search');
if (!container.is(e.target) && container.has(e.target).length === 0)
{
container.hide();
}
});
});
Also module has admin/controller file. But I think that he is not responsible for the search criteria. Any ideas where I can edit the search criteria?
I make a dynamic change of option names for each product.
The problem is that I'm writing the table change. Oc_product_option
By going to system / library / cart.php > public function getProducts() { } there is only loaded there product_option_value.
I want to load this code in system / library / cart.php > public function getProducts() { }
And then call it in the catalog / controller / common> cart.php
$data['options'] = array();
foreach ($this->model_catalog_product->getProductOptions($this->request->get['product_id']) as $option) {
$product_option_value_data = array();
foreach ($option['product_option_value'] as $option_value) {
if (!$option_value['subtract'] || ($option_value['quantity'] > 0)) {
if ((($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) && (float)$option_value['price']) {
$price = $this->currency->format($this->tax->calculate($option_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax') ? 'P' : false), $this->session->data['currency']);
} else {
$price = false;
}
$product_option_value_data[] = array(
'product_option_value_id' => $option_value['product_option_value_id'],
'option_value_id' => $option_value['option_value_id'],
'name' => $option_value['name'],
'ob_info' => $option_value['ob_info'],
'image' => $this->model_tool_image->onesize($option_value['image'], 100, 100),
'price' => $price,
'price_prefix' => $option_value['price_prefix']
);
}
}
$data['options'][] = array(
'product_option_id' => $option['product_option_id'],
'product_option_value' => $product_option_value_data,
'option_id' => $option['option_id'],
'name' => $option['name'],
'type' => $option['type'],
'value' => $option['value'],
'required' => $option['required']
);
}
Table img: http://imgur.com/a/A9Ibw
I want to do this because when I add a product it does not stay with the changed name and it takes the name of the option so dynamicname does not detect it.
Please make changes in catalog/model/catalog/product.php as following
public function getProductOptions($product_id) {
$product_option_data = array();
$product_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option po LEFT JOIN `" . DB_PREFIX . "option` o ON (po.option_id = o.option_id) LEFT JOIN " . DB_PREFIX . "option_description od ON (o.option_id = od.option_id) WHERE po.product_id = '" . (int)$product_id . "' AND od.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY o.sort_order");
foreach ($product_option_query->rows as $product_option) {
$product_option_value_data = array();
$product_option_value_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value pov LEFT JOIN " . DB_PREFIX . "option_value ov ON (pov.option_value_id = ov.option_value_id) LEFT JOIN " . DB_PREFIX . "option_value_description ovd ON (ov.option_value_id = ovd.option_value_id) WHERE pov.product_id = '" . (int)$product_id . "' AND pov.product_option_id = '" . (int)$product_option['product_option_id'] . "' AND ovd.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY ov.sort_order");
foreach ($product_option_value_query->rows as $product_option_value) {
$product_option_value_data[] = array(
'product_option_value_id' => $product_option_value['product_option_value_id'],
'option_value_id' => $product_option_value['option_value_id'],
'name' => $product_option_value['name'],
'image' => $product_option_value['image'],
'quantity' => $product_option_value['quantity'],
'subtract' => $product_option_value['subtract'],
'price' => $product_option_value['price'],
'price_prefix' => $product_option_value['price_prefix'],
'weight' => $product_option_value['weight'],
'weight_prefix' => $product_option_value['weight_prefix']
);
}
$product_option_data[] = array(
'product_option_id' => $product_option['product_option_id'],
'product_option_value' => $product_option_value_data,
'option_id' => $product_option['option_id'],
'name' => $product_option['name'],
'dynamicname' => $product_option['dynamicname'],
'type' => $product_option['type'],
'value' => $product_option['value'],
'required' => $product_option['required']
);
}
return $product_option_data;
}
after that you can get the dynamicname in controller as following
$data['options'] = array();
foreach ($this->model_catalog_product->getProductOptions($this->request->get['product_id']) as $option) {
$product_option_value_data = array();
foreach ($option['product_option_value'] as $option_value) {
if (!$option_value['subtract'] || ($option_value['quantity'] > 0)) {
if ((($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) && (float)$option_value['price']) {
$price = $this->currency->format($this->tax->calculate($option_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax') ? 'P' : false), $this->session->data['currency']);
} else {
$price = false;
}
$product_option_value_data[] = array(
'product_option_value_id' => $option_value['product_option_value_id'],
'option_value_id' => $option_value['option_value_id'],
'name' => $option_value['name'],
'ob_info' => $option_value['ob_info'],
'image' => $this->model_tool_image->onesize($option_value['image'], 100, 100),
'price' => $price,
'price_prefix' => $option_value['price_prefix']
);
}
}
$data['options'][] = array(
'product_option_id' => $option['product_option_id'],
'product_option_value' => $product_option_value_data,
'option_id' => $option['option_id'],
'name' => $option['name'],
'dynamicname' => $option['dynamicname'],
'type' => $option['type'],
'value' => $option['value'],
'required' => $option['required']
);
}
Am new in Opencart I need an If then statement that will load a different .tpl paged depend on category_id.
I tried but showing error like
Parse error: syntax error, unexpected 'if' (T_IF), expecting ')' in D:\xampp\htdocs\ramesh\lmw\catalog\controller\product\sub_category.php on line 28
This is my code
sub_category.php
foreach ($category_info as $result) {
$data['categories'][] = array(
'name' => $result['name'],
'parent_id' => $result['parent_id'],
'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height')),
'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
#'href' => $this->url->link('product/filter', '&category_id=' . $result['category_id'])
#'href' => $this->url->link('product/sub_category')
if($result['category_id'] == 24)
{
'href' => $this->url->link('product/transmission', 'sub_category_id='.$result['parent_id'].'&category_id=' . $result['category_id'])
}
else
{
'href' => $this->url->link('product/filter', 'sub_category_id='.$result['parent_id'].'&category_id=' . $result['category_id'])
}
);
}
Try this,
foreach ($category_info as $result) {
$data['categories'][] = array(
'name' => $result['name'],
'parent_id' => $result['parent_id'],
'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height')),
'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
#'href' => $this->url->link('product/filter', '&category_id=' . $result['category_id'])
#'href' => $this->url->link('product/sub_category')
if($result['category_id'] == 24)
{
'href' => $this->url->link('product/transmission', 'sub_category_id='.$result['parent_id'].'&category_id=' . $result['category_id'])
}
else
{
'href' => $this->url->link('product/filter', 'sub_category_id='.$result['parent_id'].'&category_id=' . $result['category_id'])
};
);
}
Looks like you missed a ";" after the if statement. Also you should comment out using /* not "#"
foreach ($category_info as $result) {
if($result['category_id']==24)
{
$link1 = $this->url->link('product/transmission', 'sub_category_id='.$result['parent_id'].'&category_id=' . $result['category_id']);
}
else
{
$link1 = $this->url->link($_SERVER["REQUEST_URI"]);
}
$data['categories'][] = array(
'name' => $result['name'],
'parent_id' => $result['parent_id'],
'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height')),
'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
/*'href' => $this->url->link('product/filter', '&category_id=' . $result['category_id'])
'href' => $this->url->link('product/sub_category')
'href' => $this->url->link('product/transmission', 'sub_category_id='.$result['parent_id'].'&category_id=' . $result['category_id'])*/
'href' => $link1
);
So I have Opencart 1.5.6 and I need to hide one category to not show up in latest product module... How can I fix php to do that and not use any 3rd party modules?
I understand it is somewhere in catalog\controller\module\latest.php, so here is my code:
<?php
class ControllerModuleLatest extends Controller {
protected function index($setting) {
$this->language->load('module/latest');
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['button_cart'] = $this->language->get('button_cart');
$this->load->model('catalog/product');
$this->load->model('tool/image');
$this->data['products'] = array();
$data = array(
'sort' => 'p.date_added',
'order' => 'DESC',
'start' => 0,
'limit' => $setting['limit']
);
$results = $this->model_catalog_product->getProducts($data);
foreach ($results as $result) {
if ($result['image']) {
$image = $this->model_tool_image->resize($result['image'], $setting['image_width'], $setting['image_height']);
} else {
$image = false;
}
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;
}
$this->data['products'][] = array(
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'price' => $price,
'special' => $special,
'rating' => $rating,
'reviews' => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
'href' => $this->url->link('product/product', 'product_id=' . $result['product_id']),
);
}
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/latest.tpl')) {
$this->template = $this->config->get('config_template') . '/template/module/latest.tpl';
} else {
$this->template = 'default/template/module/latest.tpl';
}
$this->render();
}
}
?>
First you must get product categories:
$get_categories = $this->model_catalog_product->getCategories($result['product_id']);
Then with in_array function, check if product has not a certain category, here for example 24 is the id of category, we don't want to show its products:
if(!in_array(24, $categories))
so your file will be:
<?php
class ControllerModuleLatest extends Controller {
protected function index($setting) {
$this->language->load('module/latest');
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['button_cart'] = $this->language->get('button_cart');
$this->load->model('catalog/product');
$this->load->model('tool/image');
$this->data['products'] = array();
$data = array(
'sort' => 'p.date_added',
'order' => 'DESC',
'start' => 0,
'limit' => $setting['limit']
);
$results = $this->model_catalog_product->getProducts($data);
foreach ($results as $result) {
if ($result['image']) {
$image = $this->model_tool_image->resize($result['image'], $setting['image_width'], $setting['image_height']);
} else {
$image = false;
}
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;
}
$get_categories = $this->model_catalog_product->getCategories($result['product_id']);
$categories = array();
foreach($get_categories as $category){
$categories[] = $category['category_id'];
}
if(!in_array(24, $categories)){
$this->data['products'][] = array(
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'price' => $price,
'special' => $special,
'rating' => $rating,
'reviews' => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
'href' => $this->url->link('product/product', 'product_id=' . $result['product_id']),
);
}
}
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/latest.tpl')) {
$this->template = $this->config->get('config_template') . '/template/module/latest.tpl';
} else {
$this->template = 'default/template/module/latest.tpl';
}
$this->render();
}
}
?>
I am using the featured module to list products to my homepage. But while the product option works fine in the product details page, it doesnt work well in the homepage(featured module). The option values for the last product is getting repeated to all the product listings. Also add to cart has some problem. Can anyone provide a proper solution to this?
Code is as follows :
controller:
$this->data['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) {
if ($product_info['image']) {
$image = $this->model_tool_image->resize($product_info['image'], $setting['image_width'], $setting['image_height']);
} else {
$image = false;
}
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;
}
$this->data['products'][] = array(
'product_id' => $product_info['product_id'],
'thumb' => $image,
'name' => $product_info['name'],
'price' => $price,
'product_description' => $product_info['product_description'],
'special' => $special,
'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']),
);
$this->data['options'] = array();
//print_r($this->model_catalog_product->getProductOptions($this->request->get['product_id']));
//die("");
$option=$this->model_catalog_product->getProductOptions($product_id);
//foreach ($this->model_catalog_product->getProductOptions($product_id) as $option) //{
$option_value_data = array();
foreach ($option['option_value'] as $option_value) {
if (!$option_value['subtract'] || ($option_value['quantity'] > 0)) {
if ((($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) && (float)$option_value['price']) {
$price = $this->currency->format($this->tax->calculate($option_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));
} else {
$price = false;
}
$option_value_data[] = array(
'product_option_value_id' => $option_value['product_option_value_id'],
'option_value_id' => $option_value['option_value_id'],
'name' => $option_value['name'],
'image' => $this->model_tool_image->resize($option_value['image'], 50, 50),
'price' => $price,
'price_prefix' => $option_value['price_prefix']
);
}
}
$this->data['options'][] = array(
'product_option_id' => $option['product_option_id'],
'option_id' => $option['option_id'],
'name' => $option['name'],
'type' => $option['type'],
'option_value' => $option_value_data,
'required' => $option['required']
);
//}
}
}
view:
<?php foreach ($products as $product) { ?>
<img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" />
<?php if ($options) { ?>
<div class="options" style="color: #457A33; float: left;line-height: 23px; margin-right: 20px; width:300px;">
<?php foreach ($options as $option) { ?>
<?php if ($option['type'] == 'select') { ?>
<div id="option-<?php echo $option['product_option_id']; ?>" class="option" style="float:left; width:150px;">
<?php if ($option['required']) { ?>
<span class="required">*</span>
<?php } ?>
<b><?php echo $option['name']; ?>:</b><br />
<select name="option[<?php echo $option['product_option_id']; ?>]">
<option value=""><?php echo $text_select; ?></option>
<?php foreach ($option['option_value'] as $option_value) { ?>
<option value="<?php echo $option_value['product_option_value_id']; ?>"><?php echo $option_value['name']; ?>
<?php if ($option_value['price']) { ?>
(<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)
<?php } ?>
</option>
<?php } ?>
</select>
<br />
What's this
</div>
<?php } ?>
<?php } ?>
The options has to be assigned to the concrete product - so populated and processed before $this->data['products'][] = array(...);:
$this->data['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) {
if ($product_info['image']) {
$image = $this->model_tool_image->resize($product_info['image'], $setting['image_width'], $setting['image_height']);
} else {
$image = false;
}
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;
}
$options = array();
foreach ($this->model_catalog_product->getProductOptions($product_id) as $option) {
$option_value_data = array();
foreach ($option['option_value'] as $option_value) {
if (!$option_value['subtract'] || ($option_value['quantity'] > 0)) {
if ((($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) && (float)$option_value['price']) {
$price = $this->currency->format($this->tax->calculate($option_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));
} else {
$price = false;
}
$option_value_data[] = array(
'product_option_value_id' => $option_value['product_option_value_id'],
'option_value_id' => $option_value['option_value_id'],
'name' => $option_value['name'],
'image' => $this->model_tool_image->resize($option_value['image'], 50, 50),
'price' => $price,
'price_prefix' => $option_value['price_prefix']
);
}
}
$options[] = array(
'product_option_id' => $option['product_option_id'],
'option_id' => $option['option_id'],
'name' => $option['name'],
'type' => $option['type'],
'option_value' => $option_value_data,
'required' => $option['required']
);
}
$this->data['products'][] = array(
'product_id' => $product_info['product_id'],
'thumb' => $image,
'name' => $product_info['name'],
'price' => $price,
'product_description' => $product_info['product_description'],
'special' => $special,
'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']),
'options' => $options,
);
}
Now You should have the options loaded in each product respectively. Just modify your template accordingly:
<?php foreach ($products as $product) { ?>
<img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" />
<?php if ($product['options']) { ?>
<div class="options" style="color: #457A33; float: left;line-height: 23px; margin-right: 20px; width:300px;">
<?php foreach ($product['options'] as $option) { ?>
<?php if ($option['type'] == 'select') { ?>
<div id="option-<?php echo $option['product_option_id']; ?>" class="option" style="float:left; width:150px;">
<?php if ($option['required']) { ?>
<span class="required">*</span>
<?php } ?>
<b><?php echo $option['name']; ?>:</b><br />
<select name="option[<?php echo $option['product_option_id']; ?>]">
<option value=""><?php echo $text_select; ?></option>
<?php foreach ($option['option_value'] as $option_value) { ?>
<option value="<?php echo $option_value['product_option_value_id']; ?>"><?php echo $option_value['name']; ?>
<?php if ($option_value['price']) { ?>
(<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)
<?php } ?>
</option>
<?php } ?>
</select>
<br />
What's this
</div>
<?php } ?>
<?php } ?>