The Business Logic is: If product is already purchased, upgrade the product
I have a customer input form to get information, along with some fields which should be auto populated based on what the customer chooses.
Screen Shot:
https://i.stack.imgur.com/Fkyim.png
Note: Price and Shipping Weight are done with Ajax,
When we come to the shipping cost I am getting it from Magento, using a PHP function.
form :
https://paste.ofcode.org/335FVUhpBGbazQtrcPLVQUs
PHP :
sp_cost.php
https://paste.ofcode.org/hvG2sP9TW9CEPgMMuKXNuw
From the above code I am given the predefined value,
$results = getShippingEstimate('14419','1',"IN","642001");
How can i get country and zipcode from the user entry and return the shipping cost?
8 1633 gits 5,390
Expert Mod 4TB
in the code here: https://paste.ofcode.org/335FVUhpBGbazQtrcPLVQUs
you can easyly see that at the bottom are 3 script-elements that basically do assign an event-handler (onchange) to the element with the id="new" - and all 3 handlers invoke a request each with passing the exact same data to different endpoints: -
var old_val = $("#old option:selected").val();
-
var new_val = $("#new option:selected").val();
-
-
// ...
-
-
data: { old: old_val, new: new_val},
-
this means that you simply need to retrieve the data from the fields correctly in your javascript sections and pass it in the data-object of the ajax call to the endpoint(s) that should receive it. For optimization of all that it would even be preferable to just send 1 request and not fire 3 in parallel.
@gits : Okay, with my code how can i use input form values in PHP function arguments,
as said,
sp_cost.php https://paste.ofcode.org/hvG2sP9TW9CEPgMMuKXNuw
From the above code I am given the predefined value, - $results = getShippingEstimate('14419','1',"IN","642001");
-
How can i pass my zip code & country from form and pass by using ajax.
i know the following is wrong, how can i write the right code, - <script>
-
$(document).ready(function(){
-
$('#new').on('change',function(){
-
-
var old_val = $("#old option:selected").val();
-
var new_val = $("#new option:selected").val();
-
-
$.ajax({
-
type: "POST",
-
// url: "ajax_ship_cost_data.php",
-
url: "sp_cost.php",
-
dataType: "text",
-
data: { old: old_val, new: new_val},
-
success: function(data)
-
{
-
// Check the output of ajax call on firebug console
-
//console.log(data);
-
$('#findata').html(data);
-
$('#shipping_cost').val(data);
-
-
}
-
});
-
-
});
-
});
-
</script>
gits 5,390
Expert Mod 4TB
as i said - you need to retrieve the correct values from the form elements and pass it to the data object in the jQuery ajax call. I suggest to read the jQuery API docs if you don't know how to do it - i probably won't write the code for you - basically its easy changes and considered as the minimum knowledge when working with jQuery. you can start from here: http://api.jquery.com/val/
for example and then go on from there.
Using this -> http://api.jquery.com/val/ i did my couple of fields as you see [Price & weight]. Here shipping cost field is not predefined value, actually it gets from Magento [PHP CMS]. I need some help regarding how to pass my value which is getting from Magento and insert into shipping cost field, for me, it's quite tough, workout :
My PHP function : - <?php
-
ob_start();
-
// require_once(__DIR__ . '/app/Mage.php');
-
require_once('./../app/Mage.php');
-
umask(0);
-
ini_set('display_errors',true);
-
ini_set('memory_limit', '1024M');
-
Mage::app()->loadArea('frontend');
-
-
function getShippingEstimate($productId,$productQty,$countryId,$postcode ) {
-
-
// $quote = Mage::getModel('sales/quote')->setStoreId(Mage::app()->getStore('default')->getId());
-
$quote = Mage::getModel('sales/quote')->setStoreId(Mage::app()->getStore('english')->getId());
-
$_product = Mage::getModel('catalog/product')->load($productId);
-
-
$_product->getStockItem()->setUseConfigManageStock(false);
-
$_product->getStockItem()->setManageStock(false);
-
-
$quote->addProduct($_product, $productQty);
-
$quote->getShippingAddress()->setCountryId($countryId)->setPostcode($postcode);
-
$quote->getShippingAddress()->collectTotals();
-
$quote->getShippingAddress()->setCollectShippingRates(true);
-
$quote->getShippingAddress()->collectShippingRates();
-
-
$_rates = $quote->getShippingAddress()->getShippingRatesCollection();
-
-
$shippingRates = array();
-
foreach ($_rates as $_rate):
-
if($_rate->getPrice() > 0) {
-
$shippingRates[] = array("Title" => $_rate->getMethodTitle(), "Price" => $_rate->getPrice());
-
}
-
endforeach;
-
-
return $shippingRates;
-
-
}
-
-
// echo "<pre>";
-
// product id, quantity, country, postcode
-
// print_r(getShippingEstimate('14419','1',"IN","642001"));
-
-
// echo "</pre>";
-
-
//$results = getShippingEstimate('14419','1',"IN","642001");
-
-
// $results = getShippingEstimate('14419','1',"US","99501");
-
-
-
-
<!-- if(isset($_POST['zip_postal_code']) && isset($_POST['country']))
-
{
-
$zip_postal_code = $_POST['zip_postal_code'];
-
$country = $_POST['country'];
-
} -->
-
-
-
$results = getShippingEstimate('14419','1',"IN","642001");
-
-
//$results = getShippingEstimate('14419','1',"$country","$zip_postal_code");
-
-
-
$count = -1;
-
echo "<select>";
-
foreach ($results as $result):
-
$count++;
-
?>
-
<option value="<?php echo $count; ?>"> <?php echo $result["Title"]." - Rs ".$result["Price"]?>
-
</option>
-
-
<?php
-
endforeach;
-
echo "</select>";
-
?>
FYI -> In PHP function :
shipping cost calculated using :
$results = getShippingEstimate('14419','1',"IN","642001");
and passing the shipping cost value using,
<option value="<?php echo $count; ?>"> <?php echo $result["Title"]." - Rs ".$result["Price"]?>
</option>
Note: By using $results = getShippingEstimate('14419','1',"IN","642001"); its returned the value, i need if customer enter the zip_code and country, once the customer entered those values using ajax passing value to -> $results = getShippingEstimate('14419','1',"IN","642001"); and returned to the shipping cost.
I hope I explained well. Can I get some help?
Solved :
Actually error in Ajax & error in passing fields, - <script>
-
$(document).ready(function(){
-
$('#new').on('change',function(){
-
-
var zip = $("#zip_postal_code").val();
-
var country = $("#country").val();
-
-
$.ajax({
-
type: "POST",
-
// url: "ajax_ship_cost_data.php",
-
url: "sp_cost.php",
-
dataType: "text",
-
data: {zip_postal_code : zip, country: country},
-
success: function(data)
-
{
-
// Check the output of ajax call on firebug console
-
//console.log(data);
-
$('#findata').html(data);
-
$('#shipping_cost').val(data);
-
-
}
-
});
-
-
});
-
});
-
</script>
gits 5,390
Expert Mod 4TB
grats :) the only thing to note is that the requests are only send when the value of the select-element with id="new" is changed. so if a user only changes some other field like zip-code or something else - the request is not fired. If that's how it should work then all is good - else you would need to attach the the correct eventhandlers to the fields that are relevant for new calculations.
@gits I am facing error while select shipping cost, if i select anyone from dropdown all the values saves into db, how to modify my code.
Output : https://snag.gy/BIJZb7.jpg
Any help thanks.
gits 5,390
Expert Mod 4TB
this screenshot doesn't tell much. your program in fact acts as you programmed it. in case the code didn't change much - you fire at least 3 requests in parallel always when you change the value of the select-element with id="new". So you need to check all entrypoints that you call and even if its necessary/correct to call them all at the same time - and see what values they get received and what they then do - i cant help much with that without seeing more of the actual code.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Joe Ray |
last post by:
I am interested in passing encrypted HTML form data to a JSP page
where it is than decrypted. Can someone suggest a technique to do this
and the technology or encryption method I should use. If you...
|
by: Matt |
last post by:
I have a html form, and I want to transform html form data to xml
string. Given XSD (xml schema), how to transform the form data to xml
string?
|
by: Clive Moore |
last post by:
I have a database search web application in which the user is presented
with a search page. The search page has a number of values by the body
onload method.
My problem lies when the user...
|
by: teknowbabble |
last post by:
I would like to know how to convert HTML code that users input into a
TEXTAREA box on a HTML FORM into a separate WEBPAGE.
I have something like the diagram below on my webpage. The user is...
|
by: dragoncoder |
last post by:
Consider the following code.
#include <stdio.h>
int main()
{
int i =1;
printf("%d ,%d ,%d\n",i,++i,i++);
return 0;
}
|
by: bp_jobemail |
last post by:
I'm trying to use PHP to wrap the output of an HTML form before it goes
into a precompiled C cgi script.
Essentially, the company that I work for uses a purchased precompiled c
program for their...
|
by: burtell |
last post by:
I have designed an HTML form. The name of each element corresponds to a heading in an Access database on my computer. Is there a way for me to program the HTML form to send the data from the form...
|
by: burtell |
last post by:
Previously, I wrote:
I have designed an HTML form. The name of each element corresponds to a heading in an Access database on my computer. Is there a way for me to program the HTML form to send the...
|
by: sumap |
last post by:
hi i m trying to svave html form data into excel by save button but its not working and i can't findout the error where exactly where it is .
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |