Try this:
IN:
AFTER:
ADD:
where your attribute group name is "Shipping".
IN:
Code: Select all
/catalog/view/theme/YOURTHEME/template/product/category.tpl
Code: Select all
<span class="price-tax"><?php echo $text_tax; ?> <?php echo $product['tax']; ?></span>
<?php } ?>
Code: Select all
<?php
$this->load->model('catalog/product');
$attributes = $this->model_catalog_product->getProductAttributes($product['product_id']);
foreach ($attributes as $attribute) {
if ($attribute['name'] == 'Shipping') {
echo '<br />Shipping: ' . $attribute['attribute'][0]['name'];
}
}
?>
nothing happens expect category.tpl stops loading and all I see is a white screen.Johnathan wrote:Try this:
IN:AFTER:Code: Select all
/catalog/view/theme/YOURTHEME/template/product/category.tpl
ADD:Code: Select all
<span class="price-tax"><?php echo $text_tax; ?> <?php echo $product['tax']; ?></span> <?php } ?>
where your attribute group name is "Shipping".Code: Select all
<?php $this->load->model('catalog/product'); $attributes = $this->model_catalog_product->getProductAttributes($product['product_id']); foreach ($attributes as $attribute) { if ($attribute['name'] == 'Shipping') { echo '<br />Shipping: ' . $attribute['attribute'][0]['name']; } } ?>
Are you using the very first version of 1.5.0, or 1.5.0.5? If you're using the former, I would upgrade your files to the latest version, since you can just upload everything except config.php and /admin/config.php. (Always make a backup before uploading, though!)
Have you made other edits to your category.tpl file? Can you post its contents?
Have you made other edits to your category.tpl file? Can you post its contents?
I've actually made quite a few amendments and installed vqmod, not sure I should updated, plus I don't know how.Johnathan wrote:Are you using the very first version of 1.5.0, or 1.5.0.5? If you're using the former, I would upgrade your files to the latest version, since you can just upload everything except config.php and /admin/config.php. (Always make a backup before uploading, though!)
Have you made other edits to your category.tpl file? Can you post its contents?
Code: Select all
<?php echo $header; ?><?php echo $column_left; ?><?php echo $column_right; ?>
<div id="content"><?php echo $content_top; ?>
<div class="breadcrumb">
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
<?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
<?php } ?>
</div>
<h1><?php echo $heading_title; ?></h1>
<?php if ($thumb || $description) { ?>
<div class="category-info">
<?php if ($thumb) { ?>
<div class="image"><img src="<?php echo $thumb; ?>" alt="<?php echo $heading_title; ?>" /></div>
<?php } ?>
<?php if ($description) { ?>
<?php echo $description; ?>
<?php } ?>
</div>
<?php } ?>
<?php if ($categories) { ?>
<h2><?php echo $text_refine; ?></h2>
<div class="category-list">
<?php if (count($categories) <= 5) { ?>
<ul>
<?php foreach ($categories as $category) { ?>
<li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a></li>
<?php } ?>
</ul>
<?php } else { ?>
<?php for ($i = 0; $i < count($categories);) { ?>
<ul>
<?php $j = $i + ceil(count($categories) / 4); ?>
<?php for (; $i < $j; $i++) { ?>
<?php if (isset($categories[$i])) { ?>
<li><a href="<?php echo $categories[$i]['href']; ?>"><?php echo $categories[$i]['name']; ?></a></li>
<?php } ?>
<?php } ?>
</ul>
<?php } ?>
<?php } ?>
</div>
<?php } ?>
<?php if ($products) { ?>
<div class="product-filter">
<!--<div class="display"><b><?php echo $text_display; ?></b> <?php echo $text_list; ?> <b>/</b> <a onclick="display('grid');"><?php echo $text_grid; ?></a></div>-->
<div class="limit"><b><?php echo $text_limit; ?></b>
<select onchange="location = this.value;">
<?php foreach ($limits as $limits) { ?>
<?php if ($limits['value'] == $limit) { ?>
<option value="<?php echo $limits['href']; ?>" selected="selected"><?php echo $limits['text']; ?></option>
<?php } else { ?>
<option value="<?php echo $limits['href']; ?>"><?php echo $limits['text']; ?></option>
<?php } ?>
<?php } ?>
</select>
</div>
<div class="sort"><b><?php echo $text_sort; ?></b>
<select onchange="location = this.value;">
<?php foreach ($sorts as $sorts) { ?>
<?php if ($sorts['value'] == $sort . '-' . $order) { ?>
<option value="<?php echo $sorts['href']; ?>" selected="selected"><?php echo $sorts['text']; ?></option>
<?php } else { ?>
<option value="<?php echo $sorts['href']; ?>"><?php echo $sorts['text']; ?></option>
<?php } ?>
<?php } ?>
</select>
</div>
</div>
<div class="product-compare"><a href="<?php echo $compare; ?>" id="compare_total"><?php echo $text_compare; ?></a></div>
<div class="list-headers">
<ol>
<li>Retailer</li>
<li>Retailer message</li>
<li>Quantity</li>
<li>Price</li>
<li>Price per unit</li>
</ol>
</div>
<div class="product-list">
<?php foreach ($products as $product) { ?>
<div>
<?php if ($product['thumb']) { ?>
<div class="image"><!--<a href="<?php echo $product['href']; ?>"><img src="<?php echo $product['thumb']; ?>" title="<?php echo $product['name']; ?>" alt="<?php echo $product['name']; ?>" /></a>--></div>
<?php } ?>
<div class="name">
<a href="http://<?php echo $product['sku']; ?>"><?php echo $product['manufacturer']; ?></a>
</div>
<div class="retailer"><?php echo $product['description']; ?><div></div></div>
<div class="quantity"><?php echo $product['quantity']; ?></div>
<?php if ($product['price']) { ?>
<div class="price">
<?php if (!$product['special']) { ?>
<?php echo $product['price']; ?>
<?php } else { ?>
<span class="price-old"><?php echo $product['price']; ?></span> <span class="price-new"><?php echo $product['special']; ?></span>
<?php } ?>
<?php if ($product['tax']) { ?>
<br />
<span class="price-tax"><!--<?php echo $text_tax; ?> <?php echo $product['tax']; ?>--></span>
<?php } ?>
<?php
$this->load->model('catalog/product');
$attributes = $this->model_catalog_product->getProductAttributes($product['product_id']);
foreach ($attributes as $attribute) {
if ($attribute['name'] == 'Shipping') {
echo '<br />Shipping: ' . $attribute['attribute'][0]['name'];
}
}
?>
</div>
<?php } ?>
<?php if ($product['rating']) { ?>
<div class="rating"><img src="catalog/view/theme/default/image/stars-<?php echo $product['rating']; ?>.png" alt="<?php echo $product['reviews']; ?>" /></div>
<?php } ?>
<div class="cart"></div>
<div class="wishlist"></div>
<div class="compare">
<a onclick="window.open('<?php echo $product['href']; ?>')" class="custom_button"><span>View product</span></a>
<div class="spacer"> </div>
<a onclick="window.open('http://<?php echo $product['sku']; ?>')" class="custom_button"><span>Go to Store</span></a>
<div class="spacer"> </div>
<div class="compare"><a onclick="addToCompare('<?php echo $product['product_id']; ?>');"><?php echo $button_compare; ?></a></div></a>
</div>
</div>
<?php } ?>
</div>
<div class="pagination"><?php echo $pagination; ?></div>
<?php } ?>
<?php if (!$categories && !$products) { ?>
<div class="content"><?php echo $text_empty; ?></div>
<div class="buttons">
<div class="right"><a href="<?php echo $continue; ?>" class="button"><span><?php echo $button_continue; ?></span></a></div>
</div>
<?php } ?>
<?php echo $content_bottom; ?></div>
<script type="text/javascript"><!--
function display(view) {
if (view == 'list') {
$('.product-grid').attr('class', 'product-list');
$('.product-list > div').each(function(index, element) {
html = '<div class="right">';
html += ' <div class="cart">' + $(element).find('.cart').html() + '</div>';
html += ' <div class="wishlist">' + $(element).find('.wishlist').html() + '</div>';
html += ' <div class="compare">' + $(element).find('.compare').html() + '</div>';
html += '</div>';
html += '<div class="left">';
var image = $(element).find('.image').html();
if (image != null) {
html += '<div class="image">' + image + '</div>';
}
var price = $(element).find('.price').html();
if (price != null) {
html += '<div class="price">' + price + '</div>';
}
html += ' <div class="name">' + $(element).find('.name').html() + '</div>';
html += ' <div class="retailer">' + $(element).find('.retailer').html() + '</div>';
/* html += ' <div class="description">' + $(element).find('.description').html() + '</div>'; */
html += ' <div class="quantity">' + $(element).find('.quantity').html() + '</div>';
var rating = $(element).find('.rating').html();
if (rating != null) {
html += '<div class="rating">' + rating + '</div>';
}
html += '</div>';
$(element).html(html);
});
$('.display').html('<b><?php echo $text_display; ?></b> <?php echo $text_list; ?> <b>/</b> <a onclick="display(\'grid\');"><?php echo $text_grid; ?></a>');
$.cookie('display', 'list');
} else {
$('.product-list').attr('class', 'product-grid');
$('.product-grid > div').each(function(index, element) {
html = '';
var image = $(element).find('.image').html();
if (image != null) {
html += '<div class="image">' + image + '</div>';
}
html += '<div class="name">' + $(element).find('.name').html() + '</div>';
html += '<div class="description">' + $(element).find('.description').html() + '</div>';
var price = $(element).find('.price').html();
if (price != null) {
html += '<div class="price">' + price + '</div>';
}
var rating = $(element).find('.rating').html();
if (rating != null) {
html += '<div class="rating">' + rating + '</div>';
}
html += '<div class="cart">' + $(element).find('.cart').html() + '</div>';
html += '<div class="wishlist">' + $(element).find('.wishlist').html() + '</div>';
html += '<div class="compare">' + $(element).find('.compare').html() + '</div>';
$(element).html(html);
});
$('.display').html('<b><?php echo $text_display; ?></b> <a onclick="display(\'list\');"><?php echo $text_list; ?></a> <b>/</b> <?php echo $text_grid; ?>');
$.cookie('display', 'grid');
}
}
view = $.cookie('display');
if (view) {
display(view);
} else {
display('list');
}
//--></script>
<?php echo $footer; ?>
If you've made a bunch of modifications and are using vQmod, I can't say for sure what the problem is. I took a quick look at your file and it looks like you've changed the order of the code around. The piece of code I posted should still work, but it may have to be placed somewhere else.
Your only other options are to try pasting it in other locations within the
loop and see if it shows up, or hire someone with the know-how to fix it.
Best of luck
Your only other options are to try pasting it in other locations within the
Code: Select all
<?php foreach ($products as $product) { ?>
Best of luck
Got it: this code show attribute and value of attribute (from shipping group) but I dont know why just for first attribute
For example if got several attributes in shipping group it show just 1. somebody know why?
For example if got several attributes in shipping group it show just 1. somebody know why?
Code: Select all
<?php
$this->load->model('catalog/product');
$attributes = $this->model_catalog_product->getProductAttributes($product['product_id']);
foreach ($attributes as $attribute) {
if ($attribute['name'] == 'Shipping') {
echo '<br />Shipping-group: ' . $attribute['attribute'][0]['name'] .": ". $attribute['attribute'][0]['text'];
}
}
?>
[OpenCart 1.5.6]
I need the same thing to be done ... display a single attribute in category.tpl ... but where did you define 'attribute group'?
I need the same thing to be done ... display a single attribute in category.tpl ... but where did you define 'attribute group'?
You need to add this code in the category.tpl page I'm using Category names to change the format of the table, also I have my options in a select box with a quantity box and a button to add it to the cart. You can remove everything you don't need.
/catalog/view/theme/your-template/template/product/category.tpl
Now you will need to add this code inside the data product array under product_id in your catalog/controller/product/category.php
Like this, copy paste in controller everything you're missing from here
/catalog/view/theme/your-template/template/product/category.tpl
Code: Select all
<?php $AllAttributes = array(); ?>
<?php foreach ($products as $product) {
foreach($product['attribute_groups'] as $attribute_group) {
foreach ($attribute_group['attribute'] as $attribute) {
$attribute_name = $attribute['name'];
if(!in_array($attribute_name, $AllAttributes)) {
$AllAttributes[] = $attribute_name;
}
}
}
} ?>
<table class="table table-bordered" width="100%">
<thead>
<tr>
<th>PART</th>
<?php for ($i=0; $i < sizeof($AllAttributes); $i++) { ?>
<th><?php echo $AllAttributes[$i];?></th>
<?php } ?>
<?php if ($heading_title == 'BULK CABLE') { ?>
<th>JACKET COLOR OPTIONS</th>
<?php } else { ?>
<th>EXTENDED LENGTH OPTIONS</th>
<?php } ?>
<th>QUANTITY</th>
</tr>
</thead>
<?php foreach ($products as $product) { ?>
<tbody>
<tr>
<td data-original-title="<?php echo $product['description']; ?>" data-container="body"
data-toggle="tooltip" data-placement="left" title=""><strong><a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a></strong></td>
<?php for($i=0; $i <sizeof($AllAttributes) ; $i++) { ?>
<td>
<?php foreach($product['attribute_groups'] as $attribute_group) {
foreach ($attribute_group['attribute'] as $attribute) {
if($attribute['name'] == $AllAttributes[$i]) {
echo $attribute['text'] . "</td>";
continue 3;
}
} ?>
</td>
<?php } ?>
<?php } ?>
<td>
<?php foreach ($product['option'] as $option) { ?>
<?php if ($option['type'] == 'select') { ?>
<div id="option-<?php echo $product['product_id']; ?>">
<select name="option[<?php echo $option['product_option_id']; ?>]" id="input-option<?php echo $option['product_option_id']; ?>" class="form-control option-<?php echo $product['product_id']; ?>">
<?php foreach ($option['product_option_value'] as $option_value) { ?>
<option value="<?php echo $option_value['product_option_value_id']; ?>"><?php echo $option_value['name']; ?> @
<?php if ($heading_title == 'BULK CABLE') { ?>
<?php if ($option_value['price']) { ?>
(<?php echo $option_value['price']; ?>/Feet)
<?php } ?>
<?php } else { ?>
<?php if ($option_value['price']) { ?>
(<?php echo $option_value['price']; ?>/ea)
<?php } ?>
<?php } ?>
</option>
<?php } ?>
</select>
</div>
<?php } ?>
<?php } ?>
</td>
<td><input type="text" value="1" size="2" class="item-<?php echo $product['product_id']; ?>" data-original-title="<?php foreach ($product['discounts'] as $discount) { echo sprintf($text_discount, $discount['quantity'], $discount['price']).' >> '; } ?>" data-container="body" data-toggle="tooltip" data-placement="top" title=""/><button type="button" value="<?php echo $button_cart; ?>" onclick="addQtyToCart('<?php echo $product['product_id']; ?>');"><i class="fa fa-shopping-cart"></i> <span class="hidden-xs hidden-sm hidden-md"><?php echo $button_cart; ?></span></button></td>
</tr>
<?php } ?>
</tbody>
</table>
Code: Select all
'attribute_groups' => $this->model_catalog_product->getProductAttributes($result['product_id']),
Code: Select all
foreach ($discount_query as $discount) {
$discounts[] = array(
'quantity' => $discount['quantity'],
'price' => $this->currency->format($this->tax->calculate($discount['price'], $result['tax_class_id'], $this->config->get('config_tax')))
);
}
$option_data = array();
foreach ($this->model_catalog_product->getProductOptions($result['product_id']) as $option) {
foreach ($option['product_option_value'] as $option_value) {
$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'],
'image' => $this->model_tool_image->resize($option_value['image'], 50, 50),
'price' => $price,
'price_prefix' => $option_value['price_prefix']
);
}
$option_data[] = 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']
);
}
$data['products'][] = array(
'product_id' => $result['product_id'],
'attribute_groups' => $this->model_catalog_product->getProductAttributes($result['product_id']),
'thumb' => $image,
'name' => $result['name'],
'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
'price' => $price,
'special' => $special,
'tax' => $tax,
'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
'rating' => $result['rating'],
'href' => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url),
'discounts' => $discounts,
'option' => $option_data
);
Who is online
Users browsing this forum: No registered users and 191 guests