Post by Balbaroy » Tue Aug 03, 2010 12:40 am

I am looking for a way to add the Stock Status to the latest Module like what is displayed on the Product page. I just want it to show In Stock or Out of Stock. I would list it under the model on the latest_home.tpl

I found this code for the product page which is what I think I need but I am not sure how to incorporate it into the latest.php and latest_home.tpl or if there are other files I need to edit also. Any help would be great!

From Product.php
$this->data['text_availability'] = $this->language->get('text_availability');
From Product.tpl
<?php echo $text_availability; ?>

Newbie

Posts

Joined
Tue Aug 03, 2010 12:24 am

Post by Balbaroy » Tue Aug 03, 2010 8:25 am

Ok, I figured out an answer to my problem. I am a newb when it comes to PHP programming so there may be a better way to do this but from what I can tell it works great! Ill post how I got it to work in case someone else was wondering the same thing.

First find the following in latest.php and add code 'availability' => $result['quantity'],

Code: Select all

$this->data['products'][] = array(
                'product_id'    => $result['product_id'],
                'name'            => $result['name'],
                'model'           => $result['model'],
                'rating'          => $rating,
                'stars'           => sprintf($this->language->get('text_stars'), $rating),
                'price'           => $price,
                'options'       => $options,
                'availability'  => $result ['quantity'],
                'special'         => $special,
 
Then in latest_home.tpl find <span style="color: #999; font-size: 11px;"><?php echo $products[$j]['model']; ?></span><br /> Below this line add the following code:

Code: Select all

    <?php
    if ($products[$j]['availability'] == 0)
        $stockdisplay = "Out of Stock";
    else 
        $stockdisplay = "In Stock";
    ?>
     <span style="color: #000; font-size: 11px; font-weight: bold;"><?php echo $stockdisplay; ?></span><br />

To see an example of how it works check out my sotre: http://www.segastyle.com/store

Newbie

Posts

Joined
Tue Aug 03, 2010 12:24 am

Post by vkaltchev » Fri Sep 10, 2010 2:28 pm

I liked what you did; might decide to use it myself - thanks for posting it.

New member

Posts

Joined
Fri Apr 16, 2010 11:02 am

Post by Qphoria » Fri Sep 10, 2010 9:58 pm

Yes that is the correct way to do it

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by RonA » Wed Sep 22, 2010 9:11 am

This really helped me out a lot... thanks for taking the time to post it Balbaroy!!

I'm curious though if I could tweak the code just a bit so that if there was only one or two items left it would say 'Only One (Or Only Two) Left!' I've been playing with it but can't quite figure it out.

Thanks again.

New member

Posts

Joined
Tue Mar 09, 2010 4:11 pm

Post by leandromello » Thu May 28, 2015 12:21 am

How to do this, based on "stock_status_id"?
O.C: 1.5.5.1

New member

Posts

Joined
Fri Oct 28, 2011 3:29 am
Who is online

Users browsing this forum: No registered users and 5 guests