本文整理汇总了PHP中Magento\Customer\Api\CustomerRepositoryInterface::delete方法的典型用法代码示例。如果您正苦于以下问题:PHP CustomerRepositoryInterface::delete方法的具体用法?PHP CustomerRepositoryInterface::delete怎么用?PHP CustomerRepositoryInterface::delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Customer\Api\CustomerRepositoryInterface
的用法示例。
在下文中一共展示了CustomerRepositoryInterface::delete方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testDelete
/**
* @magentoAppArea adminhtml
* @magentoDataFixture Magento/Customer/_files/customer.php
* @magentoAppIsolation enabled
*/
public function testDelete()
{
$fixtureCustomerEmail = 'customer@example.com';
$customer = $this->customerRepository->get($fixtureCustomerEmail);
$this->customerRepository->delete($customer);
/** Ensure that customer was deleted */
$this->setExpectedException('Magento\\Framework\\Exception\\NoSuchEntityException', 'No such entity with email = customer@example.com, websiteId = 1');
$this->customerRepository->get($fixtureCustomerEmail);
}
示例2: testCustomerDeletedAdminArea
/**
* @magentoAppArea adminhtml
* @magentoDataFixture Magento/Newsletter/_files/subscribers.php
*/
public function testCustomerDeletedAdminArea()
{
$customer = $this->customerRepository->getById(1);
$objectManager = Bootstrap::getObjectManager();
/** @var \Magento\Newsletter\Model\Subscriber $subscriber */
$subscriber = $objectManager->create('Magento\\Newsletter\\Model\\Subscriber');
$subscriber->loadByEmail('customer@example.com');
$this->assertTrue($subscriber->isSubscribed());
$this->customerRepository->delete($customer);
$this->verifySubscriptionNotExist('customer@example.com');
}
示例3: createAccountWithPasswordHash
/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function createAccountWithPasswordHash(CustomerInterface $customer, $hash, $redirectUrl = '')
{
// This logic allows an existing customer to be added to a different store. No new account is created.
// The plan is to move this logic into a new method called something like 'registerAccountWithStore'
if ($customer->getId()) {
$customer = $this->customerRepository->get($customer->getEmail());
$websiteId = $customer->getWebsiteId();
if ($this->isCustomerInStore($websiteId, $customer->getStoreId())) {
throw new InputException(__('This customer already exists in this store.'));
}
// Existing password hash will be used from secured customer data registry when saving customer
}
// Make sure we have a storeId to associate this customer with.
if (!$customer->getStoreId()) {
if ($customer->getWebsiteId()) {
$storeId = $this->storeManager->getWebsite($customer->getWebsiteId())->getDefaultStore()->getId();
} else {
$storeId = $this->storeManager->getStore()->getId();
}
$customer->setStoreId($storeId);
}
// Update 'created_in' value with actual store name
if ($customer->getId() === null) {
$storeName = $this->storeManager->getStore($customer->getStoreId())->getName();
$customer->setCreatedIn($storeName);
}
$customerAddresses = $customer->getAddresses() ?: [];
$customer->setAddresses(null);
try {
// If customer exists existing hash will be used by Repository
$customer = $this->customerRepository->save($customer, $hash);
} catch (AlreadyExistsException $e) {
throw new InputMismatchException(__('A customer with the same email already exists in an associated website.'));
} catch (LocalizedException $e) {
throw $e;
}
try {
foreach ($customerAddresses as $address) {
$address->setCustomerId($customer->getId());
$this->addressRepository->save($address);
}
} catch (InputException $e) {
$this->customerRepository->delete($customer);
throw $e;
}
$customer = $this->customerRepository->getById($customer->getId());
$newLinkToken = $this->mathRandom->getUniqueHash();
$this->changeResetPasswordLinkToken($customer, $newLinkToken);
$this->sendEmailConfirmation($customer, $redirectUrl);
return $customer;
}