Example #1
0
 /**
  * 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;
 }
Example #2
0
 /**
  * Delete  shipment
  *
  * @param  Dhl_Intraship_Model_Shipment             $shipment
  * @return Dhl_Intraship_Model_Soap_Client_Response
  */
 public function delete(Dhl_Intraship_Model_Shipment $shipment)
 {
     // Set request parameters.
     $params = $this->_cli->getDefaultParams();
     $params += array('ShipmentNumber' => array('shipmentNumber' => $shipment->getShipmentNumber()));
     // Get response message.
     $response = $this->_cli->DeleteShipmentDD($params);
     return $response->DeletionState;
 }
Example #3
0
 /**
  * Execute
  *
  * @param  ArrayObject                  $settings
  * @param  boolean                      $multipack
  * @return Dhl_Intraship_Model_Shipment $this
  */
 public function execute(ArrayObject $settings, $multipack = null)
 {
     $helper = new Dhl_Intraship_Model_Autocreate();
     $model = new Mage_Sales_Model_Order();
     $myOrder = $model->loadByIncrementId($this->getOrderId());
     $myOrder->setReordered(true);
     $data = array('currency' => 'EUR', 'account' => array('group_id' => 1, 'email' => '*****@*****.**'), 'billing_address' => $myOrder->getBillingAddress()->getData(), 'shipping_address' => $myOrder->getShippingAddress()->getData(), 'shipping_method' => 'flatrate_flatrate', 'comment' => array('customer_note' => false, 'send_confirmation' => false));
     $admin = new Mage_Adminhtml_Model_Sales_Order_Create();
     $order = $admin->initFromOrder($myOrder)->importPostData($data)->createOrder();
     $shipment = $helper->checkOrder($order)->createShipment($order);
     $helper->saveShipment($shipment, $settings);
     $intraship = new Dhl_Intraship_Model_Shipment();
     $intraship->load($shipment->getId(), 'shipment_id');
     if (true === $multipack) {
         $intraship->setPackages(array('package_0' => array('weight' => 0.1), 'package_1' => array('weight' => 0.2), 'package_2' => array('weight' => 0.3)))->save();
     }
     return $intraship;
 }
Example #4
0
 /**
  * Recover a document.
  *
  * @param  Dhl_Intraship_Model_Shipment_Document    $document
  * @param  Dhl_Intraship_Model_Shipment             $shipment
  * @return Dhl_Intraship_Helper_Pdf                 $this
  */
 public function recoverDocument(Dhl_Intraship_Model_Shipment_Document $document, Dhl_Intraship_Model_Shipment $shipment)
 {
     try {
         if (file_exists($document->getFilePath())) {
             return $this;
         }
         /* @var $helper Dhl_Intraship_Helper_Pdf_Document */
         $helper = Mage::helper('intraship/pdf_document');
         $helper->setPdfName($helper->getFileNameLabel($shipment->getShipmentNumber()))->setPdfContent(file_get_contents($document->getDocumentUrl()))->savePdf();
         /*
          * Workaround - sometimes the given path to the pdf is not identic with the generated one
          * In this case, save the new generated path to the document
          */
         if ($document->getFilePath() != $helper->getPathToPdf()) {
             $document->setFilePath($helper->getPathToPdf());
             $document->save();
         }
     } catch (Exception $e) {
         Mage::log($e->getMessage());
         throw new Dhl_Intraship_Helper_Pdf_Exception('pdf creation failed. service temporary not available. ' . $e->getMessage(), $e->getCode());
     }
     return $this;
 }
Example #5
0
 /**
  * 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());
     }
 }