Magento更改默认付款方式

杰姆斯

我有一个功能,可以对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
            )
        );
    }
}
编码

如果我没看错代码,就想default_payment用给定的值更新客户属性

为此,您需要:

  • 通过ID加载客户
  • 为客户属性设置新值 default_payment
  • 保存客户
public function setDefaultPayment($value)
{
    $customerId = $this->_getSession()->getCustomer()->getId();
    $write = Mage::getSingleton('core/resource')->getConnection('core_write');

    $customer = Mage::getModel('customer/customer')->load($customerId);
    $oldValue = $customer->getDefaultPayment(); // optional, just for checking
    $customer->setDefaultPayment($value);
    $customer->save();

}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Magento更改默认付款方式

来自分类Dev

Magento:购物车,付款方式订购

来自分类Dev

magento:已付款多少和运输方式

来自分类Dev

Magento:无法检索付款方式实例

来自分类Dev

WooCommerce-取消选择默认付款方式

来自分类Dev

Magento选择特定的送货方式后如何删除付款方式

来自分类Dev

从Magento发票pdf中删除运输方式和付款方式

来自分类Dev

基于Woocommerce选择的付款方式结账图像更改付款按钮

来自分类Dev

Magento-OnePage Checkout-根据付款方式隐藏付款方式

来自分类Dev

如何通过编程方式在magento中将付款方式从现有订单的一种更改为另一种?

来自分类Dev

Magento Collection通过付款方式吸引客户

来自分类Dev

自定义付款方式Magento-$ _formBlockType

来自分类Dev

magento自定义付款方式重定向

来自分类Dev

Magento; 更改客户登录方式

来自分类Dev

Braintree不更新用户首选/默认付款方式

来自分类Dev

C#Stripe使用默认付款方式创建客户无效

来自分类Dev

条纹-客户的默认付款方式不在卡对象中

来自分类Dev

Braintree不更新用户首选/默认付款方式

来自分类Dev

以编程方式更改默认场景

来自分类Dev

在WooCommerce结帐中更改特定产品的付款方式标题

来自分类Dev

在 WooCommerce 中更改特定付款方式的结帐提交按钮文本

来自分类Dev

在magento中以编程方式更改翻译语言

来自分类Dev

在magento中以编程方式更改翻译语言

来自分类Dev

更改默认TTY快捷方式

来自分类Dev

限制magento 1.9.0中某些邮政编码的默认货到付款

来自分类Dev

Magento付款方式不要求我提供我的商人帐户

来自分类Dev

在magento中基于自定义API的付款方式中实现3D安全验证

来自分类Dev

Magento-获取totals.phtml中按顺序使用的付款方式

来自分类Dev

如何获取magento2中的所有订单付款方式信息

Related 相关文章

  1. 1

    Magento更改默认付款方式

  2. 2

    Magento:购物车,付款方式订购

  3. 3

    magento:已付款多少和运输方式

  4. 4

    Magento:无法检索付款方式实例

  5. 5

    WooCommerce-取消选择默认付款方式

  6. 6

    Magento选择特定的送货方式后如何删除付款方式

  7. 7

    从Magento发票pdf中删除运输方式和付款方式

  8. 8

    基于Woocommerce选择的付款方式结账图像更改付款按钮

  9. 9

    Magento-OnePage Checkout-根据付款方式隐藏付款方式

  10. 10

    如何通过编程方式在magento中将付款方式从现有订单的一种更改为另一种?

  11. 11

    Magento Collection通过付款方式吸引客户

  12. 12

    自定义付款方式Magento-$ _formBlockType

  13. 13

    magento自定义付款方式重定向

  14. 14

    Magento; 更改客户登录方式

  15. 15

    Braintree不更新用户首选/默认付款方式

  16. 16

    C#Stripe使用默认付款方式创建客户无效

  17. 17

    条纹-客户的默认付款方式不在卡对象中

  18. 18

    Braintree不更新用户首选/默认付款方式

  19. 19

    以编程方式更改默认场景

  20. 20

    在WooCommerce结帐中更改特定产品的付款方式标题

  21. 21

    在 WooCommerce 中更改特定付款方式的结帐提交按钮文本

  22. 22

    在magento中以编程方式更改翻译语言

  23. 23

    在magento中以编程方式更改翻译语言

  24. 24

    更改默认TTY快捷方式

  25. 25

    限制magento 1.9.0中某些邮政编码的默认货到付款

  26. 26

    Magento付款方式不要求我提供我的商人帐户

  27. 27

    在magento中基于自定义API的付款方式中实现3D安全验证

  28. 28

    Magento-获取totals.phtml中按顺序使用的付款方式

  29. 29

    如何获取magento2中的所有订单付款方式信息

热门标签

归档