2015-08-22 3 views
3

Я успешно установил новый пользовательский атрибут через схему установки во время расширения существующего объекта клиента.Как сохранить пользовательский атрибут пользователя в magento 2

Моя проблема в том, когда когда-либо я пытался спасти клиента, он дал мне ошибку, как показано ниже.

Fatal error: Call to a member function get() on a non-object in /var/www/html/magento2/lib/internal/Magento/Framework/ObjectManager/Factory/AbstractFactory.php on line 236

Я пытаюсь сохранить атрибут клиента через ниже код:

$customerData[\Magento\Framework\Api\CustomAttributesDataInterface::CUSTOM_ATTRIBUTES] = [\Magento\Framework\Api\AttributeInterface::ATTRIBUTE_CODE=>'md_customer_profile_id',\Magento\Framework\Api\AttributeInterface::VALUE=>$customerProfileId]; 
$this->dataObjectHelper->populateWithArray($customerObject, $customerData, '\Magento\Customer\Api\Data\CustomerInterface'); 
$this->customerRepository->save($customerObject); 

ответ

0

Это, как я пишу пользовательские атрибуты для клиентов.

use Magento\Customer\Api\CustomerRepositoryInterface; 
use Magento\Customer\Api\Data\CustomerInterface; 
use Magento\Customer\Api\Data\CustomerInterfaceFactory; 

$this->objectManager = Bootstrap::create(BP, $_SERVER)->getObjectManager(); 
$this->customerRepo = $this->objectManager->create(CustomerRepositoryInterface::class); 

/** @var CustomerInterface $customer */ 
$customer = $factory->create(); 

// Create new Customer 
$factory = $this->objectManager->create(CustomerInterfaceFactory::class); 

// Set custom attribute 
$customer->setCustomAttribute('my_custom_attribute_customer_profile_id', '123abc'); 


$this->customerRepo->save($customer); 
Смежные вопросы