Magento2 마이그레이션 된 사용자 지정 고객 속성이 값을 저장하지 않습니다.

Aug 21 2020

Magento 데이터를 버전 1.9.0.1에서 버전 2.3.5-p1로 마이그레이션했습니다. 1.9.0.1 설정에는 mobile_no라는 사용자 지정 고객 속성이 생성되었습니다. M2 설정에서 데이터와 속성이 자동으로 생성되었습니다. mobile_no 데이터는 M2 관리자에서도 볼 수 있습니다. 그러나 번호를 편집하고 저장하려고하면 업데이트 된 값을 사용하지 않고 이전 값을 저장합니다. 누구든지 이것으로 나를 도울 수 있습니까? 프런트 엔드 등록 양식에서이 속성을 호출해야합니다.

답변

2 PratsMagento Aug 27 2020 at 08:04

여러 가지를 확인하고 데이터베이스를 파헤친 후 마침내 문제를 발견하여 답변을 공유했습니다. 문제는 마이그레이션 후 eav_entity_attribute각 속성 에 대한 표 에서 항목이 누락되었습니다 . 아래 데이터 패치를 사용하여 속성을 업데이트하고 문제를 수정했습니다. 이제 값을 저장할 수 있습니다.

<?php declare(strict_types=1);

/**
 * Patch for the Customer Attribute
 *
 * Patch Class to update the migrated field mobile_no in the `eav_entity_attribute` table. 
 */

namespace VendorName\ModuleName\Setup\Patch\Data;

use Zend_Validate_Exception;
use Magento\Eav\Model\Config;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Eav\Model\Entity\Attribute\Source\Boolean;
use Magento\Eav\Model\Entity\Attribute\SetFactory as AttributeSetFactory;

/**
 * Patch Class to update the mobile_no in the `eav_entity_attribute` table.
 */
class UpdateEavMobileNoAttribute implements DataPatchInterface
{
    /**
     * @var Config
     */
    private $eavConfig; /** * @var EavSetupFactory */ private $eavSetupFactory;

    /**
     * @var AttributeSetFactory
     */
    private $attributeSetFactory; /** * AddressAttribute constructor. * * @param Config $eavConfig
     * @param EavSetupFactory     $eavSetupFactory * @param AttributeSetFactory $attributeSetFactory
     */
    public function __construct(
        Config $eavConfig, EavSetupFactory $eavSetupFactory,
        AttributeSetFactory $attributeSetFactory ) { $this->eavConfig = $eavConfig; $this->eavSetupFactory = $eavSetupFactory; $this->attributeSetFactory = $attributeSetFactory; } /** * {@inheritdoc} */ public static function getDependencies(): array { return []; } /** * Create strategic account customer attribute * @return void * @throws LocalizedException * @throws Zend_Validate_Exception */ public function apply(): void { $eavSetup = $this->eavSetupFactory->create(); $customerEntity = $this->eavConfig->getEntityType('customer'); $attributeSetId = $customerEntity->getDefaultAttributeSetId(); $attributeSet = $this->attributeSetFactory->create(); $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);

        $customAttribute = $this->eavConfig->getAttribute('customer', 'mobile_no');

        $customAttribute->addData([ 'attribute_set_id' => $attributeSetId,
            'attribute_group_id' => $attributeGroupId, 'used_in_forms' => ['adminhtml_customer', 'customer_account_edit'] ]); $customAttribute->save();

    }

    /**
     * {@inheritdoc}
     */
    public function getAliases(): array
    {
        return [];
    }
}