/** * Send order to MailChimp * * @param Mage_Sales_Model_Order $order * @return bool|array */ public function logSale($order) { $this->_order = $order; $api = Mage::getSingleton('monkey/api', array('store' => $this->_order->getStoreId())); if (!$api) { return false; } $subtotal = $this->_order->getSubtotal(); $discount = (double) $this->_order->getDiscountAmount(); if ($discount != 0) { $subtotal = $subtotal + $discount; } $this->_info = array('id' => $this->_order->getIncrementId(), 'total' => $subtotal, 'shipping' => $this->_order->getShippingAmount(), 'tax' => $this->_order->getTaxAmount(), 'store_id' => $this->_order->getStoreId(), 'store_name' => $this->_order->getStoreName(), 'plugin_id' => 1215, 'items' => array()); $emailCookie = $this->_getEmailCookie(); $campaignCookie = $this->_getCampaignCookie(); $this->setItemstoSend(); if ($emailCookie && $campaignCookie) { $this->_info['email_id'] = $emailCookie; $this->_info['campaign_id'] = $campaignCookie; //Send order to MailChimp $rs = $api->campaignEcommOrderAdd($this->_info); } else { $this->_info['email'] = $this->_order->getCustomerEmail(); $rs = $api->ecommOrderAdd($this->_info); } if ($rs === TRUE) { $this->_logCall(); return true; } else { return $rs; } }
/** * @return array */ protected function _prepareCustomerData() { $customer_id = null; $customer = null; $customer_log = null; $billing_address = $this->_order->getBillingAddress(); $customer_verified = false; $customer_orders_count = 0; $gender = $this->_order->getCustomerGender(); if (!$this->_order->getCustomerIsGuest()) { $customer_id = $this->_order->getCustomerId(); if ($customer_id) { /** @var Mage_Customer_Model_Customer $customer */ $customer = Mage::getModel("customer/customer"); $customer->load($customer_id); /** @var Mage_Log_Model_Customer $customer_log */ $customer_log = Mage::getModel('log/customer')->load($customer_id); } $customer_verified = $this->getCustomerIsConfirmedStatus($customer); $orders = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('customer_id', $customer_id); /** @noinspection PhpUndefinedMethodInspection */ $customer_orders_count = $orders->count(); } $data = array_filter(array('customer_id' => $customer_id, 'customer_is_guest' => $this->_order->getCustomerIsGuest(), 'verified' => $customer_verified, 'language_code' => $this->_language_code, 'last_login_on' => $customer_log ? $customer_log->getLoginAt() : null, 'created_on' => $customer ? $customer->getData('created_at') : null, 'updated_on' => $customer ? $customer->getData('updated_at') : null, 'birthdate' => $this->_order->getCustomerDob(), 'email' => $this->_order->getCustomerEmail(), 'title' => '', 'prefix' => $this->_order->getCustomerPrefix(), 'suffix' => $this->_order->getCustomerSuffix(), 'first_name' => $this->_order->getCustomerFirstname(), 'middle_name' => $this->_order->getCustomerMiddlename(), 'last_name' => $this->_order->getCustomerLastname(), 'company_name' => $billing_address ? $billing_address->getCompany() : null, 'gender' => $gender == 1 ? 'male' : ($gender == 2 ? 'female' : null), 'telephone1' => $billing_address ? $billing_address->getTelephone() : null, 'telephone2' => '', 'telephone3' => '', 'fax' => $billing_address ? $billing_address->getFax() : null, 'vat_number' => $this->_order->getCustomerTaxvat(), 'reg_ip_address' => '', 'customer_orders_count' => $customer_orders_count)); return $data; }
/** * Generate and return order secret * * @param Mage_Sales_Model_Order $order * @return string */ public function getOrderSecret($order) { $email = $order->getCustomerEmail(); $orderId = $order->getRealOrderId(); $storeSecret = $this->getSBSecret(); return md5($email . $orderId . $storeSecret); }
/** * @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(); }
/** * Returns the current customers email adress. * @param Mage_Sales_Model_Quote|Mage_Sales_Model_Order $object * @return string the customers email adress */ public function getCustomerEmail($object) { $email = $object->getCustomerEmail(); if (empty($email)) { $email = $object->getBillingAddress()->getEmail(); } return $email; }
/** * Send Payment Decline email */ protected function _sendPaymentDeclineEmail(Mage_Sales_Model_Order $order, $type = 'soft') { $emailTemplate = Mage::getModel('core/email_template')->loadDefault('amazon_payments_async_decline_' . $type); $orderUrl = Mage::getUrl('sales/order/view', array('order_id' => $order->getId(), '_store' => $order->getStoreId(), '_forced_secure' => true)); $templateParams = array('order_url' => $orderUrl, 'store' => Mage::app()->getStore($order->getStoreId()), 'customer' => Mage::getModel('customer/customer')->load($order->getCustomerId())); $sender = array('name' => Mage::getStoreConfig('trans_email/ident_general/email', $order->getStoreId()), 'email' => Mage::getStoreConfig('trans_email/ident_general/name', $order->getStoreId())); $emailTemplate->sendTransactional($emailTemplate->getId(), $sender, $order->getCustomerEmail(), $order->getCustomerName(), $templateParams, $order->getStoreId()); }
/** * Retorna um array com informações do Sender(Cliente) para ser enviado pra API * @param Mage_Sales_Model_Order $order * @param $payment * @return array */ public function getSenderParams(Mage_Sales_Model_Order $order, $payment) { $digits = new Zend_Filter_Digits(); $cpf = $this->_getCustomerCpfValue($order->getCustomer(), $payment); //telefone $phone = $this->_extractPhone($order->getBillingAddress()->getTelephone()); $retorno = array('senderName' => sprintf('%s %s', trim($order->getCustomerFirstname()), trim($order->getCustomerLastname())), 'senderEmail' => $order->getCustomerEmail(), 'senderHash' => $payment['additional_information']['sender_hash'], 'senderCPF' => $digits->filter($cpf), 'senderAreaCode' => $phone['area'], 'senderPhone' => $phone['number']); return $retorno; }
/** * * * @param Mage_Sales_Model_Order $order */ public function recordPointsUponFirstOrder($order) { try { if (!Mage::getModel('rewardsref/referral_firstorder')->hasReferralPoints()) { return $this; } //$order = $observer->getEvent()->getInvoice()->getOrder(); $referralModel = Mage::getModel('rewardsref/referral_firstorder'); if ($referralModel->isSubscribed($order->getCustomerEmail()) && !$referralModel->isConfirmed($order->getCustomerEmail())) { $child = Mage::getModel('rewards/customer')->load($order->getCustomerId()); Mage::getModel('rewardsref/referral_firstorder')->trigger($child); $parent = Mage::getModel('rewards/customer')->load($referralModel->getReferralParentId()); $referralModel->sendConfirmation($parent, $child, $parent->getEmail()); } } catch (Exception $e) { Mage::logException($e); } }
/** * Converting order object to quote object * * @param Mage_Sales_Model_Order $order * @return Mage_Sales_Model_Quote */ public function toQuote(Mage_Sales_Model_Order $order, $quote = null) { if (!$quote instanceof Mage_Sales_Model_Quote) { $quote = Mage::getModel('sales/quote'); } $quote->setStoreId($order->getStoreId())->setOrderId($order->getId())->setCustomerId($order->getCustomerId())->setCustomerEmail($order->getCustomerEmail())->setCustomerGroupId($order->getCustomerGroupId())->setCustomerTaxClassId($order->getCustomerTaxClassId())->setCustomerIsGuest($order->getCustomerIsGuest())->setBaseCurrencyCode($order->getBaseCurrencyCode())->setStoreCurrencyCode($order->getStoreCurrencyCode())->setQuoteCurrencyCode($order->getOrderCurrencyCode())->setStoreToBaseRate($order->getStoreToBaseRate())->setStoreToQuoteRate($order->getStoreToOrderRate())->setGrandTotal($order->getGrandTotal())->setBaseGrandTotal($order->getBaseGrandTotal())->setCouponCode($order->getCouponCode())->setGiftcertCode($order->getGiftcertCode())->setAppliedRuleIds($order->getAppliedRuleIds())->collectTotals(); Mage::dispatchEvent('sales_convert_order_to_quote', array('order' => $order, 'quote' => $quote)); return $quote; }
/** * Send Payment Decline email */ protected function _sendPaymentDeclineEmail(Mage_Sales_Model_Order $order) { $emailTemplate = Mage::getModel('core/email_template')->loadDefault('amazon_payments_async_decline'); $orderUrl = Mage::getUrl('sales/order/view', array('order_id' => $order->getId(), '_store' => $order->getStoreId(), '_forced_secure' => true)); $templateParams = array('order_url' => $orderUrl, 'store' => Mage::app()->getStore($order->getStoreId()), 'customer' => Mage::getModel('customer/customer')->load($order->getCustomerId())); $processedTemplate = $emailTemplate->getProcessedTemplate($templateParams); // Test template: //var_dump($emailTemplate->debug()); echo $processedTemplate; $emailTemplate->setSenderEmail(Mage::getStoreConfig('trans_email/ident_general/email', $order->getStoreId()))->setSenderName(Mage::getStoreConfig('trans_email/ident_general/name', $order->getStoreId()))->send($order->getCustomerEmail(), $order->getCustomerName(), $templateParams); }
public static function createGuessCustomerFromOrder(Mage_Sales_Model_Order $order) { $aCustomer = new self(); $aCustomer->email = $order->getCustomerEmail(); $aCustomer->type = 'g'; $aCustomer->gender = 0; $aCustomer->first_name = $order->getCustomerFirstname(); $aCustomer->last_name = $order->getCustomerLastname(); return $aCustomer; }
/** Send order to MailChimp Automatically by Order Status * * */ public function autoExportJobs() { $allow_sent = false; $orderIds[] = '0'; $ecommerceOrders = Mage::getModel('monkey/ecommerce')->getCollection()->getData(); if ($ecommerceOrders) { foreach ($ecommerceOrders as $ecommerceOrder) { $orderIds[] = $ecommerceOrder['order_id']; } } $orders = Mage::getResourceModel('sales/order_collection'); //Get ALL orders which has not been sent to MailChimp $orders->getSelect()->where('main_table.entity_id NOT IN(?)', $orderIds); //Get status options selected in the Configuration $states = explode(',', Mage::helper('monkey')->config('order_status')); foreach ($orders as $order) { foreach ($states as $state) { if ($order->getStatus() == $state || $state == 'all_status') { $allow_sent = true; } } if ($allow_sent == true) { $this->_order = $order; $api = Mage::getSingleton('monkey/api', array('store' => $this->_order->getStoreId())); if (!$api) { return false; } $subtotal = $this->_order->getSubtotal(); $discount = (double) $this->_order->getDiscountAmount(); if ($discount != 0) { $subtotal = $subtotal + $discount; } $this->_info = array('id' => $this->_order->getIncrementId(), 'total' => $subtotal, 'shipping' => $this->_order->getShippingAmount(), 'tax' => $this->_order->getTaxAmount(), 'store_id' => $this->_order->getStoreId(), 'store_name' => $this->_order->getStoreName(), 'plugin_id' => 1215, 'items' => array()); $email = $this->_order->getCustomerEmail(); $campaign = $this->_order->getEbizmartsMagemonkeyCampaignId(); $this->setItemstoSend(); if ($email && $campaign) { $this->_info['email_id'] = $email; $this->_info['campaign_id'] = $campaign; //Send order to MailChimp $rs = $api->campaignEcommOrderAdd($this->_info); } else { $this->_info['email'] = $email; $rs = $api->ecommOrderAdd($this->_info); } $allow_sent = false; if ($rs === TRUE) { $this->_logCall(); } } } }
public function getScript() { $request = Mage::app()->getRequest(); $module = $request->getModuleName(); $controller = $request->getControllerName(); $action = $request->getActionName(); $flag = false; $currency = Mage::app()->getStore()->getCurrentCurrencyCode(); $script = "<script>var apiKey = '" . $this->getKey() . "';</script>" . "\n"; if ($module == 'checkout' && $controller == 'onestep' && $action == 'success' || $module == 'checkout' && $controller == 'onepage' && $action == 'success' || $module == 'securecheckout' && $controller == 'index' && $action == 'success' || $module == 'customdownloadable' && $controller == 'onepage' && $action == 'success' || $module == 'onepagecheckout' && $controller == 'index' && $action == 'success' || $module == 'onestepcheckout' && $controller == 'index' && $action == 'success') { $order = new Mage_Sales_Model_Order(); $orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId(); $order->loadByIncrementId($orderId); // Load order details $order_total = round($order->getGrandTotal(), 2); // Get grand total $order_coupon = $order->getCouponCode(); // Get coupon used $items = $order->getAllItems(); // Get items info $cartInfo = array(); // Convert object to string foreach ($items as $item) { $product = Mage::getModel('catalog/product')->load($item->getProductId()); $name = $item->getName(); $qty = $item->getQtyToInvoice(); $cartInfo[] = array('id' => $item->getProductId(), 'name' => $name, 'quantity' => $qty); } $cartInfoString = serialize($cartInfo); $cartInfoString = addcslashes($cartInfoString, "'"); $order_name = $order->getCustomerName(); // Get customer's name $order_email = $order->getCustomerEmail(); // Get customer's email id // Call invoiceRefiral function $scriptAppend = "<script>whenAvailable('invoiceRefiral',function(){invoiceRefiral('{$order_total}','{$order_total}','{$order_coupon}','{$cartInfoString}','{$order_name}','{$order_email}','{$orderId}', '{$currency}')});</script>" . "\n"; if ($this->debug()) { $scriptAppend .= "<script>console.log('Module: " . $module . ", Controller: " . $controller . ", Action: " . $action . "');</script>"; $scriptAppend .= "<script>console.log('Total: " . $order_total . ", Coupon: " . $order_coupon . ", Cart: " . $cartInfoString . ", Name: " . $order_name . ", Email: " . $order_email . ", Id: " . $orderId . ", Currency: " . $currency . "');</script>"; } $script .= '<script>var showButton = false;</script>' . "\n"; } else { if ($this->debug()) { $scriptAppend = "<script>console.log('Module: " . $module . ", Controller: " . $controller . ", Action: " . $action . "');</script>"; } else { $scriptAppend = ''; } $script .= '<script>var showButton = true;</script>' . "\n"; } $script .= '<script type="text/javascript">(function e(){var e=document.createElement("script");e.type="text/javascript",e.async=true,e.src="//rfer.co/api/v1/js/all.js";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(e,t)})();</script>' . "\n"; return $script . $scriptAppend; }
/** * Creates new customer from order, adds order addresses as customer addresses * * @param Mage_Sales_Model_Order|bool $order * @return Mage_Customer_Model_Customer */ protected function _createCustomerFromOrder($order) { if (!$order instanceof Mage_Sales_Model_Order) { return false; } // Check if customer with email address exists $existingCustomer = Mage::getResourceModel('customer/customer_collection')->addFieldToFilter('email', $order->getCustomerEmail()); if (Mage::getSingleton('customer/config_share')->isWebsiteScope()) { $existingCustomer->addFieldToFilter('website_id', $order->getWebsiteId()); } $existingCustomer = $existingCustomer->getFirstItem(); if (!$existingCustomer instanceof Mage_Customer_Model_Customer || !$existingCustomer->getId()) { return Mage::getModel('customer/customer'); } // Create customer /** @var Mage_Customer_Model_Customer $customer */ $customer = Mage::getModel('customer/customer')->setEmail($order->getCustomerEmail())->setStoreId($order->getStoreId())->setPrefix($order->getCustomerPrefix())->setFirstname($order->getCustomerFirstname())->setLastname($order->getCustomerLastname()); $customer->save(); // Create customer addresses foreach ($order->getAddressesCollection() as $orderAddress) { /** @var Mage_Sales_Model_Order_Address $orderAddress */ /** @var Mage_Customer_Model_Address $address */ $address = Mage::getModel('customer/address')->setParentId($customer->getEntityId())->setCustomerId($customer->getEntityId())->setIsActive(true)->setPrefix($orderAddress->getPrefix())->setFirstname($orderAddress->getFirstname())->setMiddlename($orderAddress->getMiddlename())->setLastname($orderAddress->getLastname())->setSuffix($orderAddress->getSuffix())->setStreet($orderAddress->getStreet())->setCity($orderAddress->getCity())->setPostcode($orderAddress->getPostcode())->setCountryId($orderAddress->getCountryId())->setTelephone($orderAddress->getTelephone())->setCompany($orderAddress->getCompany())->setRegion($orderAddress->getRegion())->setRegionId($orderAddress->getRegionId()); $address->save(); // Save default billing and shipping if ($orderAddress->getAddressType() == 'billing') { $customer->setDefaultBilling($address->getEntityId()); } elseif ($orderAddress->getAddressType() == 'shipping') { $customer->setDefaultShipping($address->getEntityId()); } } // Force confirmation $customer->setConfirmation($customer->getRandomConfirmationKey()); $customer->save(); return $customer; }
/** * @param Mage_Sales_Model_Order $order * @throws Mage_Core_Exception */ protected function _sendEmail(Mage_Sales_Model_Order $order) { // Send email $translate = Mage::getSingleton('core/translate'); $translate->setTranslateInline(false); /** @var Mage_Core_Helper_Data $helper */ $helper = Mage::helper('core'); $loginUrl = Mage::getUrl('ho_customer/account/login', array('encryption' => $helper->getEncryptor()->encrypt($order->getCustomerId()), 'forward_url' => base64_encode(Mage::getUrl('ho_customer/account/completeProfile')))); /** @var Mage_Core_Model_Email_Template $emailTemplate */ $emailTemplate = Mage::getModel('core/email_template'); $emailTemplate->setDesignConfig(array('area' => 'frontend', 'store' => $order->getStoreId()))->sendTransactional($this->getConfig()->getEmailTemplate($order->getStoreId()), $this->getConfig()->getEmailSender($order->getStoreId()), $order->getCustomerEmail(), $order->getCustomerName(), array('order' => $order, 'login_url' => $loginUrl)); $customer = Mage::getModel('customer/customer')->load($order->getCustomerId()); $customer->setData('complete_profile_sent', true)->getResource()->saveAttribute($customer, 'complete_profile_sent'); $translate->setTranslateInline(true); }
/** * Notify Sailthru that a purchase has been made. This automatically cancels * any scheduled abandoned cart email. * */ public function sendOrder(Mage_Sales_Model_Order $order) { try { $this->_eventType = 'placeOrder'; $data = array('email' => $order->getCustomerEmail(), 'items' => $this->_getItems($order->getAllVisibleItems()), 'adjustments' => $this->_getAdjustments($order), 'message_id' => $this->getMessageId(), 'send_template' => 'Purchase Receipt', 'tenders' => $this->_getTenders($order)); /** * Send order data to purchase API */ $responsePurchase = $this->apiPost('purchase', $data); /** * Send customer data to user API */ //$responseUser = Mage::getModel('sailthruemail/client_user')->sendCustomerData($customer); } catch (Exception $e) { Mage::logException($e); return false; } }
/** * 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; }
/** * 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; }
/** * Build up the customers data onto an object * * @param Mage_Sales_Model_Order $order * * @return array */ private function buildCustomer(Mage_Sales_Model_Order $order, $includeId = true) { $customer = array('firstName' => $order->getCustomerFirstname(), 'lastName' => $order->getCustomerLastname(), 'email' => $order->getCustomerEmail(), 'phone' => $order->getBillingAddress()->getTelephone()); // Shall we include the customer ID? if ($includeId) { $customer['id'] = $this->getBraintreeId(); } // Handle empty data with alternatives if (empty($customer['firstName'])) { $customer['firstName'] = $order->getBillingAddress()->getFirstname(); } if (empty($customer['lastName'])) { $customer['lastName'] = $order->getBillingAddress()->getLastname(); } if (empty($customer['email'])) { $customer['email'] = $order->getBillingAddress()->getEmail(); } return $customer; }
/** * Sets the customer info if available * * @param Mage_Sales_Model_Quote|Mage_Sales_Model_Order $object * @return $this */ protected function _addCustomer($object) { $format = Mage::getStoreConfig('tax/avatax/cust_code_format', $object->getStoreId()); $customer = Mage::getModel('customer/customer'); if ($object->getCustomerId()) { $customer->load($object->getCustomerId()); $taxClass = Mage::getModel('tax/class')->load($customer->getTaxClassId())->getOpAvataxCode(); $this->_request->setCustomerUsageType($taxClass); } switch ($format) { case OnePica_AvaTax_Model_Source_Customercodeformat::LEGACY: if ($customer->getId()) { $customerCode = $customer->getName() . ' (' . $customer->getId() . ')'; } else { $address = $object->getBillingAddress() ? $object->getBillingAddress() : $object; $customerCode = $address->getFirstname() . ' ' . $address->getLastname() . ' (Guest)'; } break; case OnePica_AvaTax_Model_Source_Customercodeformat::CUST_EMAIL: $customerCode = $object->getCustomerEmail() ? $object->getCustomerEmail() : $customer->getEmail(); break; case OnePica_AvaTax_Model_Source_Customercodeformat::CUST_ID: default: $customerCode = $object->getCustomerId() ? $object->getCustomerId() : 'guest-' . $object->getId(); break; } $this->_request->setCustomerCode($customerCode); return $this; }
public function updateorderstatus() { //$from = 'Robin'; // sender //$subject = 'ABCD'; $message = 'Cron Job Running123456'; // message lines should not exceed 70 characters (PHP rule), so wrap it //$message = wordwrap($message, 70); // send mail $from = 'Arun'; // sender $subject = 'ABCD12345'; $wsdlUrl = Mage::getStoreConfig('unicom_options/unigroup/uniurl'); $wsdllUrl = Mage::getStoreConfig('unicom_options/unigroup/unilurl'); $username = Mage::getStoreConfig('unicom_options/unigroup/uniusername'); $password = Mage::getStoreConfig('unicom_options/unigroup/unipass'); /*$wsdlUrl = "https://demo.unicommerce.com/services/soap/uniware15.wsdl"; $wsdllUrl = "http://demo.unicommerce.com/services/soap/?version=1.5&facility=01"; $username = "******"; $password = "******"; */ $soapClient = new SoapClient($wsdlUrl, array('trace' => 1, 'exception' => 0)); $soapClient->__setLocation($wsdllUrl); $strWSSENS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"; $objSoapVarUser = new SoapVar($username, XSD_STRING, NULL, $strWSSENS, "UserName", $strWSSENS); $objSoapVarPass = new SoapVar($password, XSD_STRING, NULL, $strWSSENS, "Password", $strWSSENS); $objWSSEAuth = new clsWSSEAuth($objSoapVarUser, $objSoapVarPass); $objSoapVarWSSEAuth = new SoapVar($objWSSEAuth, SOAP_ENC_OBJECT, NULL, $strWSSENS, 'UsernameToken', $strWSSENS); $objWSSEToken = new clsWSSEToken($objSoapVarWSSEAuth); $objSoapVarWSSEToken = new SoapVar($objWSSEToken, SOAP_ENC_OBJECT, NULL, $strWSSENS, 'UsernameToken', $strWSSENS); $objSoapVarHeaderVal = new SoapVar($objSoapVarWSSEToken, SOAP_ENC_OBJECT, NULL, $strWSSENS, 'Security', $strWSSENS); $objSoapVarWSSEHeader = new SoapHeader($strWSSENS, 'Security', $objSoapVarHeaderVal, true); $soapClient->__setSoapHeaders(array($objSoapVarWSSEHeader)); //Mage::app('default'); $model = Mage::getModel('rcredit/rcredit'); $order = new Mage_Sales_Model_Order(); $order_details = $model->orderids(); //print_r($order_details); $i = 0; $check = array(); $msg = array(); foreach ($order_details as $details) { $msg[] = $details[order_id]; $shipping = $soapClient->GetSaleOrder(array('SaleOrder' => array('Code' => $details[order_id]))); //echo '<pre>'; //print_r($shipping); $delivcnt = count($shipping->SaleOrder->ShippingPackages->ShippingPackage); foreach ($shipping->SaleOrder->ShippingPackages as $v) { $order->loadByIncrementId($details[order_id]); $payment = $order->getPayment()->getMethodInstance()->getCode(); $customer_status = $model->customerstatus($order->getCustomerEmail()); if ($delivcnt > 1) { $deliverDate = $v[$delivcnt - 1]->DeliveredOn; $vstatus = $v[$delivcnt - 1]->StatusCode; } else { $deliverDate = $v->DeliveredOn; $vstatus = $v->StatusCode; } if ($vstatus == 'DELIVERED') { $day = explode('T', $deliverDate); if ($day[0] >= $customer_status['credit_start_date']) { //echo 'In Second Cycle'.$details[cycle].'-->'.$details[order_id].'-->'.$details[order_value].'-->'.$order->getCustomerEmail().'-->'.$customer_status[credit_cycle].'-->'.$customer_status[utlized_amt]; //echo '<br/>'; $model->updateordercycle($details[order_id], $customer_status[credit_cycle]); } $model->updateorderdate($details[order_id], $day[0]); } $i++; } //mail("*****@*****.**",$subject,$details[order_id],"From: $from\n"); $order = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('increment_id', $details[order_id])->getFirstItem(); if ($order->getStatus() == 'Canceled' || $order->getStatus() == 'canceled') { $order->loadByIncrementId($details[order_id]); $payment = $order->getPayment()->getMethodInstance()->getCode(); if ($payment == 'rcredit') { $payment_status = 'Refund'; $order_cycle_value = $model->ordercyclehistory($details[order_id]); //Getting the cycle using the order_id. $cycle = $order_cycle_value['cycle']; $customer_email = $order->getCustomerEmail(); $grandtotal = round($details[order_value], 2); $customer_status = $model->customerstatus($customer_email); // Getting the customer status from the Shopper Credit Module $customer_credit_limit = $customer_status['credit_limit']; // Getting customer's credit limit. $customer_current_bal = $customer_status['bal_amt']; // Getting customer's current balance $balance_amount = $customer_status['bal_amt'] + $grandtotal; // Calculating the updated balance after sucessful purchase. $utlized_amt = $customer_status['utlized_amt']; // Getting customer's current balance $total_used_amt = $utlized_amt - $grandtotal; // Getting the total utlized amt. $pay_interval = $customer_status['pay_interval']; // Getting customer's payinterval date $expiry_date = $customer_status['enddate']; // Getting expiry date for the customer $action = 'Refund due to cancellation'; $todate = date("Y-m-d"); $order_status = "Cancel"; if ($order_cycle_value['action'] != 'Cancel') { $model->cancelledorderdetails($details[order_id], $total_used_amt, $balance_amount, $action, $order_status); $model->updateoncancel($grandtotal, $customer_email, $cycle); } } } } }
/** * @param Male_Sales_Model_Order $order */ protected function _createCustomer(Mage_Sales_Model_Order $order) { $data = array('email' => array('emailAddress' => $order->getCustomerEmail()), 'lastModifiedDate' => date('c', strtotime($order->getUpdatedAt())), 'customerId' => null); return $data; }
/** * @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; }
/** * @param Mage_Sales_Model_Order $order * @return HpsTransactionDetails */ protected function _getTxnDetailsData($order) { $memo = array(); $ip = ''; if (isset($_SERVER['REMOTE_ADDR'])) { $ip = $_SERVER['REMOTE_ADDR']; } if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } if ($ip) { $memo[] = 'Customer IP Address: ' . $ip; } if (isset($_SERVER['HTTP_USER_AGENT'])) { $memo[] = 'User Agent: ' . $_SERVER['HTTP_USER_AGENT']; } $memo = implode(', ', $memo); $details = new HpsTransactionDetails(); $details->memo = substr($memo, 0, 200); // Actual limit unknown.. $details->invoiceNumber = $order->getIncrementId(); $details->customerId = substr($order->getCustomerEmail(), 0, 25); // Actual limit unknown.. return $details; }
/** Send order to MailChimp Automatically by Order Status * * */ public function autoExportJobs($storeId) { $allow_sent = false; //Get status options selected in the Configuration $states = explode(',', Mage::getStoreConfig(Ebizmarts_MageMonkey_Model_Config::ECOMMERCE360_ORDER_STATUS, $storeId)); $max = Mage::getStoreConfig(Ebizmarts_MageMonkey_Model_Config::ECOMMERCE360_ORDER_MAX, $storeId); $count = 0; foreach ($states as $state) { if ($max == $count) { break; } $ecommerceTable = Mage::getSingleton('core/resource')->getTableName('monkey/ecommerce'); if ($state != 'all_status') { $orders = Mage::getResourceModel('sales/order_collection')->addFieldToFilter('main_table.store_id', array('eq' => $storeId)); // $orders->getSelect()->joinLeft(array('ecommerce' => Mage::getSingleton('core/resource')->getTableName('monkey/ecommerce')), 'main_table.entity_id = ecommerce.order_id', 'main_table.*')->where('ecommerce.order_id is null AND main_table.status = \'' . $state . '\'') // ->limit($max - $count); $orders->getSelect()->where('main_table.status = \'' . $state . '\' ' . 'AND main_table.entity_id NOT IN ' . "(SELECT ecommerce.order_id FROM {$ecommerceTable} AS ecommerce WHERE ecommerce.store_id = {$storeId})")->limit($max - $count); } else { $orders = Mage::getResourceModel('sales/order_collection')->addFieldToFilter('main_table.store_id', array('eq' => $storeId)); // $orders->getSelect()->joinLeft(array('ecommerce' => Mage::getSingleton('core/resource')->getTableName('monkey/ecommerce')), 'main_table.entity_id = ecommerce.order_id', 'main_table.*')->where('ecommerce.order_id is null') // ->limit($max - $count); $orders->getSelect()->where('main_table.entity_id NOT IN ' . "(SELECT ecommerce.order_id FROM {$ecommerceTable} AS ecommerce WHERE ecommerce.store_id = {$storeId})")->limit($max - $count); } $count += count($orders); foreach ($orders as $order) { $this->_order = $order; $ordersToSend = Mage::getModel('monkey/asyncorders')->getCollection()->addFieldToFilter('processed', array('eq' => 0)); foreach ($ordersToSend as $orderToSend) { $info = (array) unserialize($orderToSend->getInfo()); if ($this->_order->getIncrementId() == $info['id']) { continue; } } $api = Mage::getSingleton('monkey/api', array('store' => $this->_order->getStoreId())); if (!$api) { return false; } $subtotal = $this->_order->getBaseSubtotal(); $discount = (double) $this->_order->getBaseDiscountAmount(); if ($discount != 0) { $subtotal = $subtotal + $discount; } $createdAtArr = str_split($this->_order->getCreatedAt(), 10); $this->_info = array('id' => $this->_order->getIncrementId(), 'total' => $subtotal, 'shipping' => $this->_order->getBaseShippingAmount(), 'tax' => $this->_order->getBaseTaxAmount(), 'store_id' => $this->_order->getStoreId(), 'store_name' => $this->_order->getStoreName(), 'order_date' => $createdAtArr[0], 'plugin_id' => 1215, 'items' => array()); $email = $this->_order->getCustomerEmail(); $campaign = $this->_order->getEbizmartsMagemonkeyCampaignId(); $this->setItemstoSend($storeId); $rs = false; if ($email && $campaign) { $this->_info['email_id'] = $email; $this->_info['campaign_id'] = $campaign; if (Mage::getStoreConfig('monkey/general/checkout_async', Mage::app()->getStore()->getId())) { $sync = Mage::getModel('monkey/asyncorders'); $this->_info['order_id'] = $this->_order->getId(); $sync->setInfo(serialize($this->_info))->setCreatedAt($createdAtArr[0])->setProcessed(0)->save(); $rs['complete'] = true; } else { //Send order to MailChimp $rs = $api->campaignEcommOrderAdd($this->_info); } } else { $this->_info['email'] = $email; if (Mage::getStoreConfig('monkey/general/checkout_async', Mage::app()->getStore()->getId())) { $sync = Mage::getModel('monkey/asyncorders'); $this->_info['order_id'] = $this->_order->getId(); $sync->setInfo(serialize($this->_info))->setCreatedAt(Mage::getModel('core/date')->gmtDate())->setProcessed(0)->save(); $rs['complete'] = true; } else { $rs = $api->ecommOrderAdd($this->_info); } } if (isset($rs['complete']) && $rs['complete'] == TRUE && !Mage::getStoreConfig('monkey/general/checkout_async', Mage::app()->getStore()->getId())) { $order = Mage::getModel('monkey/ecommerce')->setOrderIncrementId($this->_info['id'])->setOrderId($this->_info['order_id'])->setMcEmailId($this->_info['email'])->setCreatedAt($createdAtArr[0])->setStoreId($this->_info['store_id']); if (isset($this->_info['campaign_id']) && $this->_info['campaign_id']) { $order->setMcCampaignId($this->_info['campaign_id']); } $order->save(); //$this->_logCall(); } } } }
/** * set the order information * * @param Mage_Sales_Model_Order $orderData */ public function setOrderData(Mage_Sales_Model_Order $orderData) { $this->id = (string) $orderData->getIncrementId(); $this->quote_id = (string) $orderData->getQuoteId(); $this->email = (string) $orderData->getCustomerEmail(); $this->store_name = (string) $orderData->getStoreName(); $created_at = new Zend_Date($orderData->getCreatedAt(), Zend_Date::ISO_8601); $this->purchase_date = $created_at->toString(Zend_Date::ISO_8601); $this->delivery_method = $orderData->getShippingDescription(); $this->delivery_total = (double) number_format($orderData->getShippingAmount(), 2, '.', ''); $this->currency = $orderData->getStoreCurrencyCode(); if ($payment = $orderData->getPayment()) { $this->payment = $payment->getMethodInstance()->getTitle(); } $this->couponCode = (string) $orderData->getCouponCode(); //set order custom attributes $this->_setOrderCustomAttributes($orderData); //billing $this->_setBillingData($orderData); //shipping $this->_setShippingData($orderData); //order items $this->_setOrderItems($orderData); //sales data $this->order_subtotal = (double) number_format($orderData->getData('subtotal'), 2, '.', ''); $this->discount_ammount = (double) number_format($orderData->getData('discount_amount'), 2, '.', ''); $orderTotal = abs($orderData->getData('grand_total') - $orderData->getTotalRefunded()); $this->order_total = (double) number_format($orderTotal, 2, '.', ''); $this->order_status = (string) $orderData->getStatus(); }
/** * Process the seamless Payment after Order is complete * * @param Varien_Event_Observer $observer * * @throws Exception * @return Phoenix_WirecardCheckoutPage_Model_Observer */ public function salesOrderPaymentPlaceEnd(Varien_Event_Observer $observer) { /** * @var Phoenix_WirecardCheckoutPage_Model_Abstract */ $payment = $observer->getPayment(); $this->_order = $payment->getOrder(); $storeId = $this->_order->getStoreId(); $paymentInstance = $payment->getMethodInstance(); if (Mage::getStoreConfigFlag('payment/' . $payment->getMethod() . '/useSeamless', $storeId)) { $storageId = $payment->getAdditionalData(); $orderIdent = $this->_order->getQuoteId(); $customerId = Mage::getStoreConfig('payment/' . $payment->getMethod() . '/customer_id', $storeId); $shopId = Mage::getStoreConfig('payment/' . $payment->getMethod() . '/shop_id', $storeId); $secretKey = Mage::getStoreConfig('payment/' . $payment->getMethod() . '/secret_key', $storeId); $serviceUrl = Mage::getUrl(Mage::getStoreConfig('payment/' . $payment->getMethod() . '/service_url', $storeId)); $paymentType = $this->_getMappedPaymentCode($payment->getMethod()); $returnurl = Mage::getUrl('wirecard_checkout_page/processing/checkresponse', array('_secure' => true, '_nosid' => true)); $pluginVersion = WirecardCEE_Client_QPay_Request_Initiation::generatePluginVersion('Magento', Mage::getVersion(), $paymentInstance->getPluginName(), $paymentInstance->getPluginVersion()); $initiation = new WirecardCEE_Client_QPay_Request_Initiation($customerId, $shopId, $secretKey, substr(Mage::app()->getLocale()->getLocaleCode(), 0, 2), $pluginVersion); $consumerData = new WirecardCEE_Client_QPay_Request_Initiation_ConsumerData(); if (Mage::getStoreConfigFlag('payment/' . $payment->getMethod() . '/send_additional_data', $storeId)) { $consumerData->setEmail($this->_order->getCustomerEmail()); $dob = $payment->getMethodInstance()->getCustomerDob(); if ($dob) { $consumerData->setBirthDate($dob); } $consumerData->addAddressInformation($this->_getBillingObject()); if ($this->_order->hasShipments()) { $consumerData->addAddressInformation($this->_getShippingObject()); } } if ($payment->getMethod() == 'wirecard_checkout_page_invoice' || $payment->getMethod() == 'wirecard_checkout_page_installment') { $consumerData->setEmail($this->_order->getCustomerEmail()); $dob = $payment->getMethodInstance()->getCustomerDob(); if ($dob) { $consumerData->setBirthDate($dob); } else { throw new Exception('Invalid dob'); } $consumerData->addAddressInformation($this->_getBillingObject('invoice')); } $consumerData->setIpAddress($this->_order->getRemoteIp()); $consumerData->setUserAgent(Mage::app()->getRequest()->getServer('HTTP_USER_AGENT')); $initiation->setConfirmUrl(Mage::getUrl('wirecard_checkout_page/processing/seamlessConfirm', array('_secure' => true, '_nosid' => true))); $initiation->setWindowName('paymentIframe'); $initiation->orderId = $this->_order->getIncrementId(); $initiation->companyTradeRegistryNumber = $payment->getMethodInstance()->getCompanyTradeRegistrationNumber(); if ($orderIdent && $storageId) { $initiation->setStorageReference($orderIdent, $storageId); } if (Mage::getStoreConfigFlag('payment/' . $payment->getMethod() . '/auto_deposit', $storeId)) { $initiation->setAutoDeposit(true); } $initiation->setOrderReference($this->_order->getIncrementId()); $financialInstitution = $payment->getMethodInstance()->getFinancialInstitution(); if ($financialInstitution) { $initiation->setFinancialInstitution($financialInstitution); } Phoenix_WirecardCheckoutPage_Helper_Configuration::configureWcsLibrary(); $response = $initiation->initiate(round($this->_order->getBaseGrandTotal(), 2), $this->_order->getBaseCurrencyCode(), $paymentType, $this->_order->getIncrementId(), $returnurl, $returnurl, $returnurl, $returnurl, $serviceUrl, $consumerData); if (isset($response) && $response->getStatus() == WirecardCEE_Client_QPay_Response_Initiation::STATE_SUCCESS) { $payment->setAdditionalData(serialize($payment->getAdditionalData()))->save(); Mage::getSingleton('core/session')->unsetData('wirecard_checkout_page_payment_info'); Mage::getSingleton('core/session')->setWirecardCheckoutPageRedirectUrl(urldecode($response->getRedirectUrl())); } elseif (isset($response)) { $errorMessage = ''; foreach ($response->getErrors() as $error) { $errorMessage .= ' ' . $error->getMessage(); } throw new Exception(trim($errorMessage)); } else { $payment->setAdditionalData(serialize($payment->getAdditionalData()))->save(); Mage::getSingleton('core/session')->unsetData('wirecard_checkout_page_payment_info'); } } return $this; }
/** * Should an order be excluded from tracking? * * @param Mage_Sales_Model_Order $order * @return bool */ protected function _isExcluded(Mage_Sales_Model_Order $order) { $emails = $this->getConfig('excluded_emails', $order->getStoreId()); if (!empty($emails)) { $emails = explode("\n", $emails); foreach ($emails as $email) { $email = trim($email); if (stripos($order->getCustomerEmail(), $email) !== false) { return true; } } } $groups = $this->getConfig('excluded_customer_groups', $order->getStoreId()); if (!empty($groups)) { $groups = explode(',', $groups); foreach ($groups as $group) { if ($group == $order->getCustomerGroupId()) { return true; } } } return false; }
/** * Loads the buyer info from a Magento order model. * * @param Mage_Sales_Model_Order $order the order model. */ public function loadData(Mage_Sales_Model_Order $order) { $this->_firstName = $order->getCustomerFirstname(); $this->_lastName = $order->getCustomerLastname(); $this->_email = $order->getCustomerEmail(); }
/** * Send email id payment is in Fraud status * @param Mage_Customer_Model_Customer $receiver * @param Mage_Sales_Model_Order $order * @param string $message * @return Mage_Checkout_Helper_Data */ public function sendFraudPaymentEmail($receiver, $order, $message, $email_key = 'fraud_payment') { $translate = Mage::getSingleton('core/translate'); /* @var $translate Mage_Core_Model_Translate */ $translate->setTranslateInline(false); $mailTemplate = Mage::getModel('core/email_template'); /* @var $mailTemplate Mage_Core_Model_Email_Template */ $template = Mage::getStoreConfig('hipay/' . $email_key . '/template', $order->getStoreId()); $copyTo = $this->_getEmails('hipay/' . $email_key . '/copy_to', $order->getStoreId()); $copyMethod = Mage::getStoreConfig('hipay/' . $email_key . '/copy_method', $order->getStoreId()); if ($copyTo && $copyMethod == 'bcc') { $mailTemplate->addBcc($copyTo); } $sendTo = array(array('email' => $receiver->getEmail(), 'name' => $receiver->getName())); if ($copyTo && $copyMethod == 'copy') { foreach ($copyTo as $email) { $sendTo[] = array('email' => $email, 'name' => null); } } $shippingMethod = ''; if ($shippingInfo = $order->getShippingAddress()->getShippingMethod()) { $data = explode('_', $shippingInfo); $shippingMethod = $data[0]; } $paymentMethod = ''; if ($paymentInfo = $order->getPayment()) { $paymentMethod = $paymentInfo->getMethod(); } $items = ''; foreach ($order->getAllVisibleItems() as $_item) { /* @var $_item Mage_Sales_Model_Quote_Item */ $items .= $_item->getProduct()->getName() . ' x ' . $_item->getQty() . ' ' . $order->getStoreCurrencyCode() . ' ' . $_item->getProduct()->getFinalPrice($_item->getQty()) . "\n"; } $total = $order->getStoreCurrencyCode() . ' ' . $order->getGrandTotal(); foreach ($sendTo as $recipient) { $mailTemplate->setDesignConfig(array('area' => 'frontend', 'store' => $order->getStoreId()))->sendTransactional($template, Mage::getStoreConfig('hipay/' . $email_key . '/identity', $order->getStoreId()), $recipient['email'], $recipient['name'], array('reason' => $message, 'dateAndTime' => Mage::app()->getLocale()->date(), 'customer' => $order->getCustomerFirstname() . ' ' . $order->getCustomerLastname(), 'customerEmail' => $order->getCustomerEmail(), 'billingAddress' => $order->getBillingAddress(), 'shippingAddress' => $order->getShippingAddress(), 'shippingMethod' => Mage::getStoreConfig('carriers/' . $shippingMethod . '/title'), 'paymentMethod' => Mage::getStoreConfig('payment/' . $paymentMethod . '/title'), 'items' => nl2br($items), 'total' => $total)); } $translate->setTranslateInline(true); return $this; }