3

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

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

致命错误:在第 236 行的 /var/www/html/magento2/lib/internal/Magento/Framework/ObjectManager/Factory/AbstractFactory.php 中的非对象上调用成员函数 get()

我正在尝试通过以下代码保存客户属性:

$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);
4

1 回答 1

-1

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

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);
于 2018-01-12T12:24:07.533 回答