Ich habe ein Problem mit dem Speichern von Sitzungsvariablen nach einer Umleitung. Hier ist ein Modell des relevanten Codes:
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();
}
}
In der Controller-Klasse:
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());
}
}
Controller, den die Umleitung trifft:
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');
}
}
Kann jemand etwas Licht ins Dunkel bringen, warum die quote_id
Variable nach der Umleitung nicht bestehen bleibt?
Bearbeiten 1:
In der ersten Steuerung:
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
(
)
)
In der Umleitungssteuerung:
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
(
)
)
Auflösung:
Die Other_Company_SomeController
Klasse hatte die preDispatch
Methode überschrieben und die übergeordnete Klasse nicht ordnungsgemäß aufgerufen.
setFoo('bar')
und später erfolgreich abzurufen?
Mage::getSingleton('company_x/session')
einCompany_X_Model_Session
Objekt zurück?