Originally Posted by
DrByte
The context is important, but you're avoiding that in your posts.
Please explain WHY you're doing this.
What is the javascript activity you're doing, and why?
For adding a shipping estimate on product_info page, I create a new file as modules\shipping_estimator_Pinfo.php which modified from shipping_estimator.php
Code:
if (!defined('IS_ADMIN_FLAG')) {
die('Illegal Access');
}
if ($current_page_base != 'popup_shipping_estimator') {
require(DIR_WS_MODULES . '/pages/popup_shipping_estimator/jscript_addr_pulldowns.php');
}
?>
<script language="javascript" type="text/javascript">
function estimat_submit(){
document.cart_quantity.action = this.location.href;
update_zone(this.form);
document.cart_quantity.submit();
return false;
}
</script>
<?php
require_once('includes/classes/http_client.php');
$selected_country = "";
if(isset($_POST['zone_country_id'])){
$selected_country = $_POST['zone_country_id'];
$_SESSION['customer_selected_country']= $_POST['zone_country_id'];
}elseif($_SESSION['customer_selected_country']){
$selected_country = $_SESSION['customer_selected_country'];
}elseif ($_SESSION['customer_country_id']) {
$selected_country = $_SESSION['customer_country_id'];
}
require(DIR_WS_CLASSES . 'shipping.php');
$shipping_modules = new shipping;
$quotes = $shipping_modules->quote();
/** followed by the code to show the estimation result**/
That code will be call in the tpl_product_info_display.php and it is work. Now, I am trying to use ajax to update the estimation part only. I created a file with the same name as "shipping_estimator_Pinfo.php" in root fold.
Code:
<?php
require_once('/vendor/autoload.php');
require ('includes/application_top.php');
require_once('includes/classes/http_client.php'); // shipping in basket
$language_page_directory = DIR_WS_LANGUAGES.$_SESSION['language'].'/';
$selected_country = "";
if(isset($_POST['zone_country_id'])){
$selected_country = $_POST['zone_country_id'];
$_SESSION['customer_selected_country']= $_POST['zone_country_id'];
}elseif($_SESSION['customer_selected_country']){
$selected_country = $_SESSION['customer_selected_country'];
}elseif ($_SESSION['customer_country_id']) {
$selected_country = $_SESSION['customer_country_id'];
}
// weight and count needed for shipping !
require(DIR_WS_CLASSES . 'shipping.php');
$shipping_modules = new shipping;
$quotes = $shipping_modules->quote();
/** followed code to handle the $quotes **/
in the modules\shipping_estimator_Pinfo.php I modified the js code as
Code:
$(document).ready(function(){
$("#country").change(function(){
$.ajax({
type: "POST",
url: "shipping_estimator_Pinfo.php",
data: {
zone_country_id: $(this).children('option:selected').val(),
cart_quantity: $("input[name='cart_quantity']").val(),
products_id: <?php echo $_GET["products_id"];?>
},
dataType: "json",
success: function(data){
if (data.success) {
$("#createResult").html(data.msg);
} else {
$("#createResult").html("error:" + data.msg);
}
},
error: function(jqXHR){
alert("error:" + jqXHR.status);
},
});
});
});
Bookmarks