当前位置: 首页>>代码示例>>PHP>>正文


PHP CustomerFactory::create方法代码示例

本文整理汇总了PHP中Magento\Customer\Model\CustomerFactory::create方法的典型用法代码示例。如果您正苦于以下问题:PHP CustomerFactory::create方法的具体用法?PHP CustomerFactory::create怎么用?PHP CustomerFactory::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Customer\Model\CustomerFactory的用法示例。


在下文中一共展示了CustomerFactory::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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;
 }
开发者ID:dotmailer,项目名称:dotmailer-magento2-extension,代码行数:32,代码来源:ReviewSaveAutomation.php

示例2: 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, []);
     }
 }
开发者ID:dotmailer,项目名称:dotmailer-magento2-extension,代码行数:40,代码来源:RegisterWishlist.php

示例3: 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;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:34,代码来源:QuoteAddressValidator.php

示例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;
 }
开发者ID:dotmailer,项目名称:dotmailer-magento2-extension,代码行数:38,代码来源:CreateUpdateContact.php

示例5: 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;
 }
开发者ID:ktplKunj,项目名称:TestMagento,代码行数:15,代码来源:Helper.php

示例6: 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;
 }
开发者ID:rogyar,项目名称:m2-sampledata-generator,代码行数:12,代码来源:CustomersCreator.php

示例7: 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;
 }
开发者ID:LavoWeb,项目名称:Magento2-Inchoo_SocialConnect,代码行数:14,代码来源:User.php

示例8: 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;
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:13,代码来源:Session.php

示例9: 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;
 }
开发者ID:rafaelstz,项目名称:magento2,代码行数:30,代码来源:QuoteManagement.php

示例10: getList

 /**
  * {@inheritdoc}
  */
 public function getList(SearchCriteriaInterface $searchCriteria)
 {
     $searchResults = $this->searchResultsFactory->create();
     $searchResults->setSearchCriteria($searchCriteria);
     /** @var \Magento\Customer\Model\Resource\Customer\Collection $collection */
     $collection = $this->customerFactory->create()->getCollection();
     // This is needed to make sure all the attributes are properly loaded
     foreach ($this->customerMetadata->getAllAttributesMetadata() as $metadata) {
         $collection->addAttributeToSelect($metadata->getAttributeCode());
     }
     // Needed to enable filtering on name as a whole
     $collection->addNameToSelect();
     // Needed to enable filtering based on billing address attributes
     $collection->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left')->joinAttribute('company', 'customer_address/company', 'default_billing', null, 'left');
     //Add filters from root filter group to the collection
     foreach ($searchCriteria->getFilterGroups() as $group) {
         $this->addFilterGroupToCollection($group, $collection);
     }
     $searchResults->setTotalCount($collection->getSize());
     $sortOrders = $searchCriteria->getSortOrders();
     if ($sortOrders) {
         foreach ($searchCriteria->getSortOrders() as $sortOrder) {
             $collection->addOrder($sortOrder->getField(), $sortOrder->getDirection() == SearchCriteriaInterface::SORT_ASC ? 'ASC' : 'DESC');
         }
     }
     $collection->setCurPage($searchCriteria->getCurrentPage());
     $collection->setPageSize($searchCriteria->getPageSize());
     $customers = [];
     /** @var \Magento\Customer\Model\Customer $customerModel */
     foreach ($collection as $customerModel) {
         $customers[] = $customerModel->getDataModel();
     }
     $searchResults->setItems($customers);
     return $searchResults;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:38,代码来源:CustomerRepository.php

示例11: 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;
 }
开发者ID:magefan,项目名称:module-login-as-customer,代码行数:11,代码来源:Login.php

示例12: 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;
 }
开发者ID:semaio,项目名称:magento2-advancedlogin,代码行数:33,代码来源:AccountManagement.php

示例13: 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();
                 }
             }
         }
     }
 }
开发者ID:praxigento,项目名称:mage2_ext_login_as,代码行数:60,代码来源:RedirectController.php

示例14: getHeader

 /**
  * Get data for Header section of RSS feed
  *
  * @return array
  */
 public function getHeader()
 {
     $customerId = $this->getWishlist()->getCustomerId();
     $customer = $this->customerFactory->create()->load($customerId);
     $title = __('%1\'s Wishlist', $customer->getName());
     $newUrl = $this->urlBuilder->getUrl('wishlist/shared/index', ['code' => $this->getWishlist()->getSharingCode()]);
     return ['title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8'];
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:13,代码来源:Wishlist.php

示例15: generateData

 /**
  * @param array $giftRegistryData
  * @return array
  */
 protected function generateData(array $giftRegistryData)
 {
     $giftRegistryData['sku'] = explode("\n", $giftRegistryData['sku']);
     $customer = $this->customerFactory->create();
     $customer->setWebsiteId($this->storeManager->getWebsiteId())->loadByEmail($giftRegistryData['customer_email']);
     $address = $customer->getDefaultBillingAddress()->getData();
     return ['customer_id' => $customer->getId(), 'type_id' => 1, 'title' => $giftRegistryData['title'], 'message' => $giftRegistryData['message'], 'is_public' => 1, 'is_active' => 1, 'event_country' => $address['country_id'], 'event_country_region' => $address['region_id'], 'event_country_region_text' => '', 'event_date' => date('Y-m-d'), 'address' => ['firstname' => $address['firstname'], 'lastname' => $address['lastname'], 'company' => '', 'street' => $address['street'], 'city' => $address['city'], 'region_id' => $address['region_id'], 'region' => $address['region'], 'postcode' => $address['postcode'], 'country_id' => $address['country_id'], 'telephone' => $address['telephone'], 'fax' => ''], 'items' => $this->productSkuToId($giftRegistryData['sku'])];
 }
开发者ID:vinai-drive-by-commits,项目名称:magento2-sample-data,代码行数:12,代码来源:GiftRegistry.php


注:本文中的Magento\Customer\Model\CustomerFactory::create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。