如何保存客户自定义属性在magento 2



我已经通过在现有客户实体中扩展期间安装模式成功地安装了新的自定义属性。

我的问题是每当我试图保存客户时,它都会给我下面的错误。

致命错误:调用/var/网址/html/magento2/lib/internal/magento/framework/objectmanager/Factory/AbstractFactory.php中非对象的成员函数get()

我试图通过下面的代码保存客户属性:

$customerData[MagentoFrameworkApiCustomAttributesDataInterface::CUSTOM_ATTRIBUTES] = [MagentoFrameworkApiAttributeInterface::ATTRIBUTE_CODE=>'md_customer_profile_id',MagentoFrameworkApiAttributeInterface::VALUE=>$customerProfileId];
$this->dataObjectHelper->populateWithArray($customerObject, $customerData, 'MagentoCustomerApiDataCustomerInterface');
$this->customerRepository->save($customerObject);

这是我为客户编写自定义属性的方法。

use MagentoCustomerApiCustomerRepositoryInterface;
use MagentoCustomerApiDataCustomerInterface;
use MagentoCustomerApiDataCustomerInterfaceFactory;
$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);

最新更新