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


PHP Session::setCustomerId方法代码示例

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


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

示例1: testToHtml

 /**
  * @magentoDataFixture Magento/Customer/_files/customer.php
  */
 public function testToHtml()
 {
     $this->customerSession->setCustomerId(1);
     $html = $this->block->toHtml();
     $this->assertContains("<div class=\"block block-dashboard-welcome\">", $html);
     $this->assertContains("<strong>Hello, Firstname Lastname!</strong>", $html);
 }
开发者ID:aiesh,项目名称:magento2,代码行数:10,代码来源:HelloTest.php

示例2: testGetSubscriptionObject

 /**
  * @magentoDataFixture Magento/Customer/_files/customer.php
  */
 public function testGetSubscriptionObject()
 {
     $this->customerSession->setCustomerId(1);
     $subscriber = $this->block->getSubscriptionObject();
     $this->assertInstanceOf('Magento\\Newsletter\\Model\\Subscriber', $subscriber);
     $this->assertFalse($subscriber->isSubscribed());
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:10,代码来源:NewsletterTest.php

示例3: testAddProductWithSession

 public function testAddProductWithSession()
 {
     $this->_session->setCustomerId(1);
     /** @var $product \Magento\Catalog\Model\Product */
     $product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product')->load(1);
     $this->_model->addProduct($product);
     $this->assertTrue($this->_model->hasItems(1, $this->_visitor->getId()));
 }
开发者ID:buskamuza,项目名称:magento2-skeleton,代码行数:8,代码来源:ListCompareTest.php

示例4: execute

 /**
  * Reset session data when customer re-authenticates
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute($observer)
 {
     $this->_customerSession->setCustomerId(null)->setCustomerGroupId(null);
     if ($this->_requestHttp->getParam('context') != 'checkout') {
         $this->quoteManager->expire();
         return;
     }
     $this->quoteManager->setGuest();
 }
开发者ID:zhangjiachao,项目名称:magento2,代码行数:15,代码来源:CustomerAuthenticatedEvent.php

示例5: testGetPrimaryAddressesBillingShippingDifferent

 /**
  * Verify that the specified customer has different default billing and shipping addresses.
  *
  * @magentoDataFixture Magento/Customer/_files/customer.php
  * @magentoDataFixture Magento/Customer/_files/customer_primary_addresses.php
  */
 public function testGetPrimaryAddressesBillingShippingDifferent()
 {
     $this->customerSession->setCustomerId(1);
     $addresses = $this->block->getPrimaryAddresses();
     $this->assertCount(2, $addresses);
     $this->assertNotEquals($addresses[0], $addresses[1]);
     $this->assertTrue($addresses[0]->isDefaultBilling());
     $this->assertTrue($addresses[1]->isDefaultShipping());
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:15,代码来源:DashboardTest.php

示例6: execute

 /**
  * Set persistent data to customer session
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute($observer)
 {
     if (!$this->_persistentData->canProcess($observer) || !$this->_persistentData->isShoppingCartPersist()) {
         return $this;
     }
     if ($this->_persistentSession->isPersistent() && !$this->_customerSession->isLoggedIn()) {
         $customer = $this->_customerAccountService->getCustomer($this->_persistentSession->getSession()->getCustomerId());
         $this->_customerSession->setCustomerId($customer->getId())->setCustomerGroupId($customer->getGroupId());
     }
     return $this;
 }
开发者ID:zhangjiachao,项目名称:magento2,代码行数:17,代码来源:EmulateCustomer.php

示例7: execute

 /**
  * Set persistent data to customer session
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @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()) {
         $customer = $this->customerRepository->getById($this->_persistentSession->getSession()->getCustomerId());
         $this->_customerSession->setCustomerId($customer->getId())->setCustomerGroupId($customer->getGroupId());
     }
     return $this;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:17,代码来源:EmulateCustomerObserver.php

示例8: execute

 /**
  * Check and clear session data if persistent session expired
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if (!$this->_persistentData->canProcess($observer)) {
         return;
     }
     if ($this->_persistentData->isEnabled() && !$this->_persistentSession->isPersistent() && !$this->_customerSession->isLoggedIn() && $this->_checkoutSession->getQuoteId() && !$observer->getControllerAction() instanceof \Magento\Checkout\Controller\Onepage) {
         $this->_eventManager->dispatch('persistent_session_expired');
         $this->quoteManager->expire();
         $this->_customerSession->setCustomerId(null)->setCustomerGroupId(null);
     }
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:17,代码来源:CheckExpirePersistentQuoteObserver.php

示例9: execute

 /**
  * Unset persistent cookie and make customer's quote as a guest
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute($observer)
 {
     if (!$this->_persistentData->canProcess($observer) || !$this->_persistentSession->isPersistent()) {
         return;
     }
     $this->_persistentSession->getSession()->removePersistentCookie();
     if (!$this->_customerSession->isLoggedIn()) {
         $this->_customerSession->setCustomerId(null)->setCustomerGroupId(null);
     }
     $this->quoteManager->setGuest();
 }
开发者ID:zhangjiachao,项目名称:magento2,代码行数:17,代码来源:RemovePersistentCookie.php

示例10: setUp

 protected function setUp()
 {
     $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $this->_customerSession = $objectManager->get('\\Magento\\Customer\\Model\\Session');
     $this->_customerSession->setCustomerId(1);
     $this->_context = $objectManager->get('Magento\\Backend\\Block\\Template\\Context');
     $this->_requestId = $this->_context->getRequest()->getParam('id');
     $this->_context->getRequest()->setParam('id', '1');
     $objectManager->get('Magento\\Framework\\App\\State')->setAreaCode('frontend');
     /** @var $layout \Magento\Framework\View\Layout */
     $layout = $objectManager->get('Magento\\Framework\\View\\LayoutInterface');
     $currentCustomer = $objectManager->create('Magento\\Customer\\Helper\\Session\\CurrentCustomer', array('customerSession' => $this->_customerSession));
     $this->_block = $layout->createBlock('Magento\\Customer\\Block\\Address\\Edit', '', array('customerSession' => $this->_customerSession, 'currentCustomer' => $currentCustomer));
 }
开发者ID:aiesh,项目名称:magento2,代码行数:14,代码来源:EditTest.php

示例11: tearDown

 protected function tearDown()
 {
     $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $this->_customerSession->setCustomerId(null);
     $this->_context->getRequest()->setParam('id', $this->_requestId);
     /** @var \Magento\Customer\Model\AddressRegistry $addressRegistry */
     $addressRegistry = $objectManager->get('Magento\\Customer\\Model\\AddressRegistry');
     //Cleanup address from registry
     $addressRegistry->remove(1);
     $addressRegistry->remove(2);
     /** @var \Magento\Customer\Model\CustomerRegistry $customerRegistry */
     $customerRegistry = $objectManager->get('Magento\\Customer\\Model\\CustomerRegistry');
     //Cleanup customer from registry
     $customerRegistry->remove(1);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:15,代码来源:EditTest.php

示例12: 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;
 }
开发者ID:koliaGI,项目名称:magento2,代码行数:33,代码来源:EmulateCustomerObserver.php

示例13: testGetPrimaryBillingAddressEditUrl

 /**
  * @magentoDataFixture Magento/Customer/_files/customer.php
  * @magentoDataFixture Magento/Customer/_files/customer_two_addresses.php
  * @magentoDataFixture Magento/Customer/_files/customer_no_address.php
  * @dataProvider getPrimaryAddressEditUrlDataProvider
  */
 public function testGetPrimaryBillingAddressEditUrl($customerId, $expected)
 {
     if (!empty($customerId)) {
         $this->_customerSession->setCustomerId($customerId);
     }
     $url = $this->_block->getPrimaryBillingAddressEditUrl();
     $this->assertEquals($expected, $url);
 }
开发者ID:andrewhowdencom,项目名称:m2onk8s,代码行数:14,代码来源:AddressTest.php

示例14: testGetEmail

 /**
  * @magentoDataFixture Magento/Customer/_files/customer.php
  */
 public function testGetEmail()
 {
     $this->customerSession->setCustomerId(1);
     $this->assertEquals('customer@example.com', $this->block->getEmail());
 }
开发者ID:aiesh,项目名称:magento2,代码行数:8,代码来源:SendTest.php

示例15: tearDown

 protected function tearDown()
 {
     $this->customerSession->setCustomerId(null);
     $this->coreSession->unsData('_form_key');
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:5,代码来源:ManageTest.php


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