Zen Cart Logo
If this is your first visit, check our documentation. To post, register or login.
Forums / Customizing the Look of Your Shop / Templates, Stylesheets, Page Layout / How to add the customized price,quantiy and days of shipping?

How to add the customized price,quantiy and days of shipping?

Locked

Started by samchenthati on 9 Jan 2010, 1:20 AM · Views: 1,183

Results 1 to 4 of 4
This thread is locked. New replies are disabled.
9 Jan 2010, 1:20 AM
#1
samchenthati avatar

samchenthati

New Zenner

Join Date:
Jan 2010
Posts:
3
Plugin Contributions:
0

Post #1 by samchenthati

Hi,
Can anyone help me with this.... and very new to zencart and php.
Basically, my requirement was: For a product, I have to calculate the price depending upon the values entered by the user and that price selected by the user should be become unit price of the product and corresponding quantity and days of shipping should be updated.

To achieve that, I created the attributes for the product(baseprice=$0.00). I collected the values entered in those attributes text field using javascript in the tpl_modules_attributes.php page. An ajax calculate button would post those values to the CalculationScript.php where i calculate the price of the product and display the price table(which displays prices and quantity and days of shipping accordingly).

Upon the selection of one price and Addcart event, corresponding values of Unitprice, quantity, days of shipping should be reflected in the corresponding values of Shopping cart.

I able to overwrite the Unit price..by manuplating final prcie but not quantity and totals.. can anybody please give me some suggestions... !!!how to modify the quantity? and days of Shipping..? Plz iam pretty much in the bad. shape.. !!!

Thanx in advance.

11 Jan 2010, 11:20 PM
#2
jackie_taferner avatar

jackie_taferner

Totally Zenned

Join Date:
Jun 2009
Location:
Orange County, California
Posts:
547
Plugin Contributions:
3

Post #2 by jackie_taferner

hello sam,

can you please post the code you've used in these pages? it will be easier to troubleshoot that way.

Also, in order to port the numbers to display in the shopping cart, you'll need to edit this page too: includes/classes/shopping_cart.php

Jackie Taferner - JT Website Design
Custom Website Design and Ecommerce
Support the community. Don't Private Message, post your questions in the forum.

11 Jan 2010, 11:53 PM
#3
samchenthati avatar

samchenthati

New Zenner

Join Date:
Jan 2010
Posts:
3
Plugin Contributions:
0

Post #3 by samchenthati

<?php /** * Module Template * * Template used to render attribute display/input fields * * @package templateSystem * @copyright Copyright 2003-2005 Zen Cart Development Team * @copyright Portions Copyright 2003 osCommerce * @license <http://www.zen-cart.com/license/2_0.txt> GNU Public License V2.0 * @version $Id: tpl_modules_attributes.php 3208 2006-03-19 16:48:57Z birdbrain $ */ ?> <div id="productAttributes"> <?php if ($zv_display_select_option > 0) { ?> <h3 id="attribsOptionsText"><?php echo TEXT_PRODUCT_OPTIONS; ?></h3> <?php } // show please select unless all are readonly ?> <?php //var_dump($options_name); //echo $options_name["Part-N"][1]; //exit(); // place to enter your code for($i=0;$i<sizeof($options_name);$i++) { ?> <?php if ($options_comment[$i] != '' and $options_comment_position[$i] == '0') { ?> <h3 class="attributesComments"><?php echo $options_comment[$i]; ?></h3> <?php } ?> <div class="wrapperAttribsOptions"> <h4 class="optionName back"><?php echo $options_name[$i]; ?></h4> <div class="back"><?php echo "\n" . $options_menu[$i]; ?></div> <br class="clearBoth" /> </div> <?php if ($options_comment[$i] != '' and $options_comment_position[$i] == '1') { ?>
<div class="ProductInfoComments"><?php echo $options_comment[$i]; ?></div>
<?php } ?> <?php if ($options_attributes_image[$i] != '') { ?> <?php echo $options_attributes_image[$i]; ?> <?php } ?> <br class="clearBoth" /> <?php } ?>

<?php // Customized Code for checking the values entered in the form // and using those values to calculate the final price according // to the Business logic of EM solutions, with the php script and // displaying them with the an ajax call. ?>

<html><body> <!-- Starting the javascript --> <script language="javascript" type="text/javascript">

//Function to hide the Estimated price field value.
/* window.onload=function(){
var att1 = document.getElementById('attrib-20-0');
var att2 = document.getElementById('attrib-26-0');

	if(att1.style.display != 'none' && att2.style.display != 'none' ){
		att1.style.display = 'none';
		att2.style.display = 'none'; 
     }

} */

var count=0; //global variable;
var quantity=0;
//Browser Support Code
function ajaxFunction(){
var ajaxRequest; // The variable that makes Ajax possible!

try{
	// Opera 8.0+, Firefox, Safari
	ajaxRequest = new XMLHttpRequest();
} catch (e){
	// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
			} 
			catch (e) {
				try{
					ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
					} 
				catch (e){
			// Something went wrong
			alert("Your browser broke!");
			return false;
			}
		}
	}

// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
//var ajaxDisplay = document.getElementById('ajaxDiv');
document.getElementById('ajaxDiv').innerHTML = ajaxRequest.responseText;

	}
}

// Getting the values entered in the form
var x1 = document.getElementById('attrib-10-0').value;
var x2 = document.getElementById('attrib-9-0').value;
var x3 = document.getElementById('attrib-21-0').value;
var x4 = document.getElementById('attrib-11-0').value;

 // checking for the first radio button 	 
 if(document.getElementById('attrib-12-69').checked)
	{
		var x5="1";		
	}
 else if(document.getElementById('attrib-12-70').checked)	
	{
		var x5="2";
	}
		
 q1 = document.getElementById('q1').value;
 q2 = document.getElementById('q2').value;
 q3 = document.getElementById('q3').value;
 q4 = document.getElementById('q4').value;
 var sid = Math.random();

//Building the url to be sent
var queryString = "?x1=" + x1 + "&x2=" + x2 + "&x3=" + x3 + "&x4=" + x4 +"&x5=" +x5 + "&q1=" + q1 + "&q2=" + q2 + "&q3=" + q3 + "&q4=" + q4 +"&sid=" + sid;

//Just alerts the queryString which is been sent and souly used for the debugging - will be removed soon.
//alert("count:" +count);
//alert("Query:" +queryString);
alert("Please Click OK to display the Caculated Price Table");

//ajax call
ajaxRequest.open("GET","calculationScript.php" + queryString, true);
ajaxRequest.send(null);

}//end of ajax function

// This function will show the hidden Elements by object ID
// Works with IE and Mozilla based browsers
// This function also calls the ajax function
function showID(obj){

if(count==0){
	var el = document.getElementById(obj);
	if(el.style.display != 'none'){
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
	count++;
	ajaxFunction(); // Calling the ajax function;
	
}
else{
	alert("User Requested for the Re-Caculation");
	ajaxFunction(); // Calling the ajax function for the second time and onwards;
}					

}// end of the function;

// To check the value of the Radio Button's selected from the Price-table.
// and write that selected value into Estimated price fields value and
// Quantity field
function ShowValue(id){

if(document.getElementById('Radio'+id).checked)
{  
	var val=document.getElementById('Radio'+id).value;
	var r = confirm("Click OK for the Estimated Price");
	if (r==true){
	alert("Price selected is: $" + val);
	document.getElementById('attrib-26-0').value= val;
	
	// writing in quantity text field.
	switch(true){
	case (id<5):
	 document.getElementById('attrib-20-0').value=q1;
	 quantity=q1;
	break;
	case (id<10): 
	 document.getElementById('attrib-20-0').value=q2;
	 quantity=q2;
	break; 
	case (id<15):
	 document.getElementById('attrib-20-0').value=q3;
	 quantity=q3;
	break; 
	case (id<20):
	 document.getElementById('attrib-20-0').value=q4; 
	 quantity=q4;
	break;
	default: break; 
	} 
	
	ajaxFunction1();
		
	}
	else{
	alert("Please select the other Price");
	}	
} 				

}// end of the function.

function ajaxFunction1(){
var ajaxRequest; // The variable that makes Ajax possible!

try{
	// Opera 8.0+, Firefox, Safari
	ajaxRequest = new XMLHttpRequest();
} catch (e){
	// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
			} 
			catch (e) {
				try{
					ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
					} 
				catch (e){
			// Something went wrong
			alert("Your browser broke!");
			return false;
			}
		}
	}

// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
//var ajaxDisplay = document.getElementById('ajaxDiv');
//document.getElementById('ajaxDiv').innerHTML = ajaxRequest.responseText;
var cart_qty=ajaxRequest.responseText;
alert("cart_qty:"+cart_qty);
}
}

var rid=Math.random();
var cv=quantity;
var queryString1 = "?cv=" + cv + "&rid=" + rid; 
alert("queryString1:"+queryString1);

//ajax call
ajaxRequest.open("GET","save_cart.php" + queryString1, true);
ajaxRequest.send(null);

}//end of ajax function

</script><!-- end of javascript -->

<!-- Div tag to display Calculate Button --> <div align="center" > <form> <b> Qty1:</b> <input type="text" id="q1" size="7" /> <b> Qty2:</b> <input type="text" id="q2" size="7" /> <b> Qty3:</b> <input type="text" id="q3" size="7"/> <b> Qty4:</b> <input type="text" id="q4" size="7"/> <br /><br /> <input type='button' style = 'padding:4px 20px 4px 20px;font-weight:bold' onClick="showID('ajaxDiv')" value="CALCULATE" /> </form> <br/> <br/>
<!-- Hidden Div tag which will be shown upon the Click event of Calculate button -->
<div id='ajaxDiv' style="display:none;">
</div> <br/> <br/>	
</div> </body></html> <?php if ($show_onetime_charges_description == 'true') { ?>
<div class="wrapperAttribsOneTime"><?php echo TEXT_ONETIME_CHARGE_SYMBOL . TEXT_ONETIME_CHARGE_DESCRIPTION; ?></div>
<?php } ?> <?php if ($show_attributes_qty_prices_description == 'true') { ?>
<div class="wrapperAttribsQtyPrices"><?php echo zen_image(DIR_WS_TEMPLATE_ICONS . 'icon_status_green.gif', TEXT_ATTRIBUTES_QTY_PRICE_HELP_LINK, 10, 10) . ' ' . '<a href="javascript:popupWindowPrice(\'' . zen_href_link(FILENAME_POPUP_ATTRIBUTES_QTY_PRICES, 'products_id=' . $_GET['products_id'] . '&products_tax_class_id=' . $products_tax_class_id) . '\')">' . TEXT_ATTRIBUTES_QTY_PRICE_HELP_LINK . '</a>'; ?></div>
<?php } ?> </div>

From this page i collect the attribute values and passing them to calculationScript.php which calculates and echo's the price table and user select the appropriate price,quantity and days of shipping from the price table. upon which i have to update the shopping cart.php,. I hav to update the QUANTIY, AND unit PRICE and days of shipping exactly which user selected. can please tell me what to modify in shopping_cart.php. or shall i directly modify in the session itself??

12 Jan 2010, 4:48 PM
#4
jackie_taferner avatar

jackie_taferner

Totally Zenned

Join Date:
Jun 2009
Location:
Orange County, California
Posts:
547
Plugin Contributions:
3

Post #4 by jackie_taferner

The attached .zip file is the attribute calculator I've made (it's not an official release, but someday soon will be available in the downloads section). Looks like you're almost there with yours and it has a slightly different functionality (ie calculator directly on the product page).

My methods for adding an attribute calculator was different from yours, but the technique used on the shopping_cart.php page should still be somewhat similar.

Take a close look at shopping_cart.php (File Change.html is useful for seeing code changes). Notice the additional variables created and added together for $extraCharge. This $extraCharge variable is called later in the shopping cart, and is added to the totals.

What you need to do is search your custom calculating script, find the variable for the total you want to add, and use code similar to this:

$extraCharge = $YOUR_TOTAL_VARIABLE

You'll still need to use some of the other code found in shopping_cart.php, but you'll need to figure that out based on what portions you've already taken care of in your calculating script (ie you already have the product price multiplied, so no need for that code portion, etc).

Hope this helps!

Jackie Taferner - JT Website Design
Custom Website Design and Ecommerce
Support the community. Don't Private Message, post your questions in the forum.