Database-Based & Redis-Based Customer-Session Empty Data Issue in Magento 2 Using 2 Web-ServersSessions...
How do ISS astronauts "get their stripes"?
How can I handle a player who pre-plans arguments about my rulings on RAW?
How to mitigate "bandwagon attacking" from players?
What is the difference between ashamed and shamed?
How do I construct an nxn matrix?
Skis versus snow shoes - when to choose which for travelling the backcountry?
Linear regression when Y is bounded and discrete
How would we write a misogynistic character without offending people?
Has the Isbell–Freyd criterion ever been used to check that a category is concretisable?
How to count occurrences of Friday 13th
What if I store 10TB on azure servers and then keep the vm powered off?
Is divide-by-zero a security vulnerability?
Where is the fallacy here?
Is there a low-level alternative to Animate Objects?
Replacement ford fiesta radiator has extra hose
chrony vs. systemd-timesyncd – What are the differences and use cases as NTP clients?
How to avoid being sexist when trying to employ someone to function in a very sexist environment?
What are these green text/line displays shown during the livestream of Crew Dragon's approach to dock with the ISS?
If a druid in Wild Shape swallows a creature whole, then turns back to her normal form, what happens?
How to properly claim credit for peer review?
What is a term for a function that when called repeatedly, has the same effect as calling once?
How to count words in a line
How can atoms be electrically neutral when there is a difference in the positions of the charges?
The change directory (cd) command is not working with a USB drive
Database-Based & Redis-Based Customer-Session Empty Data Issue in Magento 2 Using 2 Web-Servers
Sessions writing to database instead of RedisMissing blocks on live systemRedis Session SlownessFull page cache causes checkout POST request to fail, only when logged in!Magento 2 Redis Session Storage Database TableuiComponent Form Save Button Not workingAdmin logged out if autocomplete used in order createMagento 2 Add to cart using Ajax on response from other domainMagento 2 customer session data not giving customer data
I am facing a problem in getting session data in Magento 2, when I deploy my Build on 2 Web-Servers. I am facing no issue on Single Web-Server.
Problem Details I am setting some data in session, in first AJAX request, and then getting that data in the next consecutive AJAX
request but the session returns no values.
AJAX-Request Format:
jQuery.ajax({
url: myUrl,
type: 'POST',
dataType: 'json',
data: myData,
cache: false,
})
Problem Resolution Approaches
Printed overall session data and found empty customer data. Only the following data is returned.
Array([customer_segment_ids] => Array([1] => Array([0] => 3))[wishlist_item_count] => 0)
Tried to load session data using ObjectManager, while created object of
MagentoCustomerModelSession
and provided the SessionID to get data from the Database-Table using my custom code, but it returned empty array.Tried to load session data using MySQL Custom Query by SessionID on that table and got data.
Changed Session storage to Redis in my
app/etc/env.php
file, as directed here, but got the same empty session issue.
Changed Session storage to Files in my
app/etc/env.php
file and I got the correct data as expected.
Can I have a solution for this problem?
magento-2.1 database ajax customer-session redis
add a comment |
I am facing a problem in getting session data in Magento 2, when I deploy my Build on 2 Web-Servers. I am facing no issue on Single Web-Server.
Problem Details I am setting some data in session, in first AJAX request, and then getting that data in the next consecutive AJAX
request but the session returns no values.
AJAX-Request Format:
jQuery.ajax({
url: myUrl,
type: 'POST',
dataType: 'json',
data: myData,
cache: false,
})
Problem Resolution Approaches
Printed overall session data and found empty customer data. Only the following data is returned.
Array([customer_segment_ids] => Array([1] => Array([0] => 3))[wishlist_item_count] => 0)
Tried to load session data using ObjectManager, while created object of
MagentoCustomerModelSession
and provided the SessionID to get data from the Database-Table using my custom code, but it returned empty array.Tried to load session data using MySQL Custom Query by SessionID on that table and got data.
Changed Session storage to Redis in my
app/etc/env.php
file, as directed here, but got the same empty session issue.
Changed Session storage to Files in my
app/etc/env.php
file and I got the correct data as expected.
Can I have a solution for this problem?
magento-2.1 database ajax customer-session redis
add a comment |
I am facing a problem in getting session data in Magento 2, when I deploy my Build on 2 Web-Servers. I am facing no issue on Single Web-Server.
Problem Details I am setting some data in session, in first AJAX request, and then getting that data in the next consecutive AJAX
request but the session returns no values.
AJAX-Request Format:
jQuery.ajax({
url: myUrl,
type: 'POST',
dataType: 'json',
data: myData,
cache: false,
})
Problem Resolution Approaches
Printed overall session data and found empty customer data. Only the following data is returned.
Array([customer_segment_ids] => Array([1] => Array([0] => 3))[wishlist_item_count] => 0)
Tried to load session data using ObjectManager, while created object of
MagentoCustomerModelSession
and provided the SessionID to get data from the Database-Table using my custom code, but it returned empty array.Tried to load session data using MySQL Custom Query by SessionID on that table and got data.
Changed Session storage to Redis in my
app/etc/env.php
file, as directed here, but got the same empty session issue.
Changed Session storage to Files in my
app/etc/env.php
file and I got the correct data as expected.
Can I have a solution for this problem?
magento-2.1 database ajax customer-session redis
I am facing a problem in getting session data in Magento 2, when I deploy my Build on 2 Web-Servers. I am facing no issue on Single Web-Server.
Problem Details I am setting some data in session, in first AJAX request, and then getting that data in the next consecutive AJAX
request but the session returns no values.
AJAX-Request Format:
jQuery.ajax({
url: myUrl,
type: 'POST',
dataType: 'json',
data: myData,
cache: false,
})
Problem Resolution Approaches
Printed overall session data and found empty customer data. Only the following data is returned.
Array([customer_segment_ids] => Array([1] => Array([0] => 3))[wishlist_item_count] => 0)
Tried to load session data using ObjectManager, while created object of
MagentoCustomerModelSession
and provided the SessionID to get data from the Database-Table using my custom code, but it returned empty array.Tried to load session data using MySQL Custom Query by SessionID on that table and got data.
Changed Session storage to Redis in my
app/etc/env.php
file, as directed here, but got the same empty session issue.
Changed Session storage to Files in my
app/etc/env.php
file and I got the correct data as expected.
Can I have a solution for this problem?
magento-2.1 database ajax customer-session redis
magento-2.1 database ajax customer-session redis
edited 7 mins ago
Jehangir Wahid
asked Feb 11 at 16:18
Jehangir WahidJehangir Wahid
63
63
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I use the following code to get customer data with the cache enabled which I can achieve by the following code. But you are using the ajax controller request so for you cache will be no problem. kindly share your full code here.
namespace QaisarSattiModuleBlock;
class HelloWorld extends MagentoFrameworkViewElementTemplate
{
protected $objectmanager;
public function __construct(
MagentoFrameworkObjectManagerInterface $objectmanager
) {
$this->objectmanager = $objectmanager;
}
public function getCustomerData()
{
$customerSession = $this->objectmanager->create('MagentoCustomerModelSessionFactory')->create();
return $customerSession;
}
}
Reference
Thank you for your consideration, There is nothing special about my code, I used the conventional way to get data from the Customer-Session, as follows;namespace MyNamespaceMyModuleControllerArea;
use MagentoCustomerModelSession;
class MyController extends MagentoFrameworkAppActionAction
{
protected $_customerCollection;
public function __construct(Session $customerSession)
{
$this->_customerSession = $customerSession;
}
public function execute()
{
$myData = $this->_customerSession->getMyCustomData();
}
}
– Jehangir Wahid
Feb 25 at 16:58
@JehangirWahid if you want to get customer attribute then load through the model. follow blog.qaisarsatti.com/magento_2/magento2-load-customer-by-id
– Qaisar Satti
yesterday
No Sir, I am not trying to get Customer Attributes. I am setting some custom data in session the first client request, and then am trying to get that data in the next consecutive request.
– Jehangir Wahid
yesterday
Can you share code where you set the session?
– Qaisar Satti
11 hours ago
Yes, for sure.namespace MyNamespaceMyModuleControllerArea; use MagentoCustomerModelSession; class MyController extends MagentoFrameworkAppActionAction { protected $_customerCollection; public function __construct(Session $customerSession) { $this->_customerSession = $customerSession; } public function execute() { // $myData is an array $this->_customerSession->setMyCustomData($myData); } }
– Jehangir Wahid
3 mins ago
|
show 1 more comment
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f261289%2fdatabase-based-redis-based-customer-session-empty-data-issue-in-magento-2-usin%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I use the following code to get customer data with the cache enabled which I can achieve by the following code. But you are using the ajax controller request so for you cache will be no problem. kindly share your full code here.
namespace QaisarSattiModuleBlock;
class HelloWorld extends MagentoFrameworkViewElementTemplate
{
protected $objectmanager;
public function __construct(
MagentoFrameworkObjectManagerInterface $objectmanager
) {
$this->objectmanager = $objectmanager;
}
public function getCustomerData()
{
$customerSession = $this->objectmanager->create('MagentoCustomerModelSessionFactory')->create();
return $customerSession;
}
}
Reference
Thank you for your consideration, There is nothing special about my code, I used the conventional way to get data from the Customer-Session, as follows;namespace MyNamespaceMyModuleControllerArea;
use MagentoCustomerModelSession;
class MyController extends MagentoFrameworkAppActionAction
{
protected $_customerCollection;
public function __construct(Session $customerSession)
{
$this->_customerSession = $customerSession;
}
public function execute()
{
$myData = $this->_customerSession->getMyCustomData();
}
}
– Jehangir Wahid
Feb 25 at 16:58
@JehangirWahid if you want to get customer attribute then load through the model. follow blog.qaisarsatti.com/magento_2/magento2-load-customer-by-id
– Qaisar Satti
yesterday
No Sir, I am not trying to get Customer Attributes. I am setting some custom data in session the first client request, and then am trying to get that data in the next consecutive request.
– Jehangir Wahid
yesterday
Can you share code where you set the session?
– Qaisar Satti
11 hours ago
Yes, for sure.namespace MyNamespaceMyModuleControllerArea; use MagentoCustomerModelSession; class MyController extends MagentoFrameworkAppActionAction { protected $_customerCollection; public function __construct(Session $customerSession) { $this->_customerSession = $customerSession; } public function execute() { // $myData is an array $this->_customerSession->setMyCustomData($myData); } }
– Jehangir Wahid
3 mins ago
|
show 1 more comment
I use the following code to get customer data with the cache enabled which I can achieve by the following code. But you are using the ajax controller request so for you cache will be no problem. kindly share your full code here.
namespace QaisarSattiModuleBlock;
class HelloWorld extends MagentoFrameworkViewElementTemplate
{
protected $objectmanager;
public function __construct(
MagentoFrameworkObjectManagerInterface $objectmanager
) {
$this->objectmanager = $objectmanager;
}
public function getCustomerData()
{
$customerSession = $this->objectmanager->create('MagentoCustomerModelSessionFactory')->create();
return $customerSession;
}
}
Reference
Thank you for your consideration, There is nothing special about my code, I used the conventional way to get data from the Customer-Session, as follows;namespace MyNamespaceMyModuleControllerArea;
use MagentoCustomerModelSession;
class MyController extends MagentoFrameworkAppActionAction
{
protected $_customerCollection;
public function __construct(Session $customerSession)
{
$this->_customerSession = $customerSession;
}
public function execute()
{
$myData = $this->_customerSession->getMyCustomData();
}
}
– Jehangir Wahid
Feb 25 at 16:58
@JehangirWahid if you want to get customer attribute then load through the model. follow blog.qaisarsatti.com/magento_2/magento2-load-customer-by-id
– Qaisar Satti
yesterday
No Sir, I am not trying to get Customer Attributes. I am setting some custom data in session the first client request, and then am trying to get that data in the next consecutive request.
– Jehangir Wahid
yesterday
Can you share code where you set the session?
– Qaisar Satti
11 hours ago
Yes, for sure.namespace MyNamespaceMyModuleControllerArea; use MagentoCustomerModelSession; class MyController extends MagentoFrameworkAppActionAction { protected $_customerCollection; public function __construct(Session $customerSession) { $this->_customerSession = $customerSession; } public function execute() { // $myData is an array $this->_customerSession->setMyCustomData($myData); } }
– Jehangir Wahid
3 mins ago
|
show 1 more comment
I use the following code to get customer data with the cache enabled which I can achieve by the following code. But you are using the ajax controller request so for you cache will be no problem. kindly share your full code here.
namespace QaisarSattiModuleBlock;
class HelloWorld extends MagentoFrameworkViewElementTemplate
{
protected $objectmanager;
public function __construct(
MagentoFrameworkObjectManagerInterface $objectmanager
) {
$this->objectmanager = $objectmanager;
}
public function getCustomerData()
{
$customerSession = $this->objectmanager->create('MagentoCustomerModelSessionFactory')->create();
return $customerSession;
}
}
Reference
I use the following code to get customer data with the cache enabled which I can achieve by the following code. But you are using the ajax controller request so for you cache will be no problem. kindly share your full code here.
namespace QaisarSattiModuleBlock;
class HelloWorld extends MagentoFrameworkViewElementTemplate
{
protected $objectmanager;
public function __construct(
MagentoFrameworkObjectManagerInterface $objectmanager
) {
$this->objectmanager = $objectmanager;
}
public function getCustomerData()
{
$customerSession = $this->objectmanager->create('MagentoCustomerModelSessionFactory')->create();
return $customerSession;
}
}
Reference
answered Feb 25 at 10:11
Qaisar SattiQaisar Satti
26.8k1255107
26.8k1255107
Thank you for your consideration, There is nothing special about my code, I used the conventional way to get data from the Customer-Session, as follows;namespace MyNamespaceMyModuleControllerArea;
use MagentoCustomerModelSession;
class MyController extends MagentoFrameworkAppActionAction
{
protected $_customerCollection;
public function __construct(Session $customerSession)
{
$this->_customerSession = $customerSession;
}
public function execute()
{
$myData = $this->_customerSession->getMyCustomData();
}
}
– Jehangir Wahid
Feb 25 at 16:58
@JehangirWahid if you want to get customer attribute then load through the model. follow blog.qaisarsatti.com/magento_2/magento2-load-customer-by-id
– Qaisar Satti
yesterday
No Sir, I am not trying to get Customer Attributes. I am setting some custom data in session the first client request, and then am trying to get that data in the next consecutive request.
– Jehangir Wahid
yesterday
Can you share code where you set the session?
– Qaisar Satti
11 hours ago
Yes, for sure.namespace MyNamespaceMyModuleControllerArea; use MagentoCustomerModelSession; class MyController extends MagentoFrameworkAppActionAction { protected $_customerCollection; public function __construct(Session $customerSession) { $this->_customerSession = $customerSession; } public function execute() { // $myData is an array $this->_customerSession->setMyCustomData($myData); } }
– Jehangir Wahid
3 mins ago
|
show 1 more comment
Thank you for your consideration, There is nothing special about my code, I used the conventional way to get data from the Customer-Session, as follows;namespace MyNamespaceMyModuleControllerArea;
use MagentoCustomerModelSession;
class MyController extends MagentoFrameworkAppActionAction
{
protected $_customerCollection;
public function __construct(Session $customerSession)
{
$this->_customerSession = $customerSession;
}
public function execute()
{
$myData = $this->_customerSession->getMyCustomData();
}
}
– Jehangir Wahid
Feb 25 at 16:58
@JehangirWahid if you want to get customer attribute then load through the model. follow blog.qaisarsatti.com/magento_2/magento2-load-customer-by-id
– Qaisar Satti
yesterday
No Sir, I am not trying to get Customer Attributes. I am setting some custom data in session the first client request, and then am trying to get that data in the next consecutive request.
– Jehangir Wahid
yesterday
Can you share code where you set the session?
– Qaisar Satti
11 hours ago
Yes, for sure.namespace MyNamespaceMyModuleControllerArea; use MagentoCustomerModelSession; class MyController extends MagentoFrameworkAppActionAction { protected $_customerCollection; public function __construct(Session $customerSession) { $this->_customerSession = $customerSession; } public function execute() { // $myData is an array $this->_customerSession->setMyCustomData($myData); } }
– Jehangir Wahid
3 mins ago
Thank you for your consideration, There is nothing special about my code, I used the conventional way to get data from the Customer-Session, as follows;
namespace MyNamespaceMyModuleControllerArea;
use MagentoCustomerModelSession;
class MyController extends MagentoFrameworkAppActionAction
{
protected $_customerCollection;
public function __construct(Session $customerSession)
{
$this->_customerSession = $customerSession;
}
public function execute()
{
$myData = $this->_customerSession->getMyCustomData();
}
}
– Jehangir Wahid
Feb 25 at 16:58
Thank you for your consideration, There is nothing special about my code, I used the conventional way to get data from the Customer-Session, as follows;
namespace MyNamespaceMyModuleControllerArea;
use MagentoCustomerModelSession;
class MyController extends MagentoFrameworkAppActionAction
{
protected $_customerCollection;
public function __construct(Session $customerSession)
{
$this->_customerSession = $customerSession;
}
public function execute()
{
$myData = $this->_customerSession->getMyCustomData();
}
}
– Jehangir Wahid
Feb 25 at 16:58
@JehangirWahid if you want to get customer attribute then load through the model. follow blog.qaisarsatti.com/magento_2/magento2-load-customer-by-id
– Qaisar Satti
yesterday
@JehangirWahid if you want to get customer attribute then load through the model. follow blog.qaisarsatti.com/magento_2/magento2-load-customer-by-id
– Qaisar Satti
yesterday
No Sir, I am not trying to get Customer Attributes. I am setting some custom data in session the first client request, and then am trying to get that data in the next consecutive request.
– Jehangir Wahid
yesterday
No Sir, I am not trying to get Customer Attributes. I am setting some custom data in session the first client request, and then am trying to get that data in the next consecutive request.
– Jehangir Wahid
yesterday
Can you share code where you set the session?
– Qaisar Satti
11 hours ago
Can you share code where you set the session?
– Qaisar Satti
11 hours ago
Yes, for sure.
namespace MyNamespaceMyModuleControllerArea; use MagentoCustomerModelSession; class MyController extends MagentoFrameworkAppActionAction { protected $_customerCollection; public function __construct(Session $customerSession) { $this->_customerSession = $customerSession; } public function execute() { // $myData is an array $this->_customerSession->setMyCustomData($myData); } }
– Jehangir Wahid
3 mins ago
Yes, for sure.
namespace MyNamespaceMyModuleControllerArea; use MagentoCustomerModelSession; class MyController extends MagentoFrameworkAppActionAction { protected $_customerCollection; public function __construct(Session $customerSession) { $this->_customerSession = $customerSession; } public function execute() { // $myData is an array $this->_customerSession->setMyCustomData($myData); } }
– Jehangir Wahid
3 mins ago
|
show 1 more comment
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f261289%2fdatabase-based-redis-based-customer-session-empty-data-issue-in-magento-2-usin%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown