【问题标题】:Get value from customer_entity_varchar - Magento从 customer_entity_varchar 获取价值 - Magento
【发布时间】:2017-04-20 00:00:03
【问题描述】:

我在后端 magento 中创建了一个客户属性,但我想将此属性显示给用户,以便他可以在前端更改其值。我的输入字段显示在前端,但值不存在。我无法得到这个值。我发现我需要显示的值在 apscustomer_entity_varchar 表中,该列称为“值”。如何从该表中获取该值?我正在尝试这个:

$collection = Mage::getModel('eav/entity_attribute')->getCollection();
foreach ($collection as $data) {
  return $data;
}

但它不起作用,所以我使用了 SQL 代码并且它起作用了。但是我知道这不是在 Magento 中做到这一点的好方法。我所做的是这样的:

$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
$sql        = "SELECT * FROM `apscustomer_entity_varchar ` WHERE `entity_id`='$id'";
$rows       = $connection->fetchAll($sql); 

如何使用 getModel 以 magento 方式从我的 apscustomer_entity_varchar 表中获取值列?

【问题讨论】:

    标签: sql database magento orm


    【解决方案1】:

    你需要检索会话的客户,然后你才能得到你想要的属性:

    Mage::getSingleton('customer/session')->getData('attributeName');
    Mage::getSingleton('customer/session')->getAttributeName(); //Magic getter
    

    其中attributeName是要取值的属性的名称。

    【讨论】:

      【解决方案2】:

      我发现了如何做到这一点:D

      其实很简单。即使这是一个自定义客户属性(在 Magento 管理面板中创建),我也需要不使用“eav/entity_attribute”模型,而是使用“客户/客户”模型来获取属性。所以我只需要这样做:

      $customer_data = Mage::getModel('customer/customer')->load($customer_id)->getData();
      echo $customer_data['attributeThatYouWant'];
      

      如果您不确定您的属性名称是什么,您可以查看客户/管理属性下的 Magento 管理面板,或者您可以在获取模型后使用它:

      var_dump($customer_data);
      

      现在您可以获取所有客户属性的名称。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-08-15
        • 2017-01-08
        • 2012-10-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多