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; }
/** * Getter for shipment address by format * * @param Mage_Sales_Model_Order_Shipment $shipment * @return string */ public function getShipmentAddressFormattedHtml($shipment) { $shippingAddress = $shipment->getShippingAddress(); if (!$shippingAddress instanceof Mage_Sales_Model_Order_Address) { return ''; } return $shippingAddress->format('html'); }
/** * 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; }