/**
  * {@inheritdoc}
  */
 public function deleteById($customerId)
 {
     $customerModel = $this->customerRegistry->retrieve($customerId);
     $customerModel->delete();
     $this->customerRegistry->remove($customerId);
     return true;
 }
Ejemplo n.º 2
0
 /**
  * Save customer address.
  *
  * @param \Magento\Customer\Api\Data\AddressInterface $address
  * @return \Magento\Customer\Api\Data\AddressInterface
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function save(\Magento\Customer\Api\Data\AddressInterface $address)
 {
     $addressModel = null;
     $customerModel = $this->customerRegistry->retrieve($address->getCustomerId());
     if ($address->getId()) {
         $addressModel = $this->addressRegistry->retrieve($address->getId());
     }
     if ($addressModel === null) {
         $addressModel = $this->addressFactory->create();
         $addressModel->updateData($address);
         $addressModel->setCustomer($customerModel);
     } else {
         $addressModel->updateData($address);
     }
     $inputException = $this->_validate($addressModel);
     if ($inputException->wasErrorAdded()) {
         throw $inputException;
     }
     $addressModel->save();
     // Clean up the customer registry since the Address save has a
     // side effect on customer : \Magento\Customer\Model\Resource\Address::_afterSave
     $this->customerRegistry->remove($address->getCustomerId());
     $this->addressRegistry->push($addressModel);
     $customerModel->getAddressesCollection()->clear();
     return $addressModel->getDataModel();
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function saveAddresses($customerId, $addresses)
 {
     $customerModel = $this->customerRegistry->retrieve($customerId);
     $addressModels = [];
     $inputException = new InputException();
     for ($i = 0; $i < count($addresses); $i++) {
         $address = $addresses[$i];
         $addressModel = null;
         if ($address->getId()) {
             $addressModel = $customerModel->getAddressItemById($address->getId());
         }
         if (is_null($addressModel)) {
             $addressModel = $this->addressConverter->createAddressModel($address);
             $addressModel->setCustomer($customerModel);
         } else {
             $this->addressConverter->updateAddressModel($addressModel, $address);
         }
         $inputException = $this->_validate($addressModel, $inputException, $i);
         $addressModels[] = $addressModel;
     }
     $this->customerRegistry->remove($customerId);
     if ($inputException->wasErrorAdded()) {
         throw $inputException;
     }
     $addressIds = array();
     /** @var \Magento\Customer\Model\Address $addressModel */
     foreach ($addressModels as $addressModel) {
         $addressModel->save();
         $this->addressRegistry->remove($addressModel->getId());
         $addressIds[] = $addressModel->getId();
     }
     return $addressIds;
 }
Ejemplo n.º 4
0
 /**
  * @magentoDataFixture Magento/Customer/_files/customer.php
  * @expectedException \Magento\Framework\Exception\NoSuchEntityException
  * @magentoAppArea adminhtml
  */
 public function testRemove()
 {
     $customer = $this->_model->retrieve(self::CUSTOMER_ID);
     $this->assertInstanceOf('\\Magento\\Customer\\Model\\Customer', $customer);
     $customer->delete();
     $this->_model->remove(self::CUSTOMER_ID);
     $this->_model->retrieve(self::CUSTOMER_ID);
 }
 public function testRemove()
 {
     $this->customer->expects($this->exactly(2))->method('load')->with(self::CUSTOMER_ID)->will($this->returnValue($this->customer));
     $this->customer->expects($this->any())->method('getId')->will($this->returnValue(self::CUSTOMER_ID));
     $this->customerFactory->expects($this->exactly(2))->method('create')->will($this->returnValue($this->customer));
     $actual = $this->customerRegistry->retrieve(self::CUSTOMER_ID);
     $this->assertEquals($this->customer, $actual);
     $this->customerRegistry->remove(self::CUSTOMER_ID);
     $actual = $this->customerRegistry->retrieve(self::CUSTOMER_ID);
     $this->assertEquals($this->customer, $actual);
 }
 /**
  * Retrieve customer data by Id
  *
  * @param int $customerId
  * @return \Magento\Customer\Api\Data\CustomerInterface
  */
 protected function _getCustomerData($customerId)
 {
     $customerData = $this->customerRepository->getById($customerId);
     $this->customerRegistry->remove($customerId);
     return $customerData;
 }
 /**
  * {@inheritdoc}
  */
 public function deleteCustomerByEmail($customerEmail, $websiteId = null)
 {
     $customerModel = $this->customerRegistry->retrieveByEmail($customerEmail, $websiteId);
     $customerId = $customerModel->getId();
     $customerModel->delete();
     $this->customerRegistry->remove($customerId);
     return true;
 }