本文整理汇总了PHP中Magento\Customer\Model\Session::isLoggedIn方法的典型用法代码示例。如果您正苦于以下问题:PHP Session::isLoggedIn方法的具体用法?PHP Session::isLoggedIn怎么用?PHP Session::isLoggedIn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Customer\Model\Session
的用法示例。
在下文中一共展示了Session::isLoggedIn方法的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];
}
示例2: execute
/**
* Confirm customer account by id and confirmation key
*
* @return \Magento\Framework\Controller\Result\Redirect
*/
public function execute()
{
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
if ($this->session->isLoggedIn()) {
$resultRedirect->setPath('*/*/');
return $resultRedirect;
}
try {
$customerId = $this->getRequest()->getParam('id', false);
$key = $this->getRequest()->getParam('key', false);
if (empty($customerId) || empty($key)) {
throw new \Exception(__('Bad request.'));
}
// log in and send greeting email
$customerEmail = $this->customerRepository->getById($customerId)->getEmail();
$customer = $this->customerAccountManagement->activate($customerEmail, $key);
$this->session->setCustomerDataAsLoggedIn($customer);
$this->messageManager->addSuccess($this->getSuccessMessage());
$resultRedirect->setUrl($this->getSuccessRedirect());
return $resultRedirect;
} catch (StateException $e) {
$this->messageManager->addException($e, __('This confirmation key is invalid or has expired.'));
} catch (\Exception $e) {
$this->messageManager->addException($e, __('There was an error confirming the account'));
}
$url = $this->urlModel->getUrl('*/*/index', ['_secure' => true]);
return $resultRedirect->setUrl($this->_redirect->error($url));
}
示例3: execute
/**
* Login post action
*
* @return \Magento\Framework\Controller\Result\Redirect
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function execute()
{
if ($this->session->isLoggedIn() || !$this->formKeyValidator->validate($this->getRequest())) {
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath('*/*/');
return $resultRedirect;
}
if ($this->getRequest()->isPost()) {
$login = $this->getRequest()->getPost('login');
if (!empty($login['username']) && !empty($login['password'])) {
try {
$customer = $this->customerAccountManagement->authenticate($login['username'], $login['password']);
$this->session->setCustomerDataAsLoggedIn($customer);
$this->session->regenerateId();
} catch (EmailNotConfirmedException $e) {
$value = $this->customerUrl->getEmailConfirmationUrl($login['username']);
$message = __('This account is not confirmed.' . ' <a href="%1">Click here</a> to resend confirmation email.', $value);
$this->messageManager->addError($message);
$this->session->setUsername($login['username']);
} catch (AuthenticationException $e) {
$message = __('Invalid login or password.');
$this->messageManager->addError($message);
$this->session->setUsername($login['username']);
} catch (\Exception $e) {
$this->messageManager->addError(__('Invalid login or password.'));
}
} else {
$this->messageManager->addError(__('A login and a password are required.'));
}
}
return $this->accountRedirect->getRedirect();
}
示例4: tearDown
/**
* Clear wishlist helper property
*/
protected function tearDown()
{
$this->_wishlistHelper = null;
if ($this->_customerSession->isLoggedIn()) {
$this->_customerSession->logout();
}
}
示例5: execute
/**
* Send confirmation link to specified email
*
* @return \Magento\Framework\Controller\Result\Redirect|\Magento\Framework\View\Result\Page
*/
public function execute()
{
if ($this->session->isLoggedIn()) {
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath('*/*/');
return $resultRedirect;
}
// try to confirm by email
$email = $this->getRequest()->getPost('email');
if ($email) {
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
try {
$this->customerAccountManagement->resendConfirmation($email, $this->storeManager->getStore()->getWebsiteId());
$this->messageManager->addSuccess(__('Please check your email for confirmation key.'));
} catch (InvalidTransitionException $e) {
$this->messageManager->addSuccess(__('This email does not require confirmation.'));
} catch (\Exception $e) {
$this->messageManager->addException($e, __('Wrong email.'));
$resultRedirect->setPath('*/*/*', ['email' => $email, '_secure' => true]);
return $resultRedirect;
}
$this->session->setUsername($email);
$resultRedirect->setPath('*/*/index', ['_secure' => true]);
return $resultRedirect;
}
/** @var \Magento\Framework\View\Result\Page $resultPage */
$resultPage = $this->resultPageFactory->create();
$resultPage->getLayout()->getBlock('accountConfirmation')->setEmail($this->getRequest()->getParam('email', $email));
return $resultPage;
}
示例6: getConfig
/**
* Set configuration for AdyenHPP payemnt method
*
* @return array
*/
public function getConfig()
{
// set to active
$config = ['payment' => [self::CODE => ['isActive' => true, 'redirectUrl' => $this->_urlBuilder->getUrl('adyen/process/redirect', ['_secure' => $this->_getRequest()->isSecure()])]]];
// get customer
if ($this->_customerSession->isLoggedIn()) {
$gender = \Adyen\Payment\Model\Gender::getAdyenGenderFromMagentoGender($this->_customerSession->getCustomerData()->getGender());
// format to calendar date
$dob = $this->_customerSession->getCustomerData()->getDob();
$dob = strtotime($dob);
$dob = date('m/d/Y', $dob);
} else {
$gender = "";
$dob = "";
}
// add to config
$config['payment']['adyenHpp']['gender'] = $gender;
$config['payment']['adyenHpp']['dob'] = $dob;
// gender types
$config['payment']['adyenHpp']['genderTypes'] = \Adyen\Payment\Model\Gender::getGenderTypes();
$paymentMethodSelectionOnAdyen = $this->_adyenHelper->getAdyenHppConfigDataFlag('payment_selection_on_adyen');
$config['payment']['adyenHpp']['isPaymentMethodSelectionOnAdyen'] = $paymentMethodSelectionOnAdyen;
$config['payment']['adyenHpp']['showGender'] = $this->_adyenHelper->getAdyenHppConfigDataFlag('show_gender');
$config['payment']['adyenHpp']['showDob'] = $this->_adyenHelper->getAdyenHppConfigDataFlag('show_dob');
$config['payment']['adyenHpp']['showTelephone'] = $this->_adyenHelper->getAdyenHppConfigDataFlag('show_telephone');
return $config;
}
示例7: toHtml
/**
* {@inheritdoc}
*/
public function toHtml()
{
if ($this->customerSession->isLoggedIn() || !$this->registration->isAllowed() || !$this->accountManagement->isEmailAvailable($this->getEmailAddress()) || !$this->validateAddresses()) {
return '';
}
return parent::toHtml();
}
示例8: execute
/**
* Set persistent data to customer session
*
* @param \Magento\Framework\Event\Observer $observer
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
* @return $this
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
if (!$this->_persistentData->canProcess($observer) || !$this->_persistentData->isShoppingCartPersist()) {
return $this;
}
if ($this->_persistentSession->isPersistent() && !$this->_customerSession->isLoggedIn()) {
/** @var \Magento\Customer\Api\Data\CustomerInterface $customer */
$customer = $this->customerRepository->getById($this->_persistentSession->getSession()->getCustomerId());
if ($defaultShipping = $customer->getDefaultShipping()) {
/** @var \Magento\Customer\Model\Data\Address $address */
$address = $this->addressRepository->getById($defaultShipping);
if ($address) {
$this->_customerSession->setDefaultTaxShippingAddress(['country_id' => $address->getCountryId(), 'region_id' => $address->getRegion() ? $address->getRegionId() : null, 'postcode' => $address->getPostcode()]);
}
}
if ($defaultBilling = $customer->getDefaultBilling()) {
$address = $this->addressRepository->getById($defaultBilling);
if ($address) {
$this->_customerSession->setDefaultTaxBillingAddress(['country_id' => $address->getCountryId(), 'region_id' => $address->getRegion() ? $address->getRegionId() : null, 'postcode' => $address->getPostcode()]);
}
}
$this->_customerSession->setCustomerId($customer->getId())->setCustomerGroupId($customer->getGroupId());
}
return $this;
}
示例9: aroundGetSectionData
/**
* Reset quote reward point amount
*
* @param \Magento\Customer\CustomerData\Customer $subject
* @param \Closure $proceed
*
* @return array
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundGetSectionData(\Magento\Customer\CustomerData\Customer $subject, \Closure $proceed)
{
/** unset customer first name */
if (!$this->customerSession->isLoggedIn() && $this->persistentData->isEnabled() && $this->persistentSession->isPersistent()) {
return [];
}
return $proceed();
}
示例10: afterGetConfig
/**
* @param \Magento\Checkout\Model\DefaultConfigProvider $subject
* @param array $result
* @return array
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterGetConfig(\Magento\Checkout\Model\DefaultConfigProvider $subject, array $result)
{
if ($this->persistentHelper->isEnabled() && $this->persistentSession->isPersistent() && !$this->customerSession->isLoggedIn()) {
/** @var $quoteIdMask \Magento\Quote\Model\QuoteIdMask */
$quoteIdMask = $this->quoteIdMaskFactory->create();
$result['quoteData']['entity_id'] = $quoteIdMask->load($this->checkoutSession->getQuote()->getId(), 'quote_id')->getMaskedId();
}
return $result;
}
示例11: execute
/**
* Set quote to be loaded even if not active
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
if (!($this->_persistentSession->isPersistent() && !$this->_customerSession->isLoggedIn() && !$this->_persistentData->isShoppingCartPersist())) {
return;
}
if ($this->_checkoutSession) {
$this->_checkoutSession->setLoadInactive();
}
}
示例12: execute
/**
* Make persistent quote to be guest
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
*/
public function execute($observer)
{
/** @var $action \Magento\Persistent\Controller\Index */
$action = $observer->getEvent()->getControllerAction();
if ($action instanceof \Magento\Persistent\Controller\Index) {
if ($this->_persistentSession->isPersistent() && !$this->_customerSession->isLoggedIn() || $this->_persistentData->isShoppingCartPersist()) {
$this->quoteManager->setGuest(true);
}
}
}
示例13: processViews
/**
* @param $productId
* @return bool|void
*/
public function processViews($productId)
{
if (!$this->_config->isEnabled()) {
return false;
}
if ($this->_customerSession->isLoggedIn()) {
return $this->_eventClient->saveCustomerViewProduct($this->_customerSession->getCustomerId(), $productId);
}
return false;
}
示例14: execute
/**
* Apply persistent data
*
* @param \Magento\Framework\Event\Observer $observer
* @return $this
*/
public function execute($observer)
{
if (!$this->_persistentData->canProcess($observer) || !$this->_persistentSession->isPersistent() || $this->_customerSession->isLoggedIn()) {
return $this;
}
/** @var \Magento\Persistent\Model\Persistent\Config $persistentConfig */
$persistentConfig = $this->_persistentConfigFactory->create();
$persistentConfig->setConfigFilePath($this->_persistentData->getPersistentConfigFilePath())->fire();
return $this;
}
示例15: execute
/**
* Prevent clear checkout session
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
/** @var $action \Magento\Persistent\Controller\Index */
$action = $observer->getEvent()->getControllerAction();
if ($action instanceof \Magento\Persistent\Controller\Index) {
if ($this->_persistentSession->isPersistent() && !$this->_customerSession->isLoggedIn() || !$this->_persistentData->isShoppingCartPersist()) {
$action->setClearCheckoutSession(false);
}
}
}