示例#1
0
 /**
  * Returns the shipping method of the given order.
  *
  * @param Mage_Sales_Model_Order $order The order to return info from
  * @return String The name of the shipping method
  */
 protected function getShippingMethod($order)
 {
     if (!$order->getIsVirtual() && $order->getShippingMethod()) {
         return $order->getShippingMethod();
     }
     return '';
 }
示例#2
0
/**
 * Returns the shipping method of the given order.
 *
 * @param Mage_Sales_Model_Order $order The order to return info from
 * @return String The name of the shipping method
 */
function getShippingMethod($order)
{
    if (!$order->getIsVirtual() && $order->getShippingDescription()) {
        return $order->getShippingDescription();
    } else {
        if (!$order->getIsVirtual() && $order->getShippingMethod()) {
            return $order->getShippingMethod();
        }
    }
    return '';
}
示例#3
0
 /**
  * Do a few checks to see if the template should be rendered before actually rendering it.
  *
  * @return string
  *
  * @see Mage_Adminhtml_Block_Abstract::_toHtml()
  */
 protected function _toHtml()
 {
     $shippingMethod = $this->_order->getShippingMethod();
     if (!$this->_helper->isEnabled() || !$this->_order || !$this->_helper->shippingMethodIsMyParcel($shippingMethod)) {
         return '';
     }
     return parent::_toHtml();
 }
 /**
  * Sends notification mail for selected shipping rate
  *
  * The code for this functionality is based on Mage_Sales_Model_Order::sendNewOrderEmail()
  *
  * @param Mage_Sales_Model_Order $order
  * @return boolean
  * @throws Exception
  * @see Mage_Sales_Model_Order
  */
 public function sendEmailNotification($order)
 {
     if (strncmp($order->getShippingMethod(), 'shippingrates_', 14) != 0) {
         return false;
     }
     $notificationMail = $order->getShippingCarrier()->getNotificationMail($order->getShippingMethod());
     if (!strlen(trim($notificationMail))) {
         return false;
     }
     $storeId = $order->getStore()->getId();
     // Start store emulation process
     $appEmulation = Mage::getSingleton('core/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(Mage_Sales_Model_Order::XML_PATH_EMAIL_GUEST_TEMPLATE, $storeId);
         $customerName = $order->getBillingAddress()->getName();
     } else {
         $templateId = Mage::getStoreConfig(Mage_Sales_Model_Order::XML_PATH_EMAIL_TEMPLATE, $storeId);
         $customerName = $order->getCustomerName();
     }
     $mailer = Mage::getModel('core/email_template_mailer');
     $emailInfo = Mage::getModel('core/email_info');
     $emailInfo->addTo($notificationMail);
     $mailer->addEmailInfo($emailInfo);
     // Set all required params and send emails
     $mailer->setSender(Mage::getStoreConfig(Mage_Sales_Model_Order::XML_PATH_EMAIL_IDENTITY, $storeId));
     $mailer->setStoreId($storeId);
     $mailer->setTemplateId($templateId);
     $mailer->setTemplateParams(array('order' => $order, 'billing' => $order->getBillingAddress(), 'payment_html' => $paymentBlockHtml));
     $mailer->send();
     return true;
 }
示例#5
0
 /**
  * @return array
  */
 protected function _prepareOrderData()
 {
     // magento 1.5 compat
     $shipping_method_c = $this->_order->getShippingMethod(true);
     $shipping_method = $this->_order->getData('shipping_method');
     $shipping_method_code = $shipping_method_c ? $shipping_method_c->getData('carrier_code') : $shipping_method;
     $data = array_filter(array('currency_code' => $this->_order->getOrderCurrencyCode(), 'shipping_method_code' => $shipping_method_code, 'shipping_method_title' => $this->_order->getShippingDescription(), 'created_on' => $this->_order->getCreatedAt(), 'updated_on' => $this->_order->getUpdatedAt(), 'state' => $this->_order->getState(), 'status' => $this->_order->getStatus(), 'is_gift' => $this->_order->getGiftMessageId() != null, 'ref_quote_id' => $this->_order->getQuoteId(), 'order_subtotal_with_tax' => $this->_order->getSubtotalInclTax(), 'order_subtotal' => $this->_order->getSubtotal(), 'order_tax' => $this->_order->getTaxAmount(), 'order_hidden_tax' => $this->_order->getHiddenTaxAmount(), 'order_shipping_with_tax' => $this->_order->getShippingInclTax(), 'order_shipping' => $this->_order->getShippingAmount(), 'order_discount' => $this->_order->getDiscountAmount(), 'order_shipping_discount' => $this->_order->getShippingDiscountAmount(), 'order_total' => $this->_order->getGrandTotal(), 'order_total_items' => $this->_order->getTotalItemCount()));
     return $data;
 }
示例#6
0
 public static function createFromOrder(Mage_Sales_Model_Order $order)
 {
     $address = $order->getShippingAddress();
     $shippingInfo = new self();
     $shippingInfo->first_name = $address->getFirstname();
     $shippingInfo->last_name = $address->getLastname();
     $shippingInfo->street = $address->getStreet(1);
     $shippingInfo->city = $address->getCity();
     $shippingInfo->state = $address->getRegion();
     $shippingInfo->country = $address->getCountryModel()->getIso2Code();
     $shippingInfo->postcode = $address->getPostcode();
     $shippingInfo->name = $order->getShippingMethod();
     $shippingInfo->price = Aplazame_Sdk_Serializer_Decimal::fromFloat($order->getShippingAmount());
     $shippingInfo->phone = $address->getTelephone();
     $shippingInfo->alt_phone = $address->getAltTelephone();
     $shippingInfo->address_addition = $address->getStreet(2);
     if ($order->getShippingAmount() > 0) {
         $shippingInfo->tax_rate = Aplazame_Sdk_Serializer_Decimal::fromFloat(100 * $order->getShippingTaxAmount() / $order->getShippingAmount());
     }
     $shippingInfo->discount = Aplazame_Sdk_Serializer_Decimal::fromFloat($order->getShippingDiscountAmount());
     return $shippingInfo;
 }
示例#7
0
 /**
  * @param Mage_Sales_Model_Order $order
  * @return array
  */
 private function getShippingConfiguration(Mage_Sales_Model_Order $order)
 {
     return explode('_', $order->getShippingMethod());
 }
示例#8
0
 /**
  * Returns carrier code of order
  *
  * @param Mage_Sales_Model_Order $order
  * @return string
  */
 protected function _getCarrierCodeFromOrder(Mage_Sales_Model_Order $order)
 {
     list($carrierCode, $method) = explode('_', $order->getShippingMethod(), 2);
     return $carrierCode;
 }
示例#9
0
 /**
  * Convert order to shipping address
  *
  * @param   Mage_Sales_Model_Order $order
  * @return  Mage_Sales_Model_Quote_Address
  */
 public function toQuoteShippingAddress(Mage_Sales_Model_Order $order)
 {
     $address = $this->addressToQuoteAddress($order->getShippingAddress());
     $address->setWeight($order->getWeight())->setShippingMethod($order->getShippingMethod())->setShippingDescription($order->getShippingDescription())->setShippingRate($order->getShippingRate())->setSubtotal($order->getSubtotal())->setTaxAmount($order->getTaxAmount())->setDiscountAmount($order->getDiscountAmount())->setShippingAmount($order->getShippingAmount())->setGiftcertAmount($order->getGiftcertAmount())->setCustbalanceAmount($order->getCustbalanceAmount())->setGrandTotal($order->getGrandTotal())->setBaseSubtotal($order->getBaseSubtotal())->setBaseTaxAmount($order->getBaseTaxAmount())->setBaseDiscountAmount($order->getBaseDiscountAmount())->setBaseShippingAmount($order->getBaseShippingAmount())->setBaseGiftcertAmount($order->getBaseGiftcertAmount())->setBaseCustbalanceAmount($order->getBaseCustbalanceAmount())->setBaseGrandTotal($order->getBaseGrandTotal());
     return $address;
 }
示例#10
0
 /**
  * Build a hash over some unmodifiable(!) order properties.
  *
  * @param Mage_Sales_Model_Order $order
  * @return string
  */
 public function createHashForOrder(Mage_Sales_Model_Order $order)
 {
     $orderHash = $order->getId();
     $orderHash .= $order->getIncrementId();
     $orderHash .= $order->getQuoteId();
     $orderHash .= $order->getCustomerEmail();
     $orderHash .= $order->getCustomerFirstname();
     $orderHash .= $order->getCustomerLastname();
     $orderHash .= $order->getShippingMethod();
     $orderHash .= $order->getStoreName();
     $orderHash .= $order->getGrandTotal();
     return hash("sha512", $orderHash);
 }
示例#11
0
 /**
  * Enter description here...
  *
  * @param Mage_Sales_Model_Order $order
  * @return Mage_Sales_Model_Quote
  */
 public function createFromOrder(Mage_Sales_Model_Order $order)
 {
     $this->setStoreId($order->getStoreId());
     $this->setBillingAddress(Mage::getModel('sales/quote_address')->importOrderAddress($order->getBillingAddress()));
     $this->setShippingAddress(Mage::getModel('sales/quote_address')->importOrderAddress($order->getShippingAddress()));
     foreach ($order->getItemsCollection() as $item) {
         if ($item->getQtyToShip() > 0) {
             $this->addItem(Mage::getModel('sales/quote_item')->importOrderItem($item));
         }
     }
     $this->getShippingAddress()->setCollectShippingRates(true);
     $this->getShippingAddress()->setShippingMethod($order->getShippingMethod());
     $this->getPayment()->importOrderPayment($order->getPayment());
     $this->setCouponCode($order->getCouponeCode());
     return $this;
 }
 /**
  * Return shipping code based on PagSeguro Documentation
  * 1 – PAC, 2 – SEDEX, 3 - Desconhecido
  * @param Mage_Sales_Model_Order $order
  *
  * @return string
  */
 private function _getShippingType(Mage_Sales_Model_Order $order)
 {
     $method = strtolower($order->getShippingMethod());
     if (strstr($method, 'pac') !== false) {
         return '1';
     } else {
         if (strstr($method, 'sedex') !== false) {
             return '2';
         }
     }
     return '3';
 }
示例#13
0
 /**
  *
  * @param Mage_Sales_Model_Order $order
  * @param string                 $city
  * @param string                 $postcode
  * @param array                  $weightsPackages
  * @param string                 $errorStr
  *
  * @return double
  */
 public function getShippingCost(Mage_Sales_Model_Order $order, $city, $postcode, $weightsPackages, &$errorStr)
 {
     $shippingAddress = $order->getShippingAddress();
     $city = $city ? $city : $shippingAddress->getCity();
     $postcode = $postcode ? $postcode : $shippingAddress->getPostcode();
     $serviceCode = $this->_getHelper()->getDPDServiceCode($order->getShippingMethod());
     $street = is_array($shippingAddress->getStreetFull()) ? implode("\n", $shippingAddress->getStreetFull()) : $shippingAddress->getStreetFull();
     $apiParams = $this->_getWsHelper()->getShipmentParams($order->getStore());
     $apiParams['method'] = Zitec_Dpd_Api_Configs::METHOD_SHIPMENT_CALCULATE_PRICE;
     try {
         $dpdApi = new Zitec_Dpd_Api($apiParams);
         $calculatePrice = $dpdApi->getApiMethodObject();
         $calculatePrice->setReceiverAddress($street, $city, $postcode, $shippingAddress->getCountryId())->setShipmentServiceCode($serviceCode);
         foreach ($weightsPackages as $parcelWeight) {
             $calculatePrice->addParcel($parcelWeight);
         }
         $insurance = Mage::helper('zitec_dpd')->extractInsuranceValuesByOrder($order);
         $calculatePrice = $calculatePrice->setAdditionalHighInsurance($insurance['goodsValue'], $insurance['currency'], $insurance['content']);
         $calculatePrice->execute();
     } catch (Exception $e) {
         $errorStr = $this->_getHelper()->__("Error obtaining shipping price: %s", $e->getMessage());
         $this->_getHelper()->log("An error occurred whilst calculating the DPD price for the shipment {$e->getMessage()}");
         return 0;
     }
     $response = $calculatePrice->getCalculatePriceResponse();
     if ($response->hasError()) {
         $errorStr = $this->_getHelper()->__("DPD error: %s", $response->getErrorText());
         $this->_getHelper()->log("DPD returned the following error whilst attempting to calculate the price of a shipment: {$response->getErrorText()}");
         return 0;
     }
     if ($order->getBaseCurrencyCode() == $response->getCurrency()) {
         return $response->getAmount();
     } else {
         if ($order->getBaseCurrencyCode() == $response->getCurrencyLocal()) {
             return $response->getAmountLocal();
         } else {
             $errorStr = $this->_getHelper()->__("Shipping price not available in order currency");
             $this->_getHelper()->log("An error occurred whilst calculating the price of a shipment. The base currency of the shipment ({$order->getBaseCurrencyCode()}) does not correspond to the currency ({$response->getCurrency()}) or the local currency ({$response->getCurrencyLocal()})  used by DPD.");
             return 0;
         }
     }
 }