1

On onestepcheckout page, in billing section we have a country field select box, on selecting country from drop-down, ajax request is send and the selected country is set as billing address's country. I want to create a country drop down with same functionality on cart page. I have created the country select box using the following code

  <?php $_countries = Mage::getModel('directory/country')
                                              ->getResourceCollection()
                                              ->loadByStore()
                                              ->toOptionArray(true);?>

and using foreach loop to show the options in a select box. Now I have problem with the functionality. On onestepcheckout page when the country is selected, an ajax request is send and the following country gets selected. I am trying to copy this process but could not succeed.Here is my ajax code in cart.phtml file

jQuery('#country').change(function(){
var countryName = (jQuery(this).val());
jQuery.ajax({
    type: 'POST',
    url: "<?php echo $this->getUrl('checkout/cart/estimatePost')?>",
    data: {'country_id' : countryName},
    success: function(data){
        alert(data);
    }

}); });

On onestepcheckout page ajax request hits the following url

  url: "<?php echo $this->getUrl('onestepcheckout/ajax/save_billing')?>"

I am trying to copy this function on cart page but could not understand how to proceed. Please any one have any idea on how to proceed.

save_billingAction() in Ajaxcontroller.php has lot of functionalities which I could not understand. I just want to save the country so that when the page is reloaded that country is set as billing address's country. Any one could help me how to proceed

1

For showing select box the below code is used

<?php echo Mage::getBlockSingleton('directory/data')->getCountryHtmlSelect() ?>

It shows country dropdown. Then on selecting the country the ajax request is

jQuery('#country').change(function(){
var countryId = (jQuery(this).val());
jQuery.ajax({
    type: 'POST',
    url: "<?php echo $this->getUrl('checkout/cart/custom_update_billing')?>",
    data: {'country_id': countryId},
    success: function(data){
    }
});

});

Now the function custom_update_billing that set country as billing address's default country

public function custom_update_billingAction()
{
    $country_id = $this->getRequest()->getParam('country_id');
    $address = $this->_getQuote()->getBillingAddress()->setCountryId($country_id);
    $this->_getQuote()->save();
} 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.