Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

PHP Math Question


danop

Recommended Posts

All I need to do is show the price of the product and next to it a discounted price. On my product_info.php I have:

 

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

 

And the price is displayed. Next to it I just want to add the same price BUT discounted by 10%. Just want to see: $40.00 $36.00. I know when I get a reply to this I'm going to feel really dumb. I've been doing PHP math tutorials online with no luck.

 

Thanks

 

Dan

Link to comment
Share on other sites

This is as far as I've got. I changed it around a little to get this:

 

<td class="pageHeading" align="right" valign="top"><?php echo $products_price; ?></td>
         </tr>
       <tr>        
       <td  colspan="2" class="subHeading" align="right" valign="top"><b><?php echo round(($products_price/0.90),2); ?> Club card price</b></td>
       </tr></tr>

 

But when it runs on the server, the price just comes up at 0. What am I doing wrong here?

 

Dan

Link to comment
Share on other sites

I've got it working, sort of now. This is my code:

 

<td class="pageHeading" align="right" valign="top"><?php echo $products_price; ?></td>
         </tr>
       <tr>        
       <td  colspan="2" class="subHeading" align="right" valign="top"><b> Club Card price <?php echo (($product_info['products_price']) * 0.90) ?></b></td>
       </tr></tr>

 

The only issue now is that the price is displaying WITHOUT a currency symbol and WITHOUT any decimal places. I wanted to use the whole "round" thing but I can't integrate it with this code.

 

There must be someone out there laughing at my attempts to get this right. Hopefully when the giggles subside, they can help me fix this bloody thing! Thanks!

 

Dan

Link to comment
Share on other sites

Personally I wouldn't do that. You could cause more problems than you think. Look into one of the discount contributions. They will take all calculations into account, such as taxes and shipping.

Link to comment
Share on other sites

Personally I wouldn't do that. You could cause more problems than you think. Look into one of the discount contributions. They will take all calculations into account, such as taxes and shipping.

 

I've already tried loading SPPC but near the end I ran into some issues with it conflicting with QTPRO. I was just going to use this instead and I have something else sorted out for when the customer with the club card checks out.

 

Dan

Link to comment
Share on other sites

Create a separate little PHP program and have a play around with this:

<?php

$products_price = 12.5;

$tempstr = sprintf("%.2f %.2f<BR>", $products_price, .9*$products_price);

echo "tempstr is ".$tempstr; ?>

 

But be careful with what you change in your shop.

Link to comment
Share on other sites

Create a separate little PHP program and have a play around with this:

<?php

$products_price = 12.5;

$tempstr = sprintf("%.2f %.2f<BR>", $products_price, .9*$products_price);

echo "tempstr is ".$tempstr; ?>

 

But be careful with what you change in your shop.

As far as I know any changes you want make to the price have to be done through the order class or the shopping cart class, which is why you should use one of the discount contribs or SPPC. Trying to change it this way is probably only going to create problems.

Link to comment
Share on other sites

I'm not trying to change the real price. When someone goes to checkout, the real price will still be processed. I am just trying to display an additional price that is 90% of the real price. Basically this:

 

$40.00

Club Card Price $36.00

 

Unless someone has been added to the discount group they will be paying $40.00. I was the $36.00 to be purely a visual thing and not affect checkout or any other processes.

 

Does that make sense?

 

Thanks

 

Dan

Link to comment
Share on other sites

Well if all you want is for visual purposes it can be done. Remember you will need one of the discount contribs to affect the price in the shopping cart.

 

You need to determine if you want to give this Club Card Discount on products that are already on special or not. If you do then find in catalog/product_info.php

   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>';
   } else {
     $products_price = $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id']));
   }

Right below that add

   if ($new_club_price = tep_get_products_special_price($product_info['products_id'])) {
     $club_price = 'Club Card Price <span class="productSpecialPrice">' . $currencies->display_price($new_club_price * .9, tep_get_tax_rate($product_info['products_tax_class_id'])) . '</span>';
   } else {
     $club_price = 'Club Card Price <span class="productSpecialPrice">' . $currencies->display_price($product_info['products_price'] * .9, tep_get_tax_rate($product_info['products_tax_class_id'])) . '</span>';
   }

If not then add

   if (!$new_club_price = tep_get_products_special_price($product_info['products_id'])) {
     $club_price = 'Club Card Price <span class="productSpecialPrice">' . $currencies->display_price($product_info['products_price'] * .9, tep_get_tax_rate($product_info['products_tax_class_id'])) . '</span>';
   }

Find

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

Change to

           <td class="pageHeading" align="right" valign="top"><?php echo $products_price; ?><?php if (tep_not_null($club_price)) echo '<br>' . $club_price; ?></td>

If you want to keep multiple langage functionality then put Club Card Price in a define and add it to catalog/includes/languages/english/product_info.php and any other language files you need. Such as

define('CLUB_CARD_PRICE', 'Club Card Price');

Then change in the aboce if statement

'Club Card Price <span class="productSpecialPrice">'

to

CLUB_CARD_PRICE . ' <span class="productSpecialPrice">'

Link to comment
Share on other sites

THANK YOU SOOO MUCH! That worked perfectly! Thanks for putting in the time and thought into helping a random stranger. I was pulling my hair out on this one thing. I installed a discount contribution to actually give the discount to those who purchase the club card and it all seems to be working perfectly!

 

Thanks bktrain again!

 

Dan

Link to comment
Share on other sites

  • 2 weeks later...

Round II:

 

I've added QTPRO and when the radioset is displayed I wanted to add the Club Card Price to that as well. In the file that creates the radioset I tried adding the code you wrote. Here is the code below for that file:

 

<?php

 require_once(DIR_WS_CLASSES . 'pad_single_dropdown.php');

 class pad_single_radioset extends pad_single_dropdown {

   function _draw_stocked_attributes() {
     global $languages_id;

     $out='';

     $attributes = $this->_build_attributes_array(true, false);
     if (sizeof($attributes)>0) {
       $combinations = array();
       $selected_combination = 0;
       $this->_build_attributes_combinations($attributes, $this->show_out_of_stock == 'True', $this->mark_out_of_stock, $combinations, $selected_combination);

       $combname='';
       foreach ($attributes as $attrib) {
         $combname.=', '.$attrib['oname'];
       }
       $combname=substr($combname,2).':';

       foreach ($combinations as $combindex => $comb) {
         $out.="<tr>\n";
         $out.='  <td align="right" class=main><b>'.$combname."</b></td>\n  <td class=main>";
         $out.=tep_draw_radio_field('attrcomb', $combinations[$combindex]['id'], ($combindex==$selected_combination)) . $comb['text'];
         $out.="</td>\n";
         $out.="</tr>\n";
         $combname='';
       }
     }

     $out.=$this->_draw_out_of_stock_message_js($attributes);

     return $out;
   }

 }
?>

 

This displays a radio button, the attribute option and then the price. Right after that I need it to display the Club Card price. I've messed about with it quite a bit only to have a few billion errors come up. Any ideas?

 

At one point I was getting the error: "Call to a member function display_price() on a non-object in..." so I was looking at how to call display_price() but none of the solutions I found on the forums/online were working.

 

Thanks

 

Dan

Link to comment
Share on other sites

  • 2 weeks later...

Archived

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

×
×
  • Create New...