/** * Returns Unlock button data * * @return array */ public function getButtonData() { $customerId = $this->getCustomerId(); $data = []; if ($customerId) { $customer = $this->customerRegistry->retrieve($customerId); if ($customer->isCustomerLocked()) { $data = ['label' => __('Unlock'), 'class' => 'unlock unlock-customer', 'on_click' => sprintf("location.href = '%s';", $this->getUnlockUrl()), 'sort_order' => 50]; } } return $data; }
/** * {@inheritdoc} */ public function deleteById($customerId) { $customerModel = $this->customerRegistry->retrieve($customerId); $customerModel->delete(); $this->customerRegistry->remove($customerId); return true; }
/** * {@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; }
/** * Check if customer is locked and throw exception. * * @api * @param \Magento\Customer\Api\Data\CustomerInterface $customer * @throws \Magento\Framework\Exception\State\UserLockedException * @return void */ public function checkIfLocked(\Magento\Customer\Api\Data\CustomerInterface $customer) { $currentCustomer = $this->customerRegistry->retrieve($customer->getId()); if ($currentCustomer->isCustomerLocked()) { throw new UserLockedException(__('The account is locked. Please wait and try again or contact %1.', $this->scopeConfig->getValue('contact/email/recipient_email'))); } }
/** * @magentoDataFixture Magento/Customer/_files/customer.php * @expectedException \Magento\Framework\Exception\NoSuchEntityException * @magentoAppArea adminhtml */ public function testRemoveByEmail() { $customer = $this->_model->retrieve(self::CUSTOMER_ID); $this->assertInstanceOf('\\Magento\\Customer\\Model\\Customer', $customer); $customer->delete(); $this->_model->removeByEmail(self::CUSTOMER_EMAIL, self::WEBSITE_ID); $this->_model->retrieveByEmail(self::CUSTOMER_EMAIL, $customer->getWebsiteId()); }
/** * 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 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); }
/** * {@inheritdoc} */ public function assignCustomer($cartId, $customerId) { $storeId = $this->storeManager->getStore()->getId(); $quote = $this->quoteFactory->create()->load($cartId); if ($quote->getId() != $cartId || $quote->getStoreId() != $storeId) { throw new NoSuchEntityException('There is no cart with provided ID.'); } $customer = $this->customerRegistry->retrieve($customerId); if (!in_array($storeId, $customer->getSharedStoreIds())) { throw new StateException('Cannot assign customer to the given cart. The cart belongs to different store.'); } if ($quote->getCustomerId()) { throw new StateException('Cannot assign customer to the given cart. The cart is not anonymous.'); } $currentCustomerQuote = $this->quoteFactory->create()->loadByCustomer($customer); if ($currentCustomerQuote->getId()) { throw new StateException('Cannot assign customer to the given cart. Customer already has active cart.'); } $quote->setCustomer($customer); $quote->setCustomerIsGuest(0); $quote->save(); return true; }
/** * Validate the Reset Password Token for a customer. * * @param int $customerId * @param string $resetPasswordLinkToken * @return CustomerModel * @throws \Magento\Framework\Exception\State\InputMismatchException If token is mismatched * @throws \Magento\Framework\Exception\State\ExpiredException If token is expired * @throws \Magento\Framework\Exception\InputException If token or customer id is invalid * @throws \Magento\Framework\Exception\NoSuchEntityException If customer doesn't exist */ private function validateResetPasswordToken($customerId, $resetPasswordLinkToken) { if (!is_int($customerId) || empty($customerId) || $customerId < 0) { $params = ['value' => $customerId, 'fieldName' => 'customerId']; throw new InputException(InputException::INVALID_FIELD_VALUE, $params); } if (!is_string($resetPasswordLinkToken) || empty($resetPasswordLinkToken)) { $params = ['fieldName' => 'resetPasswordLinkToken']; throw new InputException(InputException::REQUIRED_FIELD, $params); } $customerModel = $this->customerRegistry->retrieve($customerId); $customerToken = $customerModel->getRpToken(); if (strcmp($customerToken, $resetPasswordLinkToken) !== 0) { throw new InputMismatchException('Reset password token mismatch.'); } else { if ($customerModel->isResetPasswordLinkTokenExpired($customerId)) { throw new ExpiredException('Reset password token expired.'); } } return $customerModel; }
/** * {@inheritdoc} */ public function isLocked($customerId) { $currentCustomer = $this->customerRegistry->retrieve($customerId); return $currentCustomer->isCustomerLocked(); }