本文整理汇总了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);
}
示例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());
}
示例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()));
}
示例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();
}
示例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());
}
示例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;
}
示例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;
}
示例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);
}
}
示例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();
}
示例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));
}
示例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);
}
示例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;
}
示例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);
}
示例14: testGetEmail
/**
* @magentoDataFixture Magento/Customer/_files/customer.php
*/
public function testGetEmail()
{
$this->customerSession->setCustomerId(1);
$this->assertEquals('customer@example.com', $this->block->getEmail());
}
示例15: tearDown
protected function tearDown()
{
$this->customerSession->setCustomerId(null);
$this->coreSession->unsData('_form_key');
}