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; }