설치 스크립트를 사용하여 고객에 대한 다중 선택 속성을 작성하는 방법은 무엇입니까?


9

많은 기사를 따르고 있지만 다중 선택 속성을 만들 수 없습니다. 그리고 나는 다음과 같은 오류가 발생합니다.

a : 5 : {i : 0; s : 50 : "속성"exinent1 "에 대한 소스 모델" "을 찾을 수 없음"; i : 1; s : 3008 : "# 0 C : \ wamp \ www \ magento8 \ app \ code \핵심.

내 스크립트는 다음과 같습니다

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

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');

$entityTypeId     = $setup->getEntityTypeId('customer');
$attributeSetId   = $setup->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);

$setup->addAttribute('customer', 'exinent1', array(
    'input'         => 'multiselect', 
    'type'          => 'varchar', 
    'backend'       => 'eav/entity_attribute_backend_array',
    'label'         => 'exinent1',
    'visible'       => 1,
    'required'      => 0,
    'user_defined'  => 1,
    'option'        => array (
                'value' => array('optionone' => array('First Option'),
                         'optiontwo' => array('Second Option'),
                         'optionthree' => array('Third Option'),
                         )
                        ),

));

$setup->addAttributeToGroup(
 $entityTypeId,
 $attributeSetId,
 $attributeGroupId,
 'exinent1',
 '100'
);

$oAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'exinent1');
$oAttribute->setData('used_in_forms', array('adminhtml_customer')); 
$oAttribute->save();

$setup->endSetup();

config.xml은 다음과 같습니다.

<?xml version="1.0"?>
<config>
    <modules>
        <Exinent_Cusatt>
            <version>3.1.5.6</version>
        </Exinent_Cusatt>
    </modules>
    <global>
    <resources>
    <exinent_cusatt_setup>
        <setup>
            <module>Exinent_Cusatt</module>
        </setup>
    </exinent_cusatt_setup>
</resources>
    </global>
</config>

EAV 자원 모델을 설정해야합니다.
— Elavarasan

당신은 어떤 기사를 참조 할 수 있습니까?
— sivakumar

답변:


10

많은 실수를했다고 생각합니다.

etc / config.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Exinent_Cusatt>
      <version>0.1.0</version>
    </Exinent_Cusatt>
  </modules>
  <global>
    <helpers>
      <cusatt>
        <class>Exinent_Cusatt_Helper</class>
      </cusatt>
    </helpers>
    <models>
      <cusatt>
        <class>Exinent_Cusatt_Model</class>
        <resourceModel>cusatt_mysql4</resourceModel>
      </cusatt>
    </models>
    <resources>
      <customerattribute1404212233_setup>
        <setup>
          <module>Exinent_Cusatt</module>
          <class>Mage_Customer_Model_Entity_Setup</class>
        </setup>
        <connection>
          <use>core_setup</use>
        </connection>
      </customerattribute1404212233_setup>
      <customerattribute1404212233_write>
        <connection>
          <use>core_write</use>
        </connection>
      </customerattribute1404212233_write>
      <customerattribute1404212233_read>
        <connection>
          <use>core_read</use>
        </connection>
      </customerattribute1404212233_read>
    </resources>
  </global>
</config> 

헬퍼 /Data.php :

<?php
class Exinent_Cusatt_Helper_Data extends Mage_Core_Helper_Abstract
{
}

모드 / 이브 / 엔티티 / 속성 / 소스 / 고객 옵션 14042122330.php

<?php
class Exinent_Cusatt_Model_Eav_Entity_Attribute_Source_Customeroptions14042122330 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")->__("Myoption-1"),
                    "value" =>  1
                ),

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

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

                array(
                    "label" => Mage::helper("eav")->__("Myoption-4"),
                    "value" =>  4
                ),

            );
        }
        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);
    }
}

sql / customerattribute1404212233_setup / mysql4-install-0.1.0.php

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


$installer->addAttribute("customer", "exinent",  array(
    "type"     => "text",
    "backend"  => "",
    "label"    => "exinent1",
    "input"    => "multiselect",
    "source"   => "cusatt/eav_entity_attribute_source_customeroptions14042122330",
    "visible"  => true,
    "required" => false,
    "default" => "",
    "frontend" => "",
    "unique"     => false,
    "note"       => ""

    ));

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


$used_in_forms=array();

$used_in_forms[]="adminhtml_customer";
        $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();

.. 모듈이 코드 풀을 선언하도록 설정하고 숫자와 혼동하지 마십시오 <customerattribute1404212233_setup> . 중복 항목을 방지하기 위해 속성 ID를 임의로 지정하지 않습니다. 건배 ..!


실제로 내 다중 선택 속성은 배송 조건입니다. 그리고 두 개의 열이있는 엔터티를 포함하는 하나의 모듈을 생성하고 있습니다 (배송 조건, 활성화 / 비활성화).이 엔티티를 생성 된 배송 조건 속성 옵션에 매핑해야합니다. .
— sivakumar

1

엘라 바라산과 시바 쿠마르

static .....에서 옵션 코드를 호출하는 것은 좋지 않습니다. Eav 테이블을 사용하여 가져 오기만하면됩니다.

$attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('customer','exinent1');
 $collection =Mage::getResourceModel('eav/entity_attribute_option_collection')
                ->setPositionOrder('asc')
                ->setAttributeFilter($attributeId)
                ->setStoreFilter(0)
                ->load();

surcemodel getAllOptions ()는

 public function getAllOptions()
    {

 if (is_null($this->_options)) {

        attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('customer','attribute_name');
 $collection =Mage::getResourceModel('eav/entity_attribute_option_collection')
                ->setPositionOrder('asc')
                ->setAttributeFilter($attributeId)
                ->setStoreFilter(0)
                ->load();
        $this->_options = $collection->toOptionArray()

    }
    }

실제로 내 다중 선택 속성은 배송 조건입니다. 그리고 두 개의 열이있는 엔터티 (배송 조건, 사용 가능, 비활성화)가 포함 된 하나의 모듈 (최종 모듈 작성자 사용)을 만들고 있습니다. 따라서이 엔터티를 생성 된 배송 조건 속성 옵션에 매핑해야합니다. 이것에 약간의 지시를주세요.
— sivakumar

나는 당신에게 말하고 있습니다. 약간의 변화가 필요합니다 Elavaras answer. 그냥 소스 모델 코드에서 코드를 변경하십시오
— Amit Bera

예를 들어 감사합니다. 예를 들어 모든 옵션이 동적입니다 (배송 조건 표에서 옵션 가져 오기). 스크립트 설치 후 일부 레코드를 비활성화합니다 (배송 조건). 그래서 고객 계정 정보에 반영됩니까?
— sivakumar
당사 사이트를 사용함과 동시에 당사의 쿠키 정책과 개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.