/** * Retorna um array com informações do dono do Cartao(Cliente) para ser enviado pra API * @param Mage_Sales_Model_Order $order * @param $payment * @return array */ public function getCreditCardHolderParams(Mage_Sales_Model_Order $order, $payment) { $digits = new Zend_Filter_Digits(); $cpf = $this->_getCustomerCpfValue($order->getCustomer(), $payment); //dados $creditCardHolderBirthDate = $this->_getCustomerCcDobValue($order->getCustomer(), $payment); $phone = $this->_extractPhone($order->getBillingAddress()->getTelephone()); $retorno = array('creditCardHolderName' => $payment['additional_information']['credit_card_owner'], 'creditCardHolderBirthDate' => $creditCardHolderBirthDate, 'creditCardHolderCPF' => $digits->filter($cpf), 'creditCardHolderAreaCode' => $phone['area'], 'creditCardHolderPhone' => $phone['number']); return $retorno; }
/** * Get customer balance model using sales entity * * @param Mage_Sales_Model_Quote|Mage_Sales_Model_Order $salesEntity * * @return Enterprise_CustomerBalance_Model_Balance|bool */ public function getCustomerBalanceModelFromSalesEntity($salesEntity) { if ($salesEntity instanceof Mage_Sales_Model_Order) { $customerId = $salesEntity->getCustomerId(); $quote = $salesEntity->getQuote(); } elseif ($salesEntity instanceof Mage_Sales_Model_Quote) { $customerId = $salesEntity->getCustomer()->getId(); $quote = $salesEntity; } else { return false; } if (!$customerId) { return false; } $customerBalanceModel = Mage::getModel('enterprise_customerbalance/balance')->setCustomerId($customerId)->setWebsiteId(Mage::app()->getStore($salesEntity->getStoreId())->getWebsiteId())->loadByCustomer(); if ($quote->getBaseCustomerBalanceVirtualAmount() > 0) { $customerBalanceModel->setAmount($customerBalanceModel->getAmount() + $quote->getBaseCustomerBalanceVirtualAmount()); } return $customerBalanceModel; }
/** * Add the items from the given order to the Order Sync queue. Does nothing if * Order Sync is disabled for the store that the order was placed in. * * @param Mage_Sales_Model_Order $order * @param bool $force Skip enabled check * * @return $this */ public function addOrderToQueue(Mage_Sales_Model_Order $order, $force = false) { if (!$this->isEnabled($order->getStoreId()) && !$force) { return $this; } $items = array(); $order_date = Mage::helper("klevu_search/compat")->now(); $session_id = session_id(); $ip_address = Mage::helper("klevu_search")->getIp(); $order_email = 'unknown'; if ($order->getCustomerId()) { $order_email = $order->getCustomer()->getEmail(); //logged in customer } else { $order_email = $order->getBillingAddress()->getEmail(); //not logged in customer } foreach ($order->getAllVisibleItems() as $item) { /** @var Mage_Sales_Model_Order_Item $item */ // For configurable products add children items only, for all other products add parents if ($item->getProductType() == Mage_Catalog_Model_Product_Type_Configurable::TYPE_CODE) { foreach ($item->getChildrenItems() as $child) { if ($child->getId() != null) { $items[] = array($child->getId(), $session_id, $ip_address, $order_date, $order_email); } } } else { if ($item->getId() != null) { $items[] = array($item->getId(), $session_id, $ip_address, $order_date, $order_email); } } } // in case of multiple addresses used for shipping // its possible that items object here is empty // if so, we do not add to the item. if (!empty($items)) { $this->addItemsToQueue($items); } return $this; }
/** * Checks the current order and returns the customer model * * @param Mage_Sales_Model_Order $order Current order * @return Mage_Customer_Model_Customer|null Customer model or null */ protected function _getOrderCustomer($order) { if ($customer = $order->getCustomer()) { if ($customer->getId()) { return $customer; } } return false; }
/** * Revert authorized reward points amount for order * * @param Mage_Sales_Model_Order $order * @return Enterprise_Reward_Model_Observer */ protected function _revertRewardPointsForOrder(Mage_Sales_Model_Order $order) { if (!$order->getCustomer()->getId()) { return $this; } Mage::getModel('enterprise_reward/reward')->setCustomerId($order->getCustomer()->getId())->setWebsiteId(Mage::app()->getStore($order->getStoreId())->getWebsiteId())->setPointsDelta($order->getRewardPointsBalance())->setAction(Enterprise_Reward_Model_Reward::REWARD_ACTION_REVERT)->setActionEntity($order)->updateRewardPoints(); return $this; }
/** * Sets the vat id into the customer if not guest and always into the Quote/Order * * @param Mage_Sales_Model_Quote|Mage_Sales_Model_Order $quote * @param string $taxvat */ public function setTaxvat($quote, $taxvat) { if ($quote->getCustomerId()) { $quote->getCustomer()->setTaxvat($taxvat)->save(); } $quote->setCustomerTaxvat($taxvat)->save(); }
/** * In case customer object is missing in order object, retrieve * * @param Mage_Sales_Model_Order $order * @return Mage_Customer_Model_Customer */ public function getOrderCustomer($order) { if (!$order->hasCustomer()) { $order->setCustomer(Mage::getModel('customer/customer')->load($order->getCustomerId())); } return $order->getCustomer(); }
/** * Fetches the customer model from either an order/quote or the session, depending on what's available. * @param Mage_Sales_Model_Order $order or quote * @return TBT_Rewards_Model_Customer */ protected function _getRewardsCustomer($order = null) { // If the customer exists in the order, use that. If not, use the session customer from the rewards model. if ($order) { if ($order->getCustomer()) { // The index session dispatch requires a rewards model, so we should load that. $session_customer = $order->getCustomer(); if (!$session_customer instanceof TBT_Rewards_Model_Customer) { $session_customer = Mage::getModel('rewards/customer')->getRewardsCustomer($session_customer); } } else { $session_customer = Mage::getModel('rewards/customer')->load($order->getCustomerId()); } } else { $session_customer = $this->_getRewardsSess()->getSessionCustomer(); } return $session_customer; }
/** * Do a Postcode.nl Signal API check on a (newly created) Magento order. * (called by hook class PostcodeNl_Api_Model_Observer) * Will pass any information that can be used by the MijnPolitie.nl MIO Fraud Warning system * (email, phonenumber), or Postcode.nl address validation (billing and delivery address). * Also includes the order number, to be able to reference the Signal Check later. * * @param Mage_Sales_Model_Order $order * * @return array Signal data, or error with 'message' entry. */ public function checkOrderViaSignal($order) { // Check if we are we are enabled, configured & capable of handling an API request $message = $this->_checkApiReady('Signal'); if ($message) { return $message; } // Housenumber data is often contained within the 'street' lines of the address. $billingStreetData = $this->splitStreetData($order->getBillingAddress()->getStreet()); $shippingStreetData = $this->splitStreetData($order->getShippingAddress()->getStreet()); // No customer might be available if this is an order status change $hasCustomer = $order->getCustomer() !== null; // Note if this is executed as an admin, then do not send access details, as that might muddy the customer info $isAdmin = Mage::app()->getStore()->isAdmin(); // Only send phonenumber if it is at least 5 characters long $phoneNumber = Mage::helper('core/string')->strlen($order->getBillingAddress()->getTelephone()) >= 5 ? $order->getBillingAddress()->getTelephone() : null; $signalCheck = array('customer' => array('email' => $hasCustomer ? $order->getCustomer()->getEmail() : null, 'phoneNumber' => $phoneNumber, 'address' => array('postcode' => $order->getBillingAddress()->getPostcode(), 'houseNumber' => $billingStreetData['houseNumber'], 'houseNumberAddition' => $billingStreetData['houseNumberAddition'], 'street' => $billingStreetData['street'], 'city' => $order->getBillingAddress()->getCity(), 'region' => $order->getBillingAddress()->getRegion(), 'country' => $order->getBillingAddress()->getCountryId())), 'access' => array('ipAddress' => $isAdmin ? null : Mage::helper('core/http')->getRemoteAddr(), 'additionalIpAddresses' => array()), 'transaction' => array('internalId' => $order->getIncrementId(), 'deliveryAddress' => array('postcode' => $order->getShippingAddress()->getPostcode(), 'houseNumber' => $shippingStreetData['houseNumber'], 'houseNumberAddition' => $shippingStreetData['houseNumberAddition'], 'street' => $shippingStreetData['street'], 'city' => $order->getShippingAddress()->getCity(), 'region' => $order->getShippingAddress()->getRegion(), 'country' => $order->getShippingAddress()->getCountryId()))); // Retrieve quote for registered remote IP / proxy IP (they are registered at session start) $quoteId = $order->getQuoteId(); $quote = Mage::getModel('sales/quote')->load($quoteId); if ($quote) { $signalCheck['access'] = $this->_addAccessIpAddress($signalCheck['access'], $quote->getRemoteIp()); $signalCheck['access'] = $this->_addAccessIpAddress($signalCheck['access'], $quote->getXForwardedFor()); } // Register current forwarded-for IP address (if not admin) if (!$isAdmin) { $forwardedFor = Mage::app()->getRequest()->getServer('HTTP_X_FORWARDED_FOR'); $signalCheck['access'] = $this->_addAccessIpAddress($signalCheck['access'], $forwardedFor); } return $this->checkSignal($signalCheck); }
/** * Fetches the customer model from either an order/quote or the session, depending on what's available. * @param Mage_Sales_Model_Order $order or quote * @return TBT_Rewards_Model_Customer */ protected function _getRewardsCustomer($order = null) { // If the customer exists in the order, use that. If not, use the session customer from the rewards model. if ($order) { Mage::helper('rewards/debug')->log("Got order"); if ($order->getCustomer()) { // The index session dispatch requires a rewards model, so we should load that. $session_customer = $order->getCustomer(); Mage::helper('rewards/debug')->log("Sess cust = {$session_customer->getId()}"); if (!$session_customer instanceof TBT_Rewards_Model_Customer) { $session_customer = Mage::getModel('rewards/customer')->getRewardsCustomer($session_customer); } Mage::helper('rewards/debug')->log("ORder does not have ses cust, so reloading one from order id {$order->getCustomerId()} to give = {$session_customer->getId()}"); } else { $session_customer = Mage::getModel('rewards/customer')->load($order->getCustomerId()); Mage::helper('rewards/debug')->log("ORder does not have ses cust, so reloading one from order id {$order->getCustomerId()} to give = {$session_customer->getId()}"); } } else { $session_customer = $this->_getRewardsSess()->getSessionCustomer(); Mage::helper('rewards/debug')->log("ORder given not valid"); } Mage::helper('rewards/debug')->log("Sess cust = {$session_customer->getId()}"); return $session_customer; }
/** * Returns customer's CPF based on your module configuration * @param Mage_Sales_Model_Order $order * @param Mage_Payment_Model_Method_Abstract $payment * * @return mixed */ private function _getCustomerCpfValue(Mage_Sales_Model_Order $order, $payment) { $customerCpfAttribute = Mage::getStoreConfig('payment/pagseguro/customer_cpf_attribute'); if (empty($customerCpfAttribute)) { //Asked with payment data if (isset($payment['additional_information'][$payment->getMethod() . '_cpf'])) { return $payment['additional_information'][$payment->getMethod() . '_cpf']; } } $entity = explode('|', $customerCpfAttribute); $cpf = ''; if (count($entity) == 1 || $entity[0] == 'customer') { if (count($entity) == 2) { $customerCpfAttribute = $entity[1]; } $customer = $order->getCustomer(); $cpf = $customer->getData($customerCpfAttribute); } else { if (count($entity) == 2 && $entity[0] == 'billing') { //billing $cpf = $order->getShippingAddress()->getData($entity[1]); } } $cpfObj = new Varien_Object(array('cpf' => $cpf)); //you can create a module to get customer's CPF from somewhere else Mage::dispatchEvent('ricardomartins_pagseguro_return_cpf_before', array('order' => $order, 'payment' => $payment, 'cpf_obj' => $cpfObj)); return $cpfObj->getCpf(); }