Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

How to display the percentage value?


lolati

Recommended Posts

Hello

 

I am using the featured categories module + special by categories and I'd like to know how to display the value of the percentage discount applied per category and/OR the percentage per products but I'd prefer per category if possible

 

eg: -10%

 

can't figure out how to dissociate specials_price from products_price....

 

Thanks

 

Lola

MS2

Multistore

:-"

Lola

Link to comment
Share on other sites

Hello

 

I am using the featured categories module + special by categories and I'd like to know how to display the value of the percentage discount applied per category and/OR the percentage per products but I'd prefer per category if possible

 

eg: -10%

 

can't figure out how to dissociate specials_price from products_price....

 

Thanks

 

Lola

MS2

Multistore

:-"

 

not sure about that contribution but in the normal specials box I use the following which could be adapted to your case I think :

 

$savings = ceil((1-($random_product['specials_new_products_price']/$random_product['products_price'])) * 100);

 

echo '-' . $savings . '%';

Treasurer MFC

Link to comment
Share on other sites

not sure about that contribution but in the normal specials box I use the following which could be adapted to your case I think :

 

    $savings = ceil((1-($random_product['specials_new_products_price']/$random_product['products_price'])) * 100);

 

echo '-' . $savings . '%';

 

Should be something like that, why do you use $random_product? I should be able to get the percentage from this type of formula:

 

(specials_new_products_price/products_price)*100

 

but it gives me a division by zero. $products_price displays both regular price AND reduced price, can't find where to get the original $products_price with regular price only!

Lola

Link to comment
Share on other sites

Should be something like that, why do you use $random_product? I should be able to get the percentage from this type of formula:

 

(specials_new_products_price/products_price)*100

 

but it gives me a division by zero. $products_price displays both regular price AND reduced price, can't find where to get the original $products_price with regular price only!

 

$random_product because the specials box selects a random product.

 

if it generates a divide by zero then obviously the price = zero.

 

to put it in perspective, the total code for the box.

 

<?php

if ($random_product =

tep_random_select("select p.products_id,

pd.products_name,

p.products_price,

p.products_tax_class_id,

p.products_image,

s.specials_new_products_price

from " . TABLE_PRODUCTS . " p,

" . TABLE_PRODUCTS_DESCRIPTION . " pd,

" . TABLE_SPECIALS . " s

where p.products_status = '1' and

p.products_id = s.products_id and

pd.products_id = s.products_id and

pd.language_id = '" . (int)$languages_id . "' and

s.status = '1'

order by s.specials_date_added desc

limit " . MAX_RANDOM_SELECT_SPECIALS)) {

 

echo '<tr><td>';

$info_box_contents = array();

$info_box_contents[] = array('text' => '<a class="infoboxHeading" href="' . tep_href_link(FILENAME_SPECIALS) . '">' . BOX_HEADING_SPECIALS . '</a>');

new infoBoxHeading($info_box_contents, true, true, tep_href_link(FILENAME_SPECIALS));

$info_box_contents = array();

$savings = ceil((1-($random_product['specials_new_products_price']/$random_product['products_price'])) * 100);

$info_box_contents[] =

array('align' => 'center',

'text' => '<a onmouseover="window.status=\'' . $random_product['products_name'] . '\' ; return true" href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $random_product["products_id"]) . '">' .

tep_image(DIR_WS_PRODUCT_IMAGES . $random_product['products_image'], $random_product['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br>

<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $random_product['products_id']) . '">' . $random_product['products_name'] . '</a><br>

<s>' . $currencies->display_price_nodiscount($random_product['products_price'], tep_get_tax_rate($random_product['products_tax_class_id'])) . '</s><br><span class="productSpecialPrice">' . $currencies->display_price_nodiscount($random_product['specials_new_products_price'], tep_get_tax_rate($random_product['products_tax_class_id'])) . '<br><i>(-' . $savings . '%)</i></span><br><br>

<a class="smalltext" href="' . tep_href_link(FILENAME_SPECIALS) . '">' . TEXT_VIEW_ALL . '</a>');

new contentBox($info_box_contents);

echo '</td></tr>';

}

?>

Treasurer MFC

Link to comment
Share on other sites

$random_product because the specials box selects a random product.

 

if it generates a divide by zero then obviously the price = zero.

 

to put it in perspective, the total code for the box.

 

<?php

  if ($random_product =

      tep_random_select("select p.products_id,

                                pd.products_name,

                                p.products_price,

                                p.products_tax_class_id,

                                p.products_image,

                                s.specials_new_products_price

                        from " . TABLE_PRODUCTS . " p,

                              " . TABLE_PRODUCTS_DESCRIPTION . " pd,

                              " . TABLE_SPECIALS . " s

                        where p.products_status = '1' and

                              p.products_id = s.products_id and

                              pd.products_id = s.products_id and

                              pd.language_id = '" . (int)$languages_id . "' and

                              s.status = '1'

                        order by s.specials_date_added desc

                        limit " . MAX_RANDOM_SELECT_SPECIALS)) {

 

    echo '<tr><td>';

    $info_box_contents = array();

    $info_box_contents[] = array('text' => '<a class="infoboxHeading" href="' . tep_href_link(FILENAME_SPECIALS) . '">' . BOX_HEADING_SPECIALS . '</a>');

    new infoBoxHeading($info_box_contents, true, true, tep_href_link(FILENAME_SPECIALS));

    $info_box_contents = array();

    $savings = ceil((1-($random_product['specials_new_products_price']/$random_product['products_price'])) * 100);

    $info_box_contents[] =

    array('align' => 'center',

                    'text' => '<a onmouseover="window.status=\'' . $random_product['products_name'] . '\' ; return true" href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $random_product["products_id"]) . '">' .

                              tep_image(DIR_WS_PRODUCT_IMAGES . $random_product['products_image'], $random_product['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br>

                              <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $random_product['products_id']) . '">' . $random_product['products_name'] . '</a><br>

                              <s>' . $currencies->display_price_nodiscount($random_product['products_price'], tep_get_tax_rate($random_product['products_tax_class_id'])) . '</s><br><span class="productSpecialPrice">' . $currencies->display_price_nodiscount($random_product['specials_new_products_price'], tep_get_tax_rate($random_product['products_tax_class_id'])) . '<br><i>(-' . $savings . '%)</i></span><br><br>

                              <a class="smalltext" href="' . tep_href_link(FILENAME_SPECIALS) . '">' . TEXT_VIEW_ALL . '</a>');

    new contentBox($info_box_contents);

    echo '</td></tr>';

  }

?>

 

 

Has to be something like that ...but what I really don't understand is where I can pull the original price from AND the special price from , my price equal zero because it's no longer the price but two: old price and new discounted price. so of course I can't divide that.

Lola

Link to comment
Share on other sites

Has to be something like that ...but  what I really don't understand is where I can pull the original price from AND the special price from , my price equal zero because it's no longer the price but two: old price and new discounted price. so of course I can't divide that.

 

because you have to use the prices as they come from the database, not after you changed that into a string containing several prices and currency codes.

Treasurer MFC

Link to comment
Share on other sites

because you have to use the prices as they come from the database, not after you changed that into a string containing several prices and currency codes.

 

Yes, I do understand that but I simply have no idea how to pull thoses prices from the database in order to apply the formula to display the value of the percentage...

 

...

 

Lola

Ms2

:'(

Lola

Link to comment
Share on other sites

  • 1 year later...

Join the conversation

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

Guest
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...