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

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.

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

Magento get chosen shipping and billing method address fields

How can I get the choosen shipping and billing fields during checkout? (I want to show them in sidebars)
I use this in shipping.phtml but ofcourse that's just for the current 'address' (and I want to use it in methods.phtml and other pages)
$this->getAddress()->getFirstname()
So I assumed that this would work out...
Mage::getSingleton('checkout/session')->getShippingAddress()->getFirstname()
But it didn't, anybody has a tip?
Addition:
This one was helping me a lot, but I'm stuck :-S
How do I get the shipping method the user has chosen during checkout?
Shipping and billing addresses are children of quote object. So something like this shall work:
Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getFirstname();

Magento: don't send tax to paypal/don't show tax in paypal emails

I'm using magento 1.7, and one of the payment options is Paypal (UK) express checkout.
The problem is that I don't want paypal to send out emails with any tax breakdown on, is there a more straightforward way of solving this (at the Magento or Paypal end) rather than hacking the core module to pass sub+tax as sub and 0 as tax?
I can see that a lot of the fields are mapped in Model/Api/Nvp.php, but can't immediately see where I'd modify these values.
As far as I investigated, there is no easy configurable way to prevent taxes to be submitted to Paypal.
But indeed there is a core hack if you don't mind that only the total amount is submitted (no line items, no taxes).
Go to System/Config/Paypal and set Transfer Cart Line Items to No.
In your code go to function _validate() in class Mage_Paypal_Model_Cart.
At the end of this function add the following lines:
$this->_areItemsValid = false;
$this->_areTotalsValid = false;
Of course it is nicer to to rewrite this class in your app/code/local folder.

Missing amount and order summary in PayPal Express Checkout

I have integrated paypal into codeigniter with paypal_helper (didn't rememeber where I found it, but it is a slightly rewritten version of Paypals original code for express checkout. I try calling this function,
CallShortcutExpressCheckout( $paymentAmount, $currencyCodeType,
$paymentType, $returnURL, $cancelURL)
sending $paymentAmount as int, $currencyCodeType as "NOK" and $paymentType as "Sale".
Both in Sandbox and live, no amount appears on the paypal site...
What could be wrong?
Edit, to further explain my process. I use this, mostly as specified in the https://www.paypal-labs.com/integrationwizard/ecpaypal/cart.php. This should be doable without the form? The paymentAmount could be sent as a standard variable, when calling the function CallShortcutExpressCheckout?:
$resArray = CallShortcutExpressCheckout ($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL);
$ack = strtoupper($resArray["ACK"]);
if($ack=="SUCCESS" || $ack=="SUCCESSWITHWARNING")
{
RedirectToPayPal ( $resArray["TOKEN"] );
}
else
{
//Display a user friendly Error on the page using any of the following error information returned by PayPal
$ErrorCode = urldecode($resArray["L_ERRORCODE0"]);
$ErrorShortMsg = urldecode($resArray["L_SHORTMESSAGE0"]);
$ErrorLongMsg = urldecode($resArray["L_LONGMESSAGE0"]);
$ErrorSeverityCode = urldecode($resArray["L_SEVERITYCODE0"]);
echo "SetExpressCheckout API call failed. ";
echo "Detailed Error Message: " . $ErrorLongMsg;
echo "Short Error Message: " . $ErrorShortMsg;
echo "Error Code: " . $ErrorCode;
echo "Error Severity Code: " . $ErrorSeverityCode;
}
The token is saved in a database. The user gets redirected to Paypal, where no amount is listed.
As you're not passing so called 'line item details' (product data), PayPal doesn't display the total amount.
If you only want to show the amount for the current purchase, redirect buyers to https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-xxxxxx&useraction=commit (instead of https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-xxxxx)
If you want to start sending line-item details to PayPal, include the following in your SetExpressCheckout API request:
// Total amount of the purchase, incl shipping, tax, etc
PAYMENTREQUEST_0_AMT=300.0
// Total amount of items purchased, excl shipping, tax, etc
PAYMENTREQUEST_0_ITEMAMT=300.0
// Authorize the funds first (Authorization), or capture immediately (Sale)?
PAYMENTREQUEST_0_PAYMENTACTION=Sale
// First item
L_PAYMENTREQUEST_0_NAME0=Item1
L_PAYMENTREQUEST_0_QTY0=1
L_PAYMENTREQUEST_0_AMT0=100.00
// Second item
L_PAYMENTREQUEST_0_NAME1=Item2
L_PAYMENTREQUEST_0_QTY1=1
L_PAYMENTREQUEST_0_AMT1=200.00
If you want to see this in your own history as well, you'll also need to include this in DoExpressCheckoutPayment.
This was also posted in php paypal express checkout problem
After an extensive reading on messy Paypal docs site this is a short ExpressCheckout guide working on year 2013. I wanted to have item details shown on paypal payment page and merchant transaction history page.
Paypal documentation links
https://developer.paypal.com/webapps/developer/docs/classic/api/
https://developer.paypal.com/webapps/developer/docs/classic/api/merchant/SetExpressCheckout_API_Operation_NVP/
https://developer.paypal.com/webapps/developer/docs/classic/api/merchant/DoExpressCheckoutPayment_API_Operation_NVP/
https://developer.paypal.com/webapps/developer/docs/classic/api/merchant/GetExpressCheckoutDetails_API_Operation_NVP/
You can call following url methods directly on web browser, update token and payerid parameters accordingly.
This is a digital goods so shipping and handling fees are not given. Single item row. Amount and tax fees are given. Do not require a confirmed delivery address, no shipping address fields, no allow freetext note, payer don't need paypal account and no registration required (solutiontype=sole). Activate credit card section on paypal site (landingpage=billing). Use customized brand title on paypal site. Use custom field to give own value for tracking purpose. Merchant site transaction history must show item details (give item details on SetExpressCheckout and DoExpressCheckoutPayment methods).
SetExpressCheckout method opens a new transaction
https://api-3t.sandbox.paypal.com/nvp?
USER=<userid>
&PWD=<pwd>
&SIGNATURE=<mysig>
&METHOD=SetExpressCheckout
&VERSION=98
&PAYMENTREQUEST_0_PAYMENTACTION=SALE
&REQCONFIRMSHIPPING=0
&NOSHIPPING=1
&ALLOWNOTE=0
&SOLUTIONTYPE=Sole
&LANDINGPAGE=Billing
&BRANDNAME=MY+WEBSHOP+TITLE
&PAYMENTREQUEST_0_AMT=22.22
&PAYMENTREQUEST_0_TAXAMT=4.30
&PAYMENTREQUEST_0_ITEMAMT=17.92
&PAYMENTREQUEST_0_DESC=mypurdesc
&PAYMENTREQUEST_0_CUSTOM=custom1
&PAYMENTREQUEST_0_CURRENCYCODE=EUR
&L_PAYMENTREQUEST_0_NUMBER0=itemid1
&L_PAYMENTREQUEST_0_NAME0=MyItem1
&L_PAYMENTREQUEST_0_DESC0=Item1+description
&L_PAYMENTREQUEST_0_QTY0=1
&L_PAYMENTREQUEST_0_AMT0=17.92
&L_PAYMENTREQUEST_0_TAXAMT0=4.30
&RETURNURL=https://myserver.com/webapp/paypal.jsp%3Fcmd=successexp
&CANCELURL=https://myserver.com/webapp/paypal.jsp%3Fcmd=cancelexp
Reply must have ACK=Success or ACK=SuccessWithWarning, read TOKEN value
Redirect user browser to Paypal site, give token value
https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=<token>
User uses paypal account or credit card. Paypal redirects user to return or cancel url.
Redirect destination url gets token and PayerID parameter values.
Transaction is not completed yet we must call doExpressCheckoutPayment method.
Show confirm dialog on screen (with OK, CANCEL button) or simple case
commit a transaction and show "Thank you, purchase completed" message.
User has already accepted a payment in paypal site and expects transaction be finalized.
You may commit transaction within a same request-response handler or using
asynchronous background task. Paypal site may temporarily be unavailable so don't expect it to work immediately.
Commit transaction if redirect was success, use token and payerid
https://api-3t.sandbox.paypal.com/nvp?
USER=<userid>
&PWD=<pwd>
&SIGNATURE=<mysig>
&METHOD=DoExpressCheckoutPayment
&VERSION=98
&PAYMENTREQUEST_0_PAYMENTACTION=SALE
&PAYMENTREQUEST_0_AMT=22.22
&PAYMENTREQUEST_0_TAXAMT=4.30
&PAYMENTREQUEST_0_ITEMAMT=17.92
&PAYMENTREQUEST_0_CURRENCYCODE=EUR
&L_PAYMENTREQUEST_0_NUMBER0=itemid1
&L_PAYMENTREQUEST_0_NAME0=MyItem1
&L_PAYMENTREQUEST_0_QTY0=1
&L_PAYMENTREQUEST_0_AMT0=17.92
&L_PAYMENTREQUEST_0_TAXAMT0=4.30
&token=<token>
&payerid=<payerid>
Read ACK=Success and verify fields
ACK=Success
PAYMENTINFO_0_PAYMENTSTATUS=Completed
PAYMENTINFO_0_ACK=Success
PAYMENTINFO_0_AMT=22.22 total amount must match
PAYMENTINFO_0_FEEAMT=0.99 (just for fun, read paypal comission fee)
PAYMENTINFO_0_CURRENCYCODE=EUR currency must match
(Optional) Read transaction details from Paypal
You can use this during transaction workflow or any time if stored a token for later use.
https://api-3t.sandbox.paypal.com/nvp
?USER=<userid>
&PWD=<pwd>
&SIGNATURE=<mysig>
&METHOD=GetExpressCheckoutDetails
&VERSION=98
&token=<token>
Read response parameters.
ACK=Success
CHECKOUTSTATUS=PaymentActionCompleted
PAYMENTREQUEST_0_AMT=22.22
PAYMENTREQUEST_0_TAXAMT=4.30
PAYMENTREQUEST_0_CURRENCYCODE=EUR
(Optional) Read and save transaction id, correlation id and token id and write to logtable.
PAYMENTREQUEST_0_TRANSACTIONID=11E585715B622391E
CORRELATIONID=4534b683c335f
I'm willing to receive comments if there is any logic errors.
Check this link, hope it helps in some sense:
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_ECGettingStarted
PAYMENTREQUEST_0_AMT=amount //for amount

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

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

Resources