Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Product Info


MrNickRegan

Recommended Posts

Evening all,

 

I hope that someone could point me in the right direction on this, I need to change a piece of code within the product_info.php file so that my customers can see that an item is out of stock without having to go through the checkout process before being informed the item is out of stock. Currently the code just looks to see if the item has been set as available, whereas the code in the checkout process looks at the stock level. My question is how can I change the code in the info page to check the stock rather than just the availability?

 

Please see below for the snippets of code:

 

Code from products_info.php

            <div class="prod_info_name_price">
                <div class="prod_info_name"><h1 itemprop="name"><?php echo $products_name; ?></h1></div>
                <?php echo '<p class="availability">'.AVAILABILITY.'<strong itemprop="availability"> '.AVAILABILITY_IN.'</strong></p>'; ?>

 

Code from checkout_process.php

// Stock Check
  $any_out_of_stock = false;
  if (STOCK_CHECK == 'true') {
    for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
      if (tep_check_stock($order->products[$i]['id'], $order->products[$i]['qty'])) {
        $any_out_of_stock = true;
      }

    } 

 

Many thanks in advance for any assistance.

Nick :)

Link to comment
Share on other sites

Theres already a query for products_quantity in the product info page. So you just need to do something like :

 

if ($product_info['products_quantity'] == 0) {

   echo 'Product out of stock';

 } else {

   echo $product_info['products_quantity'] . ' in stock';

}

 

I don't know where your product info page was marked up with microformats, but somewhere in this forum I posted some micro format code blocks that would be more in line with what you already have. I don't know when I posted them, maybe a year or more ago.  But the $product_info['products_quantity'] is the key to do what you need.

Follow the community build:

BS3 to osCommerce Responsive from the Get Go!

Check out the new construction:

Admin Gone to Total BS!

Link to comment
Share on other sites

there is also also the function:

tep_get_products_stock($products_id);

//we have

echo 'We currently have: ' .  tep_get_products_stock($products_id)  .  ' in stock';

//then you can disable the checkout button
/*
if( tep_get_products_stock($products_id) < 1)..............
*/
Link to comment
Share on other sites

Thanks guys, however I cannot seem to locate the stock check code inside the product info.php. I have copied my code below, would you be able to assist?

 

<?php
 
/*
 
  $Id$
 
 
 
  osCommerce, Open Source E-Commerce Solutions
 
 
            rel="adjustX:-4, adjustY:-4, softFocus:true">'. tep_image(DIR_WS_IMAGES . $pi['image'], '', '', '', 'itemprop="image"') . '</a>
            </div>';
 
            ?>
 
        <div class="gallery_note"><?php echo GALLERY_NOTE; ?></div>
 
 
            <?php
        /* first image in gallery */
 
            echo '
            <div class="clearfix gallery_smallimg_wrapper">
 
            <div class="gallery_smallimg">
            <a href="'.tep_href_link(DIR_WS_IMAGES . $pi['image']).'"  class="cloud-zoom-gallery"
            rel="useZoom:\'zoom1\', smallImage: \''.tep_href_link(DIR_WS_IMAGES . $pi['image']).'\' ">'. tep_image(DIR_WS_IMAGES . $pi['image']) . '</a>
            </div>';
 
            while ($pi = tep_db_fetch_array($pi_query)) {
                  $pi_counter++;
                  $pi_entry = '
                  <div class="gallery_smallimg"><a class="cloud-zoom-gallery" rel="useZoom:\'zoom1\', smallImage: \''.tep_href_link(DIR_WS_IMAGES . $pi['image']).'\' " href="'.tep_href_link(DIR_WS_IMAGES . $pi['image']).'" >'.
                      tep_image(DIR_WS_IMAGES . $pi['image']) . '</a>
                  </div>';
                  echo $pi_entry;
            }
 
?>
        </div>
 
    </div>
 
 
 
    </div>
 
 
 
<?php
      } else {
?>
 
    <div class="product_img_wrapper">
        <div>
            <?php echo '<a href="' . tep_href_link(DIR_WS_IMAGES . $product_info['products_image'], '', 'NONSSL', false) . '" class="cloud-zoom" id="zoom1"
               rel="adjustX:-4, adjustY:-4, softFocus:true">' . tep_image(DIR_WS_IMAGES . $product_info['products_image'], addslashes($product_info['products_name']), '','', 'itemprop="image" class="scale-with-grid-resize-one cloudzoom_border"') . '</a>'; ?>
        </div>
    </div>
 
 
<?php
      }
?>
 
<?php
    }
?>
 
<div class="product_info_wrapper">
 
    <div class="clearfix" style="overflow: hidden;">
 
         <?php /* ALL PRODUCT INFO */ ?>
 
        <div class="left_info">
 
 
            <?php echo tep_draw_form('cart_quantity', tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=add_product')); ?>
 
 
            <div class="prod_info_name_price">
                <div class="prod_info_name"><h1 itemprop="name"><?php echo $products_name; ?></h1></div>
                <?php echo '<p class="availability">'.AVAILABILITY.'<strong itemprop="availability"> '.AVAILABILITY_IN.'</strong></p>'; ?>
 
 
 
                <div itemprop="offerDetails" itemscope itemtype="http://data-vocabulary.org/Offer" class="prod_info_price"><?php echo $products_price; ?></div>
 
                <?php
                    if ($product_info['products_description'] !== '') {
                        echo '<div class="product_description">'.stripslashes($product_info['products_description']).'</div>';
                    }
                ?>
            </div>
 
            <div class="reviews-box">
 
            <?php
                $reviews_query = tep_db_query("select count(*) as count, r.reviews_rating from " . TABLE_REVIEWS . " r, " . TABLE_REVIEWS_DESCRIPTION . " rd where r.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and r.reviews_id = rd.reviews_id and rd.languages_id = '" . (int)$languages_id . "' and reviews_status = 1");
                $reviews = tep_db_fetch_array($reviews_query);
 
                $review_query_rating = tep_db_query("SELECT ROUND(SUM(`reviews_rating`)/COUNT(`reviews_id`)) as rating
         FROM " . TABLE_REVIEWS . " WHERE products_id = '" . $product_info['products_id'] . "'  AND `reviews_status` = 1");
                $review_rating = tep_db_fetch_array($review_query_rating);
 
 
             ?>
                <div itemprop="review" itemscope itemtype="
                        .tep_draw_button(ADD_REVIEW, 'comment', tep_href_link(FILENAME_PRODUCT_REVIEWS_WRITE, tep_get_all_get_params()), 'primary');
 
                    ?>
 
                </div>
 
            </div>
 
 
 
 
            <?php
    $products_attributes_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "'");
    $products_attributes = tep_db_fetch_array($products_attributes_query);
    if ($products_attributes['total'] > 0) {
?>
 
        <p class="clearfix options_form_label"><?php echo TEXT_PRODUCT_OPTIONS; ?></p>
 
        <p class="clearfix options_form">
        <?php
      $products_options_name_query = tep_db_query("select distinct popt.products_options_id, popt.products_options_name from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "' order by popt.products_options_name");
      while ($products_options_name = tep_db_fetch_array($products_options_name_query)) {
        $products_options_array = array();
        $products_options_query = tep_db_query("select pov.products_options_values_id, pov.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov where pa.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pa.options_id = '" . (int)$products_options_name['products_options_id'] . "' and pa.options_values_id = pov.products_options_values_id and pov.language_id = '" . (int)$languages_id . "'");
        while ($products_options = tep_db_fetch_array($products_options_query)) {
          $products_options_array[] = array('id' => $products_options['products_options_values_id'], 'text' => $products_options['products_options_values_name']);
          if ($products_options['options_values_price'] != '0') {
            $products_options_array[sizeof($products_options_array)-1]['text'] .= ' (' . $products_options['price_prefix'] . $currencies->display_price($products_options['options_values_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) .') ';
          }
        }
 
        if (is_string($HTTP_GET_VARS['products_id']) && isset($cart->contents[$HTTP_GET_VARS['products_id']]['attributes'][$products_options_name['products_options_id']])) {
          $selected_attribute = $cart->contents[$HTTP_GET_VARS['products_id']]['attributes'][$products_options_name['products_options_id']];
        } else {
          $selected_attribute = false;
        }
?>
 
      <strong><?php echo $products_options_name['products_options_name'] . ':'; ?></strong><br class="br_space" /><br class="br_space" /><?php echo tep_draw_pull_down_menu('id[' . $products_options_name['products_options_id'] . ']', $products_options_array, $selected_attribute); ?><br class="br_space" /><br class="br_space" />
 
<?php
      }
?>
 
    </p>
 
 
<?php
    }
?>
 
            <div class="clearfix add-to-cart-box">
                 <?php if ($product_info['products_date_available'] > date('Y-m-d H:i:s')) {
                            echo '<p class="expected-date">'.sprintf(TEXT_DATE_AVAILABLE_UNISHOP, tep_date_long($product_info['products_date_available'])).'</p>';
                        } else {
                           echo '<div class="add-to-cart-button">'.tep_draw_hidden_field('products_id', $product_info['products_id']) . tep_draw_button(IMAGE_BUTTON_IN_CART, 'cart', null, 'primary'),'</div>';
                       }
                 ?>
            </div>
            </form>
 
            <div class="clearfix socials_plugins">
                <div class="google">
                    <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
                    <div class="g-plusone" data-size="medium" data-count="true"></div>
                </div>
                <div class="facebook">
                    <script>(function(d, s, id) {
                        var js, fjs = d.getElementsByTagName(s)[0];
                        if (d.getElementById(id)) return;
                        js = d.createElement(s); js.id = id;
                        js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1";
                        fjs.parentNode.insertBefore(js, fjs);
                    }(document, 'script', 'facebook-jssdk'));</script>
                    <div class="fb-like" data-send="false" data-layout="button_count" data-width="94" data-show-faces="false" data-font="arial"></div>
                </div>
                <div class="twitter">
                    <a rel="nofollow" href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-via="tonytemplates"></a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
                </div>
            </div>
 
 
 
 
        </div>
 
 
        <?php /* ALL PRODUCT INFO */ ?>
 
 
 
    </div>
 
    </div>
 
 
 
    </div>
    </div>
</div>
 
 
 
 
 
</div>
 
 
<?php
    if ((USE_CACHE == 'true') && empty($SID)) {
      echo tep_cache_also_purchased(3600);
    } else {
      include(DIR_WS_MODULES . FILENAME_ALSO_PURCHASED_PRODUCTS);
    }
?>
 
<?php
  }
 
  require(DIR_WS_INCLUDES . 'template_bottom.php');
  require(DIR_WS_INCLUDES . 'application_bottom.php');
 
?>
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...