/**
  * @magentoDataFixture Magento/Customer/_files/customer.php
  * @magentoDataFixture Magento/Customer/_files/customer_address.php
  * @expectedException \Magento\Framework\Exception\NoSuchEntityException
  */
 public function testRemove()
 {
     $addressId = 1;
     $address = $this->_model->retrieve($addressId);
     $this->assertInstanceOf('\\Magento\\Customer\\Model\\Address', $address);
     $address->delete();
     $this->_model->remove($addressId);
     $this->_model->retrieve($addressId);
 }
Ejemplo n.º 2
0
 public function testRemove()
 {
     $addressId = 1;
     $address = $this->getMockBuilder('\\Magento\\Customer\\Model\\Address')->disableOriginalConstructor()->setMethods(['load', 'getId', '__wakeup'])->getMock();
     $address->expects($this->exactly(2))->method('load')->with($addressId)->will($this->returnValue($address));
     $address->expects($this->exactly(2))->method('getId')->will($this->returnValue($addressId));
     $this->addressFactory->expects($this->exactly(2))->method('create')->will($this->returnValue($address));
     $actual = $this->unit->retrieve($addressId);
     $this->assertEquals($address, $actual);
     $this->unit->remove($addressId);
     $actual = $this->unit->retrieve($addressId);
     $this->assertEquals($address, $actual);
 }
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
 /**
  * Delete customer address by ID.
  *
  * @param int $addressId
  * @return bool true on success
  * @throws \Magento\Framework\Exception\NoSuchEntityException
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function deleteById($addressId)
 {
     $address = $this->addressRegistry->retrieve($addressId);
     $customerModel = $this->customerRegistry->retrieve($address->getCustomerId());
     $customerModel->getAddressesCollection()->clear();
     $this->addressResource->delete($address);
     $this->addressRegistry->remove($addressId);
     return true;
 }
 public function testDeleteById()
 {
     $addressId = 12;
     $customerId = 43;
     $this->address->expects($this->once())->method('getCustomerId')->willReturn($customerId);
     $addressCollection = $this->getMock('Magento\\Customer\\Model\\ResourceModel\\Address\\Collection', [], [], '', false);
     $this->addressRegistry->expects($this->once())->method('retrieve')->with($addressId)->willReturn($this->address);
     $this->customerRegistry->expects($this->once())->method('retrieve')->with($customerId)->willReturn($this->customer);
     $this->customer->expects($this->once())->method('getAddressesCollection')->willReturn($addressCollection);
     $addressCollection->expects($this->once())->method('clear');
     $this->addressResourceModel->expects($this->once())->method('delete')->with($this->address);
     $this->addressRegistry->expects($this->once())->method('remove')->with($addressId);
     $this->assertTrue($this->repository->deleteById($addressId));
 }
 /**
  * {@inheritdoc}
  */
 public function deleteCustomer($customerId)
 {
     $customerModel = $this->customerRegistry->retrieve($customerId);
     foreach ($customerModel->getAddresses() as $addressModel) {
         $this->addressRegistry->remove($addressModel->getId());
     }
     $customerModel->delete();
     $this->customerRegistry->remove($customerId);
     return true;
 }