/**
  * After generate Xml
  *
  * @param \Magento\Framework\View\LayoutInterface $subject
  * @param \Magento\Framework\View\LayoutInterface $result
  * @return \Magento\Framework\View\LayoutInterface
  */
 public function afterGenerateXml(\Magento\Framework\View\LayoutInterface $subject, $result)
 {
     if (!$this->registry->registry(self::REGISTRY_KEY)) {
         $this->registry->register(self::REGISTRY_KEY, $this->customerSession->getCustomer());
     }
     return $result;
 }
 public function testSetCustomerDataAsLoggedIn()
 {
     $customer = $this->getMock('Magento\\Customer\\Model\\Customer', [], [], '', false);
     $customerDto = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false);
     $this->customerFactoryMock->expects($this->once())->method('create')->will($this->returnValue($customer));
     $customer->expects($this->once())->method('updateData')->with($customerDto)->will($this->returnSelf());
     $this->_eventManagerMock->expects($this->at(0))->method('dispatch')->with('customer_login', ['customer' => $customer]);
     $this->_eventManagerMock->expects($this->at(1))->method('dispatch')->with('customer_data_object_login', ['customer' => $customerDto]);
     $this->_model->setCustomerDataAsLoggedIn($customerDto);
     $this->assertSame($customer, $this->_model->getCustomer());
 }
 /**
  * Make sure customer is logged in and put it into registry
  *
  * @param RequestInterface $request
  * @return \Magento\Framework\App\ResponseInterface
  */
 public function dispatch(RequestInterface $request)
 {
     if (!$request->isDispatched()) {
         return parent::dispatch($request);
     }
     if (!$this->_customerSession->authenticate($this)) {
         $this->_actionFlag->set('', 'no-dispatch', true);
     }
     $customer = $this->_customerSession->getCustomer();
     $this->_coreRegistry->register(RegistryConstants::CURRENT_CUSTOMER, $customer);
     $this->_coreRegistry->register(RegistryConstants::CURRENT_CUSTOMER_ID, $customer->getId());
     return parent::dispatch($request);
 }
 /**
  * Return array with data to send to MP api
  *
  * @return array
  */
 public function makePreference()
 {
     $orderIncrementId = $this->_checkoutSession->getLastRealOrderId();
     $order = $this->_orderFactory->create()->loadByIncrementId($orderIncrementId);
     $customer = $this->_customerSession->getCustomer();
     $payment = $order->getPayment();
     $paramsShipment = new \Magento\Framework\DataObject();
     $paramsShipment->setParams([]);
     $this->_eventManager->dispatch('mercadopago_standard_make_preference_before', ['params' => $paramsShipment, 'order' => $order]);
     $arr = [];
     $arr['external_reference'] = $orderIncrementId;
     $arr['items'] = $this->getItems($order);
     $this->_calculateDiscountAmount($arr['items'], $order);
     $this->_calculateBaseTaxAmount($arr['items'], $order);
     $total_item = $this->getTotalItems($arr['items']);
     $total_item += (double) $order->getBaseShippingAmount();
     $order_amount = (double) $order->getBaseGrandTotal();
     if (!$order_amount) {
         $order_amount = (double) $order->getBasePrice() + $order->getBaseShippingAmount();
     }
     if ($total_item > $order_amount || $total_item < $order_amount) {
         $diff_price = $order_amount - $total_item;
         $arr['items'][] = ["title" => "Difference amount of the items with a total", "description" => "Difference amount of the items with a total", "category_id" => $this->_scopeConfig->getValue('payment/mercadopago/category_id', \Magento\Store\Model\ScopeInterface::SCOPE_STORE), "quantity" => 1, "unit_price" => (double) $diff_price];
         $this->_helperData->log("Total itens: " . $total_item, 'mercadopago-standard.log');
         $this->_helperData->log("Total order: " . $order_amount, 'mercadopago-standard.log');
         $this->_helperData->log("Difference add itens: " . $diff_price, 'mercadopago-standard.log');
     }
     if ($order->canShip()) {
         $shippingAddress = $order->getShippingAddress();
         $shipping = $shippingAddress->getData();
         $arr['payer']['phone'] = ["area_code" => "-", "number" => $shipping['telephone']];
         $arr['shipments'] = $this->_getParamShipment($paramsShipment, $order, $shippingAddress);
     }
     $billing_address = $order->getBillingAddress()->getData();
     $arr['payer']['date_created'] = date('Y-m-d', $customer->getCreatedAtTimestamp()) . "T" . date('H:i:s', $customer->getCreatedAtTimestamp());
     $arr['payer']['email'] = htmlentities($customer->getEmail());
     $arr['payer']['first_name'] = htmlentities($customer->getFirstname());
     $arr['payer']['last_name'] = htmlentities($customer->getLastname());
     if (isset($payment['additional_information']['doc_number']) && $payment['additional_information']['doc_number'] != "") {
         $arr['payer']['identification'] = ["type" => "CPF", "number" => $payment['additional_information']['doc_number']];
     }
     $arr['payer']['address'] = ["zip_code" => $billing_address['postcode'], "street_name" => $billing_address['street'] . " - " . $billing_address['city'] . " - " . $billing_address['country_id'], "street_number" => ""];
     $url = $this->_helperData->getSuccessUrl();
     $arr['back_urls'] = ['success' => $this->_urlBuilder->getUrl($url), 'pending' => $this->_urlBuilder->getUrl($url), 'failure' => $this->_urlBuilder->getUrl('checkout/onepage/failure')];
     $arr['notification_url'] = $this->_urlBuilder->getUrl("mercadopago/notifications/standard");
     $arr['payment_methods']['excluded_payment_methods'] = $this->getExcludedPaymentsMethods();
     $installments = $this->getConfigData('installments');
     $arr['payment_methods']['installments'] = (int) $installments;
     $auto_return = $this->getConfigData('auto_return');
     if ($auto_return == 1) {
         $arr['auto_return'] = "approved";
     }
     $sponsor_id = $this->_scopeConfig->getValue('payment/mercadopago/sponsor_id', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     $this->_helperData->log("Sponsor_id", 'mercadopago-standard.log', $sponsor_id);
     if (!empty($sponsor_id)) {
         $this->_helperData->log("Sponsor_id identificado", 'mercadopago-standard.log', $sponsor_id);
         $arr['sponsor_id'] = (int) $sponsor_id;
     }
     return $arr;
 }
 /**
  * Check Captcha On Forgot Password Page
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $captchaModel = $this->helper->getCaptcha(self::FORM_ID);
     if ($captchaModel->isRequired()) {
         /** @var \Magento\Framework\App\Action\Action $controller */
         $controller = $observer->getControllerAction();
         if (!$captchaModel->isCorrect($this->captchaStringResolver->resolve($controller->getRequest(), self::FORM_ID))) {
             $customerId = $this->customerSession->getCustomerId();
             $this->authentication->processAuthenticationFailure($customerId);
             if ($this->authentication->isLocked($customerId)) {
                 $this->customerSession->logout();
                 $this->customerSession->start();
                 $message = __('The account is locked. Please wait and try again or contact %1.', $this->scopeConfig->getValue('contact/email/recipient_email'));
                 $this->messageManager->addError($message);
             }
             $this->messageManager->addError(__('Incorrect CAPTCHA'));
             $this->actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
             $this->redirect->redirect($controller->getResponse(), '*/*/edit');
         }
     }
     $customer = $this->customerSession->getCustomer();
     $login = $customer->getEmail();
     $captchaModel->logAttempt($login);
     return $this;
 }
Exemple #6
0
 /**
  * Get default value for From field
  *
  * @return string
  */
 public function getDefaultFrom()
 {
     if ($this->httpContext->getValue(\Magento\Customer\Helper\Data::CONTEXT_AUTH)) {
         return $this->_customerSession->getCustomer()->getName();
     } else {
         return $this->getEntity()->getBillingAddress()->getName();
     }
 }
 /**
  * Load customer user info
  *
  * @throws \Magento\Framework\Exception
  * @return \Inchoo\SocialConnect\Model\Facebook\Info\User
  */
 public function loadSelf()
 {
     if (!$this->_customerSession->isLoggedIn()) {
         if (!$this->_customer->getId()) {
             throw new \Magento\Framework\Exception(__('Could not load self since customer isn\'t logged in'));
         }
     }
     $this->_customer = $this->_customerSession->getCustomer();
     if (!$this->_customer->getId()) {
         throw new \Magento\Framework\Exception(__('Could not load by customer id'));
     }
     if (!($socialconnectFid = $this->_customer->getInchooSocialconnectFid()) || !($socialconnectFtoken = $this->_customer->getInchooSocialconnectFtoken())) {
         throw new \Magento\Framework\Exception(__('Could not retrieve token by customer id'));
     }
     $this->setAccessToken($socialconnectFtoken);
     $this->_load();
     return $this;
 }
 public function testSetCustomerDataAsLoggedIn()
 {
     $customer = $this->getMock('Magento\\Customer\\Model\\Customer', [], [], '', false);
     $customerDto = $this->getMock('Magento\\Customer\\Service\\V1\\Data\\Customer', [], [], '', false);
     $this->_converterMock->expects($this->any())->method('createCustomerModel')->will($this->returnValue($customer));
     $this->_eventManagerMock->expects($this->at(0))->method('dispatch')->with('customer_login', ['customer' => $customer]);
     $this->_eventManagerMock->expects($this->at(1))->method('dispatch')->with('customer_data_object_login', ['customer' => $customerDto]);
     $this->_model->setCustomerDataAsLoggedIn($customerDto);
     $this->assertSame($customer, $this->_model->getCustomer());
 }
 /**
  * @return \Magento\Customer\Model\Customer
  */
 public function getCustomer()
 {
     return $this->customerSession->getCustomer();
 }
 /**
  * @return \Magento\Framework\App\ResponseInterface
  */
 public function execute()
 {
     if (!$this->formKeyValidator->validate($this->getRequest()) or !$this->customerSession->getConnectorContactId()) {
         return $this->_redirect('customer/account/');
     }
     //params
     $additionalSubscriptions = $this->getRequest()->getParam('additional_subscriptions');
     $paramDataFields = $this->getRequest()->getParam('data_fields');
     $customerId = $this->customerSession->getConnectorContactId();
     $customerEmail = $this->customerSession->getCustomer()->getEmail();
     //client
     $website = $this->customerSession->getCustomer()->getStore()->getWebsite();
     //if enabled
     if ($this->helper->isEnabled($website)) {
         $client = $this->helper->getWebsiteApiClient($website);
         $client->setApiUsername($this->helper->getApiUsername($website))->setApiPassword($this->helper->getApiPassword($website));
         $contact = $client->getContactById($customerId);
         if (isset($contact->id)) {
             //contact address books
             $bookError = false;
             $addressBooks = $client->getContactAddressBooks($contact->id);
             $subscriberAddressBook = $this->helper->getSubscriberAddressBook($website);
             $processedAddressBooks = [];
             if (is_array($addressBooks)) {
                 foreach ($addressBooks as $addressBook) {
                     if ($subscriberAddressBook != $addressBook->id) {
                         $processedAddressBooks[$addressBook->id] = $addressBook->name;
                     }
                 }
             }
             if (isset($additionalSubscriptions)) {
                 foreach ($additionalSubscriptions as $additionalSubscription) {
                     if (!isset($processedAddressBooks[$additionalSubscription])) {
                         $bookResponse = $client->postAddressBookContacts($additionalSubscription, $contact);
                         if (isset($bookResponse->message)) {
                             $bookError = true;
                         }
                     }
                 }
                 foreach ($processedAddressBooks as $bookId => $name) {
                     if (!in_array($bookId, $additionalSubscriptions)) {
                         $bookResponse = $client->deleteAddressBookContact($bookId, $contact->id);
                         if (isset($bookResponse->message)) {
                             $bookError = true;
                         }
                     }
                 }
             } else {
                 foreach ($processedAddressBooks as $bookId => $name) {
                     $bookResponse = $client->deleteAddressBookContact($bookId, $contact->id);
                     if (isset($bookResponse->message)) {
                         $bookError = true;
                     }
                 }
             }
             //contact data fields
             $data = [];
             $dataFields = $client->getDataFields();
             $processedFields = [];
             foreach ($dataFields as $dataField) {
                 $processedFields[$dataField->name] = $dataField->type;
             }
             foreach ($paramDataFields as $key => $value) {
                 if (isset($processedFields[$key]) && $value) {
                     if ($processedFields[$key] == 'Numeric') {
                         $paramDataFields[$key] = (int) $value;
                     }
                     if ($processedFields[$key] == 'String') {
                         $paramDataFields[$key] = (string) $value;
                     }
                     if ($processedFields[$key] == 'Date') {
                         $paramDataFields[$key] = $this->localeDate->date($value)->format(\Zend_Date::ISO_8601);
                     }
                     $data[] = ['Key' => $key, 'Value' => $paramDataFields[$key]];
                 }
             }
             $contactResponse = $client->updateContactDatafieldsByEmail($customerEmail, $data);
             if (isset($contactResponse->message) && $bookError) {
                 $this->messageManager->addErrorMessage(__('An error occurred while saving your subscription preferences.'));
             } else {
                 $this->messageManager->addSuccessMessage(__('The subscription preferences has been saved.'));
             }
         } else {
             $this->messageManager->addErrorMessage(__('An error occurred while saving your subscription preferences.'));
         }
     }
     $this->_redirect('customer/account/');
 }
Exemple #11
0
 /**
  * @return mixed|string
  */
 public function getEmailCustomer()
 {
     $customer = $this->_customerSession->getCustomer();
     $email = $customer->getEmail();
     if (empty($email)) {
         $quote = $this->_getQuote();
         $email = $quote->getBillingAddress()->getEmail();
     }
     return $email;
 }