【问题标题】:Magento, 1 db field not savedMagento,1 db 字段未保存
【发布时间】:2011-01-13 12:27:38
【问题描述】:


我对数据库的一个字段有疑问。使用此代码:

$expireMonth = Mage::getStoreConfig('points_options/config_points/expiration_period', Mage::app()->getStore()->getId());

if (!is_null($expireMonth) && ($expireMonth > 0)) {
    $expireDate = date("Y-m-d H:i:s", strtotime("+" . $expireMonth . " month"));
} else {
    $expireDate = NULL;
}

//die($expireDate);
//store in points history table
$this->_pointsModel->setCustomerId($this->_customer->getId())
                   ->setOrdersId('welcome')
                   ->setPointsPending($pointsForNewCustomer)
                   ->setPointsComment(Mage::helper('points')->__('welcome points'))
                   ->setDateAdded(date('Y-m-d H:i:s'))
                   ->setPointsStatus(2)//confirmed
                   ->setPointsType('WE')
                   ->setStoreId(Mage::app()->getStore()->getId())
                   ->setExpireDate($expireDate)
                   ->save();

每个字段都保存在表中,expire_date 除外。如果我取消注释 die($expireData),我会看到正确的值,例如 2012-01-13 13:21:12。该字段定义为:

`expire_date` datetime NULL

有什么想法吗?

编辑:解决办法是:

$expireDate = date("Y-m-d H:i:s", strtotime("+" . $expireMonth . " months"));

查看我的 strtotime 表达式中的“s”。

【问题讨论】:

    标签: magento model save


    【解决方案1】:

    我知道许多属性允许在写入之前和之后进行某种格式设置。您是否尝试将值设置为 unix 时间戳?

    【讨论】:

    • 天啊!!!事实证明,我的 strtotime 表达式中缺少一个“s”,它必须是“months”,而不是“month”。你的答案并不是真正的解决方案,但你让我思考它并帮助我找到它,所以,这里有几点;)thanx clockworkgeek,再见
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-14
    相关资源
    最近更新 更多