Post by zebdev » Wed Sep 21, 2011 3:09 am

Hi all,

I have been trying to solve this issue for a few days and have previously posted on the forum.

I have been looking in to the issue more and think I am close to solving the issue but am also new to open cart.

I have used the category wall to show all my categories on the home page of my store. When the user clicks on a category all products from that category are listed.
Each product has a set of options and I want these options to display on this page.

I am using opencart 1.5.1

I added a line of code to this file:- catalog/controller/product/category.php

Code: Select all

$this->data['action'] = $this->url->link('index.php?route=checkout/cart'); 
Then just before the

Code: Select all

this->data['products'][] = array(
I added this:-

Code: Select all

$options = $this->model_catalog_product->getProductOptions($result['product_id']);
Then added to the product array so it looks like this:-

Code: Select all

$this->data['products'][] = array(
'id' => $result['product_id'],
'options' => $options, 
'name'        => $result['name'],
'thumb'       => $image,
'description' => substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 100) . '..',
'price'       => $price,
'special'     => $special,
'tax'         => $tax,
'rating'      => $result['rating'],
'reviews'     => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
'href'        => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'])	
				);
Then in the /mytheme/template/product/category.tpl file I added this:-

Code: Select all

<form action="<?php echo $action; ?>;" method="post" enctype="multipart/form-data" id="product_<?php echo $j;?>">
<?php if ($products['options']) { ?>
<?php foreach ($products['options'] as $option) { ?>
<div class="content"> <?php echo $option['name']; ?>: <select name="option[<?php echo $option['product_option_id']; ?>]" id="option[<?php echo $option['product_option_id']; ?>]"  onchange="document.getElementById('price<?php echo $v ?>').selectedIndex=this.selectedIndex;
alert(document.getElementById('price<?php echo $v; ?>').value);">
<?php foreach ($option['option_value'] as $option_value) { ?>
<option value="<?php echo $option_value['product_option_value_id']; ?>"><?php echo $option_value['name']; ?></option>
<?php } ?>
</select></div>

<?php } ?>   
</div>
<input type="hidden" name="quantity" size="3" value="1" />
</div>
<?php } else {  ?>
<div class="content" style="height:25px"> QTY: <input type="text" name="quantity" size="3" value="" /> </div>   
<?php } ?>
<input type="hidden" name="product_id" value="<?php echo $products[$j]['id']; ?>" />
<a onclick="alert('<?php echo $products[$j]['name']; ?> added to the cart')" id="add_to_cart_<?php echo $j;?>" rel="<?php echo $j;?>" class="button add_to_cart"><span>Add to Cart</span></a>
</form>
So I refreshed my store and had the following error:
Notice: Undefined index: options in C:\wamp\www\mystore\catalog\view\theme\mytheme\template\product\category.tpl on line 60

Any ideas how I can solve this error?

New member

Posts

Joined
Tue Sep 13, 2011 3:43 am

Post by kandarp » Thu Oct 20, 2011 2:19 am

Hey its solved.

Instead of

$options = $this->model_catalog_product->getProductOptions($result['product_id']);

Use

$this->data['options'] = array();

foreach ($this->model_catalog_product->getProductOptions($result['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)) {
$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' => (float)$option_value['price'] ? $this->currency->format($this->tax->calculate($option_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax'))) : false,
'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']
);
}
}

$options['product_id'] = $this->data['options'];


And on data['products'] add options parameter

$this->data['products'][] = array(
'product_id' => $result['product_id'],
'options' => $options['product_id'],
'thumb' => $image,
'name' => $result['name'],
'description' => mb_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 100) . '..',
'price' => $price,
'special' => $special,
'tax' => $tax,
'rating' => $result['rating'],
'reviews' => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
'href' => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'])
);



On the category view page

<div class="info">
<h3><?php echo $product['name']; ?></h3>
<p><?php echo $product['description']; ?></p>

<?php if ($product['options']) { ?>
<div class="options">
<?php foreach ($product['options'] as $option) { ?>
<?php if ($option['type'] == 'select') { ?>
<div id="option-<?php echo $option['product_option_id']; ?>" class="option"><b>
<?php if ($option['required']) { ?>
<span class="required">*</span>
<?php } ?>
<?php echo $option['name']; ?>:</b>
<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>
</div>
<br />
<?php } }
echo "</div>";
} ?>

<a class="add_to_cart_small" onclick="addToCart('<?php echo $product['product_id']; ?>');"><?php echo $button_cart; ?></a>
<a class="wishlist_small" onclick="addToWishList('<?php echo $product['product_id']; ?>');"><?php echo $text_wish; ?></a>
<a class="compare_small" onclick="addToCompare('<?php echo $product['product_id']; ?>');"><?php echo $text_compare; ?></a>
</div>



You can add more options as per your requirements. I have just simply made it for select options.

I hope it helps.

Nothing Is Impossible In This World.


Newbie

Posts

Joined
Tue Oct 18, 2011 9:10 pm
Location - New Jersey, USA

Post by gujjar » Sun Dec 11, 2011 5:04 am

Hello, guys

I have been looking for this is it possible to see the demo how does it looks like ... and that would be really great if you guys can upload the working files so that I can use them...

I would really appreciate that..

thanks,

New member

Posts

Joined
Thu May 20, 2010 6:40 pm
Location - Denmark

Post by gujjar » Mon Dec 12, 2011 4:25 am

anyone who can help me with this .. I tried to implement this code and received this error

Notice: Undefined index: product_id in C:\Users\CH-UMAR\xampp\htdocs\pizza\catalog\controller\product\category.php on line 147

and can you be bit more clear about the lines that where do I have to place them e.g before/after which line I have to place this piece of code.

Code: Select all

$this->data['action'] = $this->url->link('index.php?route=checkout/cart'); 
thanks..

New member

Posts

Joined
Thu May 20, 2010 6:40 pm
Location - Denmark

User avatar
Active Member

Posts

Joined
Thu Nov 11, 2010 6:11 pm
Location - New Zealand (Tokomaru, Palmerston North)

Post by gujjar » Tue Dec 13, 2011 2:58 am

Anyone .... No one wants to help..

New member

Posts

Joined
Thu May 20, 2010 6:40 pm
Location - Denmark

Post by kandarp » Fri Dec 16, 2011 1:50 am

Hey Gujjar,

Did You Try My Code ?

Anyone still getting any errors or notices than please post here with details so we can help you out.
Let me know in details if i can help you out to solve your issue.
Last edited by kandarp on Fri Dec 16, 2011 1:52 am, edited 1 time in total.

Nothing Is Impossible In This World.


Newbie

Posts

Joined
Tue Oct 18, 2011 9:10 pm
Location - New Jersey, USA

Post by kandarp » Fri Dec 16, 2011 1:51 am

gujjar wrote:Anyone .... No one wants to help..
Did you try my code ??

Nothing Is Impossible In This World.


Newbie

Posts

Joined
Tue Oct 18, 2011 9:10 pm
Location - New Jersey, USA

Post by gujjar » Sat Dec 17, 2011 5:59 am

kandarp wrote:
gujjar wrote:Anyone .... No one wants to help..
Did you try my code ??

Hello , kandarp

you can check this link http://umarstudio.com/shop/index.php?ro ... ry&path=20 I am using your code..

thanks.

New member

Posts

Joined
Thu May 20, 2010 6:40 pm
Location - Denmark

Post by kandarp » Tue Dec 20, 2011 5:45 am

$options_data=false;

$options_data[] = array();

foreach ($this->model_catalog_product->getProductOptions($result['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)) {
$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' => (float)$option_value['price'] ? $this->currency->format($this->tax->calculate($option_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax'))) : false,
'price_prefix' => $option_value['price_prefix']
);
}
}

$options_data[] = 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']
);
}
}


//var_dump($options_data);echo '<br>';

$this->data['products'][] = array(
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'description' => mb_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 100) . '..',
'price' => $price,
'special' => $special,
'tax' => $tax,
'rating' => $result['rating'],
'reviews' => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
'href' => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id']),
'options' => $options_data
);
}


Try it now. And please debug and verify each variables and its value.

Nothing Is Impossible In This World.


Newbie

Posts

Joined
Tue Oct 18, 2011 9:10 pm
Location - New Jersey, USA

Post by danicmyk » Mon Mar 26, 2012 12:19 am

I followed these steps but all I get is the same options appear on each product! Any ideas why this is happening? Could really do with some help on this. the site is clients.danimartin.co.uk

New member

Posts

Joined
Tue Aug 02, 2011 4:26 pm

Post by Alliance » Fri Sep 21, 2012 2:51 am

Can someone break this down step by step.. Im trying on 1.5.4 ... I need help. I keep getting errors. :(

Newbie

Posts

Joined
Wed Sep 12, 2012 10:58 pm

Post by deeve » Thu Oct 18, 2012 4:40 am

@kandarp: I'm using 1.5.2.1 & only need to pull one text value from the options array: $option['option_value']. Could this be done with something more like the original concept as I noticed my template contains a loop on the $Products array? I've tried the following but it seems to pull the full array of options. Seem to think I should be emulating an SQL Query where $Products['product_id'] = $option['option_id']. Any suggestions appreciated..

Code: Select all

$option_value = $this->model_catalog_product->getProductOptions($result['product_id']);	
							
				$this->data['products'][] = array(
					'product_id'  => $result['product_id'],
					'option_value'=> $option_value,
					'thumb'       => $image,
					'name'        => $result['name'],
					'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 100) . '..',
					'price'       => $price,
					'special'     => $special,
					'tax'         => $tax,
					'rating'      => $result['rating'],
					'reviews'     => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
					'href'        => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'])
				);

Active Member

Posts

Joined
Tue Oct 20, 2009 4:31 pm

Post by deeve » Sun Oct 21, 2012 4:28 pm

Okay, I've tried to adapt your 2nd example & include the single option per item into the $products array so I juat have the one php loop within the template. This does successfully pull in all the variables but for some reason, they're not being displayed on my page [yet are in the source code]. Thais makes me think maybe I've got something wrong in the wrong place in one of the loops in the template file. If anyone gets a chance, could you please let me know where I'm going wrong. Thanks.

category.php

Code: Select all

$options_data=false;

$options_data[] = array();

foreach ($this->model_catalog_product->getProductOptions($result['product_id']) as $option);

var_dump($option['option_value']);echo '<br>';

$this->data['products'][] = array(
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'description' => mb_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 100) . '..',
'price' => $price,
'special' => $special,
'tax' => $tax,
'rating' => $result['rating'],
'reviews' => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
'href' => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id']),
'options' => $option['option_value']
);
}
category.tpl

Code: Select all

<div class="product-list">
    <?php foreach ($products as $product) { ?>
    <div class="detail">
	  <?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="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a></div>
	  <div class="model"><?php echo $product['model']; ?></div>
	  <div class="rating"><img src="catalog/view/theme/supermarket/image/stars-<?php echo $product['rating']; ?>.png" alt="<?php echo $product['reviews']; ?>" /></div>
           
      <div class="description"><?php echo $product['description']; ?></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 } ?> <br/>
        <?php if ($product['tax']) { ?>

        <span class="price-tax"><?php echo $text_tax; ?> <?php echo $product['tax']; ?></span>
        <?php } ?>
      </div>
     <!--options loop-->
     <?php if ($product['options']) { ?>
     <div id="options">
     <div id="option-<?php echo $product['product_id']; ?>" class="option">       
        <div id="jquery_jplayer_<?php echo $product['product_id']; ?>" class="cp-jplayer"></div>
<script type="text/javascript">

					var myCirclePlayer = new CirclePlayer("#jquery_jplayer_<?php echo $product['product_id']; ?>",
			{
				m4a: "http://www.mywebsite.co.uk/sample/<?php echo $product['options']; ?>"
				
			}, {
				cssSelectorAncestor: "#cp_container_<?php echo $product['product_id']; ?>"
			});			
		
		</script>		
        </div>
        <br />
        <div id="cp_container_<?php echo $product['product_id']; ?>" class="cp-container_sm">
				<div class="cp-buffer-holder"> <!-- .cp-gt50 only needed when buffer is > than 50% -->
					<div class="cp-buffer-1"></div>
					<div class="cp-buffer-2"></div>
				</div>
				<div class="cp-progress-holder"> <!-- .cp-gt50 only needed when progress is > than 50% -->
					<div class="cp-progress-1"></div>
					<div class="cp-progress-2"></div>
				</div>
				<div class="cp-circle-control"></div>
				<ul class="cp-controls">
					<li><a href="#" class="cp-play" tabindex="1">play</a></li>
					<li><a href="#" class="cp-pause" style="display:none;" tabindex="1">pause</a></li> <!-- Needs the inline style here, or jQuery.show() uses display:inline instead of display:block -->
				</ul>
			</div> 
            </div>
            <?php } ?>            
            
            <!--end of options loop-->
            
            
      <div class="cart">
         <span class="input_but"><input type="button" value="<?php echo $button_cart; ?>" onclick="addToCart('<?php echo $product['product_id']; ?>');" class="button" /></span>
      </div>
      <div class="wishlist"><a onclick="addToWishList('<?php echo $product['product_id']; ?>');"><?php echo $button_wishlist; ?></a></div>
      <div class="compare"><a onclick="addToCompare('<?php echo $product['product_id']; ?>');"><?php echo $button_compare; ?></a></div>            
      
 <?php } ?>     
 </div><!-- end detail -->
    <!--end of product as product loop-->
    <?php } ?>
    
	</div>

Active Member

Posts

Joined
Tue Oct 20, 2009 4:31 pm

Post by deeve » Mon Oct 22, 2012 8:28 am

I've just tried achieving the same result with different code & again, the HTML is generated correctly but nothing shows on the page! I imagine this is because the new values have not been declared properly within category.php but not understanding the protocol I'm unsure what I have to add! If someone could advise I'd be really grateful. Here's my new code:

category.php

Code: Select all

$this->data['products'][] = array(
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'description' => mb_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 100) . '..',
'price' => $price,
'special' => $special,
'tax' => $tax,
'rating' => $result['rating'],
'reviews' => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
'href' => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id']),
'options' => $this->model_catalog_product->getProductOptions($result['product_id'])
);
}
category.tpl

Code: Select all

<?php if ($product['options']) { ?>
<?php foreach ($product['options'] as $option) { ?>
<div id="options">
     <div id="option-<?php echo $product['product_id']; ?>" class="option">       
        <div id="jquery_jplayer_<?php echo $product['product_id']; ?>" class="cp-jplayer"></div>
<script type="text/javascript">

					var myCirclePlayer = new CirclePlayer("#jquery_jplayer_<?php echo $product['product_id']; ?>",
			{
				m4a: "http://www.mywebsite.co.uk/sample/<?php echo $option['option_value']; ?>"
				
			}, {
				cssSelectorAncestor: "#cp_container_<?php echo $product['product_id']; ?>"
			});			
		
		</script>		
        </div>
        <br />
        <div id="cp_container_<?php echo $product['product_id']; ?>" class="cp-container_sm">
				<div class="cp-buffer-holder"> <!-- .cp-gt50 only needed when buffer is > than 50% -->
					<div class="cp-buffer-1"></div>
					<div class="cp-buffer-2"></div>
				</div>
				<div class="cp-progress-holder"> <!-- .cp-gt50 only needed when progress is > than 50% -->
					<div class="cp-progress-1"></div>
					<div class="cp-progress-2"></div>
				</div>
				<div class="cp-circle-control"></div>
				<ul class="cp-controls">
					<li><a href="#" class="cp-play" tabindex="1">play</a></li>
					<li><a href="#" class="cp-pause" style="display:none;" tabindex="1">pause</a></li> <!-- Needs the inline style here, or jQuery.show() uses display:inline instead of display:block -->
				</ul>
			</div> 
            </div>

<?php } ?>
<?php } ?> 

Active Member

Posts

Joined
Tue Oct 20, 2009 4:31 pm

Post by pooks » Sat Mar 09, 2013 4:16 am

Looking ages for this thank you!

Unfortunately only thing that i got working was the last post. My intention is however to display sizes (options) we have left in stock only or hightlight the ones that are sold with a class. Is there any way how I'd add this thing or similar to the code above?

foreach ($option['option_value'] as $option_value) {
if (!$option_value['subtract'] || ($option_value['quantity'] > 0)) {

New member

Posts

Joined
Tue Mar 27, 2012 1:42 am

Post by jaspaljass » Mon Feb 24, 2014 4:02 pm

hey im using opencart 1.5.6

i want to display product options on category page

can u help me..!!!!!

Newbie

Posts

Joined
Mon Feb 24, 2014 4:00 pm

Post by ianhaney » Sun May 25, 2014 3:37 am

Has anyone got this working for 1.5.6.4

Active Member

Posts

Joined
Sun Jun 24, 2012 2:30 am
Location - GB
Who is online

Users browsing this forum: No registered users and 13 guests