本文整理汇总了PHP中Magento\Customer\Model\Session::getCookiePath方法的典型用法代码示例。如果您正苦于以下问题:PHP Session::getCookiePath方法的具体用法?PHP Session::getCookiePath怎么用?PHP Session::getCookiePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Customer\Model\Session
的用法示例。
在下文中一共展示了Session::getCookiePath方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Renew persistent cookie
*
* @param Observer $observer
* @return void
*/
public function execute(Observer $observer)
{
if (!$this->_persistentData->canProcess($observer) || !$this->_persistentData->isEnabled() || !$this->_persistentSession->isPersistent()) {
return;
}
/** @var $request \Magento\Framework\App\RequestInterface */
$request = $observer->getEvent()->getRequest();
if ($this->_customerSession->isLoggedIn() || $request->getFullActionName() == 'customer_account_logout') {
$this->_sessionFactory->create()->renewPersistentCookie($this->_persistentData->getLifeTime(), $this->_customerSession->getCookiePath());
}
}
示例2: execute
/**
* @param Observer $observer
* @return void
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function execute(Observer $observer)
{
/** @var $customer \Magento\Customer\Api\Data\CustomerInterface */
$customer = $observer->getEvent()->getCustomer();
// Check if customer is valid (remove persistent cookie for invalid customer)
if (!$customer || !$customer->getId() || !$this->_persistentSession->isRememberMeChecked()) {
$this->_sessionFactory->create()->removePersistentCookie();
return;
}
$persistentLifeTime = $this->_persistentData->getLifeTime();
// Delete persistent session, if persistent could not be applied
if ($this->_persistentData->isEnabled() && $persistentLifeTime <= 0) {
// Remove current customer persistent session
$this->_sessionFactory->create()->deleteByCustomerId($customer->getId());
return;
}
/** @var $sessionModel \Magento\Persistent\Model\Session */
$sessionModel = $this->_persistentSession->getSession();
// Check if session is wrong or not exists, so create new session
if (!$sessionModel->getId() || $sessionModel->getCustomerId() != $customer->getId()) {
/** @var \Magento\Persistent\Model\Session $sessionModel */
$sessionModel = $this->_sessionFactory->create();
$sessionModel->setLoadExpired()->loadByCustomerId($customer->getId());
if (!$sessionModel->getId()) {
/** @var \Magento\Persistent\Model\Session $sessionModel */
$sessionModel = $this->_sessionFactory->create();
$sessionModel->setCustomerId($customer->getId())->save();
}
$this->_persistentSession->setSession($sessionModel);
}
// Set new cookie
if ($sessionModel->getId()) {
$sessionModel->setPersistentCookie($persistentLifeTime, $this->_customerSession->getCookiePath());
}
}
示例3: testSynchronizePersistentOnLogin
/**
* @covers \Magento\Persistent\Model\Observer\Session::synchronizePersistentOnLogin
*/
public function testSynchronizePersistentOnLogin()
{
$event = new \Magento\Framework\Event();
$observer = new \Magento\Framework\Event\Observer(array('event' => $event));
/** @var \Magento\Customer\Service\V1\CustomerAccountServiceInterface $customerAccountService */
$customerAccountService = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Customer\\Service\\V1\\CustomerAccountServiceInterface');
/** @var $customer \Magento\Customer\Service\V1\Data\Customer */
$customer = $customerAccountService->getCustomer(1);
$event->setData('customer', $customer);
$this->_persistentSession->setRememberMeChecked(true);
$this->_cookieMock->expects($this->once())->method('set')->with(\Magento\Persistent\Model\Session::COOKIE_NAME, $this->anything(), $this->anything(), $this->_customerSession->getCookiePath());
$this->_model->synchronizePersistentOnLogin($observer);
// check that persistent session has been stored for Customer
/** @var \Magento\Persistent\Model\Session $sessionModel */
$sessionModel = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Persistent\\Model\\Session');
$sessionModel->loadByCustomerId(1);
$this->assertEquals(1, $sessionModel->getCustomerId());
}