Exemplo n.º 1
0
 /**
  * Return callback response with shipping options
  *
  * @param array $request
  * @return string
  */
 public function getShippingOptionsCallbackResponse(array $request)
 {
     // prepare debug data
     $logger = Mage::getModel('core/log_adapter', 'payment_' . $this->_methodType . '.log');
     $debugData = array('request' => $request, 'response' => array());
     try {
         // obtain addresses
         $this->_getApi();
         $address = $this->_api->prepareShippingOptionsCallbackAddress($request);
         $quoteAddress = $this->_quote->getShippingAddress();
         // compare addresses, calculate shipping rates and prepare response
         $options = array();
         if ($address && $quoteAddress && !$this->_quote->getIsVirtual()) {
             foreach ($address->getExportedKeys() as $key) {
                 $quoteAddress->setDataUsingMethod($key, $address->getData($key));
             }
             $quoteAddress->setCollectShippingRates(true)->collectTotals();
             $options = $this->_prepareShippingOptions($quoteAddress, false, true);
         }
         $response = $this->_api->setShippingOptions($options)->formatShippingOptionsCallback();
         // log request and response
         $debugData['response'] = $response;
         $logger->log($debugData);
         return $response;
     } catch (Exception $e) {
         $logger->log($debugData);
         throw $e;
     }
 }