Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Adding Pricing to BS Gold Also Purchased Products Module


NuDreamer

Recommended Posts

Hi All,

 

I am not proficient at all with PHP, but I'm trying to learn through osCommerce here. I currently have the products_also_purchased.php enabled for product pages, and I would like to show the also purchased products pricing under the name. I inserted the additional code below: 

$also_pur_prods_content .= '      <h5 class="text-center">' . $currencies->display_price($new_price, tep_get_tax_rate($random_product['products_tax_class_id'])) . '</h5>';

But it is displaying the price of the PRODUCT PAGE itself. To clarify, whatever product I am currently looking at, all of the also purchased products show the exact same price. I'm guessing I need to add some additional lines to tell it to pull the right products, but I have no idea where to start. Can anyone help me out here? My entire Also purchased file code is below:

<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2010 osCommerce

  Released under the GNU General Public License
*/

  if (isset($HTTP_GET_VARS['products_id'])) {
    $orders_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, p.products_price, pd.products_name from " . TABLE_ORDERS_PRODUCTS . " opa, " . TABLE_ORDERS_PRODUCTS . " opb, " . TABLE_ORDERS . " o, " . TABLE_PRODUCTS . " p LEFT JOIN " . TABLE_PRODUCTS_DESCRIPTION . " pd on p.products_id = pd.products_id where opa.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and opa.orders_id = opb.orders_id and opb.products_id != '" . (int)$HTTP_GET_VARS['products_id'] . "' and opb.products_id = p.products_id and opb.orders_id = o.orders_id and p.products_status = '1' and pd.language_id = '" . (int)$languages_id . "' group by p.products_id order by o.date_purchased desc limit " . MAX_DISPLAY_ALSO_PURCHASED);
    $num_products_ordered = tep_db_num_rows($orders_query);
    if ($num_products_ordered >= MIN_DISPLAY_ALSO_PURCHASED) {

      $also_pur_prods_content = NULL;

      while ($orders = tep_db_fetch_array($orders_query)) {
        $also_pur_prods_content .= '<div class="col-sm-6 col-md-4 match-heights">';
        $also_pur_prods_content .= '  <div class="thumbnail">';
        $also_pur_prods_content .= '    <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $orders['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $orders['products_image'], $orders['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>';
        $also_pur_prods_content .= '    <div class="caption">';
        $also_pur_prods_content .= '      <h5 class="text-center"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $orders['products_id']) . '">' . $orders['products_name'] . '</a></h5>';
        $also_pur_prods_content .= '      <h5 class="text-center">' . $currencies->display_price($new_price, tep_get_tax_rate($random_product['products_tax_class_id'])) . '</h5>';
        $also_pur_prods_content .= '    </div>';
        $also_pur_prods_content .= '  </div>';
        $also_pur_prods_content .= '</div>';
      }

?>

  <br />

  <h3><?php echo TEXT_ALSO_PURCHASED_PRODUCTS; ?></h3>

  <div class="row">
    <?php echo $also_pur_prods_content; ?>
  </div>


<?php
    }
  }
?>

Thanks a ton in advance

Link to comment
Share on other sites

Hi,

why do you use $random_product? As far as I understand data gets fetched from orders_query so my guess would be to try $orders:

$currencies->display_price($orders['products_price'], tep_get_tax_rate($orders['products_tax_class_id']))

something like that maybe.

 

Best regards

Christoph

Link to comment
Share on other sites

@@beerbee you were spot on. Thanks! I think the $random_product was because I was looking at an older attempt someone used to try to do this, and it fell quite flat. My final Products_also_purchased.php file is included below for anyone looking to do the same.

<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2010 osCommerce

  Released under the GNU General Public License
*/

  if (isset($HTTP_GET_VARS['products_id'])) {
    $orders_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, p.products_price, pd.products_name from " . TABLE_ORDERS_PRODUCTS . " opa, " . TABLE_ORDERS_PRODUCTS . " opb, " . TABLE_ORDERS . " o, " . TABLE_PRODUCTS . " p LEFT JOIN " . TABLE_PRODUCTS_DESCRIPTION . " pd on p.products_id = pd.products_id where opa.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and opa.orders_id = opb.orders_id and opb.products_id != '" . (int)$HTTP_GET_VARS['products_id'] . "' and opb.products_id = p.products_id and opb.orders_id = o.orders_id and p.products_status = '1' and pd.language_id = '" . (int)$languages_id . "' group by p.products_id order by o.date_purchased desc limit " . MAX_DISPLAY_ALSO_PURCHASED);
    $num_products_ordered = tep_db_num_rows($orders_query);
    if ($num_products_ordered >= MIN_DISPLAY_ALSO_PURCHASED) {

      $also_pur_prods_content = NULL;

      while ($orders = tep_db_fetch_array($orders_query)) {
        $also_pur_prods_content .= '<div class="col-sm-6 col-md-4 match-heights">';
        $also_pur_prods_content .= '  <div class="thumbnail">';
        $also_pur_prods_content .= '    <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $orders['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $orders['products_image'], $orders['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>';
        $also_pur_prods_content .= '    <div class="caption">';
        $also_pur_prods_content .= '      <h5 class="text-center"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $orders['products_id']) . '">' . $orders['products_name'] . '</a></h5>';
        $also_pur_prods_content .= '      <h5 class="text-center">' . $currencies->display_price($orders['products_price'], tep_get_tax_rate($orders['products_tax_class_id'])) . '</h5>';
        $also_pur_prods_content .= '    </div>';
        $also_pur_prods_content .= '  </div>';
        $also_pur_prods_content .= '</div>';
      }

?>

  <br />

  <h3><?php echo TEXT_ALSO_PURCHASED_PRODUCTS; ?></h3>

  <div class="row">
    <?php echo $also_pur_prods_content; ?>
  </div>


<?php
    }
  }
?>
Link to comment
Share on other sites

@@NuDreamer @@beerbee

 

Hi,

why do you use $random_product? As far as I understand data gets fetched from orders_query so my guess would be to try $orders:

$currencies->display_price($orders['products_price'], tep_get_tax_rate($orders['products_tax_class_id']))

something like that maybe.

 

Best regards

Christoph

 

No, this will show the price that previous customers have paid for the item. If the item has increased or decreased in price then the incorrect amount will be shown (leading to some angry customers! :) )

 

The correct way to do it:

 

After

while ($orders = tep_db_fetch_array($orders_query)) {

add

        $related_product_price_query = tep_db_query("select products_tax_class_id, products_price from " . TABLE_PRODUCTS . " where products_id = '" . $orders['products_id'] . "'");
        $related_product_price = tep_db_fetch_array($related_product_price_query);
        $related_product_price['related_products_price'] = tep_get_products_special_price($orders['products_id']);

        if (tep_not_null($related_product_price['related_products_price'])) {
                  $related_products_price = '<del>' . $currencies->display_price($related_product_price['products_price'], tep_get_tax_rate($related_product_price['products_tax_class_id'])) . '</del><br />';
                  $related_products_price .= '<span class="productSpecialPrice">' . $currencies->display_price($related_product_price['related_products_price'], tep_get_tax_rate($related_product_price['products_tax_class_id'])) . '</span>';
                } else {
                  $related_products_price = $currencies->display_price($related_product_price['products_price'], tep_get_tax_rate($related_product_price['products_tax_class_id']));
                }

then change

$also_pur_prods_content .= ' <h5 class="text-center">' . $currencies->display_price($orders['products_price'], tep_get_tax_rate($orders['products_tax_class_id'])) . '</h5>';

to

$also_pur_prods_content .= ' <h5 class="text-center">' . $related_products_price . '</h5>';

osCommerce user since 2003! :thumbsup:

Link to comment
Share on other sites

@@frankl am I getting it totally wrong? The orders_query is fetching the price from the products table  TABLE_PRODUCTS . " p , so  it should be the actual one?

The only thing missing here is the special price if a product has one.

 

Best regards

Christoph

Link to comment
Share on other sites

To add to this post. I realized shortly after that I was only showing the original price, and not the FINAL price. Many of my products are listed as on sale, and so I needed to list the final price if a specials price was applied. My updated also_purchased_products.php code is here for anyone else interested.

<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2010 osCommerce

  Released under the GNU General Public License
*/

  if (isset($HTTP_GET_VARS['products_id'])) {
    $orders_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, p.products_price, pd.products_name, IF(s.status, s.specials_new_products_price, p.products_price) AS final_price from " . TABLE_ORDERS_PRODUCTS . " opa, " . TABLE_ORDERS_PRODUCTS . " opb, " . TABLE_ORDERS . " o, " . TABLE_PRODUCTS . " p LEFT JOIN " . TABLE_PRODUCTS_DESCRIPTION . " pd on p.products_id = pd.products_id left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where opa.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and opa.orders_id = opb.orders_id and opb.products_id != '" . (int)$HTTP_GET_VARS['products_id'] . "' and opb.products_id = p.products_id and opb.orders_id = o.orders_id and p.products_status = '1' and pd.language_id = '" . (int)$languages_id . "' group by p.products_id order by o.date_purchased desc limit " . MAX_DISPLAY_ALSO_PURCHASED);
    $num_products_ordered = tep_db_num_rows($orders_query);
    if ($num_products_ordered >= MIN_DISPLAY_ALSO_PURCHASED) {

      $also_pur_prods_content = NULL;

      while ($orders = tep_db_fetch_array($orders_query)) {
        $also_pur_prods_content .= '<div class="col-sm-6 col-md-4 match-heights">';
        $also_pur_prods_content .= '  <div class="thumbnail">';
        $also_pur_prods_content .= '    <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $orders['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $orders['products_image'], $orders['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>';
        $also_pur_prods_content .= '    <div class="caption">';
        $also_pur_prods_content .= '      <h5 class="text-center"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $orders['products_id']) . '">' . $orders['products_name'] . '</a></h5>';
        $also_pur_prods_content .= '      <h5 class="text-center">' . $currencies->display_price($orders['final_price'], tep_get_tax_rate($orders['products_tax_class_id'])) . '</h5>';
        $also_pur_prods_content .= '    </div>';
        $also_pur_prods_content .= '  </div>';
        $also_pur_prods_content .= '</div>';
      }

?>

  <br />

  <h3><?php echo TEXT_ALSO_PURCHASED_PRODUCTS; ?></h3>

  <div class="row">
    <?php echo $also_pur_prods_content; ?>
  </div>


<?php
    }
  }
?>
Link to comment
Share on other sites

Archived

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

×
×
  • Create New...