Post by InnoSite » Fri Jul 08, 2011 10:26 am

title pretty much says it all, I'd like to echo or print an attribute I set on category.tpl

Thanks in advance.

Ben

New member

Posts

Joined
Wed Jun 15, 2011 8:33 am

Post by InnoSite » Sun Jul 10, 2011 12:11 pm

So, is there no way to echo an attribute?

New member

Posts

Joined
Wed Jun 15, 2011 8:33 am

Post by IFFMP » Sun Jul 10, 2011 1:26 pm

Be more specific, I can help you out for sure. I just customized opencart a lot. Which attribute?

Newbie

Posts

Joined
Sat Jun 04, 2011 4:18 pm

Post by InnoSite » Mon Jul 11, 2011 4:36 am

I created a product attribute called Shipping, I'd like to echo the title of the attribute and the value of the attribute on category.tpl.

I'm not sure how I can be any more specific.

New member

Posts

Joined
Wed Jun 15, 2011 8:33 am

Post by IFFMP » Mon Jul 11, 2011 11:09 am

PM me the file if you want, and I can take a look at it. Does your attribute have a value for each of the products?

Newbie

Posts

Joined
Sat Jun 04, 2011 4:18 pm

Post by Johnathan » Mon Jul 11, 2011 3:01 pm

Try this:

IN:

Code: Select all

/catalog/view/theme/YOURTHEME/template/product/category.tpl
AFTER:

Code: Select all

<span class="price-tax"><?php echo $text_tax; ?> <?php echo $product['tax']; ?></span>
<?php } ?>
ADD:

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'];
    }
}
?>
where your attribute group name is "Shipping".

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by InnoSite » Tue Jul 12, 2011 8:05 am

Johnathan wrote:Try this:

IN:

Code: Select all

/catalog/view/theme/YOURTHEME/template/product/category.tpl
AFTER:

Code: Select all

<span class="price-tax"><?php echo $text_tax; ?> <?php echo $product['tax']; ?></span>
<?php } ?>
ADD:

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'];
    }
}
?>
where your attribute group name is "Shipping".
nothing happens expect category.tpl stops loading and all I see is a white screen.

New member

Posts

Joined
Wed Jun 15, 2011 8:33 am

Post by Johnathan » Tue Jul 12, 2011 3:31 pm

Sounds like you didn't paste it properly then. What version are you using?

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by InnoSite » Wed Jul 13, 2011 12:42 am

Johnathan wrote:Sounds like you didn't paste it properly then. What version are you using?
Version 1.5.0

I added the code again after the <?php } ?>, category.tpl still loads on localhost but not when I upload it to the server.

New member

Posts

Joined
Wed Jun 15, 2011 8:33 am

Post by Johnathan » Wed Jul 13, 2011 2:20 am

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?

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by InnoSite » Wed Jul 13, 2011 3:39 am

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?
I've actually made quite a few amendments and installed vqmod, not sure I should updated, plus I don't know how.

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">&nbsp;</div>
	  <a onclick="window.open('http://<?php echo $product['sku']; ?>')" class="custom_button"><span>Go to Store</span></a>
	  <div class="spacer">&nbsp;</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; ?>

New member

Posts

Joined
Wed Jun 15, 2011 8:33 am

Post by InnoSite » Wed Jul 13, 2011 12:32 pm

Do you know what the problem is?

New member

Posts

Joined
Wed Jun 15, 2011 8:33 am

Post by Johnathan » Wed Jul 13, 2011 3:26 pm

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

Code: Select all

<?php foreach ($products as $product) { ?>
loop and see if it shows up, or hire someone with the know-how to fix it.

Best of luck

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by InnoSite » Fri Jul 15, 2011 10:31 am

Hi, I've actually tried it everywhere and all it does is stop the page loading.

New member

Posts

Joined
Wed Jun 15, 2011 8:33 am

Post by Johnathan » Fri Jul 15, 2011 4:27 pm

Sorry...I'm not sure why it's not working for you. You might try posting a request in the Commercial Support forum.

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by skip » Sun Mar 31, 2013 2:51 am

Hi Johnathan ,
Thanx for code, works for me, but is there posibility to add value of attribute? In this case it show only attribute group and attribute.

Active Member

Posts

Joined
Mon May 09, 2011 9:57 pm

Post by skip » Mon Apr 01, 2013 8:45 pm

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?

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']; 
        }
    }
    ?>

Active Member

Posts

Joined
Mon May 09, 2011 9:57 pm

Post by PlusCybernet » Fri Nov 15, 2013 1:32 am

[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'?

User avatar
Active Member

Posts

Joined
Sun Dec 25, 2011 12:01 pm

Post by Impaler » Wed Jan 07, 2015 10:38 pm

can anybody share a modern version 1.6.5.4 solution for this? I need to display a single attribute below the product name on the category.tpl. I've tried everything here and nothing seems to work..

New member

Posts

Joined
Fri Aug 24, 2012 3:11 am

Post by josuito » Thu Sep 15, 2016 5:03 am

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

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>
Now you will need to add this code inside the data product array under product_id in your catalog/controller/product/category.php

Code: Select all

'attribute_groups' => $this->model_catalog_product->getProductAttributes($result['product_id']),
Like this, copy paste in controller everything you're missing from here

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
				);

Newbie

Posts

Joined
Tue Feb 02, 2016 1:23 am
Who is online

Users browsing this forum: No registered users and 191 guests