【发布时间】:2016-05-12 00:25:09
【问题描述】:
我有一个函数可以在 Magento 中对我们的数据库运行原始 SQL 查询。该函数所做的是将客户的默认信用卡更改为传递给该函数的值。我的问题是如何使用 Magento 模型重写函数。当前函数可以工作,但我们宁愿它不直接与 SQL 接口。
函数如下:
public function setDefaultPayment($value)
{
$customerId = $this->_getSession()->getCustomer()->getId();
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
$read = $write->query("SELECT entity_type_id FROM eav_entity_type WHERE entity_type_code='customer'");
$row = $read->fetch();
$entity_type_id = $row['entity_type_id'];
$read = $write->query("SELECT attribute_id FROM eav_attribute WHERE attribute_code='default_payment' AND entity_type_id = $entity_type_id");
$row = $read->fetch();
$attribute_id = $row['attribute_id'];
$read = $write->query("SELECT * FROM customer_entity_int WHERE entity_type_id='$entity_type_id' AND attribute_id='$attribute_id' AND entity_id='$customerId'");
if ($row = $read->fetch()) {
$write->update(
'customer_entity_int',
array('value' => $value),
"entity_type_id='$entity_type_id' AND attribute_id='$attribute_id' AND entity_id='$customerId'"
);
} else {
$write->insert(
'customer_entity_int',
array(
'entity_type_id' => $entity_type_id,
'attribute_id' => $attribute_id,
'entity_id' => $customerId,
'value' => $value
)
);
}
}
【问题讨论】:
-
您的自定义类扩展了什么原生 Magento 类?
-
属性“default_payment”从何而来?一个扩展?你是怎么创造的? - 通常信用卡数据不会存储在 Magento 中,因为 99% 运行 Magento 的商家不符合 PCI DSS (en.wikipedia.org/wiki/…)
-
@codedge,我没有创建这个。我最近在一家使用完全非标准 Magento 实践的公司接受了一份工作,甚至更换了 Magento 本身的部分核心。换句话说,我们被锁定到特定版本的 magento (1.9)。我们正在修改网站并使其成为标准。
标签: magento magento-1.9