Pergunta

I have been browsing http://docs.magentocommerce.com/Mage_Customer/Mage_Customer_Model_Address_Abstract.html for a while now, and I am not seeing anything about retrieving the city from the Address...

How do I retrieve the ship to city from the shipment class?

Thank you!

Foi útil?

Solução

Mage_Customer_Model_Address_Abstract is an abstract class and you cannot get address values from this class. Following address classes extends from Mage_Customer_Model_Address_Abstract class:

1. Mage_Customer_Model_Address
2. Mage_Sales_Model_Quote_Address
3. Mage_Sales_Model_Order_Address

And you can retrieve shipping address from shipment via this way:

/**
 * @var $shipment Mage_Sales_Model_Order_Shipment
 * @var $order    Mage_Sales_Model_Order
 */
$shipmentId  = 1;
$incrementId = 100000001;
$shipment    = Mage::getModel('sales/order_shipment')->load($shipmentId);
$city        = $shipment->getShippingAddress()->getCity();

//or you can load shipment address via order
$order       = Mage::getModel('sales/order')->loadByIncrementId($incrementId);
$shipment    = $order->getShipmentsCollection()->getFirstItem();
$anotherCity = $shipment->getShippingAddress()->getCity();
print_r($anotherCity->getData());

By the way $shipment->getShippingAddress() method returns us order shipping address, see /app/code/core/Mage/Sales/Model/Order/Shipment.php:

/**
 * Retrieve shipping address
 *
 * @return Mage_Sales_Model_Order_Address
 */
public function getShippingAddress()
{
    return $this->getOrder()->getShippingAddress();
}

If you understand examples given above, order and shipment address is same object. This class is Mage_Sales_Model_Order_Address and you can retrieve it's values (street, city, region, country, postcode, ...) via Magento's magic getSomeValue methods.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a magento.stackexchange
scroll top