Magento2 을 저장하는 방법을 사용자 정의 필드에 추가된 형태의 고객 그룹?
-
13-12-2019 - |
문제
추가했 일부 사용자 정의 필드의 형태로 고객 그룹을 사용하여 upgradeSchema.php
.
후에는 내가 발견되는 원본과 같은 분야의 고객 그룹 코드고 세 id 를 사용하여 저장 setter 방법에는 API 를 제공합니다.그것은 완전히 다른 젠토 1.X 는 사용 setxxx 메소드()를 저장합니다.
해결책
확장 특성 메커니즘에 사용되어야 하는 이 경우입니다.그것은 허용 확장자의 핵심 Api 제 3 자에 의해 모듈을 사용합니다.일반적인 단계 활성화에 대한 새로운 확장 속성:
- 선언 확장 특성으로서에서 설명 공식적인 문서.후 삭제
var
실행<project_root>/bin/magento setup:di:compile
, 해당 세터 및 getter 이 새로운 특성에 나타나야 합니다\Magento\Customer\Api\Data\GroupExtensionInterface
(이 인터페이스를 자동 생성) - 플러그인을 작성
\Magento\Customer\Api\GroupRepositoryInterface::save
,\Magento\Customer\Api\GroupRepositoryInterface::getById
(그리고 다른 서비스 방법으로 필요시)/저장하려면 로드하는 새로운 특성이 있습니다.의 확장으로 개발자,당신만이 알고 있는 이 특성을 저장할 수 있습니다.보\Magento\Downloadable\Model\Plugin\AroundProductRepositorySave::aroundSave
로 예 - 필요하신 경우에는 이 특성 컬렉션에서 볼 수 있(게 검색 가능/필터링)선언
join
노드입니다.그렇지 않으면 그냥 건너뛰기 - 액세스 사용자 지정 특성:
$customerGroup->getExtensionAttributes()->getMyAttribute()
, 디customerGroup
를 구현하는\Magento\Customer\Api\Data\GroupInterface
.setMyAttribute()
로 사용할 수 있습라
아래의 예를 구성해야할 VendorName/ModuleName/etc/extension_attributes.xml
<?xml version="1.0"?>
<config>
<extension_attributes for="Magento\Customer\Api\Data\GroupInterface">
<!--Data interface can be used as a type of attribute, see example in CatalogInventory module-->
<attribute code="name_of_attribute" type="string">
<resources>
<resource ref="VendorName_ModuleName::someAclNode"/>
</resources>
<!--Join is optional, only if you need to have added attribute visible in groups list-->
<join reference_table="table_where_attribute_is_stored" reference_field="group_id_field_in_that_table" join_on_field="group_id">
<field>name_of_added_attribute_field_in_that_table</field>
</join>
</attribute>
</extension_attributes>
</config>
다른 팁
모듈이 register.php
파일이 필요하다는 것을 잊지 마십시오. 표시되기 전에 bin/magento module:enable VendorName_ModuleName
를 사용해야합니다!
제휴하지 않습니다 magento.stackexchange