php - 将值插入我在 Magento 数据库中创建的新字段

标签 php mysql magento newsletter

对于 magento 开发人员来说,我的问题可能很蹩脚,但我对该平台非常陌生。我在新闻通讯订阅中添加了一个名为优惠类型的新输入字段,因为我鼓励用户订阅以获得促销代码。

我添加了隐藏在静态页面中的输入类型

<input placeholder="email: example@example.com" class="email-offer-revealer" name="email" required="" autocapitalize="off" autocorrect="off" spellcheck="false" type="email">
<input name="couponName" value="first offer" type="hidden">

在 app/code/core/Mage/Newsletter/controllers/SubscriberController.php 中,我添加了以下行

 $offer = (string) $this->getRequest()->getPost('couponName');
 $status = Mage::getModel('newsletter/subscriber')->subscribe($email,$offer);

在app/code/core/Mage/Newsletter/Model/Subscriber.php中我添加了以下内容

 public function subscribe($email, $offer){

$offer 作为新参数插入到数据库中新闻通讯表的优惠字段中。 我被告知 Magento 会让我自动访问 getOffer 和 setOffer 所以我为相同的方法添加了以下内容

$this->setOffer($offer);

问题是我可以回显该值,但我无法将其插入数据库,只能插入电子邮件,接下来是什么?

谢谢

最佳答案

当您更新模型中的某些值时,您可以尝试调用 save 将新值放入数据库中。

类似于:

$quote->setCouponCode();

$quote->保存();

关于php - 将值插入我在 Magento 数据库中创建的新字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43049895/

相关文章:

magento - 仅选择Magento中的特定字段

php - 如何在 Windows 上创建 PHP 扩展?

javascript - 多个ajax倒数计时器的建议(每秒调用一次)

mysql - 如何从 MySQL 中的表的每一列的名称中删除前缀?

java - Solr:缺少内容流,Magento:重新索引时出错

web-services - Magento 网络服务 API 产品选项

php - filter_var 密码

php - 检查该行是否存在于数据库中

PHP MySQL 发票 Material

mysql - 处理 mysql 数据库连接