diff --git a/vendor/magento/module-customer/ViewModel/CookieSettings.php b/vendor/magento/module-customer/ViewModel/CookieSettings.php new file mode 100644 index 000000000000..a725352f4d09 --- /dev/null +++ b/vendor/magento/module-customer/ViewModel/CookieSettings.php @@ -0,0 +1,42 @@ +scopeConfig = $scopeConfig; + } + + /** + * Get cookie domain for a store view + * + * @return mixed + */ + public function getCookieDomain() + { + return $this->scopeConfig->getValue( + self::XML_PATH_COOKIE_DOMAIN, + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + } +} diff --git a/vendor/magento/module-customer/ViewModel/Customer/Auth.php b/vendor/magento/module-customer/ViewModel/Customer/Auth.php new file mode 100644 index 000000000000..e8c9210d32e1 --- /dev/null +++ b/vendor/magento/module-customer/ViewModel/Customer/Auth.php @@ -0,0 +1,36 @@ +httpContext->getValue(Context::CONTEXT_AUTH) ?? false; + } +} diff --git a/vendor/magento/module-customer/ViewModel/Customer/JsonSerializer.php b/vendor/magento/module-customer/ViewModel/Customer/JsonSerializer.php new file mode 100644 index 000000000000..c7a7be29a294 --- /dev/null +++ b/vendor/magento/module-customer/ViewModel/Customer/JsonSerializer.php @@ -0,0 +1,36 @@ +jsonEncoder->serialize($value); + } +} diff --git a/vendor/magento/module-customer/view/frontend/layout/default.xml b/vendor/magento/module-customer/view/frontend/layout/default.xml index b431373ca412..7c2199763a30 100644 --- a/vendor/magento/module-customer/view/frontend/layout/default.xml +++ b/vendor/magento/module-customer/view/frontend/layout/default.xml @@ -48,7 +48,13 @@ + template="Magento_Customer::js/customer-data.phtml"> + + Magento\Customer\ViewModel\Customer\Auth + Magento\Customer\ViewModel\Customer\JsonSerializer + Magento\Customer\ViewModel\CookieSettings + + diff --git a/vendor/magento/module-customer/view/frontend/templates/js/customer-data.phtml b/vendor/magento/module-customer/view/frontend/templates/js/customer-data.phtml index eb50ea645478..361ebe0073eb 100644 --- a/vendor/magento/module-customer/view/frontend/templates/js/customer-data.phtml +++ b/vendor/magento/module-customer/view/frontend/templates/js/customer-data.phtml @@ -3,10 +3,22 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +use Magento\Customer\ViewModel\Customer\Data; +use Magento\Framework\App\ObjectManager; +use Magento\Customer\ViewModel\CookieSettings; /** @var \Magento\Customer\Block\CustomerData $block */ // phpcs:disable Magento2.Templates.ThisInTemplate.FoundHelper +/** @var Auth $auth */ +$auth = $block->getAuth() ?? ObjectManager::getInstance()->get(Auth::class); +/** @var JsonSerializer $jsonSerializer */ +$jsonSerializer = $block->getJsonSerializer() ?? + ObjectManager::getInstance()->get(JsonSerializer::class); +$customerDataUrl = $block->getCustomerDataUrl('customer/account/updateSession'); +$expirableSectionNames = $block->getExpirableSectionNames(); +/** @var CookieSettings $cookieSettings */ +$cookieSettings = $block->getCookieSettings(); ?>