Example #1
0
 public function generateShipmentArray(Mage_Sales_Model_Order_Shipment $shipment)
 {
     $address = $shipment->getShippingAddress();
     $trackingMethods = $shipment->getAllTracks();
     $primaryTrack = count($trackingMethods) ? $trackingMethods[0] : false;
     $array = array('@context' => 'http://schema.org', '@type' => 'ParcelDelivery', 'deliveryAddress' => array('@type' => 'PostalAddress', 'streetAddress' => $address->getStreetFull(), 'addressLocality' => $address->getCity(), 'addressRegion' => $address->getRegionCode(), 'addressCountry' => $address->getCountry(), 'postalCode' => $address->getPostcode()), 'partOfOrder' => $this->generateOrderArray($shipment->getOrder()), "expectedArrivalUntil" => date("c", time() + 60 * 60 * 24 * 365.25));
     if (count($trackingMethods)) {
         $array['carrier'] = $primaryTrack->getTitle();
         $array['trackingNumber'] = $primaryTrack->getNumber();
         $array['trackingUrl'] = $this->helper('shipping')->getTrackingPopUpUrlByTrackId($primaryTrack->getId());
     }
     return $array;
 }
 protected function _createShipmentInfo(Mage_Sales_Model_Order_Shipment $shipment)
 {
     $result = array('shipmentId' => $shipment->getIncrementId(), 'shippingFees' => array('amount' => '0', 'code' => Mage::app()->getStore()->getBaseCurrencyCode()), 'discountAmount' => null, 'discounts' => null, 'additionalCost' => null, 'packagingHandlingCost' => null, 'surcharge' => null, 'trackingDetails' => $this->_createTrackingInfo($shipment->getAllTracks()), 'shippingMethod' => $shipment->getOrder()->getShippingDescription(), 'deliveryWindow' => null, 'shippingWindow' => null, 'shippingMessage' => null);
     return $result;
 }
Example #3
0
 /**
  * Confirm crating of shipment
  *
  * @param Mage_Sales_Model_Order_Shipment $shipment
  * @return Mage_AmazonPayments_Model_Api_Cba
  */
 public function confirmShipment($shipment)
 {
     $items = array();
     foreach ($shipment->getAllItems() as $item) {
         /* @var $item Mage_Sales_Model_Order_Shipment_Item */
         if ($item->getOrderItem()->getParentItemId()) {
             continue;
         }
         $items[] = array('id' => $item->getOrderItem()->getExtOrderItemId(), 'qty' => $item->getQty());
     }
     $carrierName = '';
     $shippingMethod = '';
     $trackNumber = '';
     /**
      * Magento track numbers is not connected with items.
      * Get only first track number
      */
     foreach ($shipment->getAllTracks() as $track) {
         $carrierName = $track->getTitle();
         $trackNumber = $track->getNumber();
         break;
     }
     if (preg_match("/\\((.+)\\)/", $shipment->getOrder()->getShippingDescription(), $_result)) {
         $shippingMethod = $_result[1];
     }
     $this->getDocumentApi()->confirmShipment($shipment->getOrder()->getExtOrderId(), $carrierName, $shippingMethod, $items, $trackNumber);
     $shipment->addComment(Mage::helper('amazonpayments')->__('Shipment was created with Checkout by Amazon.'));
     return $this;
 }
 /**
  * Send order shipment to Rakuten Checkout
  *
  * @param  Mage_Sales_Model_Order_Shipment $shipment
  * @return bool
  * @throws Exception|Mage_Core_Exception
  */
 public function sendShipment($shipment)
 {
     // Create Rakuten Checkout Send Order Shipment XML request
     $xml = new SimpleXMLElement("<?xml version='1.0' encoding='UTF-8' ?><tradoria_order_shipment />");
     $merchantAuth = $xml->addChild('merchant_authentication');
     $merchantAuth->addChild('project_id', $this->_projectId);
     $merchantAuth->addChild('api_key', $this->_apiKey);
     /** @var $order Mage_Sales_Model_Order */
     $order = $shipment->getOrder();
     $xml->addChild('order_no', $order->getExtOrderId());
     $carrierTrackingId = $xml->addChild('carrier_tracking_id');
     $carrierTrackingUrl = $xml->addChild('carrier_tracking_url');
     $carrierTrackingCode = $xml->addChild('carrier_tracking_code');
     if ($tracks = $shipment->getAllTracks()) {
         /** @var $track Mage_Sales_Model_Order_Shipment_Track */
         $track = array_shift($tracks);
         // Multiple tracking codes for one shipment are supported by Magento
         $this->_addCDATA($carrierTrackingId, $track->getCarrierCode());
         $this->_addCDATA($carrierTrackingCode, $track->getNumber());
     }
     $request = $xml->asXML();
     $response = $this->sendRequest($request, 'shipment');
     try {
         $response = new SimpleXMLElement($response);
         if ($response->success != 'true') {
             throw new Mage_Core_Exception((string) $response->message, (int) $response->code);
         } else {
             if ((string) $response->invoice_number != '') {
                 $comment = Mage::helper('rakuten')->__('Rakuten Invoice No: %s', '<strong>' . (string) $response->invoice_number . '</strong><br />');
                 $shipment->addComment($comment);
                 $order->addStatusHistoryComment($comment);
             }
         }
     } catch (Mage_Core_Exception $e) {
         throw $e;
     } catch (Exception $e) {
         Mage::logException($e);
         throw $e;
     }
     return true;
 }