当前位置: 首页>>代码示例>>PHP>>正文


PHP Session::getCustomer方法代码示例

本文整理汇总了PHP中Magento\Customer\Model\Session::getCustomer方法的典型用法代码示例。如果您正苦于以下问题:PHP Session::getCustomer方法的具体用法?PHP Session::getCustomer怎么用?PHP Session::getCustomer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Customer\Model\Session的用法示例。


在下文中一共展示了Session::getCustomer方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: afterGenerateXml

 /**
  * 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;
 }
开发者ID:rejoiner,项目名称:magento2-plugin,代码行数:14,代码来源:DepersonalizePlugin.php

示例2: testSetCustomerDataAsLoggedIn

 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());
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:11,代码来源:SessionTest.php

示例3: dispatch

 /**
  * 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);
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:19,代码来源:RecurringPayment.php

示例4: makePreference

 /**
  * 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;
 }
开发者ID:SummaSolutions,项目名称:cart-magento2,代码行数:65,代码来源:Payment.php

示例5: execute

 /**
  * 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;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:31,代码来源:CheckUserEditObserver.php

示例6: getDefaultFrom

 /**
  * 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();
     }
 }
开发者ID:aiesh,项目名称:magento2,代码行数:13,代码来源:Inline.php

示例7: loadSelf

 /**
  * 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;
 }
开发者ID:LavoWeb,项目名称:Magento2-Inchoo_SocialConnect,代码行数:24,代码来源:User.php

示例8: testSetCustomerDataAsLoggedIn

 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());
 }
开发者ID:buskamuza,项目名称:magento2-skeleton,代码行数:10,代码来源:SessionTest.php

示例9: getCustomer

 /**
  * @return \Magento\Customer\Model\Customer
  */
 public function getCustomer()
 {
     return $this->customerSession->getCustomer();
 }
开发者ID:dotmailer,项目名称:dotmailer-magento2-extension,代码行数:7,代码来源:Books.php

示例10: execute

 /**
  * @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/');
 }
开发者ID:dotmailer,项目名称:dotmailer-magento2-extension,代码行数:91,代码来源:Newsletter.php

示例11: getEmailCustomer

 /**
  * @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;
 }
开发者ID:SummaSolutions,项目名称:cart-magento2,代码行数:13,代码来源:Core.php


注:本文中的Magento\Customer\Model\Session::getCustomer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。