Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

EZ new fields v1.0


minglou

Recommended Posts

  • 2 weeks later...

This contrib works great...EXCEPT the savings % calculation doesn't work for prices greater than $999.99...so any product in the thousands will show a savings of 0%

 

you can see it working and not working at my site: http://www.lildevilmotorsports.com

 

If anyone knows how to fix it to properly display the savings % for products in the thousands, please let me know!!!

 

8)

Link to comment
Share on other sites

To the substr lines, e.g.

$no_savings = substr(($currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id']))), 1);

add a preg_replace to get rid of the commas before converting to floats, e.g.

$no_savings = preg_replace("/,/", "", substr(($currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id']))), 1));

No testing has been done on this. Use at your own risk.

 

It might make sense to do an sscanf instead of the preg_replace/substr pair, but I would want to try it before recommending any actual code. I also wonder if the currencies class might not have a numeric return that would work better than the string returned by display_price.

 

Good luck,

Matt

Link to comment
Share on other sites

To the substr lines, e.g.
$no_savings = substr(($currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id']))), 1);

add a preg_replace to get rid of the commas before converting to floats, e.g.

$no_savings = preg_replace("/,/", "", substr(($currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id']))), 1));

No testing has been done on this.  Use at your own risk.

 

It might make sense to do an sscanf instead of the preg_replace/substr pair, but I would want to try it before recommending any actual code.  I also wonder if the currencies class might not have a numeric return that would work better than the string returned by display_price.

 

Good luck,

Matt

 

Very Nice! Works like a charm!

 

Here is the result: http://www.lildevilmotorsports.com/catalog...products_id=205

 

Now if I can only get the comma added to the display of the retail price I am in business!

 

Thanks Again!

Link to comment
Share on other sites

Now if I can only get the comma added to the display of the retail price I am in business!
Try number_format. It will probably end up looking something like:
echo number_format($list_price, 2);

Hth,

Matt

 

correct again! 8)

 

for those of you following this thread, this is what the complete line will look like to properly display the comma if you have products that cost thousands like I do:

<?php echo number_format($product_info['products_retail_price'], 2); ?>

Link to comment
Share on other sites

Anybody else experiencing a PHP Warning "Division by zero..." with this great contrib?

 

All my products have a retail price and a cost....

 

I think it might be the way the arithmetic is written....

 

8)

Link to comment
Share on other sites

Anybody else experiencing a PHP Warning "Division by zero..." with this great contrib?

 

All my products have a retail price and a cost....

 

I think it might be the way the arithmetic is written....

 

8)

 

Just to add another tidbit since I can't edit my own post. this warning does not seem to appear on the screen. it get written to the error_log file in your catalog root.

 

8)

Link to comment
Share on other sites

I just installed this contrib on a November snapshot of osCommerce for a client and received the "Division by Zero" error when viewing a Product on the PRODUCT_INFO.PHP page. I believe this error occurs because the contribution is written for MS1 and MS2 and you are trying to install it on a pre-MS1 snapshot.

 

If you are also getting a "Division by Zero" error with this contrib, I just figured out the cause of this error and how to fix it. In the PRODUCT_INFO.PHP file, look for the following lines of code...

      $list_price = substr(($currencies->display_price($product_info['products_retail_price'], tep_get_tax_rate($product_info['products_tax_class_id']))),1); 

     $list_price =$list_price + 0.0;

     $our_price = substr(($currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id']))),1);

Change these lines of code to look like this...

      $list_price = substr(($currencies->display_price($product_info_values['products_retail_price'], tep_get_tax_rate($product_info_values['products_tax_class_id']))),1); 

     $list_price =$list_price + 0.0;

     $our_price = substr(($currencies->display_price($product_info_values['products_price'], tep_get_tax_rate($product_info_values['products_tax_class_id']))),1);

Basically, make sure that product_info is changed to product_info_values.

 

Hope this helps others!

 

Have a great day.

 

-R

Link to comment
Share on other sites

I just installed this contrib on a November snapshot of osCommerce for a client and received the "Division by Zero" error when viewing a Product on the PRODUCT_INFO.PHP page. I believe this error occurs because the contribution is written for MS1 and MS2 and you are trying to install it on a pre-MS1 snapshot.  

 

If you are also getting a "Division by Zero" error with this contrib, I just figured out the cause of this error and how to fix it. In the PRODUCT_INFO.PHP file, look for the following lines of code...

      $list_price = substr(($currencies->display_price($product_info['products_retail_price'], tep_get_tax_rate($product_info['products_tax_class_id']))),1); 

     $list_price =$list_price + 0.0;

     $our_price = substr(($currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id']))),1);

Change these lines of code to look like this...

      $list_price = substr(($currencies->display_price($product_info_values['products_retail_price'], tep_get_tax_rate($product_info_values['products_tax_class_id']))),1); 

     $list_price =$list_price + 0.0;

     $our_price = substr(($currencies->display_price($product_info_values['products_price'], tep_get_tax_rate($product_info_values['products_tax_class_id']))),1);

Basically, make sure that product_info is changed to product_info_values.

 

Hope this helps others!

 

Have a great day.

 

-R

 

I will give it a shot but I am on MS2 and I do not get this error for every product viewed. Since I have so many products, I can't figure out which ones are trigerring it.

 

Time to test this...

Link to comment
Share on other sites

The fix that I described is for pre-MS1 snapshots. If you are using MS2, I dont think this fix would work... BUT... It could work the other way...

 

In PRODUCT_INFO.PHP, do you have code that references product_info_values? If so, try changing it to product_info and see if that helps.

 

For example...

 

<?php echo $product_info['products_price']; ?>

 

versus....

 

<?php echo $product_info_values['products_price']; ?>

 

Who knows, its worth a try. Do you have a link to see the error on one of your pages that I can see the error? I would be interested to see where the error is on the page. That will help to narrow down what piece of code is having the issue.

 

Let me know.

 

-R

Link to comment
Share on other sites

The fix that I described is for pre-MS1 snapshots. If you are using MS2, I dont think this fix would work... BUT... It could work the other way...  

 

In PRODUCT_INFO.PHP, do you have code that references product_info_values? If so, try changing it to product_info and see if that helps.

 

For example...

 

<?php echo $product_info['products_price']; ?>

 

versus....

 

<?php echo $product_info_values['products_price']; ?>

 

Who knows, its worth a try. Do you have a link to see the error on one of your pages that I can see the error? I would be interested to see where the error is on the page. That will help to narrow down what piece of code is having the issue.

 

Let me know.

 

-R

 

It really has me baffled. I went into PHPMyAdmin and made sure that I had no NULL or Zero values. then I spent hours slecting each product in my store watching the error_log file in another window to see which one triggers it. could not find it. as I mentioned above, it is not displaying the warning on the screen, only writing the warning to error_log file.

 

I can't help but wonder if something else calls product_info.php that might be generating in the warning???

 

in any case, my store is here: http://www.lildevilmotorsports.com you will see that the contrib works fine and calculates the savings % accurately now even for products over $999.99 but generates 4-5 warnings a day.....

 

:?

Link to comment
Share on other sites

Carrerarod,

 

For the novice,

can you please publish the code that worked for you in resolving the price display of products above 999,99?

 

Thanks in advance,

 

Deltablue

 

Did the file I sent you work for you?

Link to comment
Share on other sites

  • 2 weeks later...
To the substr lines, e.g.
$no_savings = substr(($currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id']))), 1);

add a preg_replace to get rid of the commas before converting to floats, e.g.

$no_savings = preg_replace("/,/", "", substr(($currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id']))), 1));

No testing has been done on this. Use at your own risk.

 

It might make sense to do an sscanf instead of the preg_replace/substr pair, but I would want to try it before recommending any actual code. I also wonder if the currencies class might not have a numeric return that would work better than the string returned by display_price.

 

Good luck,

Matt

 

This worked for me, however, when I have a special price, I get 0.00s as the list price and our price.

 

e.g.

 

List Price: 0.00

Our Price: 0.00

You Save: 6%

 

Any suggestions would be appreciated. thanks.

Link to comment
Share on other sites

To the substr lines, e.g.
$no_savings = substr(($currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id']))), 1);

add a preg_replace to get rid of the commas before converting to floats, e.g.

$no_savings = preg_replace("/,/", "", substr(($currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id']))), 1));

No testing has been done on this. Use at your own risk.

 

It might make sense to do an sscanf instead of the preg_replace/substr pair, but I would want to try it before recommending any actual code. I also wonder if the currencies class might not have a numeric return that would work better than the string returned by display_price.

 

Good luck,

Matt

 

This worked for me, however, when I have a special price, I get 0.00s as the list price and our price.

 

e.g.

 

List Price: 0.00

Our Price: 0.00

You Save: 6%

 

Any suggestions would be appreciated. thanks.

<?php

}

if ($new_price = tep_get_products_special_price($product_info['products_id'])) { 

$list_price = '<s>' . $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) . '</s>'; 

$our_price = '<span class="productSpecialPrice">' . $currencies->display_price($new_price, tep_get_tax_rate($product_info['products_tax_class_id'])) . '</span>'; 

//get the list price and special price and then display the savings 

$no_savings = preg_replace("/,/", "", substr(($currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id']))), 1));

$now_savings = preg_replace("/,/", "", substr(($currencies->display_price($new_price, tep_get_tax_rate($product_info['products_tax_class_id']))), 1)); 

$now_savings = $now_savings + 0.0; 

$savings_b = (($now_savings / $no_savings) * 100); 

$savings = (100 - $savings_b);

$savings = round($savings);



} else { 

$list_price = preg_replace("/,/", "", substr(($currencies->display_price($product_info['products_retail_price'], tep_get_tax_rate($product_info['products_tax_class_id']))),1)); 

$list_price =$list_price + 0.0;

$our_price = preg_replace("/,/", "", substr(($currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id']))),1));

$our_price = $our_price + 0.0;

$savings_a = (($our_price / $list_price) * 100);

$savings = (100 - $savings_a);

$savings = round($savings); 

}?>

<p></p>

<center>List Price: <? echo "$"; echo number_format($list_price, 2); ?><br> 

<strong>Our Price: <? echo "$"; echo number_format($our_price, 2); ?></strong><br> 

<font color="#FF0000">You Save: <? echo $savings. "%"; ?></font>  

[/CODE][CODE]

Link to comment
Share on other sites

  • 2 months later...

Peter -

 

I have the savings amount, but not the percentage on my site. You should be able to combine the code below from product_info.php with the percentage code you have to get what you want.

 

Relevant code sections:

? ? if ($new_price = tep_get_products_special_price($product_info['products_id'])) {

? ? ? $products_price = '<s>' . $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) . '</s> <span class="productSpecialPrice">' . $currencies->display_price($new_price, tep_get_tax_rate($product_info['products_tax_class_id'])) . '</span>';

? ? ? $savings = $product_info['products_list_price'] - $new_price;? ?

? ? } else {

? ? ? $products_price = $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id']));

? ? ? $savings = $product_info['products_list_price'] - $product_info['products_price'];

? ? }

? ? ? ? ? ? <td class="pageHeading" align="right" valign="top">

? ? ? ? ? ? ? <table border="0" width="100%" cellspacing="0" cellpadding="0">

? ? ? ? ? ? ? ? <tr>

? ? ? ? ? ? ? ? ? <td class="pageHeading" align="right" valign="top">list price: <s><?php echo $currencies->display_price($product_info['products_list_price'], tep_get_tax_rate($product_info['products_tax_class_id'])); ?></s></td>

? ? ? ? ? ? ? ? </tr>

? ? ? ? ? ? ? ? <tr>

? ? ? ? ? ? ? ? ? <td class="pageHeadingPrice" align="right" valign="top">price: <?php echo $products_price; ?></td>

? ? ? ? ? ? ? ? </tr>

? ? ? ? ? ? ? ? <tr>

? ? ? ? ? ? ? ? ? <td class="pageHeadingSavings" align="right" valign="top">you save: <?php echo $currencies->display_price($savings, tep_get_tax_rate($product_info['products_tax_class_id'])); ?></td>

? ? ? ? ? ? ? ? </tr>

? ? ? ? ? ? ? </table>

? ? ? ? ? ? </td>

 

P.S. I named the new database field "products_list_price". The original contribution was "products_retail_price."

Edited by MattM
Link to comment
Share on other sites

  • 1 month later...

I have installed this and after a couple of little problems I have it working fine with one exception. If I put an item on special it changes the the retail price to my normal selling price and gives me the savings from that. So a product would change

 

from

 

List Price: $ 47.45

 

Our Price: $28.95

 

You Save: 39%

 

to this

 

List Price: $ $28.95

 

Our Price: $$15.95

 

You Save: 45%

 

When it should really be this

 

List Price: $ 47.45

 

Our Price: $15.95

 

You Save: 59%

 

Well if anyone has any ideas that would be great.

 

Thanks

Richard

The Knowledge Base is a wonderful thing.

Do you have a problem? Have you checked out Common Problems?

There are many very useful osC Contributions

Are you having trouble with a installed contribution? Have you checked out the support thread found Here

BACKUP BACKUP BACKUP!!! You did backup, right??

Link to comment
Share on other sites

  • 4 months later...
  • 3 months later...

Thanks for the contribution, its really worth. I installed it and it is working great except for one thing. In the file advanced_search_result.php when one clicks the the link "Retail" (top 5th column) it gives an SQL syntax error.

1064 - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'limit 0, 20' at line 1

select distinct m.manufacturers_name, p.products_image, m.manufacturers_id, p.products_id, pd.products_name, p.products_price, p.products_retail_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from products p left join manufacturers m using(manufacturers_id), products_description pd left join specials s on p.products_id = s.products_id, categories c, products_to_categories p2c where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '1' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and (IF(s.status, s.specials_new_products_price, p.products_price) >= 4) and (IF(s.status, s.specials_new_products_price, p.products_price) <= 6) order by limit 0, 20

 

All the other links work fine the only link with error is the one which has sort value = 5a, so the link is like

http://www.somesite.com/advanced_search_result.php?inc_subcat=1&pfrom=0&pto=500&page=1&sort=5a

 

I tried to search for limit in the file advanced_search_result.php but there is no occurence of the word limit in that file als there are 2 occurences of "order by" in the file (I am not sure if somethings wrong with them).

 

I dunno if everybody faces this problem or is it just me?

 

I am not a PHP expert but I think that since we added more columns, we should have also edited this line

 

Line 304 (for me) in advanced_search_results.php

for ($i=0, $n=sizeof($column_list); $i<$n; $i++) {

 

to

for ($i=0, $n=sizeof($column_list); $i<=$n; $i++) {

Please note that = sign or may be change the variable "$column_list" Am not sure how it can be fixed.

 

Any kind of help will be appreciated.

 

Thanks

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.

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