Magento Varien对象不保存数据

时间:2012-12-28 20:00:42

标签: php magento model

我正在尝试在Address对象中使用setData。 这是代码:

//code inside another class
$this->getAddress()->setData('abc', 'abc')->collectShippingRates()->save();

class Mage_Sales_Model_Quote_Address extends Mage_Customer_Model_Address_Abstract
{
...
    public function collectShippingRates()
    {
        ...

        $found = $this->requestShippingRates();
        ...

        return $this;
    }
    public function requestShippingRates(Mage_Sales_Model_Quote_Item_Abstract $item = null)
    {
        //I knkow it's getting here, because when I echo 'blablabla', it works.
        //When I use $this->setData('abc', 'abc') here, the code bellow print 'abc'
        //The problem is when I use setData outside the class
        echo $this->getData('abc');exit; //prints nothing
        ...
    }
...
}

正如你所看到的,我在地址模型中设置了setData,但在类getData中没有返回任何内容 有人可以解释一下发生了什么吗? 当我尝试使用Mage :: register时,它也不起作用。

1 个答案:

答案 0 :(得分:1)

可能的探索途径。

  1. 您对getAddress的调用未返回Mage_Sales_Model_Quote_Address对象,或者正在返回地址对象的其他实例。

  2. 您对setData('abc', 'abc')的调用稍后会在Magento的代码执行中发生,而不是第一次调用requestShippingRates

  3. 调用getAddress和执行requestShippingRates之间的代码是重新实例化或初始化地址对象。

  4. 根据您对Mage::register的评论,我的资金排在第二位。