Estou tendo um problema com as variáveis de sessão que são salvas após um redirecionamento. Aqui está uma simulação do código relevante:
class Company_X_Model_Session extends Mage_Core_Model_Session_Abstract {
const KEY_QUOTE = 'quote';
protected function _construct() {
$this->init('company_x');
}
public function getQuote() {
if (!$this->hasData(self::KEY_QUOTE)) {
$quote = Mage::getModel('sales/quote')->setStoreId(Mage::app()->getStore()->getId());
/* @var $quote Mage_Sales_Model_Quote */
if ($this->getQuoteId()) {
$quote->load($this->getQuoteId());
}
$this->setData(self::KEY_QUOTE, $quote);
}
return $this->getData(self::KEY_QUOTE);
}
public function clear() {
$this->_quote = null;
$this->setQuoteId(null);
$this->setLastSuccessQuoteId(null);
return parent::clear();
}
}
Na classe do controlador:
class Company_X_SomeController extends Other_Company_SomeController {
protected function relevantAction() {
$session = Mage::getSingleton('company_x/session');
/* @var $session Company_X_Model_Session */
$quote = $session->getQuote();
/* @var $quote Mage_Sales_Model_Quote */
$payment = $quote->getPayment();
$payment->importData(array('method' => 'paypal_express'));
/// all sorts of interesting quote-setting-up code here
$quote->collectTotals()->save();
/// This variable is not saving properly
$session->setQuoteId($quote->getId());
$this->_redirectUrl($quote->getPayment()->getCheckoutRedirectUrl());
}
}
Controlador que o redirecionamento atinge:
class Company_X_ExpressController extends Mage_Paypal_ExpressController {
protected function _getQuote() {
if(!$this->_quote) {
$this->_quote = $this->_getCheckoutSession()->getQuote();
}
return $this->_quote;
}
protected function _getCheckoutSession() {
/// quote_id is not printed here.
print_r(Mage::getSingleton('company_x/session')->getData());
return Mage::getSingleton('company_x/session');
}
}
Alguém pode esclarecer por que a quote_id
variável não persiste após o redirecionamento?
Editar 1:
No primeiro controlador:
Company_X_Model_Session Object
(
[_skipSessionIdFlag:protected] =>
[_sessionHosts:protected] => Array
(
[company.x.local] => 1
)
[_data:protected] => Array
(
[_session_validator_data] => Array
(
[remote_addr] => 10.0.2.21
[http_via] =>
[http_x_forwarded_for] =>
[http_user_agent] => Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36
)
[quote_id] => 445
)
[_hasDataChanges:protected] =>
[_origData:protected] =>
[_idFieldName:protected] =>
[_isDeleted:protected] =>
[_oldFieldsMap:protected] => Array
(
)
[_syncFieldsMap:protected] => Array
(
)
)
No controlador de redirecionamento:
Company_X_Model_Session Object
(
[_skipSessionIdFlag:protected] =>
[_sessionHosts:protected] => Array
(
[company.x.local] => 1
)
[_data:protected] => Array
(
[_session_validator_data] => Array
(
[remote_addr] => 10.0.2.21
[http_via] =>
[http_x_forwarded_for] =>
[http_user_agent] => Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36
)
)
[_hasDataChanges:protected] =>
[_origData:protected] =>
[_idFieldName:protected] =>
[_isDeleted:protected] =>
[_oldFieldsMap:protected] => Array
(
)
[_syncFieldsMap:protected] => Array
(
)
)
Resolução:
A Other_Company_SomeController
classe substituiu o preDispatch
método e não chamou adequadamente a classe pai.
setFoo('bar')
e recuperá-lo posteriormente com êxito?
Mage::getSingleton('company_x/session')
retornando umCompany_X_Model_Session
objeto?