마 젠토 2 ui_component 형식으로 고객 속성 표시


14

ui_component 양식을 만들었습니다 .

고객 세부 사항을 표시해야하는 경우 고객 편집 과 동일 합니다.

그러나 customer_entity테이블 에서 데이터를 표시 할 수 있습니다 .

DataProvider.php

public function getData()
{
    if (isset($this->loadedData)) {
        return $this->loadedData;
    }

    // {Vendor}\{Module}\Model\GridFactory 
    // Returns Customer Resource Model
    $items = $this->gridFactory->create()->getCollection();

   $items->getSelect()->join('customer_entity_text as second', 'main_table.entity_id = second.entity_id');
    //print_r($items->getData()); exit;
    foreach($items as $contact){
        $this->loadedData[$contact->getEntityId()]['contact'] = $contact->getData();
    }

    return $this->loadedData;
}

(고객 속성) customer_entity_text을 표시하기 위해 팩토리와 테이블을 결합했습니다 status.

이제 내 두 번째 속성은 file유형입니다. 에 있습니다 customer_entity_varchar. 먼저 다른 조인을 추가한다고 생각했지만 좋은 방법은 아니라고 생각합니다.

그래서, 이것에 대한 해결책이 있습니까? 둘 다 Customer Attribute내 양식 으로 표시해야합니다 .

ui_component

<field name="value">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="label" xsi:type="string">Status</item>
                <item name="visible" xsi:type="boolean">true</item>
                <item name="dataType" xsi:type="string">text</item>
                <item name="formElement" xsi:type="string">input</item>
                <item name="source" xsi:type="string">contact</item>
            </item>
        </argument>
    </field>

1). 위 구성 요소는 상태에 적합 하지만 이미지 유형 인 프로파일 이미지 에는 적합하지 않습니다 .

<field name="value">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="label" xsi:type="string">Profile Image</item>
                <item name="visible" xsi:type="boolean">true</item>
                <item name="formElement" xsi:type="string">fileUploader</item>
                <item name="uploaderConfig" xsi:type="array">
                    <item name="url" xsi:type="url" path="path_controller"/>
                </item>
            </item>
        </argument>
    </field>

같은 이름을 가진 하나의 필드를 제거해 form element도 작동하지 않는 것 같습니다.

한 번 봐 가지고 field있다 이름 value에 대한 상태 .

이미지 필드 와 동일한 것을 사용하면 이미지 구성 요소가 사라집니다.

참고 : Magento가 이름을로 사용할 수없는 이유를 모르겠습니다 value.

원인 컬렉션에 가입했기 때문에 value배열 키로 사용됩니다.

** 질문 : 컬렉션에 참여하지 않고이 양식으로 고객 속성을 얻으려면 어떻게해야합니까?

또한 가장 환영받는 것 이외의 다른 솔루션이 있다면 **


사용중인 새 속성이 고객 엔티티의 기본 속성 세트에 있는지 확인할 수 있습니까?
— 불분명

자신의 질문을 다시 읽을 수 있습니까? 질문을 읽을 때 질문이 이해가되지 않습니다. 따라서 문제를 해결하는 데 도움이되지 않습니까?
— Herve Tribouilloy

나머지는 잊어 버리십시오. 사용자 정의 UI 양식에 고객 속성을 표시하려면 어떻게해야합니까? 하나는 이미지가 있고 다른 하나는 텍스트입니다.
— TBS 마법사

프론트 엔드 또는 백엔드에서 양식을 작성하기위한 질문이 있습니까?
— Herve Tribouilloy

답변:


0

다음과 같이 설정 스크립트를 사용하여 customer_entity 테이블 의 관계로 사용자 정의 테이블을 작성해야 합니다.

$relationalTable = 'custom_table';  
$table = $setup->getConnection()
    ->newTable($setup->getTable($relationalTable))
    // --- Add your other columns here ---
    ->addColumn('customer_id', Table::TYPE_INTEGER, 10, ['nullable' => false, 'unsigned' => true],
            'Customer Id')
    ->addForeignKey(
        $setup->getFkName(
            $relationalTable,           // priTableName
            'customer_id',              // priColumnName
            'customer_entity',          // refTableName
            'entity_id'                 // refColumnName
        ),
        'customer_id',                  // column
        $setup->getTable('customer_entity'),    
        'entity_id',                    // refColumn
        Table::ACTION_CASCADE           // onDelete
    )
    ->setComment('Customer relation table');

$setup->getConnection()->createTable($table);

그런 다음 고객 모델을로드하고 다음과 같이 DataProvider.php의 getData () 함수에서 사용자 정의 테이블을 조인해야합니다.

protected $_customerModel;

public function __construct(
    \Magento\Customer\Model\CustomerFactory $customerModel
) {
    $this->_customerModel = $customerModel;
}

public function getData()
{
    if (isset($this->loadedData)) {
        return $this->loadedData;
    }

   $customer = $this->_customerModel->create();
    $collection = $customer->getCollection();
    $collection->getSelect()->join(
        ['custom' => $this->_resource->getTableName('custom_table')],
        'e.entity_id = custom.customer_id'
    );

    foreach($collection as $item){
        $this->loadedData[$item->getId()]['contact'] = $item->getData();
        // Using $item->getData(), you can get customer object with custom attributes as $item->getStatus() or $item->getProfileImage()
    }

    return $this->loadedData;
}

이제 다음과 같이 ui_component에서 필드 이름을 사용할 수 있습니다.

<field name="status"> <!-- your custom attribute code as field name -->
...
</field>

<field name="profile_image"> <!-- your custom attribute code as field name -->
...
</field>

이 솔루션으로 문제가 해결되기를 바랍니다.


내 질문 " magento.stackexchange.com/questions/257577/… "을 통해 도움이 필요합니다
— Rv Singh
당사 사이트를 사용함과 동시에 당사의 쿠키 정책과 개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.