0

I am having problems when trying to add a new customer. I've tried the following but I am not sure if the name spacing is inaccurate?

public function __construct(
    \Magento\Framework\View\Element\Template\Context $context,
    \Magento\Customer\Model\Session $sessionSession,
    \Magento\Customer\Model\Customer $customerModel,
    array $data = []
) {
    parent::__construct($context, $data);
    $this->_customerSession = $sessionSession;
    $this->customerModel = $customerModel;
}


public function createUser()
{
    /** @var \Magento\Customer\Model\ $model */
    $model = $this->customerModel;

    $model->load($customerId);
    $model->setName("James");

    try{
        $model->save();
    }
    catch(\Exception $e){
        $this->systemHelper->setErrorMessage($e);
        return false;
    }
}

When I step over this the try/catch actually doesn't throw any errors?

tim.baker
  • 843
  • 1
  • 12
  • 29
  • die(var_dump($model)); <--- Add this after you load the customer.

    Also, where are you setting $customerId ? As far as i can see from your code, it's currently an empty variable, so model is not loading anything, therefore not saving anything.

    – Radosav Aug 30 '16 at 13:41
  • The customer ID would actually be null - it doesn't exist yet - I'm trying to create one! – tim.baker Aug 30 '16 at 14:31
  • 1
    This is not the way you do that in Magento2 , you do not need to use the Model for customer, you need to use the CustomerFactory. Refer to this – Radosav Aug 30 '16 at 22:05

0 Answers0