Пример #1
0
 /**
  * Adds shipment with specified tracking number
  *
  * @param Mage_Sales_Model_Order_Shipment $shipment
  * @param Mage_Sales_Model_Order_Shipment_Track $track
  */
 private function _addShipmentWithTrack(Mage_Sales_Model_Order_Shipment $shipment, Mage_Sales_Model_Order_Shipment_Track $track = null)
 {
     $mageCarrierCode = $this->_getCarrierCodeFromOrder($shipment->getOrder());
     $carrierCode = $this->_getConfig()->getCarrierCode($mageCarrierCode);
     $otherCarrierName = $carrierCode == Mage_GoogleTrustedStore_Model_Config::CARRIER_CODE_OTHER ? $this->_getConfig()->getOtherCarrierName($mageCarrierCode) : '';
     $this->_addRow(array($shipment->getOrder()->getIncrementId(), trim($track ? $track->getNumber() : ''), $carrierCode, $otherCarrierName, $shipment->getCreatedAtDate()->toString('yyyy-MM-dd')));
 }
Пример #2
0
 private function processOrder(Ess_M2ePro_Model_Order $order, Mage_Sales_Model_Order_Shipment $shipment, array $trackingDetails = array())
 {
     if ($order->isSingle() || !$order->isComponentModeEbay() || count($shipment->getAllItems()) != 1) {
         return $order->getChildObject()->updateShippingStatus($trackingDetails);
     }
     // combined eBay orders only
     $shipmentItems = $shipment->getAllItems();
     $shipmentItem = reset($shipmentItems);
     /** @var $shipmentItem Mage_Sales_Model_Order_Shipment_Item */
     $additionalData = $shipmentItem->getOrderItem()->getAdditionalData();
     $additionalData = is_string($additionalData) ? @unserialize($additionalData) : array();
     if (empty($additionalData['ebay_item_id']) || empty($additionalData['ebay_transaction_id'])) {
         return $order->getChildObject()->updateShippingStatus($trackingDetails);
     }
     $itemToShip = null;
     foreach ($order->getItemsCollection()->getItems() as $item) {
         /** @var $item Ess_M2ePro_Model_Order_Item */
         if ($item->getChildObject()->getItemId() == $additionalData['ebay_item_id'] || $item->getChildObject()->getTransactionId() == $additionalData['ebay_transaction_id']) {
             $itemToShip = $item;
             break;
         }
     }
     if (is_null($itemToShip)) {
         return $order->getChildObject()->updateShippingStatus($trackingDetails);
     }
     $params = array();
     if (count($trackingDetails) > 0) {
         $params['tracking_number'] = $trackingDetails['tracking_number'];
         $params['carrier_code'] = Mage::helper('M2ePro/Component_Ebay')->getCarrierTitle($trackingDetails['carrier_code'], $trackingDetails['carrier_title']);
     }
     /** @var $dispatcher Ess_M2ePro_Model_Connector_Server_Ebay_OrderItem_Dispatcher */
     $dispatcher = Mage::getModel('M2ePro/Connector_Server_Ebay_OrderItem_Dispatcher');
     $action = Ess_M2ePro_Model_Connector_Server_Ebay_OrderItem_Dispatcher::ACTION_UPDATE_STATUS;
     return $dispatcher->process($action, $itemToShip, $params);
 }
 /**
  * @param Mage_Sales_Model_Order_Shipment $shipment
  * @return array
  */
 public function buildMap(Mage_Sales_Model_Order_Shipment $shipment)
 {
     $map = array('packingslip_id_label' => $this->getSalesHelper()->__('Packingslip # '), 'order_id_label' => $this->getSalesHelper()->__('Order # '), 'order_date_label' => $this->getSalesHelper()->__('Order Date: '), 'billing_address_label' => $this->getSalesHelper()->__('Sold to:'), 'shipping_address_label' => $this->getSalesHelper()->__('Ship to:'), 'payment_method_label' => $this->getSalesHelper()->__('Payment Method:'), 'shipping_method_label' => $this->getSalesHelper()->__('Shipping Method:'), 'products_qty_label' => $this->getSalesHelper()->__('Qty'), 'products_label' => $this->getSalesHelper()->__('Products'), 'products_sku_label' => $this->getSalesHelper()->__('SKU'));
     $order = $shipment->getOrder();
     $billingAddress = $order->getBillingAddress();
     $map['packingslip_id'] = $shipment->getIncrementId();
     $map['order_id'] = Mage::getStoreConfigFlag(Mage_Sales_Model_Order_Pdf_Shipment::XML_PATH_SALES_PDF_SHIPMENT_PUT_ORDER_ID, $order->getStoreId()) ? $order->getRealOrderId() : 'N/A';
     $map['order_date'] = $this->getCoreHelper()->formatDate($order->getCreatedAtStoreDate(), 'medium', false);
     $map['billing_name'] = $billingAddress->getFirstname() . ' ' . $billingAddress->getLastname();
     $map['billing_street'] = $billingAddress->getStreetFull();
     $map['billing_city'] = $billingAddress->getCity();
     $map['billing_zip'] = $billingAddress->getPostcode();
     $map['billing_country'] = $billingAddress->getCountryModel()->getIso2Code();
     $map['billing_phone'] = $billingAddress->getTelephone();
     $shippingAddress = $order->getShippingAddress();
     $map['shipping_name'] = $shippingAddress->getFirstname() . ' ' . $shippingAddress->getLastname();
     $map['shipping_street'] = $shippingAddress->getStreetFull();
     $map['shipping_city'] = $shippingAddress->getCity();
     $map['shipping_zip'] = $shippingAddress->getPostcode();
     $map['shipping_country'] = $shippingAddress->getCountry();
     $map['shipping_phone'] = $shippingAddress->getTelephone();
     $map['payment_method'] = $paymentInfo = $this->getPaymentHelper()->getInfoBlock($order->getPayment())->setIsSecureMode(true)->toHtml();
     $map['shipping_method'] = $order->getShippingDescription();
     $map['shipping_charges'] = '(' . $this->getSalesHelper()->__('Total Shipping Charges') . ' ' . $order->formatPriceTxt($order->getShippingAmount()) . ')';
     $map['products_data'] = '';
     foreach ($shipment->getAllItems() as $item) {
         if ($item->getOrderItem()->getParentItem()) {
             continue;
         }
         $map['products_data'] .= $this->drawItem($item, $order);
     }
     return $map;
 }
Пример #4
0
 /**
  * Retrieve tracking url with params
  *
  * @param  string $key
  * @param  Mage_Sales_Model_Order|Mage_Sales_Model_Order_Shipment|Mage_Sales_Model_Order_Shipment_Track $model
  * @param  string $method Optional - method of a model to get id
  * @return string
  */
 protected function _getTrackingUrl($key, $model, $method = 'getId')
 {
     $helper = Mage::helper('Mage_Core_Helper_Data');
     $urlPart = "{$key}:{$model->{$method}()}:{$model->getProtectCode()}";
     $param = array('hash' => $helper->urlEncode($urlPart));
     $storeModel = Mage::app()->getStore($model->getStoreId());
     return $storeModel->getUrl('shipping/tracking/popup', $param);
 }
Пример #5
0
 /**
  * True is returned if we transport the shipment in a single package.
  *
  * @param Mage_Sales_Model_Order_Shipment $shipment
  *
  * @return boolean
  */
 public function mustShipInOneParcel(Mage_Sales_Model_Order_Shipment $shipment)
 {
     $carrier = $shipment->getOrder()->getShippingCarrier();
     if ($carrier instanceof Zitec_PackedShipment_Model_Carrier_Interface) {
         $shippingMethod = $shipment->getOrder()->getShippingMethod();
         return $carrier->shippingMethodRequiresShipmentsOfOnlyOneParcel($shippingMethod);
     }
     return true;
 }
Пример #6
0
 /**
  * Get html for the PGaddress
  *
  * @return string
  */
 public function getPgAddressHtml()
 {
     $res = array();
     $pgAddress = Mage::helper('tig_myparcel')->getPgAddress($this->_shipment->getOrder());
     if ($pgAddress) {
         $res = array($pgAddress->getCompany(), implode(' ', $pgAddress->getStreet()), $pgAddress->getPostcode() . ' ' . $pgAddress->getCity() . ' (' . $pgAddress->getCountry() . ')');
     }
     return empty($res) ? '' : '<p>' . implode('<br/>', $res) . '</p>';
 }
Пример #7
0
 private function getItemsToShip(Ess_M2ePro_Model_Order $order, Mage_Sales_Model_Order_Shipment $shipment)
 {
     $productTypesNotAllowedByDefault = array(Mage_Catalog_Model_Product_Type::TYPE_BUNDLE, Mage_Catalog_Model_Product_Type::TYPE_GROUPED);
     $items = array();
     $allowedItems = array();
     foreach ($shipment->getAllItems() as $shipmentItem) {
         /** @var $shipmentItem Mage_Sales_Model_Order_Shipment_Item */
         $orderItem = $shipmentItem->getOrderItem();
         $parentOrderItemId = $orderItem->getParentItemId();
         if (!is_null($parentOrderItemId)) {
             !in_array($parentOrderItemId, $allowedItems) && ($allowedItems[] = $parentOrderItemId);
             continue;
         }
         if (!in_array($orderItem->getProductType(), $productTypesNotAllowedByDefault)) {
             $allowedItems[] = $orderItem->getId();
         }
         $additionalData = $orderItem->getAdditionalData();
         $additionalData = is_string($additionalData) ? @unserialize($additionalData) : array();
         $itemId = $transactionId = null;
         $orderItemDataIdentifier = Ess_M2ePro_Helper_Data::CUSTOM_IDENTIFIER;
         if (isset($additionalData['ebay_item_id']) && isset($additionalData['ebay_transaction_id'])) {
             // backward compatibility with versions 5.0.4 or less
             $itemId = $additionalData['ebay_item_id'];
             $transactionId = $additionalData['ebay_transaction_id'];
         } elseif (isset($additionalData[$orderItemDataIdentifier]['items'])) {
             if (!is_array($additionalData[$orderItemDataIdentifier]['items']) || count($additionalData[$orderItemDataIdentifier]['items']) != 1) {
                 return null;
             }
             if (isset($additionalData[$orderItemDataIdentifier]['items'][0]['item_id'])) {
                 $itemId = $additionalData[$orderItemDataIdentifier]['items'][0]['item_id'];
             }
             if (isset($additionalData[$orderItemDataIdentifier]['items'][0]['transaction_id'])) {
                 $transactionId = $additionalData[$orderItemDataIdentifier]['items'][0]['transaction_id'];
             }
         }
         if (is_null($itemId) || is_null($transactionId)) {
             continue;
         }
         $item = Mage::helper('M2ePro/Component_Ebay')->getCollection('Order_Item')->addFieldToFilter('order_id', $order->getId())->addFieldToFilter('item_id', $itemId)->addFieldToFilter('transaction_id', $transactionId)->getFirstItem();
         if (!$item->getId()) {
             continue;
         }
         $items[$orderItem->getId()] = $item;
     }
     $resultItems = array();
     foreach ($items as $orderItemId => $item) {
         if (!in_array($orderItemId, $allowedItems)) {
             continue;
         }
         $resultItems[] = $item;
     }
     return $resultItems;
 }
Пример #8
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;
 }
Пример #9
0
 protected function getTrackingDetails(Mage_Sales_Model_Order_Shipment $shipment)
 {
     $track = $shipment->getTracksCollection()->getLastItem();
     $trackingDetails = array();
     if ($track->getData('number') != '') {
         $carrierCode = trim($track->getData('carrier_code'));
         if (strtolower($carrierCode) == 'dhlint') {
             $carrierCode = 'dhl';
         }
         $trackingDetails = array('carrier_title' => trim($track->getData('title')), 'carrier_code' => $carrierCode, 'tracking_number' => (string) $track->getData('number'));
     }
     return $trackingDetails;
 }
Пример #10
0
 /**
  * Save shipment
  *
  * @param Mage_Sales_Model_Order_Shipment $shipment
  * @param array $data
  * @return bool
  */
 public function saveShipment($shipment, $data)
 {
     $result = false;
     $carrierCode = $shipment->getOrder()->getShippingCarrier()->getCarrierCode();
     switch (true) {
         case Mage::getModel('shippingcore/carrier_aramex')->isUsed($carrierCode):
             $result = Mage::getModel('shippingcore/carrier_aramex')->saveShipment($shipment, $data);
             break;
         case Mage::getModel('shippingcore/carrier_skynet')->isUsed($carrierCode):
             $result = Mage::getModel('shippingcore/carrier_skynet')->saveShipment($shipment, $data);
             break;
     }
     return $result;
 }
Пример #11
0
 /**
  * @magentoConfigFixture current_store design/theme/full_name default/default/default
  * @magentoDataFixture Mage/Sales/_files/order.php
  */
 public function testSendEmail()
 {
     $order = new Mage_Sales_Model_Order();
     $order->loadByIncrementId('100000001');
     $order->setCustomerEmail('customer@example.com');
     $shipment = new Mage_Sales_Model_Order_Shipment();
     $shipment->setOrder($order);
     $payment = $order->getPayment();
     $paymentInfoBlock = Mage::helper('Mage_Payment_Helper_Data')->getInfoBlock($payment);
     $paymentInfoBlock->setArea('invalid-area');
     $payment->setBlockMock($paymentInfoBlock);
     $this->assertEmpty($shipment->getEmailSent());
     $shipment->sendEmail(true);
     $this->assertNotEmpty($shipment->getEmailSent());
     $this->assertEquals('frontend', $paymentInfoBlock->getArea());
 }
 /**
  * @see Varien_Object::_construct()
  * overriding in order to implement order shipment
  * business logic to replace Magento data with
  * OMS order detail data.
  * @return void
  */
 protected function _construct()
 {
     parent::_construct();
     // @see parent::_order property.
     $this->setOrder($this->getData('order'));
     // templates and blocks expect something from the getId method, so set the id to
     // the increment id to ensure output is generated.
     $this->setId($this->getIncrementId());
     // remove the order key, we no long need it.
     $this->unsetData('order');
     if (trim($this->getIncrementId())) {
         $items = $this->getOrder()->getItemsCollection();
         foreach ($this->getShippedItemIds() as $itemRefId) {
             $item = $items->getItemByColumnValue('ref_id', $itemRefId);
             if ($item && $item->getSku()) {
                 $this->_injectShipmentItems(array_merge($item->getData(), ['qty' => $item->getQtyShipped()]));
             }
         }
         $tracks = $this->getTracks();
         if (!empty($tracks)) {
             foreach ($tracks as $track) {
                 $this->_injectShipmentTracks(['number' => $track]);
             }
         }
         $this->setAllItems($this->getItems());
     }
 }
Пример #13
0
 /**
  * Surcharge la méthode after save pour mettre a jour les stocks
  *
  * @return Mage_Core_Model_Abstract
  */
 protected function _afterSave()
 {
     try {
         //appel le parent
         parent::_afterSave();
         //Define if shipment just created
         $creation = $this->getentity_id() != $this->getOrigData('entity_id');
         if ($creation) {
             //Create stock movements
             $order = $this->getOrder();
             foreach ($this->getAllItems() as $item) {
                 //retrieve informaiton
                 $qty = $this->getRealShippedQtyForItem($item);
                 try {
                     $StockMovement = mage::getmodel('Purchase/StockMovement')->setsm_product_id($item->getproduct_id())->setsm_type('order')->setsm_coef(-1)->setsm_qty($qty)->setsm_date(date('Y-m-d'))->setsm_ui($item->getId())->setsm_description(mage::helper('purchase')->__('Order #') . $this->getOrder()->getincrement_id())->save();
                 } catch (Exception $ex) {
                     //nothing, db constraint exception because stock movement already exists
                 }
                 //reset reserved qty
                 $orderItem = $item->getOrderItem();
                 $orderItem->setreserved_qty(0)->save();
             }
             //update order planning
             $orderId = $this->getOrder()->getId();
             mage::helper('BackgroundTask')->AddTask('Update planning for order ' . $orderId, 'purchase/Planning', 'updatePlanning', $orderId);
             //Met a jour les qte commandées pour le produit
             $order->UpdateProductsOrdererQty;
         }
     } catch (Exception $ex) {
         mage::log($ex->getMessage());
     }
     return $this;
 }
Пример #14
0
 public function getItemByProductId($productId)
 {
     foreach ($this->_shipment->getItemsCollection() as $item) {
         if ($item->getProductId() == $productId) {
             return $item;
         }
     }
     return false;
 }
Пример #15
0
 /**
  * @param Ess_M2ePro_Model_Order          $order
  * @param Mage_Sales_Model_Order_Shipment $shipment
  *
  * @return Ess_M2ePro_Model_Order_Item[]
  */
 private function getItemsToShip(Ess_M2ePro_Model_Order $order, Mage_Sales_Model_Order_Shipment $shipment)
 {
     $shipmentItems = $shipment->getAllItems();
     $orderItemDataIdentifier = Ess_M2ePro_Helper_Data::CUSTOM_IDENTIFIER;
     $items = array();
     foreach ($shipmentItems as $shipmentItem) {
         $additionalData = $shipmentItem->getOrderItem()->getAdditionalData();
         $additionalData = is_string($additionalData) ? @unserialize($additionalData) : array();
         if (!isset($additionalData[$orderItemDataIdentifier]['items'][0]['order_item_id'])) {
             continue;
         }
         $id = $additionalData[$orderItemDataIdentifier]['items'][0]['order_item_id'];
         $item = $order->getItemsCollection()->getItemByColumnValue('play_order_item_id', $id);
         if (is_null($item)) {
             continue;
         }
         $items[] = $item;
     }
     return $items;
 }
Пример #16
0
 /**
  * @param Ess_M2ePro_Model_Order          $order
  * @param Mage_Sales_Model_Order_Shipment $shipment
  *
  * @return null|Ess_M2ePro_Model_Order_Item
  */
 private function getItemToShip(Ess_M2ePro_Model_Order $order, Mage_Sales_Model_Order_Shipment $shipment)
 {
     if ($order->isSingle()) {
         return null;
     }
     $shipmentItems = $shipment->getAllItems();
     if (count($shipmentItems) != 1) {
         return null;
     }
     /** @var $shipmentItem Mage_Sales_Model_Order_Shipment_Item */
     $shipmentItem = reset($shipmentItems);
     $additionalData = $shipmentItem->getOrderItem()->getAdditionalData();
     $additionalData = is_string($additionalData) ? @unserialize($additionalData) : array();
     $itemId = $transactionId = null;
     $orderItemDataIdentifier = Ess_M2ePro_Helper_Data::CUSTOM_IDENTIFIER;
     if (isset($additionalData['ebay_item_id']) && isset($additionalData['ebay_transaction_id'])) {
         // backward compatibility with versions 5.0.4 or less
         $itemId = $additionalData['ebay_item_id'];
         $transactionId = $additionalData['ebay_transaction_id'];
     } elseif (isset($additionalData[$orderItemDataIdentifier]['items'])) {
         if (!is_array($additionalData[$orderItemDataIdentifier]['items']) || count($additionalData[$orderItemDataIdentifier]['items']) != 1) {
             return null;
         }
         if (isset($additionalData[$orderItemDataIdentifier]['items'][0]['item_id'])) {
             $itemId = $additionalData[$orderItemDataIdentifier]['items'][0]['item_id'];
         }
         if (isset($additionalData[$orderItemDataIdentifier]['items'][0]['transaction_id'])) {
             $transactionId = $additionalData[$orderItemDataIdentifier]['items'][0]['transaction_id'];
         }
     }
     if (is_null($itemId) || is_null($transactionId)) {
         return null;
     }
     $item = Mage::helper('M2ePro/Component_Ebay')->getCollection('Order_Item')->addFieldToFilter('order_id', $order->getId())->addFieldToFilter('item_id', $itemId)->addFieldToFilter('transaction_id', $transactionId)->getFirstItem();
     return $item->getId() ? $item : null;
 }
Пример #17
0
 /**
  * @param Ess_M2ePro_Model_Order          $order
  * @param Mage_Sales_Model_Order_Shipment $shipment
  *
  * @throws LogicException
  *
  * @return array
  */
 private function getItemsToShip(Ess_M2ePro_Model_Order $order, Mage_Sales_Model_Order_Shipment $shipment)
 {
     $shipmentItems = $shipment->getAllItems();
     $orderItemDataIdentifier = Ess_M2ePro_Helper_Data::CUSTOM_IDENTIFIER;
     $items = array();
     foreach ($shipmentItems as $shipmentItem) {
         $additionalData = $shipmentItem->getOrderItem()->getAdditionalData();
         $additionalData = is_string($additionalData) ? @unserialize($additionalData) : array();
         if (!isset($additionalData[$orderItemDataIdentifier]['items'])) {
             continue;
         }
         if (!is_array($additionalData[$orderItemDataIdentifier]['items'])) {
             continue;
         }
         $qtyAvailable = (int) $shipmentItem->getQty();
         foreach ($additionalData[$orderItemDataIdentifier]['items'] as $data) {
             if ($qtyAvailable <= 0) {
                 continue;
             }
             if (!isset($data['order_item_id'])) {
                 continue;
             }
             $item = $order->getItemsCollection()->getItemByColumnValue('amazon_order_item_id', $data['order_item_id']);
             if (is_null($item)) {
                 continue;
             }
             $qty = $item->getChildObject()->getQtyPurchased();
             if ($qty > $qtyAvailable) {
                 $qty = $qtyAvailable;
             }
             $items[] = array('qty' => $qty, 'amazon_order_item_id' => $data['order_item_id']);
             $qtyAvailable -= $qty;
         }
     }
     return $items;
 }
 /**
  * Saving shipment and order in one transaction.
  * @param  Mage_Sales_Model_Order_Shipment $shipment
  * @param  string $incrementId
  * @return self
  */
 protected function _saveShipment(Mage_Sales_Model_Order_Shipment $shipment, $incrementId)
 {
     $order = $shipment->getOrder();
     $order->setIsInProcess(true);
     $transactionSave = Mage::getModel('core/resource_transaction')->addObject($shipment)->addObject($order);
     try {
         $transactionSave->save();
     } catch (Exception $e) {
         $logData = ['increment_id' => $incrementId];
         $logMessage = 'An error occurred saving shipment confirmation to order id ({increment_id}). See exception log for details.';
         $this->_logger->error($logMessage, $this->_context->getMetaData(__CLASS__, $logData));
         $this->_logger->logException($e, $this->_context->getMetaData(__CLASS__, [], $e));
     }
     return $this;
 }
Пример #19
0
 /**
  * Prepare and do request to shipment
  *
  * @param Mage_Sales_Model_Order_Shipment $orderShipment
  * @return Varien_Object
  */
 public function requestToShipment(Mage_Sales_Model_Order_Shipment $orderShipment)
 {
     $admin = Mage::getSingleton('admin/session')->getUser();
     $order = $orderShipment->getOrder();
     $address = $order->getShippingAddress();
     $selectedShipMethod = $this->_mapShipMethod($order->getShippingMethod(true), $order->getShippingCarrier(), $address);
     $shipmentStoreId = $orderShipment->getStoreId();
     $shipmentCarrier = Mage::getModel('wsaendicia/carrier_endicia');
     $shippingMethod = $this->_getShipmentCarrier($selectedShipMethod, $shipmentCarrier->getCarrierCode());
     $baseCurrencyCode = Mage::app()->getStore($shipmentStoreId)->getBaseCurrencyCode();
     if (!$shipmentCarrier) {
         Mage::throwException('Invalid carrier: ' . $shippingMethod->getCarrierCode());
     }
     $shipperRegionCode = Mage::getStoreConfig(self::XML_PATH_STORE_REGION_ID, $shipmentStoreId);
     if (is_numeric($shipperRegionCode)) {
         $shipperRegionCode = Mage::getModel('directory/region')->load($shipperRegionCode)->getCode();
     }
     $recipientRegionCode = Mage::getModel('directory/region')->load($address->getRegionId())->getCode();
     $originStreet1 = Mage::getStoreConfig(self::XML_PATH_STORE_ADDRESS1, $shipmentStoreId);
     $originStreet2 = Mage::getStoreConfig(self::XML_PATH_STORE_ADDRESS2, $shipmentStoreId);
     $storeInfo = new Varien_Object(Mage::getStoreConfig('general/store_information', $shipmentStoreId));
     if (!$admin->getFirstname() || !$admin->getLastname() || !$storeInfo->getName() || !$storeInfo->getPhone() || !$originStreet1 || !Mage::getStoreConfig(self::XML_PATH_STORE_CITY, $shipmentStoreId) || !$shipperRegionCode || !Mage::getStoreConfig(self::XML_PATH_STORE_ZIP, $shipmentStoreId) || !Mage::getStoreConfig(self::XML_PATH_STORE_COUNTRY_ID, $shipmentStoreId)) {
         Mage::throwException(Mage::helper('sales')->__('Insufficient information to create shipping label(s). Please verify your Store Information and Shipping Settings.'));
     }
     /** @var $request Mage_Shipping_Model_Shipment_Request */
     $request = Mage::getModel('shipping/shipment_request');
     $request->setOrderShipment($orderShipment);
     $request->setShipperContactPersonName($admin->getName());
     $request->setShipperContactPersonFirstName($admin->getFirstname());
     $request->setShipperContactPersonLastName($admin->getLastname());
     $request->setShipperContactCompanyName($storeInfo->getName());
     $request->setShipperContactPhoneNumber($storeInfo->getPhone());
     $request->setShipperEmail($admin->getEmail());
     $request->setShipperAddressStreet(trim($originStreet1 . ' ' . $originStreet2));
     $request->setShipperAddressStreet1($originStreet1);
     $request->setShipperAddressStreet2($originStreet2);
     $request->setShipperAddressCity(Mage::getStoreConfig(self::XML_PATH_STORE_CITY, $shipmentStoreId));
     $request->setShipperAddressStateOrProvinceCode($shipperRegionCode);
     $request->setShipperAddressPostalCode(Mage::getStoreConfig(self::XML_PATH_STORE_ZIP, $shipmentStoreId));
     $request->setShipperAddressCountryCode(Mage::getStoreConfig(self::XML_PATH_STORE_COUNTRY_ID, $shipmentStoreId));
     $request->setRecipientContactPersonName(trim($address->getFirstname() . ' ' . $address->getLastname()));
     $request->setRecipientContactPersonFirstName($address->getFirstname());
     $request->setRecipientContactPersonLastName($address->getLastname());
     $request->setRecipientContactCompanyName($address->getCompany());
     $request->setRecipientContactPhoneNumber($address->getTelephone());
     $request->setRecipientEmail($address->getEmail());
     $request->setRecipientAddressStreet(trim($address->getStreet1() . ' ' . $address->getStreet2()));
     $request->setRecipientAddressStreet1($address->getStreet1());
     $request->setRecipientAddressStreet2($address->getStreet2());
     $request->setRecipientAddressCity($address->getCity());
     $request->setRecipientAddressStateOrProvinceCode($address->getRegionCode());
     $request->setRecipientAddressRegionCode($recipientRegionCode);
     $request->setRecipientAddressPostalCode($address->getPostcode());
     $request->setRecipientAddressCountryCode($address->getCountryId());
     $request->setShippingMethod($shippingMethod->getMethod());
     $request->setPackageWeight($order->getWeight());
     $request->setPackages($orderShipment->getPackages());
     $request->setBaseCurrencyCode($baseCurrencyCode);
     $request->setStoreId($shipmentStoreId);
     return $shipmentCarrier->requestToShipment($request);
 }
Пример #20
0
 /**
  * Add Shipment Information
  *
  * @param Mage_Sales_Model_Order_Shipment $data
  * @return Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_Page
  * @throws Exception
  */
 public function addShipmentInformation($data)
 {
     $this->_page->saveGS();
     $this->_page->setFont($this->_fontNormal, 6);
     $refCode = $data->getOrder()->getIncrementId();
     if (!$refCode) {
         throw new InvalidArgumentException(Mage::helper('usa')->__('Reference code is missing'));
     }
     $this->_page->drawText('Ref Code: ' . Mage::helper('usa')->__('Order #%s', $refCode), $this->_x(8), $this->_y(224));
     $this->_page->restoreGS();
     return $this;
 }
 /**
  * Save shipment and order in one transaction
  * @param Mage_Sales_Model_Order_Shipment $shipment
  */
 protected function _saveShipment($shipment)
 {
     $shipment->getOrder()->setIsInProcess(true);
     $transactionSave = Mage::getModel('core/resource_transaction')->addObject($shipment)->addObject($shipment->getOrder())->save();
     return $this;
 }
Пример #22
0
 /**
  * Send email with shipment data
  *
  * @param boolean $notifyCustomer
  * @param string $comment
  * @return Mage_Sales_Model_Order_Shipment
  */
 public function sendEmail($notifyCustomer = true, $comment = '')
 {
     if (!Mage::getStoreConfig('pdfpro/config/enabled')) {
         return parent::sendEmail($notifyCustomer, $comment);
     }
     switch (Mage::getStoreConfig('pdfpro/config/shipment_email_attach')) {
         case VES_PdfPro_Model_Source_Attach::ATTACH_TYPE_NO:
             return parent::sendEmail();
         case VES_PdfPro_Model_Source_Attach::ATTACH_TYPE_ADMIN:
             $this->sendEmailForAdmin($notifyCustomer, $comment, true);
             $this->sendEmailForCustomer($notifyCustomer, $comment, false);
             return $this;
         case VES_PdfPro_Model_Source_Attach::ATTACH_TYPE_CUSTOMER:
             $this->sendEmailForAdmin($notifyCustomer, $comment, false);
             $this->sendEmailForCustomer($notifyCustomer, $comment, true);
             return $this;
     }
     $order = $this->getOrder();
     $storeId = $order->getStore()->getId();
     if (!Mage::helper('sales')->canSendNewShipmentEmail($storeId)) {
         return $this;
     }
     // Get the destination email addresses to send copies to
     $copyTo = $this->_getEmails(self::XML_PATH_EMAIL_COPY_TO);
     $copyMethod = Mage::getStoreConfig(self::XML_PATH_EMAIL_COPY_METHOD, $storeId);
     // Check if at least one recepient is found
     if (!$notifyCustomer && !$copyTo) {
         return $this;
     }
     // Start store emulation process
     $appEmulation = Mage::getSingleton('pdfpro/app_emulation');
     $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);
     try {
         // Retrieve specified view block from appropriate design package (depends on emulated store)
         $paymentBlock = Mage::helper('payment')->getInfoBlock($order->getPayment())->setIsSecureMode(true);
         $paymentBlock->getMethod()->setStore($storeId);
         $paymentBlockHtml = $paymentBlock->toHtml();
     } catch (Exception $exception) {
         // Stop store emulation process
         $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
         throw $exception;
     }
     // Stop store emulation process
     $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
     // Retrieve corresponding email template id and customer name
     if ($order->getCustomerIsGuest()) {
         $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_GUEST_TEMPLATE, $storeId);
         $customerName = $order->getBillingAddress()->getName();
     } else {
         $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE, $storeId);
         $customerName = $order->getCustomerName();
     }
     $mailer = Mage::getModel('pdfpro/email_template_mailer');
     if ($notifyCustomer) {
         $emailInfo = Mage::getModel('pdfpro/email_info');
         $emailInfo->addTo($order->getCustomerEmail(), $customerName);
         if ($copyTo && $copyMethod == 'bcc') {
             // Add bcc to customer email
             foreach ($copyTo as $email) {
                 $emailInfo->addBcc($email);
             }
         }
         $mailer->addEmailInfo($emailInfo);
     }
     // Email copies are sent as separated emails if their copy method is 'copy' or a customer should not be notified
     if ($copyTo && ($copyMethod == 'copy' || !$notifyCustomer)) {
         foreach ($copyTo as $email) {
             $emailInfo = Mage::getModel('pdfpro/email_info');
             $emailInfo->addTo($email);
             $mailer->addEmailInfo($emailInfo);
         }
     }
     // Set all required params and send emails
     $mailer->setSender(Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $storeId));
     $mailer->setStoreId($storeId);
     $mailer->setTemplateId($templateId);
     $mailer->setTemplateParams(array('order' => $order, 'shipment' => $this, 'comment' => $comment, 'billing' => $order->getBillingAddress(), 'payment_html' => $paymentBlockHtml));
     /* Attach Invoice PDF in email */
     $shipmentData = Mage::getModel('pdfpro/order_shipment')->initShipmentData($this);
     try {
         $result = Mage::helper('pdfpro')->initPdf(array($shipmentData), 'shipment');
         if ($result['success']) {
             $mailer->setPdf(array('filename' => Mage::helper('pdfpro')->getFileName('shipment', $this) . '.pdf', 'content' => $result['content']));
         } else {
             Mage::log($result['msg']);
         }
     } catch (Exception $e) {
         Mage::log($e->getMessage());
     }
     $mailer->send();
     return $this;
 }
 /**
  * Create shipping label for specific shipment with validation.
  *
  * @param Mage_Sales_Model_Order_Shipment $shipment
  * @return bool
  */
 protected function _createShippingLabel(Mage_Sales_Model_Order_Shipment $shipment)
 {
     if (!$shipment) {
         return false;
     }
     $carrier = $shipment->getOrder()->getShippingCarrier();
     if (!$carrier->isShippingLabelsAvailable()) {
         return false;
     }
     $shipment->setPackages($this->getRequest()->getParam('packages'));
     $response = Mage::getModel('shipping/shipping')->requestToShipment($shipment);
     if ($response->hasErrors()) {
         Mage::throwException($response->getErrors());
     }
     if (!$response->hasInfo()) {
         return false;
     }
     $labelsContent = array();
     $trackingNumbers = array();
     $info = $response->getInfo();
     foreach ($info as $inf) {
         if (!empty($inf['tracking_number']) && !empty($inf['label_content'])) {
             $labelsContent[] = $inf['label_content'];
             $trackingNumbers[] = $inf['tracking_number'];
         }
     }
     $outputPdf = $this->_combineLabelsPdf($labelsContent);
     $shipment->setShippingLabel($outputPdf->render());
     $carrierCode = $carrier->getCarrierCode();
     $carrierTitle = Mage::getStoreConfig('carriers/' . $carrierCode . '/title', $shipment->getStoreId());
     if ($trackingNumbers) {
         foreach ($trackingNumbers as $trackingNumber) {
             $track = Mage::getModel('sales/order_shipment_track')->setNumber($trackingNumber)->setCarrierCode($carrierCode)->setTitle($carrierTitle);
             $shipment->addTrack($track);
         }
     }
     return true;
 }
Пример #24
0
 /**
  * Get default weight.
  *
  * @param  Mage_Sales_Model_Order_Shipment  $shipment
  * @return float                            $weight
  */
 public function getDefaultWeight(Mage_Sales_Model_Order_Shipment $shipment)
 {
     $weight = 0;
     if (true === $this->getConfig()->useProductWeightAsDefault()) {
         /* @var $item Mage_Sales_Model_Order_Item */
         foreach ($shipment->getOrder()->getItemsCollection() as $item) {
             if (false === Mage::helper('intraship')->isAllowedProductTypeForWeightCalculation($item->getProductType())) {
                 continue;
             }
             $weight += Mage::helper('intraship')->convertWeight((double) $item->getWeight() * (double) $item->getQtyOrdered());
         }
     } else {
         $weight = $this->getConfig()->getWeightDefault($shipment->getShippingAddress()->getCountryId());
     }
     return (double) $weight;
 }
 public static function generateDocuments(Mage_Sales_Model_Order_Shipment $shipment)
 {
     $result = array();
     if ($shipment->getDcOrderId() && Mage::getStoreConfig('dc_charge_extension/dccharge/create-documents')) {
         $helper = Mage::helper('dccharge');
         $params = array();
         $params['calculation_id'] = $shipment->getDcOrderId();
         $params['output_currency'] = $shipment->getOrder()->getOrderCurrencyCode();
         $params['seller_first_name'] = Mage::getStoreConfig('dc_charge_extension/dccharge/seller-first-name');
         $params['seller_last_name'] = Mage::getStoreConfig('dc_charge_extension/dccharge/seller-last-name');
         $params['seller_country'] = Mage::getStoreConfig('dc_charge_extension/dccharge/seller-country');
         $params['seller_address_line_1'] = Mage::getStoreConfig('dc_charge_extension/dccharge/seller-address-line');
         $params['seller_city'] = Mage::getStoreConfig('dc_charge_extension/dccharge/seller-city');
         $params['seller_zip'] = Mage::getStoreConfig('dc_charge_extension/dccharge/seller-postcode');
         $params['seller_phone'] = Mage::getStoreConfig('dc_charge_extension/dccharge/seller-phone');
         $params['shipment_invoice_no'] = $shipment->getIncrementId();
         $params['shipment_date'] = $shipment->getCreatedAt();
         $params['shipment_number_parcels'] = 1;
         $params['shipment_total_actual_weight'] = 0;
         foreach ($shipment->getAllItems() as $item) {
             $orderItem = $item->getOrderItem();
             $product = Mage::getModel('catalog/product')->load($orderItem->getProductId());
             if ($orderItem->getParentItemId() || !$orderItem->getQuoteItemId() || $product->isVirtual()) {
                 continue;
             }
             $itemWeightInKG = 0;
             if ($item->getWeight()) {
                 $weigthUnit = Mage::getStoreConfig('dc_charge_extension/dccharge/weight-unit');
                 $weight = Mage::getStoreConfig('dc_charge_extension/dccharge/allow-override-products-weight') ? Mage::getStoreConfig('dc_charge_extension/dccharge/overridden-products-weight') : $item->getWeight();
                 if ($weigthUnit == 'lb') {
                     $itemWeightInKG = round($weight * 0.45359237, 2);
                 } else {
                     $itemWeightInKG = $weight;
                 }
             }
             $params['shipment_total_actual_weight'] += $itemWeightInKG * $item->getQty();
         }
         $params['shipment_currency_sale'] = $shipment->getOrder()->getOrderCurrencyCode();
         if ($shipment->getDeliveryDutyType() == Dutycalculator_Charge_Helper_Data::DC_DELIVERY_TYPE_DDP) {
             $params['shipment_incoterms'] = 'DDP';
         } elseif ($shipment->getDeliveryDutyType() == Dutycalculator_Charge_Helper_Data::DC_DELIVERY_TYPE_DDU) {
             $params['shipment_incoterms'] = 'DAP';
         } else {
             $params['shipment_incoterms'] = '';
         }
         $shippingAddress = $shipment->getShippingAddress();
         $billingAddress = $shipment->getBillingAddress();
         $params['shipto_first_name'] = $shippingAddress->getFirstname();
         $params['shipto_last_name'] = $shippingAddress->getLastname();
         $params['shipto_address_line_1'] = $shippingAddress->getStreet(-1);
         $params['shipto_city'] = $shippingAddress->getCity();
         $params['shipto_zip'] = $shippingAddress->getPostcode();
         $params['shipto_country'] = $shippingAddress->getCountryId();
         $params['shipto_phone'] = $shippingAddress->getTelephone();
         $params['soldto_first_name'] = $billingAddress->getFirstname();
         $params['soldto_last_name'] = $billingAddress->getLastname();
         $params['soldto_address_line_1'] = $billingAddress->getStreet(-1);
         $params['soldto_city'] = $billingAddress->getCity();
         $params['soldto_zip'] = $billingAddress->getPostcode();
         $params['soldto_country'] = $billingAddress->getCountryId();
         $params['soldto_phone'] = $billingAddress->getTelephone();
         $params['print_first_name'] = Mage::getStoreConfig('dc_charge_extension/dccharge/seller-first-name');
         $params['print_last_name'] = Mage::getStoreConfig('dc_charge_extension/dccharge/seller-last-name');
         $params['print_date'] = date('Y-m-d');
         $rawXml = $helper->sendRequest('documents', $params);
         try {
             if (stripos($rawXml, '<?xml') === false) {
                 throw new Exception($rawXml);
             }
             $answer = new SimpleXMLElement($rawXml);
             $commercialInvoice = current($answer->xpath('commercial-invoice'));
             $packingList = current($answer->xpath('packing-list'));
             $result['commercial_invoice_url'] = (string) $commercialInvoice->url;
             $result['packing_list_url'] = (string) $packingList->url;
         } catch (Exception $ex) {
             Mage::logException($ex);
         }
     }
     return $result;
 }
Пример #26
0
 /**
  * Saves the Shipment changes in the Order
  *
  * @param $shipment Mage_Sales_Model_Order_Shipment
  * @param $order Mage_Sales_Model_Order
  * @param $customerEmailComments string
  */
 protected function _saveShipment(Mage_Sales_Model_Order_Shipment $shipment, Mage_Sales_Model_Order $order, $customerEmailComments = '')
 {
     $shipment->getOrder()->setIsInProcess(true);
     $transactionSave = Mage::getModel('core/resource_transaction')->addObject($shipment)->addObject($order)->save();
     $emailSentStatus = $shipment->getData('email_sent');
     if (!is_null($customerEmail) && !$emailSentStatus) {
         $shipment->sendEmail(true, $customerEmailComments);
         $shipment->setEmailSent(true);
     }
     return $this;
 }
Пример #27
0
 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;
 }
Пример #28
0
 /**
  * Send vendor comment to store owner
  *
  * @param Mage_Sales_Model_Order_Shipment $shipment
  * @param string $comment
  */
 public function sendVendorComment($shipment, $comment)
 {
     $order = $shipment->getOrder();
     $store = $order->getStore();
     $to = $store->getConfig('udropship/admin/vendor_comments_receiver');
     $subject = $store->getConfig('udropship/admin/vendor_comments_subject');
     $template = $store->getConfig('udropship/admin/vendor_comments_template');
     $vendor = $this->getVendor($shipment->getUdropshipVendor());
     $ahlp = Mage::getModel('adminhtml/url');
     if ($subject && $template && $vendor->getId()) {
         $toEmail = $store->getConfig('trans_email/ident_' . $to . '/email');
         $toName = $store->getConfig('trans_email/ident_' . $to . '/name');
         $data = array('vendor_name' => $vendor->getVendorName(), 'order_id' => $order->getIncrementId(), 'shipment_id' => $shipment->getIncrementId(), 'vendor_url' => $ahlp->getUrl('udropship/adminhtml_vendor/edit', array('id' => $vendor->getId())), 'order_url' => $ahlp->getUrl('adminhtml/sales_order/view', array('order_id' => $order->getId())), 'shipment_url' => $ahlp->getUrl('adminhtml/sales_order_shipment/view', array('shipment_id' => $shipment->getId(), 'order_id' => $order->getId())), 'comment' => $comment);
         if ($this->isUdpoActive() && ($po = Mage::helper('udpo')->getShipmentPo($shipment))) {
             $data['po_id'] = $po->getIncrementId();
             $data['po_url'] = $ahlp->getUrl('udpoadmin/order_po/view', array('udpo_id' => $po->getId(), 'order_id' => $order->getId()));
             $template = preg_replace('/{{isPoAvailable}}(.*?){{\\/isPoAvailable}}/s', '\\1', $template);
         } else {
             $template = preg_replace('/{{isPoAvailable}}.*?{{\\/isPoAvailable}}/s', '', $template);
         }
         foreach ($data as $k => $v) {
             $subject = str_replace('{{' . $k . '}}', $v, $subject);
             $template = str_replace('{{' . $k . '}}', $v, $template);
         }
         $mail = Mage::getModel('core/email')->setFromEmail($vendor->getEmail())->setFromName($vendor->getVendorName())->setToEmail($toEmail)->setToName($toName)->setSubject($subject)->setBody($template)->send();
         //mail('"'.$toName.'" <'.$toEmail.'>', $subject, $template, 'From: "'.$vendor->getVendorName().'" <'.$vendor->getEmail().'>');
     }
     Mage::helper('udropship')->addShipmentComment($shipment, $this->__($vendor->getVendorName() . ': ' . $comment));
     $shipment->getCommentsCollection()->save();
     return $this;
 }
Пример #29
0
 /**
  * Getter for billing address of order by format
  *
  * @param Mage_Sales_Model_Order_Shipment $shipment
  * @return array
  */
 public function getShipmentItems($shipment)
 {
     $res = array();
     foreach ($shipment->getItemsCollection() as $item) {
         if (!$item->getOrderItem()->getParentItem()) {
             $res[] = $item;
         }
     }
     return $res;
 }
Пример #30
0
 /**
  * Save shipment and order in one transaction
  *
  * @param Mage_Sales_Model_Order_Shipment $shipment
  * @return Mage_Adminhtml_Sales_Order_ShipmentController
  */
 protected function _saveShipment($shipment)
 {
     $shipment->getOrder()->setIsInProcess(true);
     $transactionSave = Mage::getModel('core/resource_transaction')->addObject($shipment)->addObject($shipment->getOrder());
     // HiepHM Process vendor order
     if ($vendorOrder = Mage::registry('vendor_order')) {
         /* @var $vendorOrder SM_Vendors_Model_Order */
         $vendorOrder->registerShipment($shipment);
         $transactionSave->addObject($vendorOrder);
     }
     $transactionSave->save();
     return $this;
 }