本文整理汇总了PHP中Magento\Customer\Model\CustomerFactory类的典型用法代码示例。如果您正苦于以下问题:PHP CustomerFactory类的具体用法?PHP CustomerFactory怎么用?PHP CustomerFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CustomerFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* @param \Magento\Framework\Session\SessionManagerInterface $session
* @param \Magento\Customer\Model\Session $customerSession
* @param \Magento\Customer\Model\CustomerFactory $customerFactory
* @param \Magento\Framework\App\RequestInterface $request
* @param \Magento\Framework\Module\Manager $moduleManager
* @param \Magento\Log\Model\Visitor $visitor
* @param \Magento\PageCache\Model\Config $cacheConfig
*/
public function __construct(\Magento\Framework\Session\SessionManagerInterface $session, \Magento\Customer\Model\Session $customerSession, \Magento\Customer\Model\CustomerFactory $customerFactory, \Magento\Framework\App\RequestInterface $request, \Magento\Framework\Module\Manager $moduleManager, \Magento\Log\Model\Visitor $visitor, \Magento\PageCache\Model\Config $cacheConfig)
{
$this->session = $session;
$this->customerSession = $customerSession;
$this->customer = $customerFactory->create();
$this->request = $request;
$this->moduleManager = $moduleManager;
$this->visitor = $visitor;
$this->cacheConfig = $cacheConfig;
}
示例2: setUp
/**
* SetUp
*/
protected function setUp()
{
$this->layoutMock = $this->getMock('Magento\\Framework\\View\\Layout', [], [], '', false);
$this->sessionMock = $this->getMock('Magento\\Framework\\Session\\Generic', ['clearStorage', 'setData', 'getData'], [], '', false);
$this->customerSessionMock = $this->getMock('Magento\\Customer\\Model\\Session', ['getCustomerGroupId', 'setCustomerGroupId', 'clearStorage', 'setCustomer'], [], '', false);
$this->customerFactoryMock = $this->getMock('Magento\\Customer\\Model\\CustomerFactory', ['create'], [], '', false);
$this->customerMock = $this->getMock('Magento\\Customer\\Model\\Customer', ['setGroupId', '__wakeup'], [], '', false);
$this->visitorMock = $this->getMock('Magento\\Customer\\Model\\Visitor', [], [], '', false);
$this->customerFactoryMock->expects($this->any())->method('create')->will($this->returnValue($this->customerMock));
$this->depersonalizeCheckerMock = $this->getMock('Magento\\PageCache\\Model\\DepersonalizeChecker', [], [], '', false);
$this->plugin = new \Magento\Customer\Model\Layout\DepersonalizePlugin($this->depersonalizeCheckerMock, $this->sessionMock, $this->customerSessionMock, $this->customerFactoryMock, $this->visitorMock);
}
示例3: indexAction
public function indexAction()
{
if (Praxigento_LoginAs_Config::cfgGeneralEnabled()) {
/** define operator name */
/** @var $session Mage_Admin_Model_Session */
$session = $this->backendAuthSession;
if ($session->isLoggedIn()) {
/** @var $user Mage_Admin_Model_User */
$user = $session->getUser();
$operator = $user->getName() . ' (' . $user->getEmail() . ')';
/** if there is customer data in request */
if (!is_null($this->getRequest()->getParams())) {
$params = $this->getRequest()->getParams();
if (!is_null($params[Praxigento_LoginAs_Config::REQ_PARAM_LAS_ID])) {
/** extract customer ID from request and load customer data */
$customerId = $params[Praxigento_LoginAs_Config::REQ_PARAM_LAS_ID];
/** @var $customer Mage_Customer_Model_Customer */
$customer = $this->customerCustomerFactory->create()->load($customerId);
if ($customer->getId() == $customerId) {
$customerName = $customer->getName();
/** define URL to login to customer's website */
$wsId = $customer->getData('website_id');
if (is_null($wsId)) {
$wsId = $this->storeManager->getStore()->getWebsiteId();
}
/** @var $website Mage_Core_Model_Website */
$website = $this->storeWebsiteFactory->create()->load($wsId);
$defStoreId = $website->getDefaultStore()->getId();
$baseTarget = $this->scopeConfig->getValue(\Magento\Framework\UrlInterface::XML_PATH_SECURE_URL, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $defStoreId);
$baseSource = $this->scopeConfig->getValue(\Magento\Framework\UrlInterface::XML_PATH_SECURE_URL, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
/** compose redirection URL and replace current base by target base */
$urlModel = $this->framework->create();
$store = $this->storeStoreFactory->create()->load($defStoreId);
$urlModel->setStore($store);
$url = $urlModel->getUrl(Praxigento_LoginAs_Config::XMLCFG_ROUTER_FRONT . Praxigento_LoginAs_Config::ROUTE_CUSTOMER_LOGINAS);
$url = str_replace($baseSource, $baseTarget, $url);
/** compose authentication package */
/** @var $authPack Praxigento_LoginAs_Model_Package */
$authPack = $this->loginAsPackage;
$authPack->setAdminName($operator);
$authPack->setCustomerId($customerId);
$authPack->setCustomerName($customerName);
$authPack->setRedirectUrl($url);
$validatorData = $session->getValidatorData();
$ip = $validatorData['remote_addr'];
$authPack->setIp($ip);
/** save login data to file */
$authPack->saveAsFile();
/** log event */
$log = Praxigento_LoginAs_Model_Logger::getLogger($this);
$log->trace("Operator '{$operator}' is redirected to front from ip '{$ip}' to login" . " as customer '{$customerName}' ({$customerId}).");
}
$bu = var_export($this->getLayout()->getUpdate()->getHandles(), true);
/** load layout and render blocks */
$this->loadLayout()->renderLayout();
}
}
}
}
}
示例4: execute
/**
* If it's configured to capture on shipment - do this.
*
* @param \Magento\Framework\Event\Observer $observer
*
* @return $this
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
$customer = $observer->getEvent()->getCustomer();
$email = $customer->getEmail();
$websiteId = $customer->getWebsiteId();
$customerId = $customer->getEntityId();
$isSubscribed = $customer->getIsSubscribed();
try {
// fix for a multiple hit of the observer
$emailReg = $this->registry->registry($email . '_customer_save');
if ($emailReg) {
return $this;
}
$this->registry->register($email . '_customer_save', $email);
$emailBefore = $this->customerFactory->create()->load($customer->getId())->getEmail();
$contactModel = $this->contactFactory->create()->loadByCustomerEmail($emailBefore, $websiteId);
//email change detection
if ($email != $emailBefore) {
$this->helper->log('email change detected : ' . $email . ', after : ' . $emailBefore . ', website id : ' . $websiteId);
$data = ['emailBefore' => $emailBefore, 'email' => $email, 'isSubscribed' => $isSubscribed];
$this->importerFactory->registerQueue(\Dotdigitalgroup\Email\Model\Importer::IMPORT_TYPE_CONTACT_UPDATE, $data, \Dotdigitalgroup\Email\Model\Importer::MODE_CONTACT_EMAIL_UPDATE, $websiteId);
} elseif (!$emailBefore) {
//for new contacts update email
$contactModel->setEmail($email);
}
$contactModel->setEmailImported(\Dotdigitalgroup\Email\Model\Contact::EMAIL_CONTACT_NOT_IMPORTED)->setCustomerId($customerId)->save();
} catch (\Exception $e) {
$this->helper->debug((string) $e, []);
}
return $this;
}
示例5: validate
/**
* Validates the fields in a specified address data object.
*
* @param \Magento\Quote\Api\Data\AddressInterface $addressData The address data object.
* @return bool
* @throws \Magento\Framework\Exception\InputException The specified address belongs to another customer.
* @throws \Magento\Framework\Exception\NoSuchEntityException The specified customer ID or address ID is not valid.
*/
public function validate(\Magento\Quote\Api\Data\AddressInterface $addressData)
{
//validate customer id
if ($addressData->getCustomerId()) {
$customer = $this->customerFactory->create();
$customer->load($addressData->getCustomerId());
if (!$customer->getId()) {
throw new \Magento\Framework\Exception\NoSuchEntityException(__('Invalid customer id %1', $addressData->getCustomerId()));
}
}
// validate address id
if ($addressData->getId()) {
$address = $this->quoteAddressFactory->create();
$address->load($addressData->getId());
if (!$address->getId()) {
throw new \Magento\Framework\Exception\NoSuchEntityException(__('Invalid address id %1', $addressData->getId()));
}
// check correspondence between customer id and address id
if ($addressData->getCustomerId()) {
if ($address->getCustomerId() != $addressData->getCustomerId()) {
throw new \Magento\Framework\Exception\InputException(__('Address with id %1 belongs to another customer', $addressData->getId()));
}
}
}
return true;
}
示例6: testSave
/**
* @param $addressId
* @param $isDefaultBilling
* @param $isDefaultShipping
*
* @dataProvider getSaveDataProvider
*/
public function testSave($addressId, $isDefaultBilling, $isDefaultShipping)
{
/** @var $customer \Magento\Customer\Model\Address|\PHPUnit_Framework_MockObject_MockObject */
$customer = $this->getMock('Magento\\Customer\\Model\\Customer', ['__wakeup', 'setDefaultBilling', 'setDefaultShipping', 'save', 'load'], [], '', false);
$customer->expects($this->any())->method('load')->willReturnSelf();
$this->customerFactory->expects($this->any())->method('create')->willReturn($customer);
/** @var $address \Magento\Customer\Model\Address|\PHPUnit_Framework_MockObject_MockObject */
$address = $this->getMock('Magento\\Customer\\Model\\Address', ['__wakeup', 'getId', 'getEntityTypeId', 'getIsDefaultBilling', 'getIsDefaultShipping', 'hasDataChanges', 'validateBeforeSave', 'beforeSave', 'afterSave', 'isSaveAllowed'], [], '', false);
$address->expects($this->once())->method('hasDataChanges')->willReturn(true);
$address->expects($this->once())->method('isSaveAllowed')->willReturn(true);
$address->expects($this->once())->method('validateBeforeSave');
$address->expects($this->once())->method('beforeSave');
$address->expects($this->once())->method('afterSave');
$address->expects($this->any())->method('getEntityTypeId')->willReturn('3');
$address->expects($this->any())->method('getId')->willReturn($addressId);
$address->expects($this->any())->method('getIsDefaultShipping')->willReturn($isDefaultShipping);
$address->expects($this->any())->method('getIsDefaultBilling')->willReturn($isDefaultBilling);
if ($addressId && ($isDefaultBilling || $isDefaultShipping)) {
if ($isDefaultBilling) {
$customer->expects($this->once())->method('setDefaultBilling')->with($addressId);
}
if ($isDefaultShipping) {
$customer->expects($this->once())->method('setDefaultShipping')->with($addressId);
}
$customer->expects($this->once())->method('save');
} else {
$customer->expects($this->never())->method('setDefaultBilling');
$customer->expects($this->never())->method('setDefaultShipping');
$customer->expects($this->never())->method('save');
}
$this->addressResource->setType('customer_address');
$this->addressResource->save($address);
}
示例7: registerWishlist
/**
* Automation new wishlist program.
*
* @param array $wishlist
*
* @return $this
*
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function registerWishlist($wishlist)
{
try {
$emailWishlist = $this->wishlistFactory->create();
$customer = $this->customerFactory->create();
//if wishlist exist not to save again
if (!$emailWishlist->getWishlist($wishlist['wishlist_id'])) {
$customer->load($wishlist['customer_id']);
$email = $customer->getEmail();
$wishlistId = $wishlist['wishlist_id'];
$websiteId = $customer->getWebsiteId();
$emailWishlist->setWishlistId($wishlistId)->setCustomerId($wishlist['customer_id'])->setStoreId($customer->getStoreId())->save();
$store = $this->storeManager->getStore($customer->getStoreId());
$storeName = $store->getName();
//if api is not enabled
if (!$this->helper->isEnabled($websiteId)) {
return $this;
}
$programId = $this->helper->getWebsiteConfig('connector_automation/visitor_automation/wishlist_automation', $websiteId);
//wishlist program mapped
if ($programId) {
$automation = $this->automationFactory->create();
//save automation type
$automation->setEmail($email)->setAutomationType(\Dotdigitalgroup\Email\Model\Sync\Automation::AUTOMATION_TYPE_NEW_WISHLIST)->setEnrolmentStatus(\Dotdigitalgroup\Email\Model\Sync\Automation::AUTOMATION_STATUS_PENDING)->setTypeId($wishlistId)->setWebsiteId($websiteId)->setStoreName($storeName)->setProgramId($programId);
$automation->save();
}
}
} catch (\Exception $e) {
$this->helper->error((string) $e, []);
}
}
示例8: execute
/**
* If it's configured to capture on shipment - do this.
*
* @param \Magento\Framework\Event\Observer $observer
*
* @return $this
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
$dataObject = $observer->getEvent()->getDataObject();
if ($dataObject->getCustomerId() && $dataObject->getStatusId() == \Magento\Review\Model\Review::STATUS_APPROVED) {
$customerId = $dataObject->getCustomerId();
$this->helper->setConnectorContactToReImport($customerId);
//save review info in the table
$this->registerReview($dataObject);
$store = $this->storeManager->getStore($dataObject->getStoreId());
$storeName = $store->getName();
$website = $this->storeManager->getStore($store)->getWebsite();
$customer = $this->customerFactory->create()->load($customerId);
//if api is not enabled
if (!$this->helper->isEnabled($website)) {
return $this;
}
$programId = $this->helper->getWebsiteConfig('connector_automation/visitor_automation/review_automation');
if ($programId) {
$automation = $this->automationFactory->create();
$automation->setEmail($customer->getEmail())->setAutomationType(\Dotdigitalgroup\Email\Model\Sync\Automation::AUTOMATION_TYPE_NEW_REVIEW)->setEnrolmentStatus(\Dotdigitalgroup\Email\Model\Sync\Automation::AUTOMATION_STATUS_PENDING)->setTypeId($dataObject->getReviewId())->setWebsiteId($website->getId())->setStoreName($storeName)->setProgramId($programId);
$automation->save();
}
}
return $this;
}
示例9: getCustomerByEmail
/**
* @param string $email
* @return bool|\Magento\Customer\Model\Customer
*/
public function getCustomerByEmail($email)
{
/** @var \Magento\Customer\Model\Customer $customer */
$customer = $this->customerFactory->create();
$customer->setWebsiteId($this->storeManager->getWebsiteId());
$customer->loadByEmail($email);
if ($customer->getId()) {
return $customer;
}
return false;
}
示例10: createCustomer
public function createCustomer()
{
/** @var \Magento\Customer\Model\Customer $customer */
$customer = $this->customerFactory->create();
$customerName = explode(' ', $this->titlesGenerator->generateCustomerName());
$customer->setFirstname($customerName[0]);
$customer->setLastname($customerName[1]);
$customer->setEmail(self::NAMES_PREFIX . uniqid() . '@' . self::DEFAULT_EMAIL_DOMAIN);
$customer->setWebsiteId($this->storeManager->getWebsite()->getWebsiteId());
$customer->save($customer);
return $customer;
}
示例11: loadByCustomerId
public function loadByCustomerId($customerId)
{
$this->_customer = $this->_customerFactory->create()->load($customerId);
if (!$this->_customer->getId()) {
throw new \Magento\Framework\Exception(__('Could not load by customer id'));
}
if (!($socialconnectFid = $this->_customer->getInchooSocialconnectFid()) || !($socialconnectFtoken = $this->_customer->getInchooSocialconnectFtoken())) {
throw new \Magento\Framework\Exception(__('Could not retrieve token by customer id'));
}
$this->setTarget($socialconnectFid);
$this->setAccessToken($socialconnectFtoken);
$this->_load();
return $this;
}
示例12: getCustomer
/**
* Retrieve customer
* @return \Magento\Customer\Model\Customer
*/
public function getCustomer()
{
if (is_null($this->_customer)) {
$this->_customer = $this->_customerFactory->create()->load($this->getCustomerId());
}
return $this->_customer;
}
示例13: authenticate
/**
* {@inheritdoc}
*/
public function authenticate($username, $password)
{
try {
switch ($this->advancedLoginConfigProvider->getLoginMode()) {
case LoginMode::LOGIN_TYPE_ONLY_ATTRIBUTE:
$customer = $this->loginViaCustomerAttributeOnly($username);
break;
case LoginMode::LOGIN_TYPE_BOTH:
$customer = $this->loginViaCustomerAttributeOrEmail($username);
break;
default:
$customer = $this->loginViaEmailOnly($username);
break;
}
} catch (NoSuchEntityException $e) {
throw new InvalidEmailOrPasswordException(__('Invalid login or password.'));
}
$this->checkPasswordStrength($password);
$hash = $this->customerRegistry->retrieveSecureData($customer->getId())->getPasswordHash();
if (!$this->encryptor->validateHash($password, $hash)) {
throw new InvalidEmailOrPasswordException(__('Invalid login or password.'));
}
if ($customer->getConfirmation() && $this->isConfirmationRequired($customer)) {
throw new EmailNotConfirmedException(__('This account is not confirmed.'));
}
$customerModel = $this->customerFactory->create()->updateData($customer);
$this->eventManager->dispatch('customer_customer_authenticated', ['model' => $customerModel, 'password' => $password]);
$this->eventManager->dispatch('customer_data_object_login', ['customer' => $customer]);
return $customer;
}
示例14: assignCustomer
/**
* {@inheritdoc}
*/
public function assignCustomer($cartId, $customerId, $storeId)
{
$quote = $this->quoteRepository->getActive($cartId);
$customer = $this->customerRepository->getById($customerId);
$customerModel = $this->customerModelFactory->create();
if (!in_array($storeId, $customerModel->load($customerId)->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.'));
}
try {
$this->quoteRepository->getForCustomer($customerId);
throw new StateException(__('Cannot assign customer to the given cart. Customer already has active cart.'));
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
}
$quote->setCustomer($customer);
$quote->setCustomerIsGuest(0);
$quoteIdMaskFactory = $this->getQuoteIdMaskFactory();
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
$quoteIdMask = $quoteIdMaskFactory->create()->load($cartId, 'quote_id');
if ($quoteIdMask->getId()) {
$quoteIdMask->delete();
}
$this->quoteRepository->save($quote);
return true;
}
示例15: getCustomer
/**
* Retrieve customer model object
*
* @return Customer
* @deprecated use getCustomerId() instead
*/
public function getCustomer()
{
if ($this->_customerModel === null) {
$this->_customerModel = $this->_customerFactory->create()->load($this->getCustomerId());
}
return $this->_customerModel;
}