Jump to content
  • Checkout
  • Login
  • Get in touch


The e-commerce.

A page like Allprods but 'in stock' items only


Recommended Posts

Some of my customers were getting miffed about adding stuff to their basket only to be told after the fact that it was only available to order. So I thought of making a page like all prods, but only showing the items currently in stock.


So it would show:


Product title - Product image - Price - Buy now button


And would get from the database only items with quantity of 1 or more.


I know how to create a new page, just not sure what the php for the page would be. Anyone got any ideas?


I have tried adding an 'in stock' or 'available to order' notice to the product page but it didn't work - was showing 'available to order' regardless of whether it was in stock or not. So I got fed up.

Link to comment
Share on other sites

Well, I figured I can copy the allprods page and instead of calling the whole lot from the database, I can just call those products with quantity>0.


I had a look and this is the code which calls the product and gives it the link


              $products_query = tep_db_query("SELECT p.products_id, pd.products_name FROM " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd WHERE p.products_id = pd.products_id AND p.products_status = 1 AND pd.language_id = $this_language_id ORDER BY pd.products_name");
   $products_array = array();
   while($products = tep_db_fetch_array($products_query)) {
      $products_array[] = array('id'   => $products['products_id'],
              'name' => $products['products_name']);
   for ($j=0; $j<NR_COLUMNS; $j++) {
  	 echo "   <td class=main valign=\"top\">\n";
  	 for ($k=$j; $k<sizeof($products_array); $k+=NR_COLUMNS) {
     $this_products_id   = $products_array[$k]['id'];
     $this_products_name = $products_array[$k]['name'];
     echo "     <a href=\"" . tep_href_link(FILENAME_PRODUCT_INFO, 'name=' .str_replace (array('/', ' ', '?', '"', '#'), array('_', '_'),  ($this_products_name)). '&products_id=' . $this_products_id . (($this_language_code == DEFAULT_LANGUAGE) ? '' : ('&language=' . $this_language_code)), 'NONSSL', false) . "\">" . $this_products_name . "</a><br>\n";
  	 echo "   </td>\n";
      echo " </tr>\n";


I thought maybe I could alter it but it is way beyond my abilities.


What I want is for it to show like a normal product list with image, name, buy now button and price.


Or perhaps add a function to the search so it can search by whether the item is in stock or not, although that would be a less elegant solution.

Link to comment
Share on other sites

OK - sorry to keep replying to my own post but I want you people who are good at programming to see that I am trying to do it myself and not just expecting something for nothing. I have managed to get it to list all the in stock products by simply adding


AND p.products_quantity > 0


into the db query.


I actually saw it as soon as I posted above and like the light bulb going on I realised how to do it.


But I don't know how to get it to list the images and the price and the buy now button.


Also it will really need to be in pages once the images are in, as it will take forever to load all the images in one page. I am sure that all the info I need is in the default.php page, as that is what I want it to look like. But I don't know what I'm looking for.


You can see what I have done so far here:



Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...