简体   繁体   中英

Magento Get Customer Shipping Address During Checkout

I am trying to get my customer's shipping address during checkout. What we are trying to do is make it so that if they attempt to ship by UPS to a PO Box, it outputs an error page. In the checkout page, there is a checkbox where they can check the different addresses that are saved into their account. I've gotten it where it correctly detects whether or not they are using UPS, however I can't get it to properly get the customer's address. No matter what I do, it records the default shipping address, even if they select another one. My question is what can I do to make it where it selects address 2 instead of address one? Here is my code. The reason the error outputs $street is so I can see what is contained in the variable $street.

        $quote = $this->getOnepage()->getQuote();
        $shippingAddress = $quote->getShippingAddress();
        $street = $shippingAddress->getStreet1();

        //Check to see if customer is trying to use UPS to ship to a PO Box.
        if (preg_match("/p\.* *o\.* *box/i", $street)){
            if ((($shippingMethod=="tablerate3_bestway") || ($shippingMethod=="tablerate_bestway") || ($shippingMethod=="tablerate2_bestway"))){
                $result = array (
                    'error' => -1,
                    'message' => $this->__($street)
                );
                $this->getResponse()->setBody(Zend_Json::encode($result));
            }
        }

For shipping address

Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getData();

For Billing Address

Mage::getSingleton('checkout/session')->getQuote()->getBillingAddress()->getData();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM