本文整理汇总了PHP中Magento\Customer\Model\Session类的典型用法代码示例。如果您正苦于以下问题:PHP Session类的具体用法?PHP Session怎么用?PHP Session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Session类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: _preDispatchValidateCustomer
/**
* Make sure customer is valid, if logged in
*
* By default will add error messages and redirect to customer edit form
*
* @param bool $redirect - stop dispatch and redirect?
* @param bool $addErrors - add error messages?
* @return bool
*/
protected function _preDispatchValidateCustomer($redirect = true, $addErrors = true)
{
try {
$customerId = $this->_customerSession->getCustomerId();
$customer = $this->_customerAccountService->getCustomer($customerId);
} catch (NoSuchEntityException $e) {
return true;
}
if (isset($customer)) {
$validationResult = $this->_customerAccountService->validateCustomerData($customer, $this->_customerMetadataService->getAllCustomerAttributeMetadata());
if (!$validationResult->isValid()) {
if ($addErrors) {
foreach ($validationResult->getMessages() as $error) {
$this->messageManager->addError($error);
}
}
if ($redirect) {
$this->_redirect('customer/account/edit');
$this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
}
return false;
}
}
return true;
}
开发者ID:Atlis,项目名称:docker-magento2,代码行数:34,代码来源:Action.php
示例2: _construct
/**
* @return void
*/
protected function _construct()
{
parent::_construct();
$orders = $this->_orderCollectionFactory->create()->addFieldToSelect('*')->addFieldToFilter('customer_id', $this->_customerSession->getCustomerId())->addFieldToFilter('status', array('in' => $this->_orderConfig->getVisibleOnFrontStatuses()))->setOrder('created_at', 'desc');
$this->setOrders($orders);
$this->pageConfig->setTitle(__('My Orders'));
}
开发者ID:aiesh,项目名称:magento2,代码行数:10,代码来源:History.php
示例3: dispatch
/**
* Check customer authentication for some actions
*
* @param \Magento\Framework\App\RequestInterface $request
* @return \Magento\Framework\App\ResponseInterface
*/
public function dispatch(RequestInterface $request)
{
if (!$this->customerSession->authenticate()) {
$this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
}
return parent::dispatch($request);
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:13,代码来源:Customer.php
示例4: testExecute
public function testExecute()
{
$event = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
/** @var $event \Magento\Framework\Event\Observer */
$this->customerSession->expects($this->once())->method('setWishlistItemCount')->with($this->equalTo(0));
$this->observer->execute($event);
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:7,代码来源:CustomerLogoutTest.php
示例5: dispatch
/**
* Dispatch request
*
* @param RequestInterface $request
* @return ResponseInterface
* @throws NotFoundException
*/
public function dispatch(RequestInterface $request)
{
if (!$this->customerSession->authenticate()) {
$this->_actionFlag->set('', 'no-dispatch', true);
}
return parent::dispatch($request);
}
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:14,代码来源:CardsManagement.php
示例6: testToHtml
/**
* @magentoConfigFixture current_store persistent/options/customer 1
* @magentoConfigFixture current_store persistent/options/enabled 1
* @magentoConfigFixture current_store persistent/options/remember_enabled 1
* @magentoConfigFixture current_store persistent/options/remember_default 1
* @magentoAppArea frontend
* @magentoAppIsolation enabled
*/
public function testToHtml()
{
$this->_customerSession->loginById(1);
$translation = __('Not you?');
$this->assertStringMatchesFormat('%A<span>%A<a%Ahref="' . $this->_block->getHref() . '"%A>' . $translation . '</a>%A</span>%A', $this->_block->toHtml());
$this->_customerSession->logout();
}
开发者ID:andrewhowdencom,项目名称:m2onk8s,代码行数:15,代码来源:AdditionalTest.php
示例7: execute
/**
* @param Observer $observer
* @return void
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function execute(Observer $observer)
{
if ($this->moduleManager->isEnabled('Magento_PageCache') && $this->cacheConfig->isEnabled() && $this->taxHelper->isCatalogPriceDisplayAffectedByTax()) {
/** @var \Magento\Customer\Model\Data\Customer $customer */
$customer = $observer->getData('customer');
$customerGroupId = $customer->getGroupId();
$customerGroup = $this->groupRepository->getById($customerGroupId);
$customerTaxClassId = $customerGroup->getTaxClassId();
$this->customerSession->setCustomerTaxClassId($customerTaxClassId);
/** @var \Magento\Customer\Api\Data\AddressInterface[] $addresses */
$addresses = $customer->getAddresses();
if (isset($addresses)) {
$defaultShippingFound = false;
$defaultBillingFound = false;
foreach ($addresses as $address) {
if ($address->isDefaultBilling()) {
$defaultBillingFound = true;
$this->customerSession->setDefaultTaxBillingAddress(['country_id' => $address->getCountryId(), 'region_id' => $address->getRegion() ? $address->getRegion()->getRegionId() : null, 'postcode' => $address->getPostcode()]);
}
if ($address->isDefaultShipping()) {
$defaultShippingFound = true;
$this->customerSession->setDefaultTaxShippingAddress(['country_id' => $address->getCountryId(), 'region_id' => $address->getRegion() ? $address->getRegion()->getRegionId() : null, 'postcode' => $address->getPostcode()]);
}
if ($defaultShippingFound && $defaultBillingFound) {
break;
}
}
}
}
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:35,代码来源:CustomerLoggedInObserver.php
示例8: beforeDispatch
/**
* Authenticate user
*
* @param \Magento\Framework\App\ActionInterface $subject
* @param RequestInterface $request
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function beforeDispatch(\Magento\Framework\App\ActionInterface $subject, RequestInterface $request)
{
$loginUrl = $this->customerUrl->getLoginUrl();
if (!$this->customerSession->authenticate($loginUrl)) {
$subject->getActionFlag()->set('', $subject::FLAG_NO_DISPATCH, true);
}
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:15,代码来源:Authentication.php
示例9: getBillingAgreements
/**
* Retrieve billing agreements collection
*
* @return \Magento\Paypal\Model\ResourceModel\Billing\Agreement\Collection
*/
public function getBillingAgreements()
{
if ($this->_billingAgreements === null) {
$this->_billingAgreements = $this->_agreementCollection->create()->addFieldToFilter('customer_id', $this->_customerSession->getCustomerId())->setOrder('agreement_id', 'desc');
}
return $this->_billingAgreements;
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:12,代码来源:Agreements.php
示例10: setUp
protected function setUp()
{
$this->markTestIncomplete();
$this->messageManager = $this->getMockForAbstractClass('Magento\\Framework\\Message\\ManagerInterface');
$this->config = $this->getMock('Magento\\Paypal\\Model\\Config', [], [], '', false);
$this->request = $this->getMock('Magento\\Framework\\App\\Request\\Http', [], [], '', false);
$this->quote = $this->getMock('Magento\\Quote\\Model\\Quote', [], [], '', false);
$this->quote->expects($this->any())->method('hasItems')->will($this->returnValue(true));
$this->redirect = $this->getMockForAbstractClass('Magento\\Framework\\App\\Response\\RedirectInterface');
$this->response = $this->getMock('Magento\\Framework\\App\\Response\\Http', [], [], '', false);
$this->customerData = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false);
$this->checkout = $this->getMock('Magento\\Paypal\\Model\\Express\\Checkout', [], [], '', false);
$this->customerSession = $this->getMock('Magento\\Customer\\Model\\Session', [], [], '', false);
$this->customerSession->expects($this->any())->method('getCustomerDataObject')->will($this->returnValue($this->customerData));
$this->checkoutSession = $this->getMock('Magento\\Checkout\\Model\\Session', [], [], '', false);
$this->checkoutFactory = $this->getMock('Magento\\Paypal\\Model\\Express\\Checkout\\Factory', [], [], '', false);
$this->checkoutFactory->expects($this->any())->method('create')->will($this->returnValue($this->checkout));
$this->checkoutSession->expects($this->any())->method('getQuote')->will($this->returnValue($this->quote));
$this->session = $this->getMock('Magento\\Framework\\Session\\Generic', [], [], '', false);
$objectManager = $this->getMock('Magento\\Framework\\ObjectManagerInterface');
$this->objectManagerCallback = function ($className) {
if ($className == 'Magento\\Paypal\\Model\\Config') {
return $this->config;
}
return $this->getMock($className, [], [], '', false);
};
$objectManager->expects($this->any())->method('get')->will($this->returnCallback(function ($className) {
return call_user_func($this->objectManagerCallback, $className);
}));
$objectManager->expects($this->any())->method('create')->will($this->returnCallback(function ($className) {
return call_user_func($this->objectManagerCallback, $className);
}));
$helper = new ObjectManagerHelper($this);
$this->model = $helper->getObject('\\Magento\\\\Paypal\\Controller\\Express\\' . $this->name, ['messageManager' => $this->messageManager, 'response' => $this->response, 'redirect' => $this->redirect, 'request' => $this->request, 'customerSession' => $this->customerSession, 'checkoutSession' => $this->checkoutSession, 'checkoutFactory' => $this->checkoutFactory, 'paypalSession' => $this->session, 'objectManager' => $objectManager]);
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:35,代码来源:ExpressTest.php
示例11: getWishlist
/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function getWishlist($wishlistId = null)
{
if ($this->wishlist) {
return $this->wishlist;
}
try {
if (!$wishlistId) {
$wishlistId = $this->request->getParam('wishlist_id');
}
$customerId = $this->customerSession->getCustomerId();
$wishlist = $this->wishlistFactory->create();
if (!$wishlistId && !$customerId) {
return $wishlist;
}
if ($wishlistId) {
$wishlist->load($wishlistId);
} elseif ($customerId) {
$wishlist->loadByCustomerId($customerId, true);
}
if (!$wishlist->getId() || $wishlist->getCustomerId() != $customerId) {
throw new \Magento\Framework\Exception\NoSuchEntityException(__('The requested Wish List doesn\'t exist.'));
}
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
$this->messageManager->addError($e->getMessage());
return false;
} catch (\Exception $e) {
$this->messageManager->addException($e, __('We can\'t create the Wish List right now.'));
return false;
}
$this->wishlist = $wishlist;
return $wishlist;
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:36,代码来源:WishlistProvider.php
示例12: testSubscribe
public function testSubscribe()
{
$email = '[email protected]';
$this->resource->expects($this->any())->method('loadByEmail')->willReturn(['subscriber_status' => 3, 'subscriber_email' => $email, 'name' => 'subscriber_name']);
$this->resource->expects($this->any())->method('getIdFieldName')->willReturn('id_field');
$this->scopeConfig->expects($this->any())->method('getValue')->willReturn(true);
$this->customerSession->expects($this->any())->method('isLoggedIn')->willReturn(true);
$customerDataModel = $this->getMock('\\Magento\\Customer\\Api\\Data\\CustomerInterface');
$this->customerSession->expects($this->any())->method('getCustomerDataObject')->willReturn($customerDataModel);
$this->customerSession->expects($this->any())->method('getCustomerId')->willReturn(1);
$customerDataModel->expects($this->any())->method('getEmail')->willReturn($email);
$this->customerRepository->expects($this->any())->method('getById')->willReturn($customerDataModel);
$customerDataModel->expects($this->any())->method('getStoreId')->willReturn(1);
$customerDataModel->expects($this->any())->method('getId')->willReturn(1);
$this->transportBuilder->expects($this->any())->method('setTemplateIdentifier')->willReturnSelf();
$this->transportBuilder->expects($this->any())->method('setTemplateOptions')->willReturnSelf();
$this->transportBuilder->expects($this->any())->method('setTemplateVars')->willReturnSelf();
$this->transportBuilder->expects($this->any())->method('setFrom')->willReturnSelf();
$this->transportBuilder->expects($this->any())->method('addTo')->willReturnSelf();
$storeModel = $this->getMock('\\Magento\\Store\\Model\\Store', ['getId'], [], '', false);
$this->scopeConfig->expects($this->any())->method('getValue')->willReturn('[email protected]');
$this->storeManager->expects($this->any())->method('getStore')->willReturn($storeModel);
$storeModel->expects($this->any())->method('getId')->willReturn(1);
$transport = $this->getMock('\\Magento\\Framework\\Mail\\TransportInterface');
$this->transportBuilder->expects($this->any())->method('getTransport')->willReturn($transport);
$transport->expects($this->any())->method('sendMessage')->willReturnSelf();
$inlineTranslation = $this->getMock('Magento\\Framework\\Translate\\Inline\\StateInterface');
$inlineTranslation->expects($this->any())->method('resume')->willReturnSelf();
$this->resource->expects($this->atLeastOnce())->method('save')->willReturnSelf();
$this->assertEquals(1, $this->subscriber->subscribe($email));
}
开发者ID:opexsw,项目名称:magento2,代码行数:31,代码来源:SubscriberTest.php
示例13: _prepareLayout
/**
* Prepare the layout of the address edit block.
*
* @return $this
*/
protected function _prepareLayout()
{
parent::_prepareLayout();
// Init address object
if ($addressId = $this->getRequest()->getParam('id')) {
try {
$this->_address = $this->_addressRepository->getById($addressId);
if ($this->_address->getCustomerId() != $this->_customerSession->getCustomerId()) {
$this->_address = null;
}
} catch (NoSuchEntityException $e) {
$this->_address = null;
}
}
if ($this->_address === null || !$this->_address->getId()) {
$this->_address = $this->addressDataFactory->create();
$customer = $this->getCustomer();
$this->_address->setPrefix($customer->getPrefix());
$this->_address->setFirstname($customer->getFirstname());
$this->_address->setMiddlename($customer->getMiddlename());
$this->_address->setLastname($customer->getLastname());
$this->_address->setSuffix($customer->getSuffix());
}
$this->pageConfig->getTitle()->set($this->getTitle());
if ($postedData = $this->_customerSession->getAddressFormData(true)) {
if (!empty($postedData['region_id']) || !empty($postedData['region'])) {
$postedData['region'] = ['region_id' => $postedData['region_id'], 'region' => $postedData['region']];
}
$this->dataObjectHelper->populateWithArray($this->_address, $postedData, '\\Magento\\Customer\\Api\\Data\\AddressInterface');
}
return $this;
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:37,代码来源:Edit.php
示例14: testAroundDispatch
/**
* Test aroundDispatch
*/
public function testAroundDispatch()
{
$this->customerSessionMock->expects($this->once())->method('getCustomerGroupId')->will($this->returnValue(1));
$this->customerSessionMock->expects($this->once())->method('isLoggedIn')->will($this->returnValue(true));
$this->httpContextMock->expects($this->atLeastOnce())->method('setValue')->will($this->returnValueMap([[Context::CONTEXT_GROUP, 'UAH', $this->httpContextMock], [Context::CONTEXT_AUTH, 0, $this->httpContextMock]]));
$this->assertEquals('ExpectedValue', $this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock));
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:10,代码来源:ContextPluginTest.php
示例15: 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
示例16: getUsername
/**
* Retrieve username for form field
*
* @return string
*/
public function getUsername()
{
if (-1 === $this->_username) {
$this->_username = $this->_customerSession->getUsername(true);
}
return $this->_username;
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:12,代码来源:Login.php
示例17: toHtml
/**
* {@inheritdoc}
*/
public function toHtml()
{
if ($this->customerSession->isLoggedIn() || !$this->registration->isAllowed() || !$this->accountManagement->isEmailAvailable($this->getEmailAddress()) || !$this->validateAddresses()) {
return '';
}
return parent::toHtml();
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:10,代码来源:Registration.php
示例18: 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
示例19: getSubscriptionObject
/**
* Fetch the subscription object. Create the subscriber by loading using the customerId.
*
* @return Subscriber
*/
public function getSubscriptionObject()
{
if ($this->_subscription === null) {
$this->_subscription = $this->_createSubscriber()->loadByCustomerId($this->_customerSession->getCustomerId());
}
return $this->_subscription;
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:12,代码来源:Newsletter.php
示例20: testExecute
/**
* @return void
*/
public function testExecute()
{
$customerId = 7;
$captchaValue = 'some-value';
$email = '[email protected]';
$redirectUrl = 'http://magento.com/customer/account/edit/';
$captcha = $this->getMock('Magento\\Captcha\\Model\\DefaultModel', [], [], '', false);
$captcha->expects($this->once())->method('isRequired')->willReturn(true);
$captcha->expects($this->once())->method('isCorrect')->with($captchaValue)->willReturn(false);
$this->helperMock->expects($this->once())->method('getCaptcha')->with(\Magento\Captcha\Observer\CheckUserEditObserver::FORM_ID)->willReturn($captcha);
$response = $this->getMock('Magento\\Framework\\App\\Response\\Http', [], [], '', false);
$request = $this->getMock('Magento\\Framework\\App\\Request\\Http', [], [], '', false);
$request->expects($this->any())->method('getPost')->with(\Magento\Captcha\Helper\Data::INPUT_NAME_FIELD_VALUE, null)->willReturn([\Magento\Captcha\Observer\CheckUserEditObserver::FORM_ID => $captchaValue]);
$controller = $this->getMock('Magento\\Framework\\App\\Action\\Action', [], [], '', false);
$controller->expects($this->any())->method('getRequest')->will($this->returnValue($request));
$controller->expects($this->any())->method('getResponse')->will($this->returnValue($response));
$this->captchaStringResolverMock->expects($this->once())->method('resolve')->with($request, \Magento\Captcha\Observer\CheckUserEditObserver::FORM_ID)->willReturn($captchaValue);
$customerDataMock = $this->getMock('\\Magento\\Customer\\Model\\Data\\Customer', [], [], '', false);
$this->customerSessionMock->expects($this->once())->method('getCustomerId')->willReturn($customerId);
$this->customerSessionMock->expects($this->atLeastOnce())->method('getCustomer')->willReturn($customerDataMock);
$this->authenticationMock->expects($this->once())->method('processAuthenticationFailure')->with($customerId);
$this->authenticationMock->expects($this->once())->method('isLocked')->with($customerId)->willReturn(true);
$this->customerSessionMock->expects($this->once())->method('logout');
$this->customerSessionMock->expects($this->once())->method('start');
$this->scopeConfigMock->expects($this->once())->method('getValue')->with('contact/email/recipient_email')->willReturn($email);
$message = __('The account is locked. Please wait and try again or contact %1.', $email);
$this->messageManagerMock->expects($this->exactly(2))->method('addError')->withConsecutive([$message], [__('Incorrect CAPTCHA')]);
$this->actionFlagMock->expects($this->once())->method('set')->with('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
$this->redirectMock->expects($this->once())->method('redirect')->with($response, '*/*/edit')->willReturn($redirectUrl);
$this->observer->execute(new \Magento\Framework\Event\Observer(['controller_action' => $controller]));
}
开发者ID:Doability,项目名称:magento2dev,代码行数:34,代码来源:CheckUserEditObserverTest.php
注:本文中的Magento\Customer\Model\Session类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论