Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

help getting 2 contributions to play nice


Guest

Recommended Posts

howdy all,

 

I am trying to get it so that when a customer selects the options they want for their product the price will update. For this I have picked the price update contribution (easier to install, and seems to work great).

 

I also have the options as images contribution installed.

 

Here is my problem, when I have the options as images turned off (i.e. just have drop down boxes) everything works great, prices update, etc...

 

but when I activate the options as images (after having modified the php file to also use price update contribution) I am getting errors about the function showprice(). This is due to the java scripting for the price update contribution. I have tried to add it to the options php file but that didn't work. I then went and changed the js to work on the php file but then it gives me errors about the Parse function.

 

In a nut shell I need some way for the options_images.php file to "use" the javascript of the contribution. below is my options)images.php file (with the current changes made to it to make is use the price update:

 

<?php

/*

$Id: options_images.php,v 1.0 2003/08/18

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2003 osCommerce

 

Released under the GNU General Public License

*/

 

 

$products_attributes_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "'");

$products_attributes = tep_db_fetch_array($products_attributes_query);

if ($products_attributes['total'] > 0) {

?>

 

<table border="0" cellspacing="0" cellpadding="2">

<tr>

<?php echo '<td class="main" colspan="2">' . TEXT_PRODUCT_OPTIONS . '<br>Please select your desired option using the buttons provided'; ?>

<?php if (OPTIONS_IMAGES_CLICK_ENLARGE == 'true') echo '<br>Click the images to enlarge';?>

</td>

</tr>

 

<?php

 

$products_options_name_query = tep_db_query("select distinct popt.products_options_id, popt.products_options_name, popt.products_options_sort_order, popt.products_options_images_enabled from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "'" . " order by popt.products_options_sort_order");

while ($products_options_name = tep_db_fetch_array($products_options_name_query)) {

$products_options_array = array();

$products_options_query = tep_db_query("select pov.products_options_values_id, pov.products_options_values_name, pov.products_options_values_thumbnail, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov where pa.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pa.options_id = '" . (int)$products_options_name['products_options_id'] . "' and pa.options_values_id = pov.products_options_values_id and pov.language_id = '" . (int)$languages_id . "'order by pa.products_options_sort_order");

while($products_options = tep_db_fetch_array($products_options_query)){

$products_options_array[] = array('id' => $products_options['products_options_values_id'], 'text' => $products_options['products_options_values_name'], 'thumbnail' => $products_options['products_options_values_thumbnail']);

if ($products_options['options_values_price'] != '0') {

$products_options_array[sizeof($products_options_array)-1]['text'] .= ' (' . $products_options['price_prefix'] . $currencies->display_price($products_options['options_values_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) .') ';

}

}

 

if (isset($cart->contents[$HTTP_GET_VARS['products_id']]['attributes'][$products_options_name['products_options_id']])) {

$selected_attribute = $cart->contents[$HTTP_GET_VARS['products_id']]['attributes'][$products_options_name['products_options_id']];

} else {

$selected_attribute = false;

}

 

?>

 

<tr>

<td class="main" valign="top"><?php echo $products_options_name['products_options_name'] . ':'; ?></td>

 

<?php

if ($products_options_name['products_options_images_enabled'] == 'false'){

echo '<td class="main">' . tep_draw_pull_down_menu('id[' . $products_options_name['products_options_id'] . ']', $products_options_array, $selected_attribute, "onChange='showPrice(this.form);'") . '</td></tr>';

}

else {

$count=0;

echo '<td class="main"><table><tr>';

foreach ($products_options_array as $opti_array){

echo '<td><table cellspacing="1" cellpadding="0" border="0">';

if (OPTIONS_IMAGES_CLICK_ENLARGE == 'true')

echo '<td align="center"><a href="java script:popupWindow(\'' . tep_href_link(FILENAME_OPTIONS_IMAGES_POPUP, 'oID=' . $opti_array['id']) .'\')">' . tep_image(DIR_WS_IMAGES . 'options/' . $opti_array['thumbnail'], $opti_array['text'], OPTIONS_IMAGES_WIDTH, OPTIONS_IMAGES_HEIGHT, 'class=shadow1') . '</a></td></tr>';

else echo '<tr><td align="center">' . tep_image(DIR_WS_IMAGES . 'options/' . $opti_array['thumbnail'], $opti_array['text'], OPTIONS_IMAGES_WIDTH, OPTIONS_IMAGES_HEIGHT) . '</td></tr>';

echo '<tr><td class="main" align="center">' . $opti_array['text'] . '</td></tr>';

if (($selected_attribute == false && $count == 0) || ($selected_attribute == $opti_array['id'])) {

echo '<tr><td align="center"><input type="radio" name ="id[' . $products_options_name['products_options_id'] . ']" value="' . $opti_array['id'] . '" ></td></tr></table></td>';

 

}

else {

echo '<tr><td align="center"><input type="radio" name ="id[' . $products_options_name['products_options_id'] . ']" value="' . $opti_array['id'] . '" onChange="'.showPrice(this.form).'"></td></tr></table></td>';

}

$count++;

if ($count%OPTIONS_IMAGES_NUMBER_PER_ROW == 0) {

echo '</tr><tr>';

$count = 0;

}

}

echo '</table>';

}

 

?>

</td></tr>

<?php

}

?>

</table>

<?php

}

?>

 

 

Does anyone see how/where I can make it use the js?

 

Below is how I changed the js to work in this file (this is just shooting in the dark as my programing is very weak):

 

function FormatNumber($num)

{

if(isNaN($num)) { $num = "0"; }

$sign = ($num == ($num = Math.abs($num)));

$num = Math.floor($num*100+0.50000000001);

$cents = $num%100;

$num = Math.floor($num/100).toString();

if($cents<10) { $cents = "0" + $cents; }

for ($i = 0; $i < Math.floor((num.length-(1+$i))/3); $i++)

{

$num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3));

}

return (((sign)?'':'-') + num + '.' + cents);

}

function showPrice($form)

{

$myTotalPrice = 0;

$showUP = 0;

$myMathProblem = "";

$myItemPrice = parseFloat(form.nuPrice.value);

for ($i = 0; $i < form.elements.length; $i++) {

$e = form.elements($i);

 

if ( e.type == 'select-one' ){

$showUP = 1;

$Item = e.selectedIndex;

$myPrice = e.options(Item).text;

$myDollarSign = myPrice.indexOf("$",0);

 

if ( $myDollarSign = -1){

$myParSign = myPrice.indexOf(")", $myDollarSign);

$myAttributeString = myPrice.substring($myDollarSign+1, $myParSign);

$myAttributeString = myAttributeString.replace("/","/","");

$myAttributePrice = parseFloat($myAttributeString);

$myMathProblem = myPrice.charAt($myDollarSign - 1);

} else { $myAttributePrice = 0; }

if ($myMathProblem == "-")

{

$myTotalPrice = $myTotalPrice - $myAttributePrice;

} else {

$myTotalPrice = $myTotalPrice + $myAttributePrice;

}

}

}

if ( showUP )

{

$myTotalPrice = FormatNumber($myTotalPrice + $myItemPrice);

document.getElementById("productNEWprice").$innerHTML = "Subtotal Price with Options $" + $myTotalPrice;

}

}

 

This "seems" to work except for the parseFloat call.

 

Is there a way to modify this to work?

 

I have been tempted to try to just add in somewhere to the file a reference to a js script file holding all of this, would that work? if so how show I go about doing it?

 

Any ideas or suggestion would be great, as I am totally stumped right now.

 

RavenWulf

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