本文整理汇总了PHP中Magento\Checkout\Model\Session::setCustomerData方法的典型用法代码示例。如果您正苦于以下问题:PHP Session::setCustomerData方法的具体用法?PHP Session::setCustomerData怎么用?PHP Session::setCustomerData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Checkout\Model\Session
的用法示例。
在下文中一共展示了Session::setCustomerData方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetQuoteNotInitializedCustomerSet
/**
* Test covers case when quote is not yet initialized and customer data is set to checkout session model.
*
* Expected result - quote object should be loaded and customer data should be set to it.
*
* @magentoDataFixture Magento/Sales/_files/quote_with_customer.php
*/
public function testGetQuoteNotInitializedCustomerSet()
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository */
$customerRepository = $objectManager->create('Magento\\Customer\\Api\\CustomerRepositoryInterface');
$customer = $customerRepository->getById(1);
$this->_checkoutSession->setCustomerData($customer);
/** Execute SUT */
$quote = $this->_checkoutSession->getQuote();
$this->_validateCustomerDataInQuote($quote);
}
示例2: testGetQuoteNotInitializedCustomerSet
/**
* Test covers case when quote is not yet initialized and customer data is set to checkout session model.
*
* Expected result - quote object should be loaded and customer data should be set to it.
*
* @magentoDataFixture Magento/Sales/_files/quote_with_customer.php
*/
public function testGetQuoteNotInitializedCustomerSet()
{
/** Preconditions */
$customerIdFromFixture = 1;
/** @var \Magento\Customer\Service\V1\CustomerAccountServiceInterface $customerService */
$customerService = Bootstrap::getObjectManager()->get('Magento\\Customer\\Service\\V1\\CustomerAccountServiceInterface');
$customer = $customerService->getCustomer($customerIdFromFixture);
$this->_checkoutSession->setCustomerData($customer);
/** Execute SUT */
$quote = $this->_checkoutSession->getQuote();
$this->_validateCustomerDataInQuote($quote);
}
示例3: execute
/**
* Emulate quote by persistent data
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
*/
public function execute($observer)
{
$stopActions = ['persistent_index_saveMethod', 'customer_account_createpost'];
if (!$this->_persistentData->canProcess($observer) || !$this->_persistentSession->isPersistent() || $this->_customerSession->isLoggedIn()) {
return;
}
$actionName = $observer->getEvent()->getRequest()->getFullActionName();
if (in_array($actionName, $stopActions)) {
return;
}
if ($this->_persistentData->isShoppingCartPersist()) {
$this->_checkoutSession->setCustomerData($this->customerRepository->getById($this->_persistentSession->getSession()->getCustomerId()));
if (!$this->_checkoutSession->hasQuote()) {
$this->_checkoutSession->getQuote();
}
}
}
示例4: expire
/**
* Expire persistent quote
*
* @return void
*/
public function expire()
{
$quote = $this->checkoutSession->setLoadInactive()->getQuote();
if ($quote->getIsActive() && $quote->getCustomerId()) {
$this->checkoutSession->setCustomerData(null)->clearQuote()->clearStorage();
} else {
$quote->setIsActive(true)->setIsPersistent(false)->setCustomerId(null)->setCustomerGroupId(\Magento\Customer\Api\Data\GroupInterface::NOT_LOGGED_IN_ID);
}
}
示例5: _expirePersistentSession
/**
* @return void
*/
protected function _expirePersistentSession()
{
$quote = $this->_checkoutSession->setLoadInactive()->getQuote();
if ($quote->getIsActive() && $quote->getCustomerId()) {
$this->_checkoutSession->setCustomerData(null)->clearQuote()->clearStorage();
} else {
$quote->setIsActive(true)->setIsPersistent(false)->setCustomerId(null)->setCustomerGroupId(\Magento\Customer\Service\V1\CustomerGroupServiceInterface::NOT_LOGGED_IN_ID);
}
}