예제 #1
0
 /**
  * Retrieve order item value by key
  *
  * @param Mage_Sales_Model_Order $order
  * @param string $key
  * @return string
  */
 public function getOrderItemValue(Mage_Sales_Model_Order $order, $key)
 {
     $escape = true;
     switch ($key) {
         case 'order_increment_id':
             $value = $order->getIncrementId();
             break;
         case 'created_at':
             $value = $this->helper('core')->formatDate($order->getCreatedAt(), 'short', true);
             break;
         case 'shipping_address':
             $value = $order->getShippingAddress() ? $this->htmlEscape($order->getShippingAddress()->getName()) : $this->__('N/A');
             break;
         case 'order_total':
             $value = $order->formatPrice($order->getGrandTotal());
             $escape = false;
             break;
         case 'status_label':
             $value = $order->getStatusLabel();
             break;
         case 'view_url':
             $value = $this->getUrl('*/order/view', array('order_id' => $order->getId()));
             break;
         default:
             $value = $order->getData($key) ? $order->getData($key) : $this->__('N/A');
     }
     return $escape ? $this->escapeHtml($value) : $value;
 }
예제 #2
0
 protected function _createCustomer(Mage_Sales_Model_Order $order)
 {
     $addresses = array();
     $primaryPhone = null;
     $company = null;
     if ($order->getBillingAddress()) {
         $addresses[] = Mage::helper('xcom_chronicle')->createAddress($order->getBillingAddress(), array(Xcom_Chronicle_Helper_Data::ADDRESS_TAG_BILLING));
         $company = $order->getBillingAddress()->getCompany();
         $primaryPhone = $order->getBillingAddress()->getTelephone();
     }
     if ($order->getShippingAddress()) {
         $addresses[] = Mage::helper('xcom_chronicle')->createAddress($order->getShippingAddress(), array(Xcom_Chronicle_Helper_Data::ADDRESS_TAG_SHIPPING));
     }
     $data = array('id' => Mage::helper('xcom_chronicle')->createEntityId('guest' . $order->getRealOrderId()), 'fullName' => $this->_createCustomerName($order), 'addresses' => $addresses, 'primaryPhone' => array('number' => $primaryPhone, 'type' => 'UNKNOWN'), 'email' => array('emailAddress' => $order->getCustomerEmail(), 'extension' => null), 'gender' => null, 'dateOfBirth' => null, 'company' => $company, 'dateCreated' => date('c', strtotime($order->getCreatedAt())), 'lastModified' => date('c', strtotime($order->getUpdatedAt())), 'sourceIds' => null, 'emailOptOut' => null, 'doNotCall' => null);
     return $data;
 }
 public function redirectAction()
 {
     // Retrieve order
     $order = new Mage_Sales_Model_Order();
     $ccavenue['order_id'] = Mage::getSingleton('checkout/session')->getLastRealOrderId();
     $order->loadByIncrementId($ccavenue['order_id']);
     // Get CCAvenue Parameters
     $ccavenue['action'] = Mage::getStoreConfig('payment/ccavenue/submit_url');
     $ccavenue['merchant_id'] = Mage::getStoreConfig('payment/ccavenue/merchant_id');
     $ccavenue['amount'] = round($order->base_grand_total, 2);
     $ccavenue['redirect_url'] = Mage::getBaseUrl() . 'ccavenue/payment/response';
     $ccavenue['working_key'] = Mage::getStoreConfig('payment/ccavenue/working_key');
     $ccavenue['checksum'] = $this->getCheckSum($ccavenue['merchant_id'], $ccavenue['amount'], $ccavenue['order_id'], $ccavenue['redirect_url'], $ccavenue['working_key']);
     // Retrieve order details
     $billingAddress = $order->getBillingAddress();
     $billingData = $billingAddress->getData();
     $shippingAddress = $order->getShippingAddress();
     if ($shippingAddress) {
         $shippingData = $shippingAddress->getData();
     }
     $ccavenue['billing_cust_name'] = $billingData['firstname'] . ' ' . $billingData['lastname'];
     $ccavenue['billing_cust_address'] = $billingAddress->street;
     $ccavenue['billing_cust_state'] = $billingAddress->region;
     $ccavenue['billing_cust_country'] = Mage::getModel('directory/country')->load($billingAddress->country_id)->getName();
     $ccavenue['billing_cust_tel'] = $billingAddress->telephone;
     $ccavenue['billing_cust_email'] = $order->customer_email;
     if ($shippingAddress) {
         $ccavenue['delivery_cust_name'] = $shippingData['firstname'] . ' ' . $shippingData['lastname'];
         $ccavenue['delivery_cust_address'] = $shippingAddress->street;
         $ccavenue['delivery_cust_state'] = $shippingAddress->region;
         $ccavenue['delivery_cust_country'] = Mage::getModel('directory/country')->load($shippingAddress->country_id)->getName();
         $ccavenue['delivery_cust_tel'] = $shippingAddress->telephone;
         $ccavenue['delivery_city'] = $shippingAddress->city;
         $ccavenue['delivery_zip'] = $shippingAddress->postcode;
     } else {
         $ccavenue['delivery_cust_name'] = '';
         $ccavenue['delivery_cust_address'] = '';
         $ccavenue['delivery_cust_state'] = '';
         $ccavenue['delivery_cust_country'] = '';
         $ccavenue['delivery_cust_tel'] = '';
         $ccavenue['delivery_city'] = '';
         $ccavenue['delivery_zip'] = '';
     }
     $ccavenue['merchant_param'] = '';
     $ccavenue['billing_city'] = $billingAddress->city;
     $ccavenue['billing_zip'] = $billingAddress->postcode;
     $ccavenue['billing_cust_notes'] = '';
     // Insert into CCAvenue Response Log Table
     $now = Mage::getModel('core/date')->timestamp(time());
     Mage::getModel('ccavenue/ccavenueredirect')->setMerchantId($ccavenue['merchant_id'])->setAmount($ccavenue['amount'])->setOrderId($ccavenue['order_id'])->setRedirectUrl($ccavenue['redirect_url'])->setChecksum($ccavenue['checksum'])->setBillingCustName(addslashes($ccavenue['billing_cust_name']))->setBillingCustAddress(addslashes($ccavenue['billing_cust_address']))->setBillingCustCountry(addslashes($ccavenue['billing_cust_country']))->setBillingCustState(addslashes($ccavenue['billing_cust_state']))->setBillingZip($ccavenue['billing_zip'])->setBillingCustTel($ccavenue['billing_cust_tel'])->setBillingCustEmail($ccavenue['billing_cust_email'])->setDeliveryCustName(addslashes($ccavenue['delivery_cust_name']))->setDeliveryCustAddress(addslashes($ccavenue['delivery_cust_address']))->setDeliveryCustCountry(addslashes($ccavenue['delivery_cust_country']))->setDeliveryCustState(addslashes($ccavenue['delivery_cust_state']))->setDeliveryCustTel($ccavenue['delivery_cust_tel'])->setBillingCustNotes($ccavenue['billing_cust_notes'])->setMerchantParam($ccavenue['merchant_param'])->setBillingCustCity(addslashes($ccavenue['billing_city']))->setBillingZipCode($ccavenue['billing_zip'])->setDeliveryCustCity(addslashes($ccavenue['delivery_city']))->setDeliveryZipCode($ccavenue['delivery_zip'])->setCcavenueRedirectIp($this->get_uer_ip())->setCcavenueRedirectDtime(date('Y-m-d H:i:s', $now))->save();
     // Add data to registry so it's accessible in the view file
     Mage::register('ccavenue', $ccavenue);
     // Render layout
     $this->loadLayout();
     $block = $this->getLayout()->createBlock('Mage_Core_Block_Template', 'ccavenue', array('template' => 'ccavenue/redirect.phtml'));
     $this->getLayout()->getBlock('content')->append($block);
     $this->renderLayout();
 }
예제 #4
0
 /**
  * @magentoDataFixture Mage/Downloadable/_files/product.php
  * @magentoDataFixture Mage/Downloadable/_files/order_with_downloadable_product.php
  * @magentoDataFixture Mage/Adminhtml/_files/order_shipping_address_different_to_billing.php
  */
 public function testInitFromOrderShippingAddressSameAsBillingWhenDifferent()
 {
     $order = new Mage_Sales_Model_Order();
     $order->loadByIncrementId('100000001');
     $this->assertNull($order->getShippingAddress()->getSameAsBilling());
     Mage::unregister('rule_data');
     $this->_model->initFromOrder($order);
     $this->assertFalse($order->getShippingAddress()->getSameAsBilling());
 }
예제 #5
0
 /**
  * Collect options selected at checkout and calculate type consignment
  *
  * @return string
  */
 public function getCheckoutOptionsHtml()
 {
     $html = false;
     $pgAddress = $this->_helper->getPgAddress($this->_order);
     /** @var object $data Data from checkout */
     $data = $this->_order->getMyparcelData() !== null ? json_decode($this->_order->getMyparcelData(), true) : false;
     $shippingMethod = $this->_order->getShippingMethod();
     if ($pgAddress && $this->_helper->shippingMethodIsPakjegemak($shippingMethod)) {
         if (is_array($data) && key_exists('location', $data)) {
             $dateTime = date('d-m-Y H:i', strtotime($data['date'] . ' ' . $data['start_time']));
             $html .= $this->__('PostNL location:') . ' ' . $dateTime;
             if ($data['price_comment'] != 'retail') {
                 $html .= ', ' . $this->__('TYPE_' . $data['price_comment']);
             }
             $html .= ', ' . $data['location'] . ', ' . $data['city'] . ' (' . $data['postal_code'] . ')';
         } else {
             /** Old data from orders before version 1.6.0 */
             $html .= $this->__('PostNL location:') . ' ' . $pgAddress->getCompany() . ' ' . $pgAddress->getCity();
         }
     } else {
         // Get package type
         $totalWeight = $this->_helper->getTotalWeight($this->_order->getAllVisibleItems());
         if ($totalWeight !== false) {
             $html .= $this->_helper->getPackageType($totalWeight, $this->_order->getShippingAddress()->getCountryId(), true) . ' ';
             if (is_array($data) && key_exists('date', $data)) {
                 $dateTime = date('d-m-Y H:i', strtotime($data['date'] . ' ' . $data['time'][0]['start']));
                 $html .= $this->__('deliver:') . ' ' . $dateTime;
                 if ($data['time'][0]['price_comment'] != 'standard') {
                     $html .= ', ' . $this->__('TYPE_' . $data['time'][0]['price_comment']);
                 }
                 if (key_exists('home_address_only', $data) && $data['home_address_only']) {
                     $html .= ', ' . strtolower($this->__('Home address only'));
                 }
                 if (key_exists('signed', $data) && $data['signed']) {
                     $html .= ', ' . strtolower($this->__('Signature on receipt'));
                 }
             }
         }
     }
     if (is_array($data) && key_exists('browser', $data)) {
         $html = ' <span title="' . $data['browser'] . '"">' . $html . '</span>';
     }
     return $html !== false ? '<br>' . $html : '';
 }
예제 #6
0
 /**
  * Saves billing section to order
  * @param Mage_Sales_Model_Order $Order
  * @return
  */
 public function preset(Mage_Sales_Model_Order $order, $data)
 {
     $ba = $order->getShippingAddress();
     foreach ($data as $k => $v) {
         $ba->setData($k, $v);
     }
     $ba->implodeStreetAddress();
     $ba->save();
     return $order;
 }
예제 #7
0
 /**
  * (re)Render all items and totals
  */
 protected function _render()
 {
     if (!$this->_shouldRender) {
         return;
     }
     // regular items from the sales entity
     $this->_items = array();
     foreach ($this->_salesEntity->getAllItems() as $item) {
         if (!$item->getParentItem()) {
             $this->_addRegularItem($item);
         }
     }
     end($this->_items);
     $lastRegularItemKey = key($this->_items);
     // regular totals
     $shippingDescription = '';
     if ($this->_salesEntity instanceof Mage_Sales_Model_Order) {
         $shippingDescription = $this->_salesEntity->getShippingDescription();
         $this->_totals = array(self::TOTAL_SUBTOTAL => $this->_salesEntity->getBaseSubtotal(), self::TOTAL_TAX => $this->_salesEntity->getBaseTaxAmount(), self::TOTAL_SHIPPING => $this->_salesEntity->getBaseShippingAmount(), self::TOTAL_DISCOUNT => abs($this->_salesEntity->getBaseDiscountAmount()));
         $this->_applyHiddenTaxWorkaround($this->_salesEntity);
     } else {
         $address = $this->_salesEntity->getIsVirtual() ? $this->_salesEntity->getBillingAddress() : $this->_salesEntity->getShippingAddress();
         $shippingDescription = $address->getShippingDescription();
         $this->_totals = array(self::TOTAL_SUBTOTAL => $this->_salesEntity->getBaseSubtotal(), self::TOTAL_TAX => $address->getBaseTaxAmount(), self::TOTAL_SHIPPING => $address->getBaseShippingAmount(), self::TOTAL_DISCOUNT => abs($address->getBaseDiscountAmount()));
         $this->_applyHiddenTaxWorkaround($address);
     }
     $originalDiscount = $this->_totals[self::TOTAL_DISCOUNT];
     // arbitrary items, total modifications
     Mage::dispatchEvent('paypal_prepare_line_items', array('paypal_cart' => $this));
     // distinguish original discount among the others
     if ($originalDiscount > 0.0001 && isset($this->_totalLineItemDescriptions[self::TOTAL_DISCOUNT])) {
         $this->_totalLineItemDescriptions[self::TOTAL_DISCOUNT][] = Mage::helper('sales')->__('Discount (%s)', Mage::app()->getStore()->convertPrice($originalDiscount, true, false));
     }
     // discount, shipping as items
     if ($this->_isDiscountAsItem && $this->_totals[self::TOTAL_DISCOUNT]) {
         $this->addItem(Mage::helper('paypal')->__('Discount'), 1, -1.0 * $this->_totals[self::TOTAL_DISCOUNT], $this->_renderTotalLineItemDescriptions(self::TOTAL_DISCOUNT));
     }
     $shippingItemId = $this->_renderTotalLineItemDescriptions(self::TOTAL_SHIPPING, $shippingDescription);
     if ($this->_isShippingAsItem && (double) $this->_totals[self::TOTAL_SHIPPING]) {
         $this->addItem(Mage::helper('paypal')->__('Shipping'), 1, (double) $this->_totals[self::TOTAL_SHIPPING], $shippingItemId);
     }
     // compound non-regular items into subtotal
     foreach ($this->_items as $key => $item) {
         if ($key > $lastRegularItemKey && $item->getAmount() != 0) {
             $this->_totals[self::TOTAL_SUBTOTAL] += $item->getAmount();
         }
     }
     $this->_validate();
     // if cart items are invalid, prepare cart for transfer without line items
     if (!$this->_areItemsValid) {
         $this->removeItem($shippingItemId);
     }
     $this->_shouldRender = false;
 }
 /**
  * Dispatch events for before the order has been submitted.
  *
  * @param Mage_Sales_Model_Quote
  * @param Mage_Sales_Model_Order
  * @return self
  */
 public function dispatchBeforeOrderSubmit(Mage_Sales_Model_Quote $quote, Mage_Sales_Model_Order $order)
 {
     // Dispatch the multishipping single order create event. This event
     // doesn't exactly mean the same in ROM Multishipping checkout but
     // is still used to preserve compatibility with extensions that expect
     // the event. Provide the primary shipping address as the address in
     // the event as this would be closes to the one address included
     // in base Magento. Existing observers in Magento don't appear to need
     // it but keeping it in case any 3rd party extensions do expect it.
     Mage::dispatchEvent('checkout_type_multishipping_create_orders_single', ['order' => $order, 'address' => $order->getShippingAddress()]);
     return $this;
 }
 public function redirectAction()
 {
     // Retrieve order
     $order = new Mage_Sales_Model_Order();
     $customcard['order_id'] = Mage::getSingleton('checkout/session')->getLastRealOrderId();
     $order->loadByIncrementId($customcard['order_id']);
     // Get Custom card method Parameters
     $customcard['action'] = Mage::getStoreConfig('payment/paymentmodulepackbankin_checkout/submit_url');
     $customcard['merchant_id'] = Mage::getStoreConfig('payment/paymentmodulepackbankin_checkout/merchant_id');
     $customcard['amount'] = round($order->base_grand_total, 2);
     $customcard['redirect_url'] = Mage::getBaseUrl() . 'paymentmodulepackbankin_checkout/payment/response';
     // Retrieve order details
     $billingAddress = $order->getBillingAddress();
     $billingData = $billingAddress->getData();
     $shippingAddress = $order->getShippingAddress();
     if ($shippingAddress) {
         $shippingData = $shippingAddress->getData();
     }
     $customcard['billing_cust_name'] = $billingData['firstname'] . ' ' . $billingData['lastname'];
     $customcard['billing_cust_address'] = $billingAddress->street;
     $customcard['billing_cust_state'] = $billingAddress->region;
     $customcard['billing_cust_country'] = Mage::getModel('directory/country')->load($billingAddress->country_id)->getName();
     $customcard['billing_cust_tel'] = $billingAddress->telephone;
     $customcard['billing_cust_email'] = $order->customer_email;
     if ($shippingAddress) {
         $customcard['delivery_cust_name'] = $shippingData['firstname'] . ' ' . $shippingData['lastname'];
         $customcard['delivery_cust_address'] = $shippingAddress->street;
         $customcard['delivery_cust_state'] = $shippingAddress->region;
         $customcard['delivery_cust_country'] = Mage::getModel('directory/country')->load($shippingAddress->country_id)->getName();
         $customcard['delivery_cust_tel'] = $shippingAddress->telephone;
         $customcard['delivery_city'] = $shippingAddress->city;
         $customcard['delivery_zip'] = $shippingAddress->postcode;
     } else {
         $customcard['delivery_cust_name'] = '';
         $customcard['delivery_cust_address'] = '';
         $customcard['delivery_cust_state'] = '';
         $customcard['delivery_cust_country'] = '';
         $customcard['delivery_cust_tel'] = '';
         $customcard['delivery_city'] = '';
         $customcard['delivery_zip'] = '';
     }
     $customcard['merchant_param'] = '';
     $customcard['billing_city'] = $billingAddress->city;
     $customcard['billing_zip'] = $billingAddress->postcode;
     $customcard['billing_cust_notes'] = '';
     // Add data to registry so it's accessible in the view file
     Mage::register('customcard', $customcard);
     // Render layout
     $this->loadLayout();
     $block = $this->getLayout()->createBlock('Mage_Core_Block_Template', 'customcard', array('template' => 'paymentmodulepackbankin/redirect.phtml'));
     $this->getLayout()->getBlock('content')->append($block);
     $this->renderLayout();
 }
 /**
  * Encodes a single Magento Order.
  *
  * @param Mage_Sales_Model_Order $order
  *
  * @return RTDOrder
  */
 protected function _encodeOrder(Mage_Sales_Model_Order $order)
 {
     $encodedOrder = new RTDOrder();
     $customMapping = Mage::getConfig()->getNode('rtd_mappings/order');
     foreach ($customMapping->asArray() as $magentoKey => $rtdKey) {
         $encodedOrder->setParam($rtdKey, $order->{'get' . $magentoKey}());
     }
     $this->_encodeShippingAddress($encodedOrder, $order->getShippingAddress());
     $this->_encodeBillingAddress($encodedOrder, $order->getBillingAddress());
     $this->_encodeOrderLines($encodedOrder, $order);
     $this->_encodeShipment($encodedOrder, $order);
     return $encodedOrder;
 }
 /**
  * Generate and return the Wirecard shipping Object if shipping is necessary
  *
  * @return WirecardCEE_Client_QPay_Request_Initiation_ConsumerData_Address
  */
 protected function _getShippingObject()
 {
     $shipping = $this->_order->getShippingAddress();
     $shippingAddressObj = new WirecardCEE_Client_QPay_Request_Initiation_ConsumerData_Address(WirecardCEE_Client_QPay_Request_Initiation_ConsumerData_Address::TYPE_SHIPPING);
     $shippingAddressObj->setFirstname($shipping->getFirstname());
     $shippingAddressObj->setLastname($shipping->getLastname());
     $shippingAddressObj->setAddress1($shipping->getStreet1());
     $shippingAddressObj->setAddress2($shipping->getStreet2());
     $shippingAddressObj->setCity($shipping->getCity());
     $shippingAddressObj->setCountry($shipping->getCountry());
     $shippingAddressObj->setState($shipping->getRegionCode());
     $shippingAddressObj->setZipCode($shipping->getPostcode());
     $shippingAddressObj->setFax($shipping->getFax());
     $shippingAddressObj->setPhone($shipping->getTelephone());
     return $shippingAddressObj;
 }
예제 #12
0
 /**
  * @param Mage_Sales_Model_Order $order
  * @return int
  */
 protected function _createCustomer(Mage_Sales_Model_Order $order)
 {
     /** @var $customer Mage_Customer_Model_Customer */
     $customer = Mage::getModel('customer/customer')->setWebsiteId($order->getStore()->getWebsiteId())->loadByEmail($order->getCustomerEmail());
     $customerGroupId = 1;
     // @todo load general customer group ID?
     if (!$customer->getId()) {
         $customer->addData(array('prefix' => $order->getCustomerPrefix(), 'firstname' => $order->getCustomerFirstname(), 'middlename' => $order->getCustomerMiddlename(), 'lastname' => $order->getCustomerLastname(), 'suffix' => $order->getCustomerSuffix(), 'email' => $order->getCustomerEmail(), 'group_id' => $customerGroupId, 'taxvat' => $order->getCustomerTaxvat(), 'website_id' => $order->getStore()->getWebsiteId(), 'default_billing' => '_item1', 'default_shipping' => '_item2'));
         // Billing Address
         /** @var $billingAddress Mage_Sales_Model_Order_Address */
         $billingAddress = $order->getBillingAddress();
         /** @var $customerBillingAddress Mage_Customer_Model_Address */
         $customerBillingAddress = Mage::getModel('customer/address');
         $billingAddressArray = $billingAddress->toArray();
         unset($billingAddressArray['entity_id']);
         unset($billingAddressArray['parent_id']);
         unset($billingAddressArray['customer_id']);
         unset($billingAddressArray['customer_address_id']);
         unset($billingAddressArray['quote_address_id']);
         $customerBillingAddress->addData($billingAddressArray);
         $customerBillingAddress->setPostIndex('_item1');
         $customer->addAddress($customerBillingAddress);
         // Shipping Address
         /** @var $shippingAddress Mage_Sales_Model_Order_Address */
         $shippingAddress = $order->getShippingAddress();
         /** @var $customerShippingAddress Mage_Customer_Model_Address */
         $customerShippingAddress = Mage::getModel('customer/address');
         $shippingAddressArray = $shippingAddress->toArray();
         unset($shippingAddressArray['entity_id']);
         unset($shippingAddressArray['parent_id']);
         unset($shippingAddressArray['customer_id']);
         unset($shippingAddressArray['customer_address_id']);
         unset($shippingAddressArray['quote_address_id']);
         $customerShippingAddress->addData($shippingAddressArray);
         $customerShippingAddress->setPostIndex('_item2');
         $customer->addAddress($customerShippingAddress);
         // Save the customer
         $customer->setPassword($customer->generatePassword());
         $customer->save();
     }
     // Link customer to order
     $order->setCustomerId($customer->getId());
     $order->setCustomerIsGuest(0);
     $order->setCustomerGroupId($customerGroupId);
     $order->save();
     return $customer->getId();
 }
 /**
  * @param Mage_Sales_Model_Order $order
  * @return boolean $isDifferent
  */
 protected function _addressesesAreDifferent($order)
 {
     $isDifferent = 0;
     if ($order->getIsVirtual()) {
         return $isDifferent;
     }
     $billingAddress = $order->getBillingAddress();
     $shippingAddress = $order->getShippingAddress();
     $methods = array('getStreetFull', 'getCity', 'getCountryId', 'getPostcode', 'getRegionId');
     foreach ($methods as $method_name) {
         $billingValue = call_user_func(array($billingAddress, $method_name));
         $shippingValue = call_user_func(array($shippingAddress, $method_name));
         if ($billingValue != $shippingValue) {
             $isDifferent = 1;
             break;
         }
     }
     return $isDifferent;
 }
예제 #14
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;
 }
예제 #15
0
 protected function _initShippingAddressFromOrder(Mage_Sales_Model_Order $order)
 {
     $this->getQuote()->getShippingAddress()->setCustomerAddressId('');
     Mage::helper('core')->copyFieldset('sales_copy_order_shipping_address', 'to_order', $order->getShippingAddress(), $this->getQuote()->getShippingAddress());
 }
예제 #16
0
 /**
  * Retrieve Vat Id from order
  *
  * @param Mage_Sales_Model_Order $order
  * @return string
  */
 protected function _getVatIdByOrder($order)
 {
     $shippingAddress = $order->getShippingAddress();
     if ($shippingAddress && $shippingAddress->getVatId()) {
         return $shippingAddress->getVatId();
     }
     return $order->getBillingAddress()->getVatId();
 }
예제 #17
0
 /**
  * Register on Magento's registry GUEST customer data for MergeVars for on checkout subscribe
  *
  * @param Mage_Sales_Model_Order $order
  * @return void
  */
 public function registerGuestCustomer($order)
 {
     if (Mage::registry('mc_guest_customer')) {
         return;
     }
     $customer = new Varien_Object();
     $customer->setId('guest' . time());
     $customer->setEmail($order->getBillingAddress()->getEmail());
     $customer->setStoreId($order->getStoreId());
     $customer->setFirstname($order->getBillingAddress()->getFirstname());
     $customer->setLastname($order->getBillingAddress()->getLastname());
     $customer->setPrimaryBillingAddress($order->getBillingAddress());
     $customer->setPrimaryShippingAddress($order->getShippingAddress());
     Mage::register('mc_guest_customer', $customer, TRUE);
 }
예제 #18
0
 /**
  * Article type can be documents (1), merchandise (2) or own packaging (7)
  *
  * @param Mage_Sales_Model_Order $order
  * @return int
  */
 private function getArticleType(Mage_Sales_Model_Order $order)
 {
     if ($order->getShippingAddress()->getCountry() == 'AU') {
         return 7;
     } else {
         $shippingMethod = $this->getShippingConfiguration($order);
         if (isset($shippingMethod[4]) && $shippingMethod[4] == 'D') {
             return 1;
         }
         return 2;
     }
 }
예제 #19
0
파일: Order.php 프로젝트: quyip8818/Mag
 /**
  * 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());
     Mage::helper('core')->copyFieldset('sales_convert_order', 'to_quote_address', $order, $address);
     return $address;
 }
예제 #20
0
 /**
  * Get order request data as array
  *
  * @param Mage_Sales_Model_Order $order
  * @return array
  */
 protected function _getOrderData(Mage_Sales_Model_Order $order)
 {
     $request = array('subtotal' => $this->_formatPrice($this->_formatPrice($order->getPayment()->getBaseAmountAuthorized()) - $this->_formatPrice($order->getBaseTaxAmount()) - $this->_formatPrice($order->getBaseShippingAmount())), 'tax' => $this->_formatPrice($order->getBaseTaxAmount()), 'shipping' => $this->_formatPrice($order->getBaseShippingAmount()), 'invoice' => $order->getIncrementId(), 'address_override' => 'false', 'currency_code' => $order->getBaseCurrencyCode(), 'buyer_email' => $order->getCustomerEmail());
     // append to request billing address data
     if ($billingAddress = $order->getBillingAddress()) {
         $request = array_merge($request, $this->_getBillingAddress($billingAddress));
     }
     // append to request shipping address data
     if ($shippingAddress = $order->getShippingAddress()) {
         $request = array_merge($request, $this->_getShippingAddress($shippingAddress));
     }
     return $request;
 }
예제 #21
0
 /**
  * Update order's customer information based on PayU information
  * @var array result data from payu with billing and shipping info
  */
 protected function updateCustomerData($data)
 {
     try {
         $customerRecord = $data;
         $this->_order->setCustomerFirstname($customerRecord->firstName);
         $this->_order->setCustomerLastname($customerRecord->lastName);
         $this->_order->setCustomerEmail($customerRecord->email);
         if (isset($data->delivery) && !empty($data->delivery)) {
             $shippingAddress = $data->delivery;
             /* $billing = $this->_order->getBillingAddress();
                
                            $billing->setCity($shippingAddress->city);
                            $billing->setStreet($shippingAddress->street);
                            $billing->setPostcode($shippingAddress->postalCode);
                            $billing->setCountryId($shippingAddress->countryCode);
                            
                            $this->_order->setBillingAddress($billing)->save(); */
             $recipient = explode(" ", $shippingAddress->recipientName);
             $shipping = $this->_order->getShippingAddress();
             $shipping->setFirstname($recipient[0]);
             $shipping->setLastname($recipient[1]);
             //$shipping->setTelephone($customerRecord['phone']);
             $shipping->setCity($shippingAddress->city);
             $shipping->setStreet($shippingAddress->street);
             $shipping->setPostcode($shippingAddress->postalCode);
             $shipping->setCountryId($shippingAddress->countryCode);
             $this->_order->setShippingAddress($shipping)->save();
         }
         /* if (isset($data['billing']) && !empty( $data['billing'] )) {
                        $billingAddress = $data['billing'];
            
                        $billing = $this->_order->getBillingAddress();
            
                        $recipient = explode(" ", $billingAddress['recipientName']);
                        
                        $billing->setFirstname($recipient[0]);
                        $billing->setLastname($recipient[1]);
                        $billing->setCompany($billingAddress['recipientName']);
                        $billing->setTelephone($customerRecord['phone']);
                        $billing->setCity($billingAddress['city']);
                        $billing->setStreet($billingAddress['street']);
                        $billing->setPostcode($billingAddress['postalCode']);
                        $billing->setCountryId($billingAddress['countryCode']);
                        //$this->_order->setCustomerTaxvat($billingAddress['TIN']);
            
                        $this->_order->setBillingAddress($billing)->save();
                    }
                    else
                    { 
                        $billing = $this->_order->getBillingAddress();
            
                        $billing->setFirstname($customerRecord['firstName']);
                        $billing->setLastname($customerRecord['lastName']);
                        $billing->setTelephone($customerRecord['phone']);
            
                        $this->_order->setBillingAddress($billing)->save();
                    }  */
         if (!$this->_order->getEmailSent()) {
             $this->_order->sendNewOrderEmail();
             $this->_order->setEmailSent(1);
         }
         $this->_order->save();
     } catch (Error $e) {
         Mage::logException("Can not update order data: " . $e);
     }
 }
예제 #22
0
 /**
  * Article type can be documents (1), merchandise (2) or own packaging (7)
  *
  * @param Mage_Sales_Model_Order $order
  * @return int
  */
 private function getArticleType(Mage_Sales_Model_Order $order)
 {
     if ($order->getShippingAddress()->getCountry() == Fontis_Australia_Helper_Data::AUSTRALIA_COUNTRY_CODE) {
         return 7;
     } else {
         $shippingMethod = $this->getShippingConfiguration($order);
         if (isset($shippingMethod[4]) && $shippingMethod[4] == 'D') {
             return 1;
         }
         return 2;
     }
 }
예제 #23
0
 /**
  * Add Buckaroo Payment fee tax info by recreating the tax request.
  *
  * @param Mage_Sales_Model_Order                                           $order
  * @param array                                                            $fullInfo
  * @param Mage_Sales_Model_Order_Invoice|Mage_Sales_Model_Order_Creditmemo $source
  *
  * @return array
  */
 protected function _addBuckarooFeeTaxInfoFromRequest($order, $fullInfo, $source)
 {
     $store = $order->getStore();
     $taxCalculation = Mage::getSingleton('tax/calculation');
     /**
      * Recalculate the tax request.
      */
     $customerTaxClass = $order->getCustomerTaxClassId();
     $shippingAddress = $order->getShippingAddress();
     $billingAddress = $order->getBillingAddress();
     $codTaxClass = Mage::getStoreConfig(self::XPATH_BUCKAROO_FEE_TAX_CLASS, $store);
     $taxRequest = $taxCalculation->getRateRequest($shippingAddress, $billingAddress, $customerTaxClass, $store);
     $taxRequest->setProductClassId($codTaxClass);
     /**
      * If the tax request fails, there is nothing more we can do. This might occur, if the tax rules have been
      * changed since this order was placed. Unfortunately there is nothing we can do about this.
      */
     if (!$taxRequest) {
         return $fullInfo;
     }
     /**
      * Get the applied rates.
      */
     $appliedRates = Mage::getSingleton('tax/calculation')->getAppliedRates($taxRequest);
     if (!isset($appliedRates[0]['rates'][0]['title'])) {
         return $fullInfo;
     }
     /**
      * Get the tax title from the applied rates.
      */
     $buckarooFeeTaxTitle = $appliedRates[0]['rates'][0]['title'];
     /**
      * Fo through all tax info entries and try to match the title.
      */
     foreach ($fullInfo as $key => $taxInfo) {
         if ($taxInfo['title'] == $buckarooFeeTaxTitle) {
             /**
              * Update the tax info entry with the COD fee tax.
              */
             $fullInfo[$key]['tax_amount'] += $source->getBuckarooFeeTax();
             $fullInfo[$key]['base_tax_amount'] += $source->getBaseBuckarooFeeTax();
             break;
         }
     }
     return $fullInfo;
 }
예제 #24
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());
     AO::helper('core')->copyFieldset('sales_convert_order', 'to_quote_address', $order, $address);
     //        $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;
 }
예제 #25
0
 protected function _initShippingAddressFromOrder(Mage_Sales_Model_Order $order)
 {
     $orderShippingAddress = $order->getShippingAddress();
     $quoteShippingAddress = $this->getQuote()->getShippingAddress()->setCustomerAddressId('')->setSameAsBilling($orderShippingAddress && $orderShippingAddress->getSameAsBilling());
     Mage::helper('core')->copyFieldset('sales_copy_order_shipping_address', 'to_order', $orderShippingAddress, $quoteShippingAddress);
 }
예제 #26
0
파일: Api.php 프로젝트: mollie/magento
 /**
  * @param int                    $amount
  * @param string                 $description
  * @param Mage_Sales_Model_Order $order
  * @param string                 $redirect_url
  * @param string                 $method
  * @param string                 $issuer
  *
  * @return bool
  */
 public function createPayment($amount, $description, $order, $redirect_url, $method, $issuer)
 {
     if (!$this->setAmount($amount)) {
         $this->error_message = "Het opgegeven bedrag \"{$amount}\" is ongeldig";
         return FALSE;
     }
     if (!$this->setRedirectURL($redirect_url)) {
         $this->error_message = "De opgegeven redirect URL \"{$redirect_url}\" is onjuist";
         return FALSE;
     }
     $this->setDescription($description);
     try {
         $api = $this->_getMollieAPI();
     } catch (Mollie_API_Exception $e) {
         $this->error_message = $e->getMessage();
         return FALSE;
     }
     $store = Mage::app()->getStore();
     $params = array("amount" => $this->getAmount(), "description" => $this->getDescription(), "redirectUrl" => $this->getRedirectURL(), "method" => $method, "issuer" => empty($issuer) ? NULL : $issuer, "metadata" => array("order_id" => $order->getId(), "store_id" => $store->getId()), "locale" => $this->getLocaleCode(), "webhookUrl" => $this->getWebhookURL());
     if ($method == "banktransfer" && $this->getBankTransferDueDateDays()) {
         $params += array("dueDate" => $this->getBankTransferDueDateDays(), "billingEmail" => $order->getCustomerEmail());
     }
     if ($billing = $order->getBillingAddress()) {
         $params += array("billingCity" => $billing->getCity(), "billingRegion" => $billing->getRegion(), "billingPostal" => $billing->getPostcode(), "billingCountry" => $billing->getCountryId());
     }
     if ($shipping = $order->getShippingAddress()) {
         $params += array("shippingAddress" => $shipping->getStreetFull(), "shippingCity" => $shipping->getCity(), "shippingRegion" => $shipping->getRegion(), "shippingPostal" => $shipping->getPostcode(), "shippingCountry" => $shipping->getCountry());
     }
     try {
         $payment = $api->payments->create($params);
     } catch (Mollie_API_Exception $e) {
         try {
             if ($e->getField() == "webhookUrl") {
                 unset($params["webhookUrl"]);
                 $payment = $api->payments->create($params);
             } else {
                 throw $e;
             }
         } catch (Mollie_API_Exception $e) {
             $this->error_message = __METHOD__ . ' said: Unable to set up payment. Reason: ' . $e->getMessage();
             Mage::log($this->error_message);
             return FALSE;
         }
     }
     $this->setTransactionId($payment->id);
     $this->payment_url = (string) $payment->getPaymentUrl();
     return TRUE;
 }
예제 #27
0
 /**
  * Add Payex Order Address
  * @param $orderRef
  * @param Mage_Sales_Model_Order $order
  * @return bool
  */
 public function addOrderAddress($orderRef, $order)
 {
     $billingAddress = $order->getBillingAddress()->getStreet();
     $billingCountryCode = $order->getBillingAddress()->getCountry();
     $billingCountry = Mage::getModel('directory/country')->load($billingCountryCode)->getName();
     $params = array('accountNumber' => '', 'orderRef' => $orderRef, 'billingFirstName' => $order->getBillingAddress()->getFirstname(), 'billingLastName' => $order->getBillingAddress()->getLastname(), 'billingAddress1' => $billingAddress[0], 'billingAddress2' => isset($billingAddress[1]) ? $billingAddress[1] : '', 'billingAddress3' => '', 'billingPostNumber' => (string) $order->getBillingAddress()->getPostcode(), 'billingCity' => (string) $order->getBillingAddress()->getCity(), 'billingState' => (string) $order->getBillingAddress()->getRegion(), 'billingCountry' => $billingCountry, 'billingCountryCode' => $billingCountryCode, 'billingEmail' => (string) $order->getBillingAddress()->getEmail(), 'billingPhone' => (string) $order->getBillingAddress()->getTelephone(), 'billingGsm' => '');
     // add Shipping
     $shipping_params = array('deliveryFirstName' => '', 'deliveryLastName' => '', 'deliveryAddress1' => '', 'deliveryAddress2' => '', 'deliveryAddress3' => '', 'deliveryPostNumber' => '', 'deliveryCity' => '', 'deliveryState' => '', 'deliveryCountry' => '', 'deliveryCountryCode' => '', 'deliveryEmail' => '', 'deliveryPhone' => '', 'deliveryGsm' => '');
     if (!$order->getIsVirtual()) {
         $deliveryAddress = $order->getShippingAddress()->getStreet();
         $deliveryCountryCode = $order->getShippingAddress()->getCountry();
         $deliveryCountry = Mage::getModel('directory/country')->load($deliveryCountryCode)->getName();
         $shipping_params = array('deliveryFirstName' => $order->getShippingAddress()->getFirstname(), 'deliveryLastName' => $order->getShippingAddress()->getLastname(), 'deliveryAddress1' => $deliveryAddress[0], 'deliveryAddress2' => isset($deliveryAddress[1]) ? $deliveryAddress[1] : '', 'deliveryAddress3' => '', 'deliveryPostNumber' => (string) $order->getShippingAddress()->getPostcode(), 'deliveryCity' => (string) $order->getShippingAddress()->getCity(), 'deliveryState' => (string) $order->getShippingAddress()->getRegion(), 'deliveryCountry' => $deliveryCountry, 'deliveryCountryCode' => $deliveryCountryCode, 'deliveryEmail' => (string) $order->getShippingAddress()->getEmail(), 'deliveryPhone' => (string) $order->getShippingAddress()->getTelephone(), 'deliveryGsm' => '');
     }
     $params += $shipping_params;
     $result = Mage::helper('payexautopay/api')->getPx()->AddOrderAddress2($params);
     Mage::helper('payexautopay/tools')->debugApi($result, 'PxOrder.AddOrderAddress2');
     return true;
 }
예제 #28
0
 /**
  * Sets the company into the customer if not guest and always into the Quote/Order
  *
  * @param Mage_Sales_Model_Quote|Mage_Sales_Model_Order $quote
  * @param string $company
  */
 public function setCompany($quote, $company)
 {
     $quote->getBillingAddress()->setCompany($company)->save();
     $quote->getShippingAddress()->setCompany($company)->save();
     $customerAddressId = $quote->getBillingAddress()->getCustomerAddressId();
     if ($customerAddressId) {
         $customerAddress = Mage::getModel('customer/address')->load($customerAddressId);
         $customerAddress->setCompany($company)->save();
     }
 }
예제 #29
0
 /**
  * Set entity data to request
  *
  * @param Mage_Sales_Model_Order $order
  * @param Mage_Authorizenet_Model_Directpost $paymentMethod
  * @return Mage_Authorizenet_Model_Directpost_Request
  */
 public function setDataFromOrder(Mage_Sales_Model_Order $order, Mage_Authorizenet_Model_Directpost $paymentMethod)
 {
     $payment = $order->getPayment();
     $this->setXFpSequence($order->getQuoteId());
     $this->setXInvoiceNum($order->getIncrementId());
     $this->setXAmount($payment->getBaseAmountAuthorized());
     $this->setXCurrencyCode($order->getBaseCurrencyCode());
     $this->setXTax(sprintf('%.2F', $order->getBaseTaxAmount()))->setXFreight(sprintf('%.2F', $order->getBaseShippingAmount()));
     //need to use strval() because NULL values IE6-8 decodes as "null" in JSON in JavaScript, but we need "" for null values.
     $billing = $order->getBillingAddress();
     if (!empty($billing)) {
         $this->setXFirstName(strval($billing->getFirstname()))->setXLastName(strval($billing->getLastname()))->setXCompany(strval($billing->getCompany()))->setXAddress(strval($billing->getStreet(1)))->setXCity(strval($billing->getCity()))->setXState(strval($billing->getRegion()))->setXZip(strval($billing->getPostcode()))->setXCountry(strval($billing->getCountry()))->setXPhone(strval($billing->getTelephone()))->setXFax(strval($billing->getFax()))->setXCustId(strval($billing->getCustomerId()))->setXCustomerIp(strval($order->getRemoteIp()))->setXCustomerTaxId(strval($billing->getTaxId()))->setXEmail(strval($order->getCustomerEmail()))->setXEmailCustomer(strval($paymentMethod->getConfigData('email_customer')))->setXMerchantEmail(strval($paymentMethod->getConfigData('merchant_email')));
     }
     $shipping = $order->getShippingAddress();
     if (!empty($shipping)) {
         $this->setXShipToFirstName(strval($shipping->getFirstname()))->setXShipToLastName(strval($shipping->getLastname()))->setXShipToCompany(strval($shipping->getCompany()))->setXShipToAddress(strval($shipping->getStreet(1)))->setXShipToCity(strval($shipping->getCity()))->setXShipToState(strval($shipping->getRegion()))->setXShipToZip(strval($shipping->getPostcode()))->setXShipToCountry(strval($shipping->getCountry()));
     }
     $this->setXPoNum(strval($payment->getPoNumber()));
     return $this;
 }
예제 #30
0
 /**
  * gets the shipping address if there is one, otherwise the billing address is used as shipping address
  *
  * @param $order
  * @param $billingAddress
  *
  * @return mixed
  */
 protected function getShippingAddress(Mage_Sales_Model_Order $order, $billingAddress)
 {
     $shippingAddress = $order->getShippingAddress();
     if (null === $shippingAddress || false === $shippingAddress) {
         $shippingAddress = $billingAddress;
     }
     return $shippingAddress;
 }