Magento - How to make new shipping address (additional) as default - magento

I developed a custom checkout module and is working fine. During checkout for the first when I enter new billing and shipping address, they are getting set as default billing and shipping address, which is fine. Now, I have a requirement, whenever a new shipping address is entered, this should become as default shipping address. Somehow, I cannot make this work. I have tried the following:
$shipdata is a array having the new address details.
$shipAddress = $this->getQuote()->getShippingAddress();
$shipAddress->addData($shipdata);
$shipAddress->setIsDefaultShipping(true);
if($this->getQuote()->getDefaultShipping()) {
$this->getQuote()->setData('default_shipping', '');
$this->getQuote()->addAddress($shipAddress);
}
$this->getQuote()->collectTotals();
$this->getQuote()->save();
I also tried to add the following in the $shipdata
$shipdata['default_shipping'] = 1;
but also did not help.
Can some one help in this regard?

You could try to use an observer on the "customer_address_save_before" event. Setting the isDefaultShipping flag there will work. Only thing I don't know is checking whether you are in the checkout process.

In the form that posts to the next page simply include a hidden input

Related

What could cause Magento to change new address back to default address on Paypal redirect?

I'm getting a strange bug in Onepage checkout using Paypal Express.
Logged-in Customer enters new billing address "on-the-fly", sets 'Save in Addressbook' and 'Ship to this address', then proceeds through checkout.
Address is saved in the database correctly at this point.
Customer chooses Paypal and Magento goes through it's logic (collection totals, saving quote - twice and data checks, etc).
I've stepped through the logic using Xdebug and am not able to pinpoint exactly where but right before redirecting to Paypal in /app/code/core/Mage/Sales/Model/Quote.php on line 318 in afterSave() callback, there's a line
if (null !== $this->_addresses) {
$this->getAddressesCollection()->save();
}
In $this->getAddressesCollection(), the billing and shipping addresses are wrong, they're both the Customer's default. However, the database is still correct.
Once the ->save() fires, the correct ones are overwritten.
It certainly appears to be Magento bug but I need to find a solution. This is EE 1.11.1.0.
Anyone experienced this before?
Thanks
I had a similar bug and maybe its the same with you. If you select an address as your default address in the address book it screws up the one page checkout.
Say I have 3 people in my address book: John, Suzy and Bill.
One day I happen to be in my address book and I select John as my default billing and shipping address. Then I go to my cart, order some items, select John as billing, and select ship to a different address. On the next step I select Suzy as my ship to address. I click next to go to the shipping method step, but whoa, wait! Suzy's address has been overwritten and replaced with Johns address.
Its exactly the same issue posted about here (although I dont think the guy understands what happened, but the screenshots are the same result): http://www.magentocommerce.com/boards/viewthread/7520/P0/
The issue is in the opcheckout.js file. I have a fix. basically once a default address is selected the add new address form (hidden form) is always populated with your default address.
Normally, without a default address selected in address book, I believe that the opcheckout.js properly fills in the hidden fields with the address you selected in the select box.
The following modified opcheckout.js script: ( http://pastebin.com/chiwyRJZ ) will fix it so that the hidden fields are properly filled with the correct data. From what I understand is this is an old unfixed bug, perhaps from whichever version Magento added the Add New Address form in one page checkout
To apply the fix, copy the code from paste bin and replace it with the code in your themes opcheckout.js
Usually opcheckout.js is in skin\frontend\default\yourtheme\js
OR
\skin\frontend\base\default\js
I know it is too late to post this, but I faced this issue on Magento 1.9.x. not only on paypal, but all other payment methods.
Check this method witch called upon creating new Quote:
public function assignCustomerWithAddressChange

Get "Use Billing Address" from shipping address section of Onepage checkout

I'm trying to get the gift option message to only show up when a customer is shipping to an address that's different from the billing address in the Onepage checkout flow. I can get the "Ship to same/different address" from the billing section with
$this->getQuote()->getShippingAddress()->getData('same_as_billing')
and it works great. However, if a customer makes it the shipping methods, and hits back to change the shipping address, that field doesn't seem to get updated. I tried checking
$this->getQuote()->getShippingAddress()->getData('use_billing_address')
But that data doesn't exist. In fact, when I have these two lines in additional.phtml:
Mage::log("Same as billing: ".$this->getQuote()->getShippingAddress()->getData('same_as_billing'));
Mage::log("Use billing: ".$this->getQuote()->getShippingAddress()->getData('use_billing_address'));
It doesn't trigger when I go from Shipping Address to Shipping methods. Can anyone give me some direction here?
I ended up using a javascript function instead of PHP, since it doesn't reload the page to get to each section.
In template/giftmessage/inline.phtml, I added the following:
function _showHideGift() {
var flag=document.getElementById('shipping:same_as_billing').checked;
if(!flag){
document.getElementById('gift-messages').style.display="block";
}else{
document.getElementById('gift-messages').style.display="none";
}}
And then called the function below the block inside of the CDATA, with the toogleVisilibityOnObjects calls.

Shipping Methods are not working in magento 1.7

I activated flat shipping in the shipping options and whenever you do checkout it says “Sorry, no quotes are available for this order at this time.”Any one please help me since i am a beginner in magento.
EDIT
I have tried other shipping methods too its also showing the same. we have upgraded Magento ver. 1.4.1.1 to magento 1.7. Any help would be greatly appreciated..
EDIT 2
After upgrading community folder contains only Phoenix folder. After that i added Biebersdorffolder by seeing an error in checkout page. I don't the the purpose of folders AW and RocketWeb. Since i am not familiar with magento.
If the image is not visible i have added the image in this url
http://i47.tinypic.com/14smix1.jpg
do you have any Checkout files modified on your project? Or maybe custom checkout.
I will list the code locations you need to check to make sure your Shipping works correctly.
So to begin with: Magento has very special work process with Shipping rates - it's called "collectRates" and is some modification of pattern "composite".
To make sure that everything works correctly on the code basis you need to first check the Onepage.php model (app/code/core/Mage/Checkout/Model/Type/Onepage.php): lines 330, 341, 556, 616; There should be code
{address}->setCollectShippingRates(true)
where {address} is current address variable.
This code is significant for future "collectRates" processes, because just when the Onepage Checkout page is initializing the "collectRates" process has already been processed, and the flag "collect_shipping_rates" is set to "false". If it's not set back to true, the next "collectRates" process will not be performed.
After you check the location above, and it still doesn't work - you might want to add some logging to Mage_Checkout_Block_Onepage_Shipping_Method_Available::getShippingRates method. If method is properly executed and return some rates from $this->getAddress()->getGroupedAllShippingRates() call, there might be some issues with .phtml template on your locan theme (default path to .phtml is app/design/frontend/base/default/template/checkout/onepage/shipping_method/available.phtml).
Here's how you can log the outcome from $this->getAddress()->getGroupedAllShippingRates() call (Mage_Checkout_Block_Onepage_Shipping_Method_Available::getShippingRates method):
$groups = $this->getAddress()->getGroupedAllShippingRates();
$printGroupes = array();
foreach ($groups as $code => $groupItems) {
foreach ($groupItems as $item) {
$printGroupes[$code][] = $item->getData();
}
}
Mage::log($printGroupes, null,'special.log');
Please note, that the result array with all rates will be logged into "special.log" under var/logs folder.
I wish I could be more of help, but the issue requires some digging into code, the debugger will be even more helpful than logging, if you can get hold of one.
Cheers!
Price should be entered for Flat Rate shipping to work
The problem might be of the country selection
Ship to applicable countries is set to "Specific Country" and you selected "Canada".
So you will see this shipping method only if you select Canada on the frontend during the checkout.
Or
You can make this to All Countries and check whether its working or not.

is it possible to remove zip/postal code field in magento

is it possible to remove zip/postal code field depending on country chosen in the address section of the checkout page in Magento?
e.g. when a user chooses 'Ireland' the field disappears on the fly.
thanks
Dave
In the admin panel there is an option to make zip code optional for specific countries:
System-> Configuration -> General -> Countries Options -> "Postal Code is Optional for the following countries"
Select your specific countries which you want to make optional.
If this isn't enough with a some basic modification you should be able to make the field invisible as well.
In your theme (don't modify the existing themes), copy js/opcheckout.js and modify that.
Add your observer to the zipcode fields. The best is to hide the zipcode, as the client-side validation won't fire then.
If you would like some code to get you started, I can post that in an edit.
Magento hasn't anything built-in yet. You have to wrote some javascript to do that and, of course, control this flow into Magento Core classes.
on Magento 1.7.0.2
first you have to remove 'required-entry' on zipcode field (you can use jquery to remove class)
then
go to Mage_Checkout_OnepageController
on saveBillingAction() method
$result = $this->getOnepage()->saveBilling($data, $customerAddressId);
$result = array() // clear error message;
and then on saveShippingAction() method
$result = $this->getOnepage()->saveShipping($data, $customerAddressId);
$result = array() // clear error message;
hope works!!

Magento. How to change shipping method before save order?

I must change shipping method before saving order if (condition) is true, and don't change it if false. I tried out function checkout_type_onepage_save_order($observer).
$checkout = Mage::getSingleton('checkout/type_onepage');
$checkout->saveShippingMethod('freeshipping_freeshipping');
but it doesn't work.
Sorry for my English.
Thanks.
I have had problems with things not saving properly in checkout, e.g. shipping address. I think you have to save the quote object again, but I cannot remember for sure.
However, why don't you write your own shipping module? This is the place for doing it properly and within your own module you can put together all the rules you need to set the price to what it needs to be, plus the frontend label, e.g. 'Free!' if a zero price is calculated.
Here is a tutorial that has worked very well for me in the past:
http://www.excellencemagentoblog.com/magento-create-custom-shipping-method

Resources