Magento,1 个 db 字段未保存

发布于 2024-10-11 23:53:50 字数 1378 浏览 3 评论 0原文


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

$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”。

I have a problem with one field of the DB. With this code:

$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();

Every field is saved in the table, except for expire_date. If I uncomment the die($expireData), I see the correct value, something like 2012-01-13 13:21:12. The field is defined as:

`expire_date` datetime NULL

Any thoughts?

edit: The solution is:

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

Check out the "s" in my strtotime expression.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

携君以终年 2024-10-18 23:53:50

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

I know many attributes allow for some sort of formatting before writing and after reading. Have you tried setting the value as a unix timestamp instead?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文