【问题标题】:Add my custom attribute to customer object in Magento (1.7.x)将我的自定义属性添加到 Magento (1.7.x) 中的客户对象
【发布时间】:2014-05-09 10:10:43
【问题描述】:

我使用下面的 Magento 安装程序脚本创建了一个自定义属性:

$installer = new Mage_Eav_Model_Entity_Setup();
$installer->startSetup();

$installer->addAttribute('customer', 'organisation_id', array(
    'input'         => 'select', //or select or whatever you like
    'type'          => 'int', //or varchar or anything you want it
    'label'         => 'Organisation ID',
    'visible'       => 1,
    'required'      => 0, //mandatory? then 1
    'user_defined'  => 1,
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,

));

$installer->endSetup();

在单页结帐屏幕上,我有一个下拉菜单,客户从下拉菜单中选择一个组织 - 一旦他们点击“继续”按钮,它就会发布一个 ajax 请求并进入下一步“计费”,例如发布请求看起来像这样..

org[organisation_id] - 12345
org[name] - ACME Inc

我处理此问题的函数如下 - 任何人都可以帮助如何将其添加到客户和订单对象中?

public function saveOrgAction()
{
    if ($this->_expireAjax()) {
        return;
    }
    if ($this->getRequest()->isPost()) {
        $data = $this->getRequest()->getPost('org', array());

        // todo:hook up saving the org id passed here to customer & order object

        // UPDATE... I believe this is correct?
        $customer = Mage::getSingleton('customer/session')->getCustomer(); // get customer object
        $customer->setOrganisationId($org_id)->save();

        if (!isset($result['error'])) {
            $result['goto_section'] = 'billing';
        }

        $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
    }
}

将此“organisation_id”属性添加到客户对象的最佳方法是什么(注意我使用的是 Magento 1.7.2)

【问题讨论】:

标签: magento model-view-controller frameworks e-commerce


【解决方案1】:
$customer->setOrganisationId('123')->save();

如果你需要它,你必须在当前引用对象中设置它 通过

$quote->setOrganisationId('123');

并使用此解释通过报价到订单转换自动推送属性。但不要忘记在 sales_flat_order 中创建正确的标签列!

explanation how to push any attribute automatically through quote to order conversion

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-25
    • 1970-01-01
    • 2023-03-28
    相关资源
    最近更新 更多