/** * Init * * @param Dhl_Intraship_Model_Shipment $shipment * @param array $params * @return Dhl_Intraship_Model_Soap_Client_Shipment_Create $this */ public function init(Dhl_Intraship_Model_Shipment $shipment, array $params = null) { /* @var $receiver Mage_Sales_Model_Order_Address */ $receiver = $shipment->getShipment()->getShippingAddress(); /* DHLIS-213 - avoid shipment without address */ if (!$receiver || !$receiver instanceof Mage_Sales_Model_Order_Address) { throw new Dhl_Intraship_Model_Soap_Client_Shipment_Exception('Could not generate shipment without its receiver address'); } /* @var $order Mage_Sales_Model_Order */ $order = $shipment->getShipment()->getOrder(); /* @var $config Dhl_Intraship_Model_Config */ $config = Mage::getModel('intraship/config'); /* * Set shipment data to object. */ $this->set('params', new ArrayObject($params))->set('shipment', $shipment)->set('receiver', $receiver)->set('shipper', $config->getAccountAddress($order->getStoreId()))->set('order', $order)->set('ekp', $config->getAccountEkp($order->getStoreId())); /* * Set profile. */ $this->set('profile', $config->getProfileByCountryCode($this->_getCorrectReceiverCountryId(), $shipment->getProfile())); /* * Set default data for result array. */ $data = array(); $this->_appendDetails($data)->_appendShipper($data)->_appendReceiver($data); /* * Set params to object. */ $this->get('params')->offsetSet('ShipmentOrder', array('SequenceNumber' => '1', 'LabelResponseType' => 'URL', 'Shipment' => $data)); //Zend_Debug::dump($this->toArray()); //exit; return $this; }
/** * Cancel existing shipment on DHL. * * @param Dhl_Intraship_Model_Shipment $shipment * @return void */ protected function _cancel(Dhl_Intraship_Model_Shipment &$shipment) { try { //Set Shipment to "in transmission" to avoid double shipment transmission $shipment->setAsInTransmission(); /* @var $client Dhl_Intraship_Model_Soap_Client_Shipment */ $client = Mage::getModel('intraship/soap_client_shipment', $shipment->getShipment()->getOrder()->getStoreId()); /* @var $response Dhl_Intraship_Model_Soap_Client_Response */ $response = $client->delete($shipment)->validate(); // Update shipment. $shipment->removeTracks()->removeDocuments()->setStatus(Dhl_Intraship_Model_Shipment::STATUS_CANCELED)->setClientStatusCode($response->getStatusCode())->setClientStatusMessage($response->getStatusMessage()); // Add status message to shipment. $shipment->addComment($shipment->getClientStatusMessage(), $shipment->getClientStatusCode(), 'cancel'); } catch (Dhl_Intraship_Model_Soap_Client_Response_Exception $e) { // Handle exceptions $code = Dhl_Intraship_Model_Shipment::STATUS_CANCEL_RETRY; if ($e instanceof Dhl_Intraship_Model_Soap_Client_Response_Exception) { $code = $this->_handleException($e, $code, Dhl_Intraship_Model_Shipment::STATUS_CANCELED_FAILED); } // Add status message to shipment. $shipment->addComment($e->getMessage(), $e->getCode(), 'cancel'); // Update shipment codes. $shipment->setStatus($code)->setClientStatusCode($e->getCode())->setClientStatusMessage($e->getMessage()); } }