delete condition if multiple checkbox unchecked in codeigniter - codeigniter

please help me i would like to delete some check box if checkbox unchecked.
My checkbox is automatic show from database my sql. and i would like to delete some checkbox when checkbox in not checked.
PLease Help
its my controller
public function edit_overview($id_product)
{
if ($this->input->post('submit')) {
foreach ($id_overview = $this->input->post('id_overview') as $rm) {
$check_idoverview = $this->Biostar->check_idoverview($id_product, $rm);
if ($check_idoverview==unchecked){
$data['file'] = $check_idoverview;
$this->Biostar->delete_overview($check_idoverview,$id_product);
}else{
if ($check_idoverview > 0) {
} else {
$datafield = array(
'id_product' => $id_product,
'id_overview' => $rm
);
$this->Biostar->saveoverviewproduct($datafield);
$message_success = "Data Has Been Update";
}
}
}
}
$data['message_success'] = #$message_success;
$field = $this->Biostar->get_overview($id_product);
$fieldid_product = $this->Biostar->get_id_product($id_product);
$data['field'] = $field;
$data['id_product'] = $fieldid_product;
$data['content'] = "biostar/edit_overview_product";
$this->load->view('dashboard/index', $data);
}
My Model
function delete_overview($check_overview,$id_product)
{
$sql = "delete from overview_briostar where id_overview='$check_overview' AND id_product='$id_product'";
return $sql;
}
My View
<form method="post" action="<?php echo base_url(); ?>biostar/add_overview_product/<?php echo $id_product->id_product; ?>">
<div class="box-body">
<?php foreach ($speed as $row){ ?>
<div class="checkbox">
<label>
<input type="checkbox" name="id_overview[]" onClick="EnableSubmit3(this)" value="<?php echo $row['id_overview']; ?>"<?php foreach ($field as $wor){ ?> <?php if($row['id_overview']==$wor['id_overview']) echo "checked";?> <?php } ?> ><?php echo $row['title']; ?>
</label>
</div>
<?php } ?>
<!-- /input-group -->
</div>
<div class="box-footer">
<input value="Submit" type="submit" id="submit3" name="submit" class="btn btn-primary">
</div>
</form>

Unchecked checkbox value will not get posted, so you have to use jquery and ajax
Your checkbox
<input class="id_overview" type="checkbox" name="id_overview[]" value="<?php echo $row['id_overview']; ?>"<?php foreach ($field as $wor){ ?> <?php if($row['id_overview']==$wor['id_overview']) echo "checked";?> <?php } ?> ><?php echo $row['title']; ?>
your jquery
<script type="text/javascript">
$(document).ready(function() {
$("form#frm").submit(function(e) { // give a id to your form
e.preventDefault();
var ids = new Array();
$('.id_overview').each(function() {
if ($(this).is(':checked')) {
} else {
ids.push($(this).val());
}
});
$.ajax({
// send ids through your ajax code
});
});
});
</script>
create a new function and call it by ajax to delete the ids.

You can try like this
<form method="post" action="<?php echo base_url(); ?>biostar/add_overview_product/<?php echo $id_product->id_product; ?>">
<div class="box-body">
<?php foreach ($speed as $row){ ?>
<div class="checkbox">
<label>
<input type="hidden" name="all_id[]" value="<?php echo $row['id_overview']; ?>" />
<input type="checkbox" name="id_overview<?php echo $row['id_overview']; ?>" onClick="EnableSubmit3(this)" value="<?php echo $row['id_overview']; ?>"<?php foreach ($field as $wor){ ?> <?php if($row['id_overview']==$wor['id_overview']) echo "checked";?> <?php } ?> ><?php echo $row['title']; ?>
</label>
</div>
<?php } ?>
<!-- /input-group -->
</div>
<div class="box-footer">
<input value="Submit" type="submit" id="submit3" name="submit" class="btn btn-primary">
</div>
</form>
and in you controller
if ($this->input->post('submit')) {
foreach($all_id as $row_id)
{
if($this->input->post('id_overview'.$row_id))
{
//do action where id is present
}
else
{
//do action if unchecked by getting id $row_id
}
}
}

Related

Generating admission number using id in MYSQL. I want code from CodeIgniter

In my project, I have a student id no. It should auto increment. I want to auto-generate an admission number. How do I do it?
This is my controller
$insert_id = $this->student_model->add($data);
$data_new = array(
'student_id' => $insert_id,
'class_id' => $class_id,
'section_id' => $section_id,
This is my model
public function add($data) {
if (isset($data['id'])) {
$this->db->where('id', $data['id']);
$this->db->update('students', $data);
} else {
$this->db->insert('students', $data);
return $this->db->insert_id();
}
}
Here is my view
<form id="form1" action="<?php echo site_url('student/create') ?>" id="employeeform" name="employeeform" method="post" accept-charset="utf-8" enctype="multipart/form-data">
<div class="box-body">
<div class="tshadow mb25 bozero">
<h4 class="pagetitleh2"><?php echo $this->lang->line('student'); ?> <?php echo $this->lang->line('admission'); ?> </h4>
<div class="around10">
<?php if ($this->session->flashdata('msg')) { ?>
<?php echo $this->session->flashdata('msg') ?>
<?php } ?>
<?php echo $this->customlib->getCSRF(); ?>
<input type="hidden" name="sibling_name" value="<?php echo set_value('sibling_name'); ?>" id="sibling_name_next">
<input type="hidden" name="sibling_id" value="<?php echo set_value('sibling_id',0); ?>" id="sibling_id">
<div class="row">
<div class="col-md-3">
<div class="form-group">
<label for="exampleInputEmail1"><?php echo $this->lang->line('admission_no'); ?></label> <small class="req"> *</small>
<input autofocus="" id="admission_no" name="admission_no" placeholder="" type="text" class="form-control" value="<?php echo set_value('admission_no', date($this->customlib->getSchoolDateFormat())); ?>" name="admission_no" class="form-control">
<span class="text-danger"><?php echo form_error('admission_no'); ?></span>
</div>
Here admission number put manually, but I want it auto-created. I don't know how to do. I'm new with CodeIgniter.
My database
My form view
if you want to add unique admission you must chick the admission or use this query
$this->db->order_by('admission_no','DESC');
$this->db->get('students',1)->row()->admission_no + 1;
Put the bellow code in your view in your admission input which id of it is id="admission_no" romove the input and copy paste the code. this get the lastest admission no and then add 1 to the admission no also you can remove this value and add manually another value. that must be unique
<?php
$this->db->order_by('admission_no','DESC');
$auto-add = $this->db->get('students',1)->row()->admission_no + 1;
?>
<input autofocus="" id="admission_no" name="admission_no" placeholder="" type="text" class="form-control" value="<?php echo $auto-add; ?>" class="form-control">

if click default button address should be default

One user multiple shipping address how to make it as default,if click the make as default button,that address should be default and remaining all address shown the make as default button in a particular address box,except default address box.
view page
<?php foreach ($buyer_Address as $row) { ?>
<div class="col-md-4">
<div class="panel panel-default add_min_height">
<div class="panel-heading">Default:</div>
<input type="hidden" name="de" id="de" value="<?php echo $row->b_id; ?>">
<div class="panel-body">
<address><?php echo $row->b_fullname; ?><br>
<?php echo $row->b_street_address; ?>,<?php echo $row->b_locality ?>,<br>
<?php echo $row->b_landmark; ?>,
<?php echo $row->b_city; ?>, <?php echo $row->b_state; ?>,<?php echo $row->b_pincode; ?>
India
Phone number: <?php echo $row->b_mobile_number; ?></address>
</div>
<div class="panel-footer">
<a href="<?php echo base_url(); ?>index.php/welcome/buyereditaddress?id=<?php echo $row->b_id; ?>" >Edit</a>
<i class="fa fa-ellipsis-v"></i>
Delete
<i class="fa fa-ellipsis-v"></i>
<?php if ($row->status == '0') { ?>
<button type="submit" style="color:#337ab7;background: none !important;border: none;" name="default" id="default">Make as deafault</button>
<?php } ?>
</div>
</div>
</div>
<?php } ?>
controller
public function defaultAddress() {
$id = $this->input->post('de');
$this->BuyerProfile_Model->defaultAddress($id);
redirect('welcome/buyeraddresses');
}
model
function defaultAddress($id) {
$this->db->trans_start();
$this->db->query("UPDATE buyer_order_address SET status = '0' WHERE b_id = '$id'");
$this->db->query("UPDATE buyer_order_address SET status = '1' WHERE b_id = '$id'");
$this->db->trans_complete();
}

How do I grab only comments posted by current concrete5 logged in user?

This code displays all comments by all members. How can I make this only show comments that the current logged in user posted?
I know this is simple code but for the life of me I can not seem to get it.
The code listed below is the original code from the view.php file located in the guestbook block.
<?php $c = Page::getCurrentPage(); ?>
<h4 class="guestBook-title"><?php echo $controller->title?></h4>
<?php if($invalidIP) { ?>
<div class="ccm-error"><p><?php echo $invalidIP?></p></div>
<?php } ?>
<?php
$u = new User();
if (!$dateFormat) {
$dateFormat = t('M jS, Y');
}
$posts = $controller->getEntries();
$bp = $controller->getPermissionObject();
$dh = Loader::helper('date');
foreach($posts as $p) { ?>
<?php if($p['approved'] || $bp->canWrite()) { ?>
<div class="guestBook-entry<?php if ($c->getVersionObject()->getVersionAuthorUserName() == $u- >getUserName()) {?> authorPost <?php }?>">
<?php if($bp->canWrite()) { ?>
<div class="guestBook-manage-links">
<?php echo t('Edit')?> |
<?php echo t('Remove')?> |
<?php if($p['approved']) { ?>
<?php echo t('Un-Approve')?>
<?php } else { ?>
<?php echo t('Approve')?>
<?php } ?>
</div>
<?php } ?>
<div class="contentByLine">
<!---<?php echo t('Posted by')?>
<span class="userName">
<?php
if( intval($p['uID']) ){
$ui = UserInfo::getByID(intval($p['uID']));
if (is_object($ui)) {
echo $ui->getUserName();
}
}else echo $p['user_name'];
?>
</span>
<?php echo t('on')?>--->
<span class="contentDate">
<?php echo $dh->date($dateFormat,strtotime($p['entryDate']));?>
</span>
</div>
<?php echo nl2br($p['commentText'])?>
</div>
<?php } ?>
<?php }
if (isset($response)) { ?>
<?php echo $response?>
<?php } ?>
<?php if($controller->displayGuestBookForm) { ?>
<?php
if( $controller->authenticationRequired && !$u->isLoggedIn() ){ ?>
<div><?php echo t('You must be logged in for notes.')?> <?php echo t('Login')?> »</div>
<?php }else{ ?>
<a name="guestBookForm-<?php echo $controller->bID?>"></a>
<div id="guestBook-formBlock-<?php echo $controller->bID?>" class="guestBook-formBlock">
<!---<h5 class="guestBook-formBlock-title"><?php echo t('Leave a Reply')?></h5>--->
<form method="post" action="<?php echo $this->action('form_save_entry', '#guestBookForm-'.$controller->bID)?>">
<?php if(isset($Entry->entryID)) { ?>
<input type="hidden" name="entryID" value="<?php echo $Entry->entryID?>" />
<?php } ?>
<?php if(!$controller->authenticationRequired){ ?>
<label for="name"><?php echo t('Name')?>:</label><?php echo (isset($errors['name'])?"<span class=\"error\">".$errors['name']."</span>":"")?><br />
<input type="text" name="name" value="<?php echo $Entry->user_name ?>" /> <br />
<label for="email"><?php echo t('Email')?>:</label><?php echo (isset($errors['email'])?"<span class=\"error\">".$errors['email']."</span>":"")?><br />
<input type="email" name="email" value="<?php echo $Entry->user_email ?>" /> <span class="note">(<?php echo t('Your email will not be publicly displayed.')?>)</span> <br />
<?php } ?>
<?php echo (isset($errors['commentText'])?"<br /><span class=\"error\">".$errors['commentText']."</span>":"")?>
<textarea name="commentText"><?php echo $Entry->commentText ?></textarea><br />
<?php
if($controller->displayCaptcha) {
$captcha = Loader::helper('validation/captcha');
$captcha->label();
$captcha->showInput();
$captcha->display();
echo isset($errors['captcha'])?'<span class="error">' . $errors['captcha'] . '</span>':'';
}
?>
<br/><br/>
<input type="submit" name="Post Comment" value="<?php echo t('Save Note')?>" class="button"/>
</form>
</div>
<?php } ?>
Every $posts ($p) is an array. When you print the array you will notice the ID of the author is present in the array.
If you'd like to show only the comments of the logged in user, you should override the view.php and replace line number 16
<?php if($p['approved'] || $bp->canWrite()) { ?>
to
<?php if(($p['approved'] || $bp->canWrite()) && $u->getUserID() == $p['uID']) { ?>
When you've changed that line of code, a user should only see his/her comments and not the comment of someone else.

Magento display message on page

I start to give my luck on magento for weeks now. Challenges since then. I am trying to display message above my input box but to no avail. Below are my phtml and controller.
password.phtml
<div id="account-profile">
<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
<form action="<?php echo Mage::getUrl('customer/account/emailopt'); ?>" method="post">
<input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" />
<div class="fieldset">
<ul class="form-list">
<li class="fields">
<div class="field">
<div class="input-box">
<label for="email"><?php echo $this->__('Email') ?><span class="required">*</span></label>
<input name="email" id="email" title="Email" value="" class="required-entry input-text validate-email" type="text" />
</div>
</div>
</li>
</ul>
</div>
<button type="submit" class="btn-dbbdr" title="<?php echo $this->__('Edit Options') ?>"><span><span><?php echo $this->__('Edit Options') ?></span></span></button>
</form>
accountController.php
public function emailoptAction()
{
if (!$this->_validateFormKey()) {
return $this->_redirect('*/emailoptions');
}
$customer = Mage::getSingleton('customer/session')->getCustomer();
$email = $customer->getEmail();
$_email =$this->getRequest()->getParam('email');
if ($email != $_email) {
echo 'This is not your valid email';
} else {
echo 'proceed here';
}
$this->_redirect('*/emailoptions');
}
what happens here is everytime i click on submit, it just echo the message and then redirect to that page again.
You are redirecting after echoing that might not work.
Use bellow code for message display.
$message = $this->__('Error: This is not your valid email');
Mage::getSingleton('core/session')->addError($message);
More Information here
UPDATE
public function emailoptAction()
{
if (!$this->_validateFormKey()) {
return $this->_redirect('*/emailoptions');
}
$customer = Mage::getSingleton('customer/session')->getCustomer();
$email = $customer->getEmail();
$_email =$this->getRequest()->getParam('email');
if ($email != $_email) {
//echo 'This is not your valid email';
$message = $this->__('This is not your valid email');
Mage::getSingleton('core/session')->addError($message);
} else {
//echo 'proceed here';
$message = $this->__('proceed here');
Mage::getSingleton('core/session')->addSuccess($message);
}
$this->_redirect('*/emailoptions');
}
If you are working in admin panel then use this
Mage::getSingleton('adminhtml/session')->addError("Error here");
otherwise use this for frontend
Mage::getSingleton('core/session')->addError("Error here");
For checkout
Mage::getSingleton('checkout/session')->addError("Error here");
Use these codes in your controller.
Easy i think
if ($email != $_email) {
Mage::getSingleton('adminhtml/session')->addError("Not valid"); //change adminhtml as per need
$this->_redirect('your page');
} else {
Mage::getSingleton('adminhtml/session')->addSuccess("Valid");
$this->_redirect('your page');
}

Magento - Controller to Ajax Estimate Shipping: Load Block and display phtml

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();

Resources