Ejemplo n.º 1
0
 /**
  * @param Varien_Object $row
  *
  * @return mixed
  */
 public function render(Varien_Object $row)
 {
     if ($row->getCustomerId() && Mage::getSingleton('admin/session')->isAllowed('customer/manage')) {
         $customerEditUrl = $this->getUrl('*/customer/edit', array('id' => $row->getCustomerId()));
         return sprintf('<a href="%s">%s</a>', $customerEditUrl, parent::render($row));
     }
     return parent::render($row);
 }
Ejemplo n.º 2
0
 public function render(Varien_Object $row)
 {
     $customer = Mage::getModel('customer/customer')->load($row->getCustomerId());
     if ($customer) {
         return sprintf('<a target="_blank" href="%s">%s</a>', $this->getUrl('adminhtml/customer/edit', array('id' => $customer->getId())), $customer->getName());
     }
     return $row->getCustomerId();
 }
    public function render(Varien_Object $row)
    {
        if ($row->getCustomerId()) {
            return sprintf('
				<a href="%s" title="%s">%s</a>', $this->getUrl('adminhtml/customer/edit/', array('_current' => true, 'id' => $row->getCustomerId())), Mage::helper('catalog')->__('View Customer Detail'), $row->getCustomerEmail());
        } else {
            return sprintf('%s', $row->getCustomerEmail());
        }
    }
Ejemplo n.º 4
0
 public function render(Varien_Object $row)
 {
     $links = '';
     if ($row->getCustomerId()) {
         $links .= '<a href="' . $this->getUrl('adminhtml/customer/edit', array('id' => $row->getCustomerId())) . '" title="' . $this->__('View Customer') . '">' . $this->__('View Customer') . '</a><br/>';
     }
     $links .= '<a href="' . $this->getUrl('adminhtml/sales_order/view', array('order_id' => $row->getOrderId())) . '" title="' . $this->__('View Order') . '">' . $this->__('View Order') . '</a>';
     return $links;
 }
Ejemplo n.º 5
0
 /**
  * @param Varien_Object $row
  * @return string
  */
 public function render(Varien_Object $row)
 {
     if ($row->getCustomerId()) {
         $name = $row->getFirstname() . ' ' . $row->getLastname();
         $result = sprintf('<a href="%s">%s</a>', Mage::getUrl('adminhtml/customer/edit', array('id' => $row->getCustomerId())), $name);
     } else {
         $result = 'Guest';
     }
     return $result;
 }
Ejemplo n.º 6
0
 public function render(Varien_Object $row)
 {
     if (is_null($row->getCustomerId())) {
         return Mage::helper('review')->__('Guest');
     } elseif ($row->getCustomerId() == 0) {
         return Mage::helper('review')->__('Administrator');
     } elseif ($row->getCustomerId() > 0) {
         return Mage::helper('review')->__('Customer');
     }
     //		return ($row->getCustomerId() ? Mage::helper('review')->__('Customer') : Mage::helper('review')->__('Guest'));
 }
 public function render(Varien_Object $row)
 {
     if (is_null($row->getCustomerId())) {
         if ($row->getStoreId() == Mage_Core_Model_App::ADMIN_STORE_ID) {
             return Mage::helper('review')->__('Administrator');
         } else {
             return Mage::helper('review')->__('Guest');
         }
     } elseif ($row->getCustomerId() > 0) {
         return Mage::helper('review')->__('Customer');
     }
     //		return ($row->getCustomerId() ? Mage::helper('review')->__('Customer') : Mage::helper('review')->__('Guest'));
 }
 /**
  * Renders grid column
  *
  * @param   Varien_Object $row
  * @return  string
  */
 public function render(Varien_Object $row)
 {
     $id = $row->getCustomerId();
     if (!$id) {
         return '&nbsp;';
     }
     return sprintf('<a href="%s">%s</a>', $this->getUrl('*/catalog_product_review', array('customerId' => $id)), AO::helper('adminhtml')->__('Show reviews'));
 }
Ejemplo n.º 9
0
 private function _getCustomerEmail(Varien_Object $row)
 {
     $email = $row->getData($this->getColumn()->getIndex());
     if (!$email) {
         $email = trim(Mage::getModel('customer/customer')->load($row->getCustomerId())->getEmail());
     }
     return $email;
 }
Ejemplo n.º 10
0
 /**
  * Renders grid column
  *
  * @param   Varien_Object $row
  * @return  string
  */
 public function render(Varien_Object $row)
 {
     $id = $row->getCustomerId();
     if (!$id) {
         return Mage::helper('Mage_Adminhtml_Helper_Data')->__('Show Reviews');
     }
     return sprintf('<a href="%s">%s</a>', $this->getUrl('*/catalog_product_review', array('customerId' => $id)), Mage::helper('Mage_Adminhtml_Helper_Data')->__('Show Reviews'));
 }
Ejemplo n.º 11
0
 /**
  * Render customer info to grid column html
  * 
  * @param Varien_Object $row
  */
 public function render(Varien_Object $row)
 {
     $actionName = $this->getRequest()->getActionName();
     if (strpos($actionName, 'export') === 0) {
         return $row->getCustomerEmail();
     }
     return sprintf('<a target="_blank" href="%s">%s</a>', $this->getUrl('adminhtml/customer/edit', array('id' => $row->getCustomerId())), $row->getCustomerEmail());
 }
Ejemplo n.º 12
0
 /**
  * Validate Customer Rule Condition
  *
  * @param Varien_Object $object
  *
  * @return bool
  */
 public function validate(Varien_Object $object)
 {
     $customer = Mage::getModel('customer/customer')->load($object->getCustomerId());
     if (!$customer->getId()) {
         return false;
     }
     return Mage_Rule_Model_Condition_Product_Abstract::validate($customer);
 }
 public function render(Varien_Object $recurring)
 {
     $customer = Mage::getModel('customer/customer')->load($recurring->getCustomerId());
     //        $name = $customer->getFirstname().' '.$customer->getLastname();
     //        var_dump($row->getData());
     $html = '<a ';
     $html .= 'id="customer_' . $this->getColumn()->getId() . '" ';
     $html .= 'href="' . Mage::helper("adminhtml")->getUrl("adminhtml/customer/edit/id/" . $customer->getId() . "/") . '"/>';
     $html .= $recurring->getShippingAddressObj()->format('html');
     $html .= '</a><br/>';
     return $html;
 }
 /**
  * Validate Address Rule Condition
  *
  * @param Varien_Object|Mage_Sales_Model_Order|Mage_Sales_Model_Quote $object
  * @return bool
  */
 public function validate(Varien_Object $object)
 {
     /* @var $object Mage_Sales_Model_Order|Mage_Sales_Model_Quote */
     //Get infos from billing address
     $toValidate = new Varien_Object();
     $customer_id = $object->getCustomerId();
     $orders_count = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('customer_id', $customer_id)->count();
     $toValidate->setOrdersCount($orders_count);
     $toValidate->setCustomerIsGuest(is_null($object->getCustomerIsGuest()) ? 0 : $object->getCustomerIsGuest());
     $toValidate->setDiffAddresses($this->_addressesesAreDifferent($object));
     $toValidate->setCustomerGroup($object->getCustomerGroupId());
     return parent::validate($toValidate);
 }
Ejemplo n.º 15
0
 protected function _afterSave(Varien_Object $address)
 {
     if ($address->getId() && ($address->getIsDefaultBilling() || $address->getIsDefaultShipping())) {
         $customer = Mage::getModel('customer/customer')->load($address->getCustomerId());
         if ($address->getIsDefaultBilling()) {
             $customer->setDefaultBilling($address->getId());
         }
         if ($address->getIsDefaultShipping()) {
             $customer->setDefaultShipping($address->getId());
         }
         $customer->save();
     }
     return $this;
 }
Ejemplo n.º 16
0
 public function render(Varien_Object $row)
 {
     $userName = $row->getUserName();
     $userId = $row->getCustomerId();
     return sprintf('<a href="%s">%s</a>', $this->getUrl('usermanagementadmin/adminhtml_user/edit', array('id' => $userId)), $userName);
 }
Ejemplo n.º 17
0
 /**
  * Add information about product ids to visitor/customer
  *
  *
  * @param Mage_Reports_Model_Product_Index_Abstract $object
  * @param array $productIds
  * @return Mage_Reports_Model_Resource_Product_Index_Abstract
  */
 public function registerIds(Varien_Object $object, $productIds)
 {
     $row = array('visitor_id' => $object->getVisitorId(), 'customer_id' => $object->getCustomerId(), 'store_id' => $object->getStoreId());
     $addedAt = Varien_Date::toTimestamp(true);
     $data = array();
     foreach ($productIds as $productId) {
         $productId = (int) $productId;
         if ($productId) {
             $row['product_id'] = $productId;
             $row['added_at'] = Varien_Date::formatDate($addedAt);
             $data[] = $row;
         }
         $addedAt -= $addedAt > 0 ? 1 : 0;
     }
     $matchFields = array('product_id', 'store_id');
     foreach ($data as $row) {
         Mage::getResourceHelper('reports')->mergeVisitorProductIndex($this->getMainTable(), $row, $matchFields);
     }
     return $this;
 }
Ejemplo n.º 18
0
 public function getCustomerUrl(Varien_Object $row)
 {
     return $this->getUrl('adminhtml/customer/edit', array('id' => $row->getCustomerId(), '_current' => false));
 }
Ejemplo n.º 19
0
 public function registerAction()
 {
     if (!Mage::helper('magenotification')->checkLicenseKeyFrontController($this)) {
         return;
     }
     $programId = $this->getRequest()->getParam('id');
     $program = Mage::getModel('luckydraw/program')->load($programId);
     if (!$program->getId()) {
         return false;
     }
     if ($program->getStatus() != Magestore_Luckydraw_Model_Program::STATUS_PROCESSING) {
         return $this->responseErrorMessage($this->__('Cannot register for this program at this time!'));
     }
     $post = new Varien_Object($this->_filterDates($this->getRequest()->getPost(), array('dob')));
     if ($this->_getConfigHelper()->getRegisterConfig('captcha')) {
         $captchaCode = $this->_getCoreSession()->getData('register_account_captcha_code_$programId');
         if (!$captchaCode || $captchaCode != $post->getData('account_captcha')) {
             Mage::getSingleton('core/session')->addError($this->__('Please enter the correct captcha code!'));
             return false;
         }
     }
     $sessCus = Mage::getSingleton('customer/session')->getCustomer();
     if ($sessCus && $sessCus->getId()) {
         if ($post->getCustomerId() != $sessCus->getId()) {
             return false;
         }
         $customer = Mage::getModel('luckydraw/customer')->load($sessCus->getId());
     } else {
         $customer = Mage::getModel('luckydraw/customer');
     }
     $customer->addData($post->getData())->setFirstname($post->getFirstname())->setLastname($post->getLastname());
     $model = Mage::getModel('luckydraw/code');
     $codes = $model->getCollectionByProgramEmail($program->getId(), $customer->getEmail());
     if ($codes->count()) {
         Mage::getSingleton('core/session')->addError($this->__('You have played this program already!'));
         return false;
     }
     if ($this->_getConfigHelper()->getRegisterConfig('address')) {
         if ($post->getData('account_address_id')) {
             $model->setData('address_id', $post->getData('account_address_id'));
         } else {
             $address = Mage::getModel('customer/address')->setData($post->getData('account'))->setParentId($customer->getId())->setFirstname($customer->getFirstname())->setLastname($customer->getLastname())->setId(null);
             $customer->addAddress($address);
             $errors = $address->validate();
         }
     }
     if (!isset($errors) || !is_array($errors)) {
         $errors = array();
     }
     try {
         $validationCustomer = $customer->validate();
         if (is_array($validationCustomer)) {
             $errors = array_merge($validationCustomer, $errors);
         }
         $validationResult = count($errors) == 0;
         if (true === $validationResult) {
             $customer->save();
             if (isset($address) && !$address->getId()) {
                 $address->save();
                 $model->setData('address_id', $address->getId());
             }
         } else {
             foreach ($errors as $error) {
                 Mage::getSingleton('core/session')->addError($error);
             }
             Mage::getSingleton('core/session')->setRegisterLuckydraw($post->getData());
             return false;
         }
     } catch (Exception $e) {
         Mage::getSingleton('core/session')->addError($e->getMessage());
         Mage::getSingleton('core/session')->setRegisterLuckydraw($post->getData());
         return false;
     }
     $model->setData('program_id', $programId)->setData('customer_id', $customer->getId())->setData('email', $customer->getEmail())->setData('name', $customer->getName())->setData('created_time', now())->setData('credit_rate', $program->getData('credit_rate'));
     if ($code = $this->_getCodeReferrer($programId)) {
         $model->setData('refer_user', $code->getData('customer_id'))->setData('refer_email', $code->getData('email'));
     }
     $codeStatus = Magestore_Luckydraw_Model_Code::STATUS_INACTIVE;
     $needSendActiveEmail = true;
     if ($sessCus && $sessCus->getId()) {
         if (!$this->_getConfigHelper()->getRegisterConfig('verify')) {
             $codeStatus = Magestore_Luckydraw_Model_Code::STATUS_PENDING;
             $needSendActiveEmail = false;
         }
     } else {
         if ($customer->isConfirmationRequired()) {
             $customer->sendNewAccountEmail('confirmation', $this->_getReferrerUrl(), Mage::app()->getStore()->getId());
             Mage::getSingleton('core/session')->addSuccess($this->__('Account confirmation is required. Please, check your email for the confirmation link. To resend the confirmation email please <a href="%s">click here</a>.', Mage::helper('customer')->getEmailConfirmationUrl($customer->getEmail())));
             $needSendActiveEmail = false;
         } else {
             $customer->sendNewAccountEmail('registered', $this->_getReferrerUrl(), Mage::app()->getStore()->getId());
             Mage::getSingleton('customer/session')->setCustomerAsLoggedIn($customer);
             if (!$this->_getConfigHelper()->getRegisterConfig('verify')) {
                 $codeStatus = Magestore_Luckydraw_Model_Code::STATUS_PENDING;
                 $needSendActiveEmail = false;
             }
         }
     }
     $model->setData('status', $codeStatus);
     try {
         $model->setData('program', $program)->save();
         if ($needSendActiveEmail) {
             $model->sendActiveEmail();
             Mage::getSingleton('core/session')->addSuccess($this->__('Draw code confirmation is required. Please check your email for the confirmation link. To resend the confirmation email, please <a href="%s">click here</a>.', Mage::getUrl('*/*/resend', array('id' => $programId, 'code' => $model->getDrawCode()))));
             Mage::getSingleton('customer/session')->setLuckycode($model->getData('draw_code'));
         } elseif ($codeStatus == Magestore_Luckydraw_Model_Code::STATUS_PENDING) {
             $model->sendRegisterEmail();
             Mage::getSingleton('customer/session')->setLuckycode($model->getData('draw_code'));
         }
     } catch (Exception $e) {
         Mage::getSingleton('core/session')->addError($e->getMessage());
     }
 }
 /**
  * Retrieves recent activity for customers (sorted by last visit date)
  */
 function getactivityAction()
 {
     if (!$this->_authenticate()) {
         return;
     }
     try {
         $request = $this->getRequest();
         $helper = Mage::helper('eyehubspot');
         $maxperpage = $request->getParam('maxperpage', self::MAX_CUSTOMER_PERPAGE);
         $maxAssociated = $request->getParam('maxassoc', self::MAX_ASSOC_PRODUCT_LIMIT);
         $start = date('Y-m-d H:i:s', $request->getParam('start', 0));
         $end = date('Y-m-d H:i:s', time() - 300);
         $websiteId = Mage::app()->getWebsite()->getId();
         $store = Mage::app()->getStore();
         $storeId = Mage::app()->getStore()->getId();
         $collection = Mage::getModel('customer/customer')->getCollection();
         $resource = Mage::getSingleton('core/resource');
         $read = $resource->getConnection('core_read');
         $customerData = array();
         try {
             // because of limitations in the log areas of magento, we cannot use the
             // standard collection to retreive the results
             $select = $read->select()->from(array('lc' => $resource->getTableName('log/customer')))->joinInner(array('lv' => $resource->getTableName('log/visitor')), 'lc.visitor_id = lv.visitor_id')->joinInner(array('vi' => $resource->getTableName('log/visitor_info')), 'lc.visitor_id = vi.visitor_id')->joinInner(array('c' => $resource->getTableName('customer/entity')), 'c.entity_id = lc.customer_id', array('email' => 'email', 'customer_since' => 'created_at'))->joinInner(array('p' => $resource->getTableName('log/url_info_table')), 'p.url_id = lv.last_url_id', array('last_url' => 'p.url', 'last_referer' => 'p.referer'))->where('lc.customer_id > 0')->where("lv.last_visit_at >= '{$start}'")->where("lv.last_visit_at < '{$end}'")->order('lv.last_visit_at')->limit($maxperpage);
             $collection = $read->fetchAll($select);
         } catch (Exception $e) {
             $this->_outputError(self::ERROR_CODE_UNSUPPORTED_SQL, 'DB Exception on query', $e);
             return;
         }
         foreach ($collection as $assoc) {
             $log = new Varien_Object($assoc);
             $customerId = $log->getCustomerId();
             // merge and replace older data with newer
             if (isset($customerData[$customerId])) {
                 $temp = $customerData[$customerId];
                 $log->addData($temp->getData());
                 $log->setFirstVisitAt($temp->getFirstVisitAt());
             } else {
                 $log->setViewed($helper->getProductViewedList($customerId, $maxAssociated));
                 $log->setCompare($helper->getProductCompareList($customerId, $maxAssociated));
                 $log->setWishlist($helper->getProductWishlist($customerId, $maxAssociated));
             }
             $log->unsetData('session_id');
             $customerData[$customerId] = $log;
         }
     } catch (Exception $e) {
         $this->_outputError(self::ERROR_CODE_UNKNOWN_EXCEPTION, 'Unknown exception on request', $e);
         return;
     }
     $this->_outputJson(array('visitors' => $helper->convertAttributeData($customerData), 'website' => $websiteId, 'store' => $storeId));
 }
Ejemplo n.º 21
0
 public function render(Varien_Object $row)
 {
     return $row->getCustomerId() > 0 ? Mage::helper('customer')->__('Customer') : Mage::helper('customer')->__('Visitor');
 }
Ejemplo n.º 22
0
 /**
  * Authorize or Capture payment
  *
  * @param Varien_Object|Mage_Sales_Model_Order_Payment $payment
  * @param float $amount
  * @param bool $capture
  * @return  $this
  */
 private function _authorize(Varien_Object $payment, $amount, $capture)
 {
     $order = $payment->getOrder();
     /* @var $order Mage_Sales_Model_Order */
     $multiToken = false;
     $cardData = null;
     $additionalData = new Varien_Object($payment->getAdditionalData() ? unserialize($payment->getAdditionalData()) : null);
     $secureToken = $additionalData->getSecuresubmitToken() ? $additionalData->getSecuresubmitToken() : null;
     $saveCreditCard = !!(bool) $additionalData->getCcSaveFuture();
     $customerId = $additionalData->getCustomerId();
     if ($saveCreditCard) {
         $multiToken = true;
         $cardData = new HpsCreditCard();
         $cardData->number = $payment->getCcLast4();
         $cardData->expYear = $payment->getCcExpYear();
         $cardData->expMonth = $payment->getCcExpMonth();
     }
     $chargeService = $this->_getChargeService();
     $cardHolder = $this->_getCardHolderData($order);
     $details = $this->_getTxnDetailsData($order);
     $cardOrToken = new HpsTokenData();
     $cardOrToken->tokenValue = $secureToken;
     try {
         if ($capture) {
             if ($payment->getCcTransId()) {
                 $response = $chargeService->capture($payment->getCcTransId(), $amount);
             } else {
                 $response = $chargeService->charge($amount, strtolower($order->getBaseCurrencyCode()), $cardOrToken, $cardHolder, $multiToken, $details);
             }
         } else {
             $response = $chargeService->authorize($amount, strtolower($order->getBaseCurrencyCode()), $cardOrToken, $cardHolder, $multiToken, $details);
         }
         $this->_debugChargeService($chargeService);
         $payment->setStatus(self::STATUS_APPROVED);
         $payment->setAmount($amount);
         $payment->setLastTransId($response->transactionId);
         $payment->setCcTransId($response->transactionId);
         $payment->setTransactionId($response->transactionId);
         $payment->setIsTransactionClosed(0);
         if ($multiToken) {
             $tokenData = $response->tokenData;
             /* @var $tokenData HpsTokenData */
             if ($tokenData->responseCode == '0') {
                 if ($customerId > 0) {
                     Mage::helper('hps_securesubmit')->saveMultiToken($response->tokenData->tokenValue, $cardData, $response->cardType, $customerId);
                 } else {
                     Mage::helper('hps_securesubmit')->saveMultiToken($response->tokenData->tokenValue, $cardData, $response->cardType);
                 }
             } else {
                 Mage::log('Requested multi token has not been generated for the transaction # ' . $response->transactionId, Zend_Log::WARN);
             }
         }
     } catch (HpsCreditException $e) {
         Mage::logException($e);
         $this->_debugChargeService($chargeService, $e);
         $payment->setStatus(self::STATUS_DECLINED);
         $this->throwUserError($e->getMessage(), $e->resultText, TRUE);
     } catch (HpsException $e) {
         $this->_debugChargeService($chargeService, $e);
         $payment->setStatus(self::STATUS_ERROR);
         $this->throwUserError($e->getMessage(), NULL, TRUE);
     } catch (Exception $e) {
         $this->_debugChargeService($chargeService, $e);
         Mage::logException($e);
         $payment->setStatus(self::STATUS_ERROR);
         $this->throwUserError($e->getMessage());
     }
     return $this;
 }
Ejemplo n.º 23
0
 /**
  * @param $observer
  * @return $this
  */
 protected function _addPointsForTagging($observer)
 {
     $object = $observer->getObject();
     if (($tagToApprove = $object) instanceof Mage_Tag_Model_Tag) {
         if ($this->_isModuleDisabled($tagToApprove->getStoreId())) {
             return $this;
         }
         $tagCollection = Mage::getModel('tag/tag')->getCollection()->joinRel()->addStatusFilter(Mage_Tag_Model_Tag::STATUS_APPROVED);
         $tagCollection->getSelect()->where('main_table.tag_id = ?', $tagToApprove->getTagId());
         foreach ($tagCollection->getData() as $tag) {
             $tagObject = new Varien_Object();
             unset($tag['tag_id']);
             $tagObject->setData($tag);
             $customer = Mage::getModel('customer/customer')->load($tagObject->getCustomerId());
             if ($this->_isNotSetInSummary($customer, $tagObject->getTagRelationId())) {
                 $pointsForTagging = Mage::helper('points/config')->getPointsForTaggingProduct($customer->getStoreId());
                 $product = Mage::getModel('catalog/product')->load($tagObject->getProductId());
                 Mage::getModel('points/api')->addTransaction($pointsForTagging, 'customer_tag_product', $customer, $tagObject, array('product_name' => $product->getName()));
                 $this->_addRelationIdToSummary($customer, $tagObject->getTagRelationId());
             }
         }
     }
     return $this;
 }
 /**
  * Authorize or Capture payment
  *
  * @param Varien_Object|Mage_Sales_Model_Order_Payment $payment
  * @param float $amount
  * @param bool $capture
  * @return  $this
  */
 private function _authorize(Varien_Object $payment, $amount, $capture)
 {
     $order = $payment->getOrder();
     /* @var $order Mage_Sales_Model_Order */
     $multiToken = false;
     $cardData = null;
     $additionalData = new Varien_Object($payment->getAdditionalData() ? unserialize($payment->getAdditionalData()) : null);
     $secureToken = $additionalData->getSecuresubmitToken() ? $additionalData->getSecuresubmitToken() : null;
     $saveCreditCard = !!(bool) $additionalData->getCcSaveFuture();
     $customerId = $additionalData->getCustomerId();
     $giftService = $this->_getGiftService();
     $giftCardNumber = $additionalData->getGiftcardNumber();
     if ($giftCardNumber) {
         // 1. check balance
         $giftcard = new HpsGiftCard();
         $giftcard->number = $giftCardNumber;
         $giftResponse = $giftService->balance($giftcard);
         // 2. is balance > amount?
         if ($giftResponse->balanceAmount > $amount) {
             //  2.yes. process full to gift
             try {
                 if (strpos($this->getConfigData('secretapikey'), '_cert_') !== false) {
                     $giftresp = $giftService->sale($giftcard, 10.0);
                 } else {
                     $giftresp = $giftService->sale($giftcard, $amount);
                 }
                 $order->addStatusHistoryComment('Used Heartland Gift Card ' . $giftCardNumber . ' for amount $' . $amount . '. [full payment]');
                 $payment->setTransactionAdditionalInfo(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS, array('gift_card_number' => $giftCardNumber, 'gift_card_transaction' => $giftresp->transactionId, 'gift_card_amount_charged' => $amount));
                 $payment->setStatus(self::STATUS_APPROVED);
                 $payment->setAmount($amount);
                 $payment->setLastTransId($response->transactionId);
                 $payment->setTransactionId($response->transactionId);
                 $payment->setIsTransactionClosed(0);
                 return $this;
             } catch (Exception $e) {
                 Mage::logException($e);
                 $payment->setStatus(self::STATUS_ERROR);
                 $this->throwUserError($e->getMessage(), null, true);
             }
         } else {
             //  2.no. process full gift card amt and card process remainder
             $giftresp = $giftService->sale($giftcard, $giftResponse->balanceAmount);
             $order->addStatusHistoryComment('Used Heartland Gift Card ' . $giftCardNumber . ' for amount $' . $giftResponse->balanceAmount . '. [partial payment]')->save();
             $payment->setTransactionAdditionalInfo(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS, array('gift_card_number' => $giftCardNumber, 'gift_card_transaction' => $giftresp->transactionId, 'gift_card_amount_charged' => $giftResponse->balanceAmount));
             $payment->setAmount($giftResponse->balanceAmount)->save();
             $amount = $amount - $giftResponse->balanceAmount;
             // remainder
             // 3. TODO: if the card payment fails later, refund the gift transaction
         }
     }
     if ($saveCreditCard) {
         $multiToken = true;
         $cardData = new HpsCreditCard();
         $cardData->number = $payment->getCcLast4();
         $cardData->expYear = $payment->getCcExpYear();
         $cardData->expMonth = $payment->getCcExpMonth();
     }
     $chargeService = $this->_getChargeService();
     $cardHolder = $this->_getCardHolderData($order);
     $details = $this->_getTxnDetailsData($order);
     $cardOrToken = new HpsTokenData();
     $cardOrToken->tokenValue = $secureToken;
     try {
         if ($capture) {
             if ($payment->getCcTransId()) {
                 $response = $chargeService->capture($payment->getCcTransId(), $amount);
             } else {
                 $response = $chargeService->charge($amount, strtolower($order->getBaseCurrencyCode()), $cardOrToken, $cardHolder, $multiToken, $details);
             }
         } else {
             $response = $chargeService->authorize($amount, strtolower($order->getBaseCurrencyCode()), $cardOrToken, $cardHolder, $multiToken, $details);
         }
         $this->_debugChargeService($chargeService);
         $payment->setStatus(self::STATUS_APPROVED);
         $payment->setAmount($amount);
         $payment->setLastTransId($response->transactionId);
         $payment->setCcTransId($response->transactionId);
         $payment->setTransactionId($response->transactionId);
         $payment->setIsTransactionClosed(0);
         if ($giftCardNumber) {
             $order->addStatusHistoryComment('Remaining amount to be charged to credit card  ' . $this->_formatAmount($amount) . '. [partial payment]')->save();
         }
         if ($multiToken) {
             $tokenData = $response->tokenData;
             /* @var $tokenData HpsTokenData */
             if ($tokenData->responseCode == '0') {
                 if ($customerId > 0) {
                     Mage::helper('hps_securesubmit')->saveMultiToken($response->tokenData->tokenValue, $cardData, $response->cardType, $customerId);
                 } else {
                     Mage::helper('hps_securesubmit')->saveMultiToken($response->tokenData->tokenValue, $cardData, $response->cardType);
                 }
             } else {
                 Mage::log('Requested multi token has not been generated for the transaction # ' . $response->transactionId, Zend_Log::WARN);
             }
         }
     } catch (HpsCreditException $e) {
         Mage::logException($e);
         $this->getFraudSettings();
         $this->_debugChargeService($chargeService, $e);
         // refund gift (if used)
         if ($giftCardNumber) {
             $order->addStatusHistoryComment('Reversed Heartland Gift Card ' . $giftCardNumber . ' for amount $' . $giftResponse->balanceAmount . '. [full reversal]')->save();
             $giftResponse = $giftService->reverse($giftcard, $giftResponse->balanceAmount);
         }
         if ($this->_allow_fraud && $e->getCode() == HpsExceptionCodes::POSSIBLE_FRAUD_DETECTED) {
             // we can skip the card saving if it fails for possible fraud there will be no token.
             if ($this->_email_fraud && $this->_fraud_address != '') {
                 // EMAIL THE PEOPLE
                 $this->sendEmail($this->_fraud_address, $this->_fraud_address, 'Suspicious order (' . $order->getIncrementId() . ') allowed', 'Hello,<br><br>Heartland has determined that you should review order ' . $order->getRealOrderId() . ' for the amount of ' . $amount . '.');
             }
             $payment->setStatus(self::STATUS_APPROVED);
             $payment->setAmount($amount);
             $payment->setIsTransactionClosed(0);
         } else {
             $payment->setStatus(self::STATUS_ERROR);
             if ($e->getCode() == HpsExceptionCodes::POSSIBLE_FRAUD_DETECTED) {
                 $this->throwUserError($this->_fraud_text, null, true);
             } else {
                 $this->throwUserError($e->getMessage(), null, true);
             }
         }
     } catch (HpsException $e) {
         $this->_debugChargeService($chargeService, $e);
         $payment->setStatus(self::STATUS_ERROR);
         $this->throwUserError($e->getMessage(), null, true);
     } catch (Exception $e) {
         $this->_debugChargeService($chargeService, $e);
         Mage::logException($e);
         $payment->setStatus(self::STATUS_ERROR);
         $this->throwUserError($e->getMessage());
     }
     return $this;
 }
Ejemplo n.º 25
0
 /**
  * Define the enqueue XML data
  *
  * @param Varien_Object $order
  */
 private function enfileirarData($order)
 {
     $this->_resetData();
     //Pega os dados do cliente
     $customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
     //Define os dados da cobrança
     $this->xmlCompradorNome = (string) $order->getBillingAddress()->getFirstname() . ' ' . $order->getBillingAddress()->getLastname();
     $customerDocs = explode(",", Mage::getStoreConfig('allpago/fcontrol/campo_documento'));
     $cpfLog = null;
     foreach ($customerDocs as $customerDoc) {
         $metodo = 'get' . ucfirst($customerDoc);
         if (!$this->xmlCompradorCpfCnpj && $customer->{$metodo}()) {
             $this->xmlCompradorCpfCnpj = (string) preg_replace('/[^0-9]/', '', $customer->{$metodo}());
         }
         if ($customer->{$metodo}()) {
             $cpfLog .= '<pre>' . print_r($customer->getData(), true) . '<br/>Método: ' . $metodo . ' ( ' . $customer->{$metodo}() . ' )</pre>';
         }
     }
     if (!$this->xmlCompradorCpfCnpj) {
         Mage::throwException('CPF não encontrado' . $cpfLog);
     }
     $this->xmlCompradorSexo = (string) 'M';
     // @todo: Pegar esta informação do Magento
     $this->xmlCompradorDataNascimento = (string) '1900-01-01';
     // @todo: Pegar esta informação do Magento
     $this->xmlCompradorDddTelefone = (string) substr(str_replace(' ', '', preg_replace('/[()-]*/', '', $order->getBillingAddress()->getTelephone())), 0, 2);
     $this->xmlCompradorNumeroTelefone = (string) substr(str_replace(' ', '', preg_replace('/[()-]*/', '', $order->getBillingAddress()->getTelephone())), 2, 9);
     $this->xmlCompradorDddCelular = (string) substr(str_replace(' ', '', preg_replace('/[()-]*/', '', $order->getBillingAddress()->getTelephone())), 0, 2);
     // @todo: Pegar esta informação do Magento / Community e o Enterprise
     $this->xmlCompradorNumeroCelular = (string) substr(str_replace(' ', '', preg_replace('/[()-]*/', '', $order->getBillingAddress()->getTelephone())), 2, 9);
     // @todo: Pegar esta informação do Magento / Community e o Enterprise
     $this->xmlCompradorIP = (string) $order->getRemoteIp();
     $this->xmlCompradorEmail = (string) $order->getCustomerEmail();
     $this->xmlCompradorEnderecoCep = (string) str_replace(' ', '', preg_replace('/[-.]*/', '', $order->getBillingAddress()->getPostcode()));
     $this->xmlCompradorEnderecoRua = (string) $order->getBillingAddress()->getStreet(1);
     $this->xmlCompradorEnderecoNumero = (string) $order->getBillingAddress()->getStreet(2);
     $this->xmlCompradorEnderecoComplemento = (string) Mage::helper('core/string')->truncate($order->getBillingAddress()->getStreet(3), 100);
     $this->xmlCompradorEnderecoBairro = (string) $order->getBillingAddress()->getStreet(4);
     $this->xmlCompradorEnderecoCidade = (string) $order->getBillingAddress()->getCity();
     $region = "";
     $directoryRegion = Mage::getResourceModel('directory/region_collection');
     $directoryRegion->getSelect()->reset()->from(array('main_table' => $directoryRegion->getMainTable()), 'default_name');
     $directoryRegion->addFieldToFilter('country_id', 'BR')->addFieldToFilter('region_id', $order->getBillingAddress()->getRegionId());
     $billingRegion = $directoryRegion->getResource()->getReadConnection()->fetchOne($directoryRegion->getSelect());
     $this->xmlCompradorEnderecoEstado = (string) $billingRegion;
     //Define os dados de entrega
     $this->xmlEntregaNome = (string) ($order->getShippingAddress()->getFirstname() . ' ' . $order->getShippingAddress()->getLastname());
     $customerDocs = explode(",", Mage::getStoreConfig('allpago/fcontrol/campo_documento'));
     $this->xmlEntregaCpfCnpj = null;
     foreach ($customerDocs as $customerDoc) {
         $metodo = 'get' . ucfirst($customerDoc);
         if (!$this->xmlEntregaCpfCnpj && $order->getShippingAddress()->{$metodo}()) {
             $this->xmlEntregaCpfCnpj = (string) preg_replace('/[^0-9]/', '', $order->getShippingAddress()->{$metodo}());
         }
     }
     $this->xmlEntregaCpfCnpj = $this->xmlEntregaCpfCnpj ? $this->xmlEntregaCpfCnpj : $this->xmlCompradorCpfCnpj;
     $this->xmlEntregaSexo = (string) 'M';
     // @todo: Pegar esta informação do Magento
     $this->xmlEntregaDataNascimento = (string) '1900-01-01';
     // @todo: Pegar esta informação do Magento
     $this->xmlEntregaDddTelefone = (string) substr(str_replace(' ', '', preg_replace('/[()-]*/', '', $order->getShippingAddress()->getTelephone())), 0, 2);
     $this->xmlEntregaNumeroTelefone = (string) substr(str_replace(' ', '', preg_replace('/[()-]*/', '', $order->getShippingAddress()->getTelephone())), 2, 9);
     $this->xmlEntregaDddCelular = (string) substr(str_replace(' ', '', preg_replace('/[()-]*/', '', $order->getBillingAddress()->getTelephone())), 0, 2);
     // @todo: Pegar esta informação do Magento / Community e o Enterprise
     $this->xmlEntregaNumeroCelular = (string) substr(str_replace(' ', '', preg_replace('/[()-]*/', '', $order->getShippingAddress()->getTelephone())), 2, 9);
     // @todo: Pegar esta informação do Magento / Community e o Enterprise
     $this->xmlEntregaEnderecoCep = (string) str_replace(' ', '', preg_replace('/[-.]*/', '', $order->getShippingAddress()->getPostcode()));
     $this->xmlEntregaEnderecoRua = (string) $order->getShippingAddress()->getStreet(1);
     $this->xmlEntregaEnderecoNumero = (string) $order->getShippingAddress()->getStreet(2);
     $this->xmlEntregaEnderecoComplemento = (string) Mage::helper('core/string')->truncate($order->getShippingAddress()->getStreet(3), 100);
     $this->xmlEntregaEnderecoBairro = (string) $order->getShippingAddress()->getStreet(4);
     $this->xmlEntregaEnderecoCidade = (string) $order->getShippingAddress()->getCity();
     $directoryRegion = Mage::getResourceModel('directory/region_collection');
     $directoryRegion->getSelect()->reset()->from(array('main_table' => $directoryRegion->getMainTable()), 'default_name');
     $directoryRegion->addFieldToFilter('country_id', 'BR')->addFieldToFilter('region_id', $order->getShippingAddress()->getRegionId());
     $shippingRegion = $directoryRegion->getResource()->getReadConnection()->fetchOne($directoryRegion->getSelect());
     $this->xmlEntregaEnderecoEstado = (string) $shippingRegion;
     //Define os dados dos produtos
     $totalItems = 0;
     $items = $order->getAllItems();
     $this->xmlPedidoProdutos = array();
     foreach ($items as $item) {
         $this->xmlPedidoProdutos[] = array('Codigo' => (string) $item->getProductId(), 'Descricao' => (string) $item->getName(), 'Quantidade' => (string) $item->getQtyOrdered(), 'ValorUnitario' => (string) $item->getPrice() * 100, 'ListaDeCasamento' => (string) false, 'ParaPresente' => (string) false);
         $totalItems += $item->getQtyOrdered();
     }
     //Define os dados do pagamento
     $this->xmlPedidoPagamentos = array('MetodoPagamento' => (string) 'CartaoCredito', 'Valor' => (string) ($order->getGrandTotal() * 100), 'NumeroParcelas' => (string) 1);
     //Define os dados dos pedido
     $this->xmlPedidoCodigoPedido = (string) $order->getId();
     $dataCompra = new DateTime($order->getCreatedAt());
     $dataCompra->setTimezone(new DateTimeZone('America/Sao_Paulo'));
     $this->xmlPedidoDataCompra = (string) $dataCompra->format('Y-m-d\\TH:i:s');
     $this->xmlPedidoQuantidadeItensDistintos = (string) count($items);
     $this->xmlPedidoQuantidadeTotalItens = (string) $totalItems;
     $this->xmlPedidoValorTotalCompra = (string) ($order->getGrandTotal() * 100);
     $this->xmlPedidoValorTotalFrete = (string) ($order->getPayment()->getShippingAmount() * 100);
     $this->xmlPedidoPrazoEntregaDias = (string) '0';
     $this->xmlPedidoCanalVenda = (string) 'Loja Virtual';
 }
 /**
  * Keep customer cookies synchronized with customer session
  *
  * @return Enterprise_PageCache_Model_Cookie
  */
 public function updateCustomerCookies()
 {
     /** @var Mage_Customer_Model_Session $session */
     $session = Mage::getSingleton('customer/session');
     $customerId = $session->getCustomerId();
     $customerGroupId = $session->getCustomerGroupId();
     if (!$customerId || is_null($customerGroupId)) {
         $customerCookies = new Varien_Object();
         Mage::dispatchEvent('update_customer_cookies', array('customer_cookies' => $customerCookies));
         if (!$customerId) {
             $customerId = $customerCookies->getCustomerId();
         }
         if (is_null($customerGroupId)) {
             $customerGroupId = $customerCookies->getCustomerGroupId();
         }
     }
     if ($customerId && !is_null($customerGroupId)) {
         $this->setObscure(self::COOKIE_CUSTOMER, 'customer_' . $customerId);
         $this->setObscure(self::COOKIE_CUSTOMER_GROUP, 'customer_group_' . $customerGroupId);
         if ($session->isLoggedIn()) {
             $this->setObscure(self::COOKIE_CUSTOMER_LOGGED_IN, 'customer_logged_in_' . $session->isLoggedIn());
         } else {
             $this->delete(self::COOKIE_CUSTOMER_LOGGED_IN);
         }
     } else {
         $this->delete(self::COOKIE_CUSTOMER);
         $this->delete(self::COOKIE_CUSTOMER_GROUP);
         $this->delete(self::COOKIE_CUSTOMER_LOGGED_IN);
     }
     return $this;
 }
Ejemplo n.º 27
0
 public function render(Varien_Object $row)
 {
     return $row->getCustomerId() ? Mage::helper('review')->__('Customer') : Mage::helper('review')->__('Guest');
 }