I'm getting some data from an API. I want to save those data in my user session so that the API isn't called each time the page is reached.
- First time: load API, save in session
- After, load session
So this is my simple class :
class CadencierDataSession extends CustomerUserData
{
public function getCadencier() {
return $this->_customerSession->getCadencier();
}
public function setCadencier($cadencier) {
$this->_customerSession->setCadencier($cadencier);
}
public function unsetCadencier() {
$this->_customerSession->unsCadencier();
}
}
This is how it's called :
$cadencierDataSession = new CadencierDataSession();
$cadencier = $cadencierDataSession->getCadencier();
$follow = "from session";
if($cadencier == null) {
$follow = "from api";
$cadencier = (new Cadencier())->get_cadencier($codeClient);
$cadencierDataSession->setCadencier($cadencier);
die('ok');
}
When I reach the setCadencier line, Magento throught this error :
Fatal error: Uncaught Exception: Serialization of 'SimpleXMLElement' is not allowed in /vendor/magento/framework/Session/SessionManager.php:139 Stack trace: #0 /vendor/magento/framework/Session/SessionManager.php(139): session_write_close() #1 [internal function]: Magento\Framework\Session\SessionManager->writeClose() #2 {main} thrown in /vendor/magento/framework/Session/SessionManager.php on line 139
Who to avoid it? I'd like to keep the XML structure so that I don't have to recode this page.