Post by 4bco » Fri Sep 23, 2011 10:30 pm

I would like to modify the categories page to either display, "Out of Stock" or and "Add to Cart" button...

Any help is greatly appreciated.
Last edited by 4bco on Sat Sep 24, 2011 6:55 am, edited 1 time in total.

Custom Website Design from BCO ~ Building Companies Online
If we were of assistance to you, please help my family in return with a small donation.


New member

Posts

Joined
Wed Jun 29, 2011 11:40 pm

Post by 4bco » Sat Sep 24, 2011 3:24 am

I know I need to reference the stock quantity in the controller file for the catalog and then modify the catalog template file for the catalog with something like....

Code: Select all

			<?php if ($stock <= 0) {
				echo (<b>Out Of Stock</b>)
			} else { 
				<a class="button" href="<?php echo $products[$j]['add']; ?>" title="<?php echo $button_add_to_cart; ?>" ><span><?php echo $button_add_to_cart; ?></span></a>
			} ?>
Again, any assistance is appreciated.

Custom Website Design from BCO ~ Building Companies Online
If we were of assistance to you, please help my family in return with a small donation.


New member

Posts

Joined
Wed Jun 29, 2011 11:40 pm

Post by uksitebuilder » Sat Sep 24, 2011 4:59 am

This is my take on it:

edit: catalog/model/catalog/product.php

before the closing php tag add

Code: Select all

	public function getProductHasStock($product_id) {
		$query = $this->db->query("SELECT quantity FROMM " . DB_PREFIX . "product WHERE product_id = '" . (int)$product_id . "'");
		
		if($query->row['total']>0){
			return true;
		}else{
			return false;
		}
	}	
edit: catalog/controller/product/category.php

find

Code: Select all

$this->data['products'][] = array(
add after

Code: Select all

					'stock'		  => ($this->model_catalog_product->getProductHasStock($result['product_id'])?1:0),

Your template code should work with this too.

I haven't checked this, so it could be an epic fail.

User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by 4bco » Sat Sep 24, 2011 5:14 am

Thanks Simon ~

However, if I read your code correctly, the items will only be returned if they are in stock...What I need is for the item to be returned either way, but if the available quantity is zero, it needs to say "Out of Stock" and if it is available, the add to cart button should be visible.

When the items will be in season, it will be changed to "Pre-Order" and so the custom should be able to see all of the items whether they are available for immediate purchase or not.

Let me know if you can help me get this. Thanks!

Custom Website Design from BCO ~ Building Companies Online
If we were of assistance to you, please help my family in return with a small donation.


New member

Posts

Joined
Wed Jun 29, 2011 11:40 pm

Post by uksitebuilder » Sat Sep 24, 2011 5:31 am

Hi, I think you slightly misread my code.

It will return $product['stock'] as either 1 or 0 (or at least it should)

Then your code you put in the template will do what you expect if you change $stock to $product['stock']

Try it and see :)

User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by uksitebuilder » Sat Sep 24, 2011 5:34 am

My code is based on 1.5.x

User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by 4bco » Sat Sep 24, 2011 6:20 am

I have 1.4.9.4....but I am working on this now with the code you gave me.

On the template's category.tlp file I now have...

Code: Select all

         <?php if ($product['stock'] = 0) {
            echo '<b>Out Of Stock</b>';
         } else { } ?>
            <a class="button" href="<?php echo $products[$j]['add']; ?>" title="<?php echo $button_add_to_cart; ?>" ><span><?php echo $button_add_to_cart; ?></span></a>
On the Model product.php file I now have....changed, total to quantity (not sure if this is right, but total did not work)

Code: Select all

	   public function getProductHasStock($product_id) {
      $query = $this->db->query("SELECT quantity FROM " . DB_PREFIX . "product WHERE product_id = '" . (int)$product_id . "'");
      
      if($query->row['quantity']>0){
         return true;
      }else{
         return false;
      }
   } 
On the controller category.php file I have

Code: Select all

'stock'   => ($this->model_catalog_product->getProductHasStock($result['product_id'])?1:0),
This code does not return any errors, but it also does not place the "out of stock" info with the item.

Custom Website Design from BCO ~ Building Companies Online
If we were of assistance to you, please help my family in return with a small donation.


New member

Posts

Joined
Wed Jun 29, 2011 11:40 pm

Post by 4bco » Sat Sep 24, 2011 6:21 am

The other issue I have is that I want the button to be part of the else in the code, but I can't seem to get it right with the mixture of php and html.....Please help!

Custom Website Design from BCO ~ Building Companies Online
If we were of assistance to you, please help my family in return with a small donation.


New member

Posts

Joined
Wed Jun 29, 2011 11:40 pm

Post by uksitebuilder » Sat Sep 24, 2011 6:23 am

couple of errors in your tpl code

change

if ($product['stock'] = 0

to

if ($product['stock'] == 0

and change

} else { }

to

} else {

and pop a <?php } ?> after your button html

User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by uksitebuilder » Sat Sep 24, 2011 6:27 am

Here you go

Code: Select all

<?php if ($product['stock'] == 0) {
            echo '<b>Out Of Stock</b>';
         } else { ?>
            <a class="button" href="<?php echo $products[$j]['add']; ?>" title="<?php echo $button_add_to_cart; ?>" ><span><?php echo $button_add_to_cart; ?></span></a><?php } ?>

User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by 4bco » Sat Sep 24, 2011 6:32 am

hmmm...

Now I get

Notice: Undefined variable: product in /catalog/view/theme/dillard/template/product/category.tpl on line 63
Out Of Stock

Custom Website Design from BCO ~ Building Companies Online
If we were of assistance to you, please help my family in return with a small donation.


New member

Posts

Joined
Wed Jun 29, 2011 11:40 pm

Post by 4bco » Sat Sep 24, 2011 6:37 am

This got it....

Code: Select all

<?php if ($products[$j]['stock'] == 0) {
            echo '<b>Out Of Stock</b>';
         } else { ?>
            <a class="button" href="<?php echo $products[$j]['add']; ?>" title="<?php echo $button_add_to_cart; ?>" ><span><?php echo $button_add_to_cart; ?></span></a><?php } ?>  

Custom Website Design from BCO ~ Building Companies Online
If we were of assistance to you, please help my family in return with a small donation.


New member

Posts

Joined
Wed Jun 29, 2011 11:40 pm

Post by 4bco » Sat Sep 24, 2011 6:37 am

Thank you for all your help....Do you really have 14 kids?

Custom Website Design from BCO ~ Building Companies Online
If we were of assistance to you, please help my family in return with a small donation.


New member

Posts

Joined
Wed Jun 29, 2011 11:40 pm

Post by uksitebuilder » Sat Sep 24, 2011 6:38 am

I have just downloaded 1.4.9.4 - I can see slight differences between 1.5. and 1.4.x code
One moment and I will recheck my code and yours and come back with a solution.

Haha @ 14 kids. What do you think I am, a robot? lol

User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by uksitebuilder » Sat Sep 24, 2011 6:42 am

oh you fixed it ? great stuff :)

User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by 4bco » Sat Sep 24, 2011 6:45 am

I asked about the 14 kids b/c that is what you had in your signature....lol

I myself have only 6, but with 6 kids, I could only make a small donation to say thank you for your help!

Custom Website Design from BCO ~ Building Companies Online
If we were of assistance to you, please help my family in return with a small donation.


New member

Posts

Joined
Wed Jun 29, 2011 11:40 pm

Post by uksitebuilder » Sat Sep 24, 2011 6:49 am

Much appreciated.

My sig is a bit of a joke, or is meant to be hehe.

User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by 4bco » Sat Sep 24, 2011 6:52 am

I figured so...lol...that's why I asked :o :laugh:

Custom Website Design from BCO ~ Building Companies Online
If we were of assistance to you, please help my family in return with a small donation.


New member

Posts

Joined
Wed Jun 29, 2011 11:40 pm

Post by uksitebuilder » Sat Sep 24, 2011 6:53 am

They've multiplied now ;)

User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by SimonHavelock » Mon Nov 05, 2012 8:18 am

Hi!
I'm trying to implement this code but after everything is done what I get is:

Code: Select all

Notice: Undefined index: total in /home/simon/www/simon.wine-express.pl/htdocs/catalog/model/catalog/product.php on line 516Notice: Undefined index: total in /home/simon/www/simon.wine-express.pl/htdocs/catalog/model/catalog/product.php on line 516N
A couple of times, on category page.

What should I change?

Newbie

Posts

Joined
Wed Aug 15, 2012 3:19 am
Who is online

Users browsing this forum: No registered users and 5 guests