如何在Magento One Page Checkout中添加额外字段"下拉列表"

Rah*_*hul 10 php magento magento-1.7 magento-1.8 magento-1.9

我使用模块创建了以下自定义属性.

这是Customer的Dropdown-list属性.

它应显示在结帐页面(客户作为访客/现有用户)客户帐户页面,客户帐户创建/注册页面,管理员客户编辑页面上.

目前,我可以在客户地址的管理部分中看到属性.

我希望此属性在Checkout页面上也显示在客户地址部分中.

我有检查billing.phtml文件,因为其他属性是静态编写的,但我不知道如何在billing.phtml中编写自定义属性作为其下拉列表.以及更新其他文件以查看此属性.请让我知道我在哪里做错了或在我的代码中添加任何其他内容.

任何指导将不胜感激.

以下是我的代码 -

文件名 - /app/code/local/PS/PB/etc/config.xml

<?xml version="1.0"?>
<config>
  <modules>
    <PS_PB>
      <version>0.1.0</version>
    </PS_PB>
  </modules>
  <global>
    <helpers>
      <pb>
        <class>PS_PB_Helper</class>
      </pb>
    </helpers>
    <models>
      <pb>
        <class>PS_PB_Model</class>
        <resourceModel>pb_mysql4</resourceModel>
      </pb>
    </models>
    <resources>
      <customerattribute1462360584_setup>
        <setup>
          <module>PS_P</module>
          <class>Mage_Customer_Model_Entity_Setup</class>
        </setup>
        <connection>
          <use>core_setup</use>
        </connection>
      </customerattribute1462360584_setup>
      <customerattribute1462360584_write>
        <connection>
          <use>core_write</use>
        </connection>
      </customerattribute1462360584_write>
      <customerattribute1462360584_read>
        <connection>
          <use>core_read</use>
        </connection>
      </customerattribute1462360584_read>
    </resources>
  </global>
</config> 
Run Code Online (Sandbox Code Playgroud)

档案 - /app/code/local/PS/PB/Helper/Data.php

<?php
class PS_PB_Helper_Data extends Mage_Core_Helper_Abstract
{
}
Run Code Online (Sandbox Code Playgroud)

档案 - /app/code/local/PS/PB/Model/Eav/Entity/Attribute/Source/Customeroptions14623605840.php

<?php
class PS_PB_Model_Eav_Entity_Attribute_Source_Customeroptions14623605840 extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
{
    /**
     * Retrieve all options array
     *
     * @return array
     */
    public function getAllOptions()
    {
        if (is_null($this->_options)) {
            $this->_options = array(

                array(
                    "label" => Mage::helper("eav")->__("End Consumer / DIY"),
                    "value" =>  1
                ),

                array(
                    "label" => Mage::helper("eav")->__("Service Technician"),
                    "value" =>  2
                ),

                array(
                    "label" => Mage::helper("eav")->__("Other Professional"),
                    "value" =>  3
                ),

            );
        }
        return $this->_options;
    }

    /**
     * Retrieve option array
     *
     * @return array
     */
    public function getOptionArray()
    {
        $_options = array();
        foreach ($this->getAllOptions() as $option) {
            $_options[$option["value"]] = $option["label"];
        }
        return $_options;
    }

    /**
     * Get a text for option value
     *
     * @param string|integer $value
     * @return string
     */
    public function getOptionText($value)
    {
        $options = $this->getAllOptions();
        foreach ($options as $option) {
            if ($option["value"] == $value) {
                return $option["label"];
            }
        }
        return false;
    }

    /**
     * Retrieve Column(s) for Flat
     *
     * @return array
     */
    public function getFlatColums()
    {
        $columns = array();
        $columns[$this->getAttribute()->getAttributeCode()] = array(
            "type"      => "tinyint(1)",
            "unsigned"  => false,
            "is_null"   => true,
            "default"   => null,
            "extra"     => null
        );

        return $columns;
    }

    /**
     * Retrieve Indexes(s) for Flat
     *
     * @return array
     */
    public function getFlatIndexes()
    {
        $indexes = array();

        $index = "IDX_" . strtoupper($this->getAttribute()->getAttributeCode());
        $indexes[$index] = array(
            "type"      => "index",
            "fields"    => array($this->getAttribute()->getAttributeCode())
        );

        return $indexes;
    }

    /**
     * Retrieve Select For Flat Attribute update
     *
     * @param int $store
     * @return Varien_Db_Select|null
     */
    public function getFlatUpdateSelect($store)
    {
        return Mage::getResourceModel("eav/entity_attribute")
            ->getFlatUpdateSelect($this->getAttribute(), $store);
    }
}
Run Code Online (Sandbox Code Playgroud)

档案 - /app/code/local/PS/PB/sql/customerattribute1462360584_setup

    <?php
    $installer = $this;
    $installer->startSetup();


    $installer->addAttribute("customer_address", "cstpb",  array(
        "type"     => "int",
        "backend"  => "",
        "label"    => "Primary Business",
        "input"    => "select",
        "source"   => "pb/eav_entity_attribute_source_customeroptions14623605840",
        "visible"  => true,
        "required" => true,
        "default" => "",
        "frontend" => "",
        "unique"     => false,
        "note"       => ""

        ));

            $attribute   = Mage::getSingleton("eav/config")->getAttribute("customer_address", "cstpb");


    $used_in_forms=array();
    $used_in_forms[]="adminhtml_customer";
    $used_in_forms[]="checkout_register";
    $used_in_forms[]="customer_account_create";
    $used_in_forms[]="customer_account_edit";
    $used_in_forms[]="adminhtml_checkout";
    $used_in_forms[]="adminhtml_customer_address";
    $used_in_forms[]="customer_register_address";
    $used_in_forms[]="customer_address_edit";
            $attribute->setData("used_in_forms", $used_in_forms)
            ->setData("is_used_for_customer_segment", true)
            ->setData("is_system", 0)
            ->setData("is_user_defined", 1)
            ->setData("is_visible", 1)
            ->setData("sort_order", 100)
            ;
            $attribute->save();



    $installer->endSetup();
Run Code Online (Sandbox Code Playgroud)

XML文件 - /app/etc/modules/PS_PB.xml

<?xml version="1.0"?>
<config>
  <modules>
    <PS_PB>
      <active>true</active>
      <codePool>local</codePool>
      <version>0.1.0</version>
    </PS_PB>
  </modules>
</config>
Run Code Online (Sandbox Code Playgroud)

更新

在config.xml文件中进行更正后,其工作正常.

config.xml在>任何编辑器中编辑后检查浏览器中打开此文件的错误,以便显示错误.

现在该属性显示结帐页面和管理客户页面以及客户我的帐户部分,但在此部分中.我无法更新它.需要在config.xml fot customer_account标记中添加哪些字段.

我在config.xml中添加了这样的内容

<customer_account>
   <primary_business>
       <create>1</create>
         <update>1</update>
   </primary_business>
</customer_account>
Run Code Online (Sandbox Code Playgroud)

Ste*_*rek 1

尽管我没有运行它来测试,但您的安装脚本代码对我来说似乎是正确的。

首先,确保您的安装脚本正在执行。

第二,

您可以通过管理员导航至客户 > 属性 > 管理属性来创建“客户属性”。

http://awesomescreenshot.com/0b35uq1542

如果 Magento 的行为符合预期,那么它应该在配置的区域中显示您的属性。我建议首先手动创建属性并查看它是否显示。如果不是,则您的主题或其他扩展可能已覆盖负责呈现这些属性的代码。

一旦您知道主题在您想要的位置呈现您想要的内容,您就可以创建一个沙箱脚本来加载您的属性并获取数据。查看“管理员”创建的属性数据通常会显示我错过的内容。

像这样的东西:

<?php

require_once('app/Mage.php');
Mage::app()->setCurrentStore('0');
$attribute_id = 9999; // YOU ADMIN CREATED ATTRIBUTE ID
$attributeModel = Mage::getModel('eav/attribute')->load($attribute_id);
var_dump($attributeModel->getData());
Run Code Online (Sandbox Code Playgroud)