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


PHP Session::getCustomerDataObject方法代码示例

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


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

示例1: beforeSubscribeCustomerById

 public function beforeSubscribeCustomerById($subscriber, $customerId)
 {
     $subscriber->loadByCustomerId($customerId);
     $storeId = $subscriber->getStoreId();
     if ($this->_helper->isMonkeyEnabled($storeId)) {
         $customer = $this->_customer->load($customerId);
         $mergeVars = $this->_helper->getMergeVars($customer);
         $api = $this->_api;
         $isSubscribeOwnEmail = $this->_customerSession->isLoggedIn() && $this->_customerSession->getCustomerDataObject()->getEmail() == $subscriber->getSubscriberEmail();
         if ($this->_helper->isDoubleOptInEnabled($storeId) && !$isSubscribeOwnEmail) {
             $status = 'pending';
         } else {
             $status = 'subscribed';
         }
         if ($mergeVars) {
             $data = array('list_id' => $this->_helper->getDefaultList(), 'email_address' => $customer->getEmail(), 'email_type' => 'html', 'status' => $status, 'merge_fields' => $mergeVars);
         } else {
             $data = array('list_id' => $this->_helper->getDefaultList(), 'email_address' => $customer->getEmail(), 'email_type' => 'html', 'status' => $status);
         }
         $return = $api->listCreateMember($this->_helper->getDefaultList(), json_encode($data));
         if (isset($return->id)) {
             $subscriber->setMagemonkeyId($return->id);
         }
     }
     return [$customerId];
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:26,代码来源:Subscriber.php

示例2: validate

 /**
  * Validates the fields in a specified address data object.
  *
  * @param \Magento\Quote\Api\Data\AddressInterface $addressData The address data object.
  * @return bool
  * @throws \Magento\Framework\Exception\InputException The specified address belongs to another customer.
  * @throws \Magento\Framework\Exception\NoSuchEntityException The specified customer ID or address ID is not valid.
  */
 public function validate(\Magento\Quote\Api\Data\AddressInterface $addressData)
 {
     //validate customer id
     if ($addressData->getCustomerId()) {
         $customer = $this->customerRepository->getById($addressData->getCustomerId());
         if (!$customer->getId()) {
             throw new \Magento\Framework\Exception\NoSuchEntityException(__('Invalid customer id %1', $addressData->getCustomerId()));
         }
     }
     // validate address id
     if ($addressData->getId()) {
         try {
             $address = $this->addressRepository->getById($addressData->getId());
         } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
             throw new \Magento\Framework\Exception\NoSuchEntityException(__('Invalid address id %1', $addressData->getId()));
         }
         // check correspondence between customer id and address id
         if ($addressData->getCustomerId()) {
             if ($address->getCustomerId() != $addressData->getCustomerId()) {
                 throw new \Magento\Framework\Exception\NoSuchEntityException(__('Invalid address id %1', $addressData->getId()));
             }
         }
     }
     if ($addressData->getCustomerAddressId()) {
         $applicableAddressIds = array_map(function ($address) {
             /** @var \Magento\Customer\Api\Data\AddressInterface $address */
             return $address->getId();
         }, $this->customerSession->getCustomerDataObject()->getAddresses());
         if (!in_array($addressData->getCustomerAddressId(), $applicableAddressIds)) {
             throw new \Magento\Framework\Exception\NoSuchEntityException(__('Invalid address id %1', $addressData->getCustomerAddressId()));
         }
     }
     return true;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:42,代码来源:QuoteAddressValidator.php

示例3: testProcess

 /**
  * @magentoConfigFixture current_store catalog/productalert/allow_price 1
  *
  * @magentoDataFixture Magento/ProductAlert/_files/product_alert.php
  */
 public function testProcess()
 {
     $this->_objectManager->configure(['Magento\\ProductAlert\\Model\\Observer' => ['arguments' => ['transportBuilder' => ['instance' => 'Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock']]], 'Magento\\ProductAlert\\Model\\Email' => ['arguments' => ['transportBuilder' => ['instance' => 'Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock']]], 'preferences' => ['Magento\\Framework\\Mail\\TransportInterface' => 'Magento\\TestFramework\\Mail\\TransportInterfaceMock', 'Magento\\TestFramework\\Mail\\Template\\TransportBuilder' => 'Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock']]);
     \Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea(\Magento\Framework\App\Area::AREA_FRONTEND);
     $observer = $this->_objectManager->get('Magento\\ProductAlert\\Model\\Observer');
     $observer->process();
     /** @var \Magento\TestFramework\Mail\Template\TransportBuilderMock $transportBuilder */
     $transportBuilder = $this->_objectManager->get('Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock');
     $this->assertStringMatchesFormat('%AHello %A' . $this->_customerViewHelper->getCustomerName($this->_customerSession->getCustomerDataObject()) . ',%A', $transportBuilder->getSentMessage()->getBodyHtml()->getContent());
 }
开发者ID:aiesh,项目名称:magento2,代码行数:15,代码来源:ObserverTest.php

示例4: getUserEmail

 /**
  * Get user email
  *
  * @return string
  */
 public function getUserEmail()
 {
     if (!$this->_customerSession->isLoggedIn()) {
         return '';
     }
     /**
      * @var CustomerInterface $customer
      */
     $customer = $this->_customerSession->getCustomerDataObject();
     return $customer->getEmail();
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:16,代码来源:Data.php

示例5: getWelcome

 /**
  * Retrieve welcome text
  *
  * @return string
  */
 public function getWelcome()
 {
     if (empty($this->_data['welcome'])) {
         if ($this->httpContext->getValue(Context::CONTEXT_AUTH)) {
             $customerName = $this->_customerViewHelper->getCustomerName($this->_customerSession->getCustomerDataObject());
             $this->_data['welcome'] = __('Welcome, %1!', $this->escapeHtml($customerName));
         } else {
             $this->_data['welcome'] = $this->_scopeConfig->getValue('design/header/welcome', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
         }
     }
     return $this->_data['welcome'];
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:17,代码来源:Header.php

示例6: loadCustomerQuote

 /**
  * Load data for customer quote and merge with current quote
  *
  * @return $this
  */
 public function loadCustomerQuote()
 {
     if (!$this->_customerSession->getCustomerId()) {
         return $this;
     }
     $this->_eventManager->dispatch('load_customer_quote_before', ['checkout_session' => $this]);
     try {
         $customerQuote = $this->quoteRepository->getForCustomer($this->_customerSession->getCustomerId());
     } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
         $customerQuote = $this->quoteFactory->create();
     }
     $customerQuote->setStoreId($this->_storeManager->getStore()->getId());
     if ($customerQuote->getId() && $this->getQuoteId() != $customerQuote->getId()) {
         if ($this->getQuoteId()) {
             $this->quoteRepository->save($customerQuote->merge($this->getQuote())->collectTotals());
         }
         $this->setQuoteId($customerQuote->getId());
         if ($this->_quote) {
             $this->quoteRepository->delete($this->_quote);
         }
         $this->_quote = $customerQuote;
     } else {
         $this->getQuote()->getBillingAddress();
         $this->getQuote()->getShippingAddress();
         $this->getQuote()->setCustomer($this->_customerSession->getCustomerDataObject())->setTotalsCollectedFlag(false)->collectTotals();
         $this->quoteRepository->save($this->getQuote());
     }
     return $this;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:34,代码来源:Session.php

示例7: beforeSubscribe

 public function beforeSubscribe($subscriber, $email)
 {
     $storeId = $this->_storeManager->getStore()->getId();
     $isSubscribeOwnEmail = $this->_customerSession->isLoggedIn() && $this->_customerSession->getCustomerDataObject()->getEmail() == $email;
     if (!$isSubscribeOwnEmail) {
         if ($this->_helper->isMonkeyEnabled($storeId)) {
             $subscriber->setImportMode(true);
             $api = $this->_api;
             if ($this->_helper->isDoubleOptInEnabled($storeId)) {
                 $status = 'pending';
             } else {
                 $status = 'subscribed';
             }
             $data = ['list_id' => $this->_helper->getDefaultList(), 'email_address' => $email, 'email_type' => 'html', 'status' => $status, 'merge_fields' => ['EMAIL' => $email]];
             try {
                 $return = $api->listCreateMember($this->_helper->getDefaultList(), json_encode($data));
                 if (isset($return->id)) {
                     $subscriber->setMagemonkeyId($return->id);
                 }
             } catch (\Exception $e) {
                 $this->_helper->log($e->getMessage());
             }
         }
     }
     return [$email];
 }
开发者ID:ebizmarts,项目名称:magento2-magemonkey,代码行数:26,代码来源:Subscriber.php

示例8: getCustomer

 /**
  * Retrieve current customer
  *
  * @return \Magento\Customer\Api\Data\CustomerInterface|null
  */
 public function getCustomer()
 {
     if (!$this->_currentCustomer && $this->_customerSession->isLoggedIn()) {
         $this->_currentCustomer = $this->_customerSession->getCustomerDataObject();
     }
     return $this->_currentCustomer;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:12,代码来源:Data.php

示例9: afterSubscribeCustomerById

 public function afterSubscribeCustomerById($subscriber)
 {
     $storeId = $subscriber->getStoreId();
     if ($this->_helper->isMonkeyEnabled($storeId)) {
         $customer = $this->_customer;
         $mergeVars = $this->_helper->getMergeVars($customer);
         $api = new \Ebizmarts\MageMonkey\Model\Api(array(), $this->_helper);
         $isSubscribeOwnEmail = $this->_customerSession->isLoggedIn() && $this->_customerSession->getCustomerDataObject()->getEmail() == $subscriber->getSubscriberEmail();
         if ($this->_helper->isDoubleOptInEnabled($storeId) && !$isSubscribeOwnEmail) {
             $status = 'pending';
         } else {
             $status = 'subscribed';
         }
         $data = array('list_id' => $this->_helper->getDefaultList(), 'email_address' => $subscriber->getEmail(), 'email_type' => 'html', 'status' => $status);
         $return = $api->listCreateMember($this->_helper->getDefaultList(), json_encode($data));
         if (isset($return->id)) {
             $subscriber->setMagemonkeyId($return->id)->save();
         }
     }
 }
开发者ID:aligent,项目名称:magento2-magemonkey,代码行数:20,代码来源:Subscriber.php

示例10: testSendAction

 /**
  * @magentoDataFixture Magento/Wishlist/_files/wishlist.php
  */
 public function testSendAction()
 {
     $this->_objectManager->configure(['Magento\\Wishlist\\Controller\\Index\\Send' => ['arguments' => ['transportBuilder' => ['instance' => 'Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock']]], 'preferences' => ['Magento\\Framework\\Mail\\TransportInterface' => 'Magento\\TestFramework\\Mail\\TransportInterfaceMock']]);
     \Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea(\Magento\Framework\App\Area::AREA_FRONTEND);
     $request = ['form_key' => $this->_objectManager->get('Magento\\Framework\\Data\\Form\\FormKey')->getFormKey(), 'emails' => 'test@tosend.com', 'message' => 'message', 'rss_url' => null];
     $this->getRequest()->setPost($request);
     $this->_objectManager->get('Magento\\Framework\\Registry')->register('wishlist', $this->_objectManager->get('Magento\\Wishlist\\Model\\Wishlist')->loadByCustomerId(1));
     $this->dispatch('wishlist/index/send');
     /** @var \Magento\TestFramework\Mail\Template\TransportBuilderMock $transportBuilder */
     $transportBuilder = $this->_objectManager->get('Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock');
     $this->assertStringMatchesFormat('%AThank you, %A' . $this->_customerViewHelper->getCustomerName($this->_customerSession->getCustomerDataObject()) . '%A', $transportBuilder->getSentMessage()->getBodyHtml()->getContent());
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:15,代码来源:IndexTest.php

示例11: testSendAction

 /**
  * @magentoDataFixture Magento/Wishlist/_files/wishlist.php
  */
 public function testSendAction()
 {
     \Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea(\Magento\Framework\App\Area::AREA_FRONTEND);
     $request = ['form_key' => $this->_objectManager->get('Magento\\Framework\\Data\\Form\\FormKey')->getFormKey(), 'emails' => 'test@tosend.com', 'message' => 'message', 'rss_url' => null];
     $this->getRequest()->setPostValue($request);
     $this->_objectManager->get('Magento\\Framework\\Registry')->register('wishlist', $this->_objectManager->get('Magento\\Wishlist\\Model\\Wishlist')->loadByCustomerId(1));
     $this->dispatch('wishlist/index/send');
     /** @var \Magento\TestFramework\Mail\Template\TransportBuilderMock $transportBuilder */
     $transportBuilder = $this->_objectManager->get('Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock');
     $actualResult = \Zend_Mime_Decode::decodeQuotedPrintable($transportBuilder->getSentMessage()->getBodyHtml()->getContent());
     $this->assertStringMatchesFormat('%A' . $this->_customerViewHelper->getCustomerName($this->_customerSession->getCustomerDataObject()) . ' wants to share this Wish List%A', $actualResult);
 }
开发者ID:andrewhowdencom,项目名称:m2onk8s,代码行数:15,代码来源:IndexTest.php

示例12: beforeSubscribe

 public function beforeSubscribe($subscriber, $email)
 {
     $isSubscribeOwnEmail = $this->_customerSession->isLoggedIn() && $this->_customerSession->getCustomerDataObject()->getEmail() == $subscriber->getSubscriberEmail();
     if ($isSubscribeOwnEmail) {
         $subscriber->loadByEmail($email);
     }
     $storeId = $this->_storeManager->getStore()->getId();
     if ($this->_helper->isMageiaEnabled($storeId)) {
         $api = $this->_api;
         $data = ['emails' => json_encode([['email' => $email]])];
         $listId = $this->_helper->getDefaultList();
         $return = $api->listCreateMember($listId, $data);
         if (isset($return->result) && $return->result) {
             $subscriber->setMageiaId($email);
         }
     }
 }
开发者ID:sendpulse,项目名称:mageia,代码行数:17,代码来源:Plugin.php

示例13: _construct

 /**
  * Initialize review form
  *
  * @return void
  */
 protected function _construct()
 {
     parent::_construct();
     $data = $this->_reviewSession->getFormData(true);
     $data = new \Magento\Framework\Object((array) $data);
     // add logged in customer name as nickname
     if (!$data->getNickname()) {
         $customer = $this->_customerSession->getCustomerDataObject();
         if ($customer && $customer->getId()) {
             $data->setNickname($customer->getFirstname());
         }
     }
     $this->setAllowWriteReviewFlag($this->httpContext->getValue(Context::CONTEXT_AUTH) || $this->_reviewData->getIsGuestAllowToWrite());
     if (!$this->getAllowWriteReviewFlag()) {
         $queryParam = $this->urlEncoder->encode($this->getUrl('*/*/*', ['_current' => true]) . '#review-form');
         $this->setLoginLink($this->getUrl('customer/account/login/', [Url::REFERER_QUERY_PARAM_NAME => $queryParam]));
     }
     $this->setTemplate('form.phtml')->assign('data', $data);
 }
开发者ID:opexsw,项目名称:magento2,代码行数:24,代码来源:Form.php

示例14: loadCustomerQuote

 /**
  * Load data for customer quote and merge with current quote
  *
  * @return $this
  */
 public function loadCustomerQuote()
 {
     if (!$this->_customerSession->getCustomerId()) {
         return $this;
     }
     $this->_eventManager->dispatch('load_customer_quote_before', array('checkout_session' => $this));
     $customerQuote = $this->_quoteFactory->create()->setStoreId($this->_storeManager->getStore()->getId())->loadByCustomer($this->_customerSession->getCustomerId());
     if ($customerQuote->getId() && $this->getQuoteId() != $customerQuote->getId()) {
         if ($this->getQuoteId()) {
             $customerQuote->merge($this->getQuote())->collectTotals()->save();
         }
         $this->setQuoteId($customerQuote->getId());
         if ($this->_quote) {
             $this->_quote->delete();
         }
         $this->_quote = $customerQuote;
     } else {
         $this->getQuote()->getBillingAddress();
         $this->getQuote()->getShippingAddress();
         $this->getQuote()->setCustomerData($this->_customerSession->getCustomerDataObject())->setTotalsCollectedFlag(false)->collectTotals()->save();
     }
     return $this;
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:28,代码来源:Session.php

示例15: execute

 /**
  * Share wishlist
  *
  * @return ResponseInterface|void
  * @throws NotFoundException
  */
 public function execute()
 {
     if (!$this->_formKeyValidator->validate($this->getRequest())) {
         return $this->_redirect('*/*/');
     }
     $wishlist = $this->wishlistProvider->getWishlist();
     if (!$wishlist) {
         throw new NotFoundException();
     }
     $sharingLimit = $this->_wishlistConfig->getSharingEmailLimit();
     $textLimit = $this->_wishlistConfig->getSharingTextLimit();
     $emailsLeft = $sharingLimit - $wishlist->getShared();
     $emails = explode(',', $this->getRequest()->getPost('emails'));
     $error = false;
     $message = (string) $this->getRequest()->getPost('message');
     if (strlen($message) > $textLimit) {
         $error = __('Message length must not exceed %1 symbols', $textLimit);
     } else {
         $message = nl2br(htmlspecialchars($message));
         if (empty($emails)) {
             $error = __('Email address can\'t be empty.');
         } else {
             if (count($emails) > $emailsLeft) {
                 $error = __('This wishlist can be shared %1 more times.', $emailsLeft);
             } else {
                 foreach ($emails as $index => $email) {
                     $email = trim($email);
                     if (!\Zend_Validate::is($email, 'EmailAddress')) {
                         $error = __('Please input a valid email address.');
                         break;
                     }
                     $emails[$index] = $email;
                 }
             }
         }
     }
     if ($error) {
         $this->messageManager->addError($error);
         $this->_objectManager->get('Magento\\Wishlist\\Model\\Session')->setSharingForm($this->getRequest()->getPost());
         $this->_redirect('*/*/share');
         return;
     }
     $this->inlineTranslation->suspend();
     $sent = 0;
     try {
         $customer = $this->_customerSession->getCustomerDataObject();
         $customerName = $this->_customerHelperView->getCustomerName($customer);
         /*if share rss added rss feed to email template*/
         if ($this->getRequest()->getParam('rss_url')) {
             $rss_url = $this->_view->getLayout()->createBlock('Magento\\Wishlist\\Block\\Share\\Email\\Rss')->setWishlistId($wishlist->getId())->toHtml();
             $message .= $rss_url;
         }
         $wishlistBlock = $this->_view->getLayout()->createBlock('Magento\\Wishlist\\Block\\Share\\Email\\Items')->toHtml();
         $emails = array_unique($emails);
         $sharingCode = $wishlist->getSharingCode();
         try {
             $scopeConfig = $this->_objectManager->get('Magento\\Framework\\App\\Config\\ScopeConfigInterface');
             $storeManager = $this->_objectManager->get('Magento\\Framework\\StoreManagerInterface');
             foreach ($emails as $email) {
                 $transport = $this->_transportBuilder->setTemplateIdentifier($scopeConfig->getValue('wishlist/email/email_template', \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->setTemplateOptions(array('area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeManager->getStore()->getStoreId()))->setTemplateVars(array('customer' => $customer, 'customerName' => $customerName, 'salable' => $wishlist->isSalable() ? 'yes' : '', 'items' => $wishlistBlock, 'addAllLink' => $this->_url->getUrl('*/shared/allcart', array('code' => $sharingCode)), 'viewOnSiteLink' => $this->_url->getUrl('*/shared/index', array('code' => $sharingCode)), 'message' => $message, 'store' => $storeManager->getStore()))->setFrom($scopeConfig->getValue('wishlist/email/email_identity', \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->addTo($email)->getTransport();
                 $transport->sendMessage();
                 $sent++;
             }
         } catch (\Exception $e) {
             $wishlist->setShared($wishlist->getShared() + $sent);
             $wishlist->save();
             throw $e;
         }
         $wishlist->setShared($wishlist->getShared() + $sent);
         $wishlist->save();
         $this->inlineTranslation->resume();
         $this->_eventManager->dispatch('wishlist_share', array('wishlist' => $wishlist));
         $this->messageManager->addSuccess(__('Your wish list has been shared.'));
         $this->_redirect('*/*', array('wishlist_id' => $wishlist->getId()));
     } catch (\Exception $e) {
         $this->inlineTranslation->resume();
         $this->messageManager->addError($e->getMessage());
         $this->_objectManager->get('Magento\\Wishlist\\Model\\Session')->setSharingForm($this->getRequest()->getPost());
         $this->_redirect('*/*/share');
     }
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:87,代码来源:Send.php


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