Magento – How to set billing and shipping address to Quote

magento-1.9

I want to set billing and shipping address to Quote. Actually I am creating an API for which I need to get Shipping Price and other normal checkout information. So I am thinking that, if I can able to set billing and shipping address to quote then it will easy to fetch shipping price from quote. Please help me to achieve this. Many thanks.

Best Answer

The quote class has:

public function setBillingAddress(Mage_Sales_Model_Quote_Address $address)
public function setShippingAddress(Mage_Sales_Model_Quote_Address $address)
public function addAddress(Mage_Sales_Model_Quote_Address $address) 

the address object is:

$address = Mage::getModel('sales/quote_address')->setAddressType($type);

$type can be Mage_Sales_Model_Quote_Address::TYPE_BILLING or Mage_Sales_Model_Quote_Address::TYPE_SHIPPING

or simply use:

public function getBillingAddress()
public function getShippingAddress()

both again methods of the quote object.

and use $quoteObject->collectTotals() to get the totals calculated.