Hello All This is a solution for Load more posts by wordpress ajax.
First of all suppose you have section like this.
<section class="hightech-news-content" >
<div class="container">
<?php
$page_number = (get_query_var('paged')) ? get_query_var('paged') : 1;
$page_link = get_pagenum_link(9999999999);
$args = array('post_type' => 'post','posts_per_page' => 3,'paged'=>$page_number);
$the_query = new WP_Query( $args );
$max_page = $the_query->max_num_pages;
?>
<div class="row news-list-row">
<?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="col-lg-4 col-md-4 col-sm-6 hightech-news-list">
<div class="row hightech-news-list-row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-4 hightech-news-list-img">
<?php if(has_post_thumbnail()){ ?>
<img class="img-responsive" src="<?php echo get_the_post_thumbnail_url();?>">
<?php }else{ ?>
<img class="img-responsive" src="<?php echo get_template_directory_uri(); ?>/images/Img-1.png">
<?php } ?>
<img class="hi_img" src="<?php echo get_template_directory_uri(); ?>/images/Hi.png">
</div>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-8 hightech-news-list-content">
<h3><?php the_title(); ?></h3>
<p><?php echo substr(strip_tags($post->post_content), 0, 80)."...";?></p>
<br>
<h4>> Lee verder</h4>
</div>
</div>
</div>
<?php endwhile; ?>
<?php endif ;?>
<div class="clear"></div>
</div>
<div class="text-center loading-img">
<img id="loading-img" src="<?php echo get_template_directory_uri(); ?>/images/loading.gif" >
</div>
<div class="event-more">
<a href="javascript:void(0)" id="load-more" onclick="loadMoreFun();" data-pagenumber="<?php echo $page_number; ?>" data-maxpage="<?php echo $max_page; ?>" data-pagelink="<?php echo $page_link; ?>">
<h4><img src="<?php echo get_template_directory_uri(); ?>/images/next.png" >Bekijk de agenda</h4>
</a>
</div>
</div>
</section>
Now for loadMoreFun() we can add a script like this.
<script type="text/javascript">
function loadMoreFun() {
var next_page = jQuery('#load-more').data("pagenumber");
var max_page = jQuery('#load-more').data("maxpage");
var next_page_url = jQuery('#load-more').data("pagelink");
var $load_more_btn = jQuery(this);
var request_data = jQuery(this).attr('pagenumber');
next_page++;
jQuery('#load-more').data('pagenumber',next_page);
var next_link = next_page_url.replace(/\d+(\/)?$/, next_page + '$1');
if(next_page <= max_page) {
var post_type = 'post';
$.ajax({
type : 'POST',
url : next_link,
cache: false,
beforeSend: function(){
jQuery('.loading-img').show();
},
complete: function(){
jQuery('.loading-img').hide();
},
success: function(response) {
if (jQuery(response).find('.hightech-news-list')){
var newElems = jQuery(response).find('.news-list-row').html();
jQuery('.news-list-row').append(newElems);
if(next_page == max_page){
jQuery('#load-more').text('No More News Available');
}
} else{
}
}
});
}
}
</script>
Hope it will be helpful for everyone.Please let me know it another help required.
Related
I want when user click on "more detail href". they should get this detail on modal the box.
<ul class="list-tickets">
<?php foreach ($searchFlights as $searchFlight) {
//One Way Logic
$stopInfo_O = "";
$stopCount_O = 0;
$AirlineLogo_O = $this->search_model->getAirlinelogo($searchFlight->airline_idO);
$finalDepartdate_O = $searchFlight->departure_dateO;
$DepartAirpot_O = $this->search_model->getAirportCode($searchFlight->depart_airportidO);
$totalFlightTime_O = $searchFlight->total_flighttimeO;
$finalArrivaldate_O = $searchFlight->arrival_dateO;
$totalBaggage_O = $searchFlight->baggageO;
$stopOvertime1 = $searchFlight->stopover1_staydurationO;
$className0 = $searchFlight->classNameO;
$ArrivalAirpot_O = $this->search_model->getAirportCode($searchFlight->arrival_airportidO);
$flightPrice = $searchFlight->flightPrice;
if($searchFlight->operatedby_airlineidO == "0") {
$operatedAirlinename = "";
} else {
$operatedAirlinename = $this->search_model->getAirlinename($searchFlight->operatedby_airlineidO);
}
//Stops Handling Oneway
if(empty($searchFlight->stopover1_airportidO) && empty($searchFlight->stopover2_airportidO)){ $stopInfo_O = "Direct"; }
if($searchFlight->stopover1_airportidO != 0){ $stopCount_O++; }
if($searchFlight->stopover2_airportidO != 0){ $stopCount_O++; }
if($stopCount_O>0){
$stopInfo_O .= $stopCount_O." Stop ";
//Stop oneway 1
$stopInfo_O .= $this->search_model->getAirportCode($searchFlight->stopover1_airportidO);
if($stopCount_O == 2) {
//Stop One Way 2
$stopInfo_O .= ", ".$this->search_model->getAirportCode($searchFlight->stopover2_airportidO);
}
}
?>
<li class="list-item">
<div class="list-item-inner">
<div class="list-item-main">
<!-- Oneway Section -->
<div class="list-item-top">
<div class="list-item-logo">
<img src="<?= base_url(); ?>uploads/<?php echo $AirlineLogo_O; ?>" alt="">
</div>
<div class="list-item-content">
<div class="list-item-content-left">
<!-- Final Departure Dates-->
<div class="text-bold text-base">
<?php echo $finalDepartdate_O; ?>
</div>
<!-- Departure Airport -->
<span class="small reveal-block">
<?php echo $DepartAirpot_O; ?>
</span>
</div>
<div class="list-item-content-line-wrapper small">
<!-- Total Flight Time -->
<div class="list-item-content-line-top">
<?php echo $totalFlightTime_O; ?>
</div>
<div class="list-item-content-line"></div>
<!-- Stops info -->
<div class="list-item-content-line-bottom text-primary">
<p title="<?php echo $stopOvertime1; ?>"><?php echo $stopInfo_O; ?> </p>
</div>
</div>
<div class="list-item-content-right">
<!-- Final Arrival date -->
<div class="text-bold text-base">
<?php echo $finalArrivaldate_O; ?>
</div>
<!-- Arrival Airport -->
<span class="small reveal-block">
<?php echo $ArrivalAirpot_O; ?>
</span>
</div>
</div>
</div>
</div>
<div class="list-item-footer ticket-holder-dt">
<h5 class="text-bold list-item-price"><?php echo COMMON_CurrencySymbol." ".$flightPrice;?></h5>
<span class="ticket-include"></span>
<span class="ticket-type">One way</span>
<a class="btn btn-info btn-xs btn-no-shadow" href="<?= base_url(); ?>searchflights/bookFlight?id=<?php echo $searchFlight->id; ?>">
Book Now
</a>
<br>
<a href="">
More detail <!-- I want when user click on it. they should get this detail on modal the box -->
</a>
<br>
<?php echo $className0; ?> Class
</div>
</div>
<div class="small text-gray-light list-item-subtitle">Operated by <?php echo $operatedAirlinename; ?></div>
<div class="tripbaggage">Baggage: <?php echo $totalBaggage_O; ?></div>
<?php } ?>
You can achieve this by implementing separate modal for each id inside for loop or
by implementing Ajax request to show the detail information of the corresponding id.
i try all of away that i know and suggestion on internet.
but all time return false.
please help me...
thanks
my error message is:
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: views/index.php
Line Number: 10
model.php
public function getBanner()
{
$this->db->select('album.id, album.cat_id , album.poster, album.slug, album.modify, category.id, category.name, category.slug');
$this->db->from('album,category');
$this->db->where('album.cat_id', 'category.id');
$query = $this->db->get();
if($query->num_rows() != 0)
{
$result = $query->result_array();
return $result;
}
else
{
return false;
}
}
controllers.php
$data['banner'] = $this->Fornt_model->getBanner();
showbanner.php
<section class="banner">
<div class="container">
<div class="row">
<div class="col-sm-12">
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<?php $item = 1; foreach($banner as $latest_poster): $item_class = ($item == 1) ? 'item active' : 'item'; ?>
<div class="<?php echo $item_class; ?>">
<img src="<?php echo base_url('images/poster/'.$latest_poster['poster']); ?>" class="img-responsive img-thumbnail">
<div class="carousel-caption caption">
<a href="<?php echo site_url('category/bollywood/'.$latest_poster['slug']); ?>" class="box">
<b class="h3"><?php echo $latest_poster['name']; ?></b>
<small class="p">Exclusive AT*<?php echo substr($latest_poster['modify'], 0, 10); ?></small>
</a>
</div>
</div>
<?php $item++; endforeach; ?>
</div>
</div>
</div>
</div>
<div class="clearfix" style="padding: 10px 0;"></div>
<div class="row hidden-xs">
<?php $itemto = 0; foreach($banner as $latest_poster): $item_class_active = ($itemto == 0) ? 'active' : ''; ?>
<div class="col-sm-2 pointer" data-target="#myCarousel" data-slide-to="<?php echo $itemto; ?>"><img src="<?php echo base_url('images/poster/'.$latest_poster['poster']); ?>" class="img-responsive img-thumbnail" /></div>
<?php $itemto++; endforeach; ?>
</div>
</div>
I think something wrong with your query.. try
if($query->num_rows() != 0)
{
$result = $query->result_array();
print_r($result);
}
make sure your array data is available..
If there is no rows, front_model->getBanner() will return the result as false. Due to this you are getting an error. Use following code
public function getBanner()
{
$this->db->select('album.id, album.cat_id , album.poster, album.slug, album.modify, category.id, category.name, category.slug');
$this->db->from('album,category');
$this->db->where('album.cat_id', 'category.id');
$query = $this->db->get();
return $query->result_array();
}
Hello Everybody I am new with Codeigniter I have a Registration form Popup.When User tries to Register. it register with using ajax but when user input invalid details it should shows Codeigniter Error Messages but it won't and popup automatically closed. what should i do. plz help
This is My Controller Function:-
public function register(){
$title['pageTitle'] = 'Register Page';
$this->load->library('form_validation');
$this->load->model('User_model');
$this->form_validation->set_error_delimiters('<div class = "error">','</div>');
$this->form_validation->set_rules('firstname','First Name','trim|required|alpha|min_length[3]|max_length[30]');
$this->form_validation->set_rules('lastname','Last Name','trim|required|alpha|min_length[3]|max_length[30]');
$this->form_validation->set_rules('email','Email','required|valid_email|is_unique[users.email]');
$this->form_validation->set_rules('password','Password','trim|required|md5');
$this->form_validation->set_rules('cpassword','Confirm Password','trim|required|md5|matches[password]');
if($this->form_validation->run() == false){
echo validation_errors();
}else {
$data['userdata'] = $this->User_model->addUser();
}
}
This is My Model funtion :-
public function addUser(){
$data = array(
'firstname' => $this->input->post('firstname'),
'lastname' => $this->input->post('lastname'),
'email' => $this->input->post('email'),
'password' => $this->input->post('password'),
);
$q = $this->db->insert($this->tablename,$data);
return $result = $q->result_array();
}
This is My View(Popup):-
<div class="modal fade login_form" id="signin_model" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content pdng_mdls">
<div class="modal-header model_hdngs">
<i class="fa fa-times" aria-hidden="true"></i>
<h4 class="modal-title" id="exampleModalLabel"></h4>
</div>
<div class="modal-body">
<div class="mdl_hdrs">
<?php echo form_label('Create Your Account', 'createyouraccount'); ?>
</div>
<?php
$attributes = array('name' => 'myform','id'=>'reg_form');
echo form_open('',$attributes); ?>
<div class="row">
<div class="col-sm-6">
<?php echo form_label('First Name:', 'firstname'); ?>
<?php echo form_input(array('id' => 'firstname','class'=>'inpt_bhg cracnt','name' => 'firstname','placeholder'=>'First Name'));?>
<span class="text-danger"><?php echo form_error('firstname'); ?></span>
</div>
<div class="col-sm-6">
<?php echo form_label('Last Name:', 'lastname'); ?>
<?php echo form_input(array('id' => 'lastname','class'=>'inpt_bhg cracnt','name' => 'lastname','placeholder'=>'Last Name'));?>
<span class="text-danger"><?php echo form_error('lastname'); ?></span>
</div>
<div class="col-sm-12">
<?php echo form_label('Email:', 'email'); ?>
<?php echo form_input(array('id' => 'email','class'=>'inpt_bhg cracnt','name' => 'email','placeholder'=>'Email Address'));?>
<span class="text-danger"><?php echo form_error('email'); ?></span>
</div>
<div class="col-sm-12">
<?php echo form_label('Password:', 'password'); ?>
<?php echo form_password(array('id' => 'registerpassword','class'=>'inpt_bhg cracnt','name' => 'password','placeholder'=>'Password'));?>
<span class="text-danger"><?php echo form_error('password'); ?></span>
</div>
<div class="col-sm-12">
<?php echo form_label('Confirm Password:', 'password'); ?>
<?php echo form_password(array('id' => 'registerpassword','class'=>'inpt_bhg cracnt','name' => 'cpassword','placeholder'=>'Confirm Password'));?>
<span class="text-danger"><?php echo form_error('cpassword'); ?></span>
</div>
</div>
<div class="progress model_progress_bar" id="example-progress-bar-hierarchy-container">
</div>
<div class="ps_str">Password Strength</div>
<span id = "example-getting-started-text"></span>
<div class="final_sbmt_btns">
<?php echo form_submit('submit', 'Create Account','class="finl_sbmt_btns"');?>
</div>
</form>
<div class="go_backs">Go Back</div>
</div>
</div>
</div>
</div>
And This is my AJAX :-
<script type="text/javascript">
$(document).ready(function() {
$('#reg_form').submit(function(){
$.ajax({
type: "POST",
url: BASE_URL + "User_Controller/register/",
data: $("#reg_form").serialize(),
success: function(res){
alert(res);
}
});
});
});
</script>
http://ajobis.brainiacstech.com/404_override error when i pass url
when i click on apply button to send action url this message shown is 404 page not found i think it is because of use of () brakets with test work, other url which has no any special charachter is being passed successfully, my code is as under
<div id="content-wrapper" class="container">
<div class="row">
<div class="col-lg-9">
<div>
<div class="content-wrapper">
<!-- <div class="content-header">
<script>
function goBack() {
window.history.back()
}
</script>
<div class="title"><h1><a onclick="goBack()"><img src="<?php echo base_url("resources/images/back-icon.jpg"); ?>" alt="">Back to Results</a></h1></div>
</div>-->
<div class="content">
<div id="search-result-wrapper">
<div class="title" style="color: #005580;"><h1><?php echo $job->job_title; ?></h1></div>
<div>
<p><?php echo $job->job_description; ?></p>
</div>
<?php if (!empty($job->question)) { ?>
<div class="title text-blue"><h2>Application Questions</h2></div>
<div class="question-awnser">
<ul>
<?php $counter = 0; ?>
<?php foreach ($job->question as $question) { ?>
<li><?php echo $question->question;
$counter++; ?>
<span class="answers">
<input type="radio" name="answers" id="yes" value="yes">
<label id="answer_<?php echo $counter; ?>" for="yes">Yes</label>
/
<input type="radio" name="answers" id="no" value="No">
<label for="no">No</label>
</span>
</li>
<?php } ?>
</ul>
</div>
<?php } ?>
<div class="section-row">
<div class="pull-right">
<div class="pull-left">
<img src="<?php echo base_url("resources/images/apply-icon.jpg"); ?>"> Apply
</div>
<div class="pull-left" id="<?php echo $job->id; ?>">
<button onclick="save_job('<?php echo $job->id; ?>')" class="btn btn-blue"><span class="glyphicon glyphicon-save"></span> Save</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php $this->load->view('front/common/job_detail_widget'); ?>
</div>
<div class="row">
<div class="col-lg-11">
<div class="title"><h3 style="color: #0a0;">Suggested Jobs</h3></div>
</div>
</div>
<div class="suggestion-jobs"><div class="row">
<!--suggestedJobs-->
<?php if (!empty($suggestedJobs)) { ?>
<?php foreach ($suggestedJobs as $suggestedJob) { ?>
<div class="col-lg-3 suggestions">
<input type="text" id="jobid" value="<?php echo $suggestedJob->job_url; ?>" style="display: none;">
<input type="text" id="jobid" value="<?php echo $suggestedJob->id; ?>" style="display: none;">
<div class="suggestions-info"><h4><?php echo $suggestedJob->job_title; ?></h4></div>
<div class="suggestions-info"><span>Salary: </span><?php echo $suggestedJob->min_salary; ?> - to - <?php echo $suggestedJob->max_salary; ?></div>
<div class="suggestions-info"><span>Location: </span><?php echo $suggestedJob->location; ?></div>
<div class="suggestions-info"><span>Posted on: </span><?php echo $suggestedJob->start_date; ?></div>
</div>
<?php } ?>
<?php } else { ?>
No Job Found
<?php } ?>
</div>
</div>
</div><!--
<!--</div>-->
<script src="<?php echo base_url("resources/js/icheck.js"); ?>"></script>
<script type="text/javascript">
function save_job(id) {
$.ajax({
dataType: 'json',
type: 'POST',
url: base_url + 'employee/add-to-favorite',
data: {
jobId: id
},
success: function(RESP) {
if (RESP.status == 200) {
$('#' + id).html("<button class='btn btn-green' disabled='disabled'><span class='glyphicon glyphicon-save'></span> Saved</button>");
displayUIMessage(RESP.message);
}
}
});
}
function check_killer_answers() {
var count = '<?php echo $counter; ?>';
var error = 0;
for (var i = 1; i <= count; i++) {
if ($('#answer_' + i).hasClass('active')) {
} else {
error++;
}
}
if (error == 0) {
window.location.href = '<?php echo base_url('employee/confirm-apply/' . #$job->job_url); ?>';
} else {
alert('Please answer all questions to apply.');
}
}
function report(id) {
$.ajax({
dataType: 'json',
type: 'POST',
url: base_url + 'employee/report-to-admin',
data: {
jobId: id
},
success: function(RESP) {
if (RESP.status == 200) {
displayUIMessage(RESP.message);
}
}
});
}
</script>
I copied estimatePostAction and made estimateAjaxPostAction (overriding core - I did not hack the core). The controller action works as well (class Mage_Checkout_CartController).
Now I want to get/create a block for replacing shipping block after estimate shipping with ajax. I tried this:
public function estimateAjaxPostAction()
{
$country = (string) $this->getRequest()->getParam('country_id');
$postcode = (string) $this->getRequest()->getParam('estimate_postcode');
$city = (string) $this->getRequest()->getParam('estimate_city');
$regionId = (string) $this->getRequest()->getParam('region_id');
$region = (string) $this->getRequest()->getParam('region');
$this->_getQuote()->getShippingAddress()
->setCountryId($country)
->setCity($city)
->setPostcode($postcode)
->setRegionId($regionId)
->setRegion($region)
->setCollectShippingRates(true);
$this->_getQuote()->save();
//$this->_goBack();
$this->loadLayout();
$block = $this->getLayout()->createBlock('Mage_Checkout_Block_Cart_Shipping','checkout.cart.shipping.ajax',array('template' => 'checkout/cart/shipping.phtml'));
if($block) {
$response = array();
$response['shipping'] = $block->toHtml();
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
}
}
The block checkout.cart.shipping.ajax was created. But toHtml() returns nothing.
My JSON returns:
{"shipping":""}
Why toHtml method doesn't work?
Edit: My block code (checkout/cart/shipping.phtml)
<?php /** #var $this Mage_Checkout_Block_Cart_Shipping */ ?>
<div class="row contem-shipping">
<div class="col-xs-10 shipping">
<div class="text-ship">
<h2><?php echo $this->__('Calcular o frete:') ?></h2>
<p><?php echo $this->__('Insira o CEP do endereço<br />no campo ao lado.') ?></p>
</div>
<div class="shipping-form">
<form action="<?php echo $this->getUrl('checkout/cart/estimatePost') ?>" method="post" id="shipping-zip-form">
<ul class="form-list">
<li class="no-display">
<div class="input-box">
<?php echo Mage::getBlockSingleton('directory/data')->getCountryHtmlSelect($this->getEstimateCountryId()) ?>
</div>
</li>
<?php if($this->getStateActive()): ?>
<li>
<label for="region_id"<?php if ($this->isStateProvinceRequired()) echo ' class="required"' ?>><?php if ($this->isStateProvinceRequired()) echo '<em>*</em>' ?><?php echo $this->__('State/Province') ?></label>
<div class="input-box">
<select id="region_id" name="region_id" title="<?php echo $this->__('State/Province') ?>" style="display:none;"<?php echo ($this->isStateProvinceRequired() ? ' class="validate-select"' : '') ?>>
<option value=""><?php echo $this->__('Please select region, state or province') ?></option>
</select>
<script type="text/javascript">
//<![CDATA[
$('region_id').setAttribute('defaultValue', "<?php echo $this->getEstimateRegionId() ?>");
//]]>
</script>
<input type="text" id="region" name="region" value="<?php echo $this->escapeHtml($this->getEstimateRegion()) ?>" title="<?php echo $this->__('State/Province') ?>" class="input-text" style="display:none;" />
</div>
</li>
<?php endif; ?>
<?php if($this->getCityActive()): ?>
<li>
<label for="city"<?php if ($this->isCityRequired()) echo ' class="required"' ?>><?php if ($this->isCityRequired()) echo '<em>*</em>' ?><?php echo $this->__('City') ?></label>
<div class="input-box">
<input class="input-text<?php if ($this->isCityRequired()):?> required-entry<?php endif;?>" id="city" type="text" name="estimate_city" value="<?php echo $this->escapeHtml($this->getEstimateCity()) ?>" />
</div>
</li>
<?php endif; ?>
<li>
<div class="input-box">
<input class="input-text validate-postcode<?php if ($this->isZipCodeRequired()):?> required-entry<?php endif;?>" type="text" id="postcode" name="estimate_postcode" value="<?php echo $this->escapeHtml($this->getEstimatePostcode()) ?>" />
</div>
</li>
</ul>
<div class="buttons-set">
<button id="button-cep" style="width: 100px;" type="button" title="<?php echo $this->__('Get a Quote') ?>" onclick="calculaFreteAjax(jQuery('#postcode').val()); return false;" class="btn btn-2 btn-2a"><?php echo $this->__('Get a Quote') ?></button>
</div>
</form>
<script type="text/javascript">
//<![CDATA[
new RegionUpdater('country', 'region', 'region_id', <?php echo $this->helper('directory')->getRegionJson() ?>);
//]]>
</script>
<?php $_shippingRateGroups = $this->getEstimateRates(); ?>
<?php if ($_shippingRateGroups): ?>
<form id="co-shipping-method-form" action="<?php echo $this->getUrl('checkout/cart/estimateUpdatePost') ?>">
<dl class="sp-methods">
<?php foreach ($_shippingRateGroups as $code => $_rates): ?>
<dt><?php echo $this->escapeHtml($this->getCarrierName($code)) ?></dt>
<dd>
<ul>
<?php foreach ($_rates as $_rate): ?>
<li<?php if ($_rate->getErrorMessage()) echo ' class="error-msg"';?>>
<?php if ($_rate->getErrorMessage()): ?>
<?php echo $this->escapeHtml($_rate->getErrorMessage()) ?>
<?php else: ?>
<input name="estimate_method" type="radio" value="<?php echo $this->escapeHtml($_rate->getCode()) ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> class="radio" />
<label for="s_method_<?php echo $_rate->getCode() ?>"><?php echo $this->escapeHtml($_rate->getMethodTitle()) ?>
<?php $_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax()); ?>
<?php $_incl = $this->getShippingPrice($_rate->getPrice(), true); ?>
<?php echo $_excl; ?>
<?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
(<?php echo $this->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
<?php endif; ?>
</label>
<?php endif ?>
</li>
<?php endforeach; ?>
</ul>
</dd>
<?php endforeach; ?>
</dl>
</form>
<?php endif; ?>
<script type="text/javascript">
//<![CDATA[
var coShippingMethodForm = new VarienForm('shipping-zip-form');
var countriesWithOptionalZip = <?php echo $this->helper('directory')->getCountriesWithOptionalZip(true) ?>;
coShippingMethodForm.submit = function () {
var country = $F('country');
var optionalZip = false;
for (i=0; i < countriesWithOptionalZip.length; i++) {
if (countriesWithOptionalZip[i] == country) {
optionalZip = true;
}
}
if (optionalZip) {
$('postcode').removeClassName('required-entry');
}
else {
$('postcode').addClassName('required-entry');
}
return VarienForm.prototype.submit.bind(coShippingMethodForm)();
}
//]]>
</script>
</div>
</div>
<div class="col-xs-6">
<?php
$totalItemsInCart = Mage::helper('checkout/cart')->getItemsCount(); //total items in cart
$totals = Mage::getSingleton('checkout/session')->getQuote()->getTotals(); //Total object
$subtotal = $totals["subtotal"]->getValue(); //Subtotal value
$grandtotal = $totals["grand_total"]->getValue(); //Grandtotal value
if(isset($totals['discount']) && $totals['discount']->getValue()) {
$discount = $totals['discount']->getValue(); //Discount value if applied
} else {
$discount = '';
}
$shipping = Mage::helper('checkout')->getQuote()->getShippingAddress()->getData();
$tax = $shipping["shipping_amount"];
/*if( $totals["tax"]->getValue()) {
$tax = $totals["tax"]->getValue(); //Tax value if present
} else {
$tax = '';
}*/
?>
<table class="totals-cart">
<tr>
<td class="total-tile">
Subtotal do pedido:
</td>
<td class="total-price">
<?php echo Mage::helper('core')->currency($subtotal, true, false); ?>
</td>
</tr>
<tr>
<td class="total-tile">
Frete:
</td>
<td class="total-price">
<?php echo Mage::helper('core')->currency($tax, true, false); ?>
</td>
</tr>
<?php if ($discount):?>
<tr>
<td class="total-tile">
Desconto:
</td>
<td class="total-price">
<?php echo Mage::helper('core')->currency($discount, true, false); ?>
</td>
</tr>
<?php endif;?>
</table>
</div>
</div>
<div class="row">
<div class="col-xs-16">
<div class="grand-total">
<p class="text">Total:</p>
<p class="price"><?php echo Mage::helper('core')->currency($grandtotal, true, false);?></p>
</div>
</div>
</div>
<script type="text/javascript">
function calculaFreteAjax(cep) {
jQuery('.contem-shipping .shipping').html('<span class="remove-frete" style="display: block; margin: 0 auto; width: 20px;" id="login-please-wait"><img src="http://sites.xpd.com.br/cpaps/skin/frontend/xpd/default/images/opc-ajax-loader.gif" class="v-middle" alt=""/></span>');
var param = {'country_id': 'BR','estimate_postcode': cep};
console.log(param);
jQuery.ajax({
type: "GET",
url: '<?php echo Mage::getBaseUrl().'checkout/cart/estimateAjaxPost/'; ?>', //My Custom Controller
data: param,
success: function(response) {
response = jQuery.parseJSON(response);
if(response.shipping) {
jQuery('.contem-shipping').parent().html(response.shipping);
}
else {
alert('Falha ao calcular o frete. Tente novamente.');
}
}
});
jQuery('#co-shipping-method-form dd input.radio').click(function(){
//I will submit the shipping method selected
});
}
</script>
Denis... I have modify code please check
public function estimateAjaxPostAction()
{
$country = (string) $this->getRequest()->getParam('country_id');
$postcode = (string) $this->getRequest()->getParam('estimate_postcode');
$city = (string) $this->getRequest()->getParam('estimate_city');
$regionId = (string) $this->getRequest()->getParam('region_id');
$region = (string) $this->getRequest()->getParam('region');
$this->_getQuote()->getShippingAddress()
->setCountryId($country)
->setCity($city)
->setPostcode($postcode)
->setRegionId($regionId)
->setRegion($region)
->setCollectShippingRates(true);
$this->_getQuote()->save();
$response = array();
$response['shipping']=$this->eastmatesajax();
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
}
protected function eastmatesajax()
{
$layout=$this->getLayout();
$layout->getMessagesBlock()->setMessages(Mage::getSingleton('checkout/session')->getMessages(true),Mage::getSingleton('catalog/session')->getMessages(true));
$block = $this->getLayout()->createBlock('checkout/cart_shipping')->setTemplate( 'checkout/cart/shipping.phtml');
return $block->toHtml();
}
Updated block issue solved using $this->_getQuote()->collectTotals(); before $this->_getQuote()->save();