Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Getting a certain product's price


Fyod

Recommended Posts

I'm making a slider that'll have the price of a certain product in it dynamically so that I don't have to change it twice if the product price changes. The product may have a regular price, sale price, has two currencies and has Price Per Customer also installed.

 

How would I go about changing the query to show me the price of the certain product ID?

 

This is btw on an index page that has featured, discount, new products so most of the queries are already there.

Link to comment
Share on other sites

Have a look at the code on product_info.php.

 

That should already have been changed to show the "correct" price.

 

HTH

 

G

Need help installing add ons/contributions, cleaning a hacked site or a bespoke development, check my profile

 

Virus Threat Scanner

My Contributions

Basic install answers.

Click here for Contributions / Add Ons.

UK your site.

Site Move.

Basic design info.

 

For links mentioned in old answers that are no longer here follow this link Useful Threads.

 

If this post was useful, click the Like This button over there ======>>>>>.

Link to comment
Share on other sites

Here's what I came up with if anyone's looking for the same thing.

 

 

<?php
$id1 = '1';
$specials_query = tep_db_query("select specials_new_products_price, status from " . TABLE_SPECIALS . " where products_id = " . $id1 . " and status = '1' ");
while ($spec_array = tep_db_fetch_array($specials_query)) {
$specprice = $spec_array['specials_new_products_price'];
}
$tax_query = tep_db_query("select tax_rate from " . TABLE_TAX_RATES . " where tax_rates_id = '1' ");
while ($tax_array = tep_db_fetch_array($tax_query)) {
$taxprice = $tax_array['tax_rate'];
}
$products_query = tep_db_query("select products_price from " . TABLE_PRODUCTS . " where products_id = " . $id1 . " ");
while ($prod_array = tep_db_fetch_array($products_query)) {
$prodprice = $prod_array['products_price'];
}
$msrp_query = tep_db_query("select products_msrp from " . TABLE_PRODUCTS . " where products_id = " . $id1 . " ");
while ($msrp_array = tep_db_fetch_array($msrp_query)) {
$msrpprice = round($msrp_array['products_msrp']);
}
if ($specprice > 1) {
$finalprice = round(($taxprice / 100 + 1) * $specprice);
} else {
$finalprice = round(($taxprice / 100 + 1) * $prodprice);
}
?>

 

 

 <!--LayerSlider sublayers-->
<div class="ls-s1" alt="layer1-sublayer1" style="width:100%; left:5px; top:0px; color:#990000; text-shadow:none; font-weight:bold;" rel="delayin: 600; durationin: 1600; easingin: easeInOutBack; slidedirection: top;">
	 <H1>Example text</H1>
		 <H4>Price <?php echo $finalprice ?> and msrp <?php echo $msrpprice ?></H4></a>
 </div>

 

Just a pretty basic pull from the DB. If I'm not too lazy today, I may try and get it to change currency when one is chosen on the page.

I think this should be SEO friendly and much easier to change than if each slide was a picture.

Link to comment
Share on other sites

I agree with your approach for the slide, but as for as getting the price, this might work for you because of your simple tax setup, but wont work for stores having different tax rates.

Also it's a bit convoluted as you would only get one price.

is msrp meant to be tax free ?

KEEP CALM AND CARRY ON

I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support).

So if you are still here ? What are you waiting for ?!

 

Find the most frequent unique errors to fix:

grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt

Link to comment
Share on other sites

I agree it isn't ideal for too many cases.

MSRP is the manf. price, I use it to compare it to my price and create a percentage for savings.

 

$savings = round(($finalprice / $msrpprice) * 100) . '%';

 

Is there an easy way to make the same database grab for another product without copying the whole code above, except with $id1 = 'XY';?

In other words, to get the above code working for another product ID with code as short as possible.

I feel I'm sort of "redesigning the wheel" here, but I couldn't think of a better way. Unless maybe making the slider specially for just featured items...

Link to comment
Share on other sites

$my_product_query = tep_db_query("select p.products_id, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price, products_msrp from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id  where p.products_status = '1' and p.products_id = '" . (int)$id1 . "' and pd.language_id = '" . (int)$languages_id . "'");

while ($my_product = tep_db_fetch_array($my_product_query)) {
 $finalprice = $currencies->display_price($my_product['products_price'], tep_get_tax_rate($my_product['products_tax_class_id']);
 $msrpprice = $currencies->display_price($my_product['products_msrp'], tep_get_tax_rate($my_product['products_tax_class_id']);
}

 

Untested.

Link to comment
Share on other sites

Works great! Thanks Burt!

Was just missing a ')' at the end of the last two vars ;)

 

Also had a mistake in my percentage calc

 

$savings = round(100 - ($finalprice / $msrpprice) * 100) . '%';

 

This is great. Now I just wish I could integrate the slider into the admin with the wysisyg editor like in wordpress :)

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...