Magento – How to Check if Billing and Shipping Address are Equal

billingordersquoteshippingshipping-address

I'm trying to check if billing and shipping address are equal when creating invoice PDFs.

What I've tried so far was:

$order = $invoice->getOrder();
if( $order->getBillingAddress()->getData() != $order->getShippingAddress()->getData() )

or

$order = $invoice->getOrder();
if( $order->getShippingAddress()->getData('same_as_billing')!='1' )

but neither works. I was also trying to get the quote by using $order->getQuote() but that didn't work either.

Is there any way to check if billing and shipping address are equal?

Best Answer

Use array_diff.

$order = $invoice->getOrder();
$billing = $order->getBillingAddress()->getData();
$shipping = $order->getShippingAddress()->getData();

$diff = array_diff($billing,$shipping);

ref: http://us3.php.net/array_diff

you may have to strip out some of the data of each array, before the diff. I am sure you can work it out ;)

Related Topic