/**
  * 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;
 }
 /**
  * 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, []);
     }
 }
 /**
  * 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;
 }
 /**
  * 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
0
 /**
  * @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;
 }
 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;
 }
 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;
 }
Пример #8
0
 /**
  * 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;
 }
Пример #9
0
 /**
  * {@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;
 }
 /**
  * {@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;
 }
Пример #11
0
 /**
  * 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;
 }
 /**
  * {@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;
 }
 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();
                 }
             }
         }
     }
 }
Пример #14
0
 /**
  * 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'];
 }
 /**
  * @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'])];
 }
 /**
  * Number of customers with duplicate emails, emails as total number.
  *
  * @return mixed
  */
 public function getCustomersWithDuplicateEmails()
 {
     $customers = $this->customerFactory->create()->getCollection();
     //duplicate emails
     //@codingStandardsIgnoreStart
     $customers->getSelect()->columns(['emails' => 'COUNT(e.entity_id)'])->group('email')->having('emails > ?', 1);
     //@codingStandardsIgnoreEnd
     return $customers;
 }
Пример #17
0
 /**
  * Process object relations
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return void
  */
 public function processRelation(\Magento\Framework\Model\AbstractModel $object)
 {
     /**
      * @var $object \Magento\Customer\Model\Address
      */
     if (!$object->getIsCustomerSaveTransaction() && $this->isAddressDefault($object)) {
         $customer = $this->customerFactory->create()->load($object->getCustomerId());
         $changedAddresses = [];
         if ($object->getIsDefaultBilling()) {
             $changedAddresses['default_billing'] = $object->getId();
         }
         if ($object->getIsDefaultShipping()) {
             $changedAddresses['default_shipping'] = $object->getId();
         }
         if ($changedAddresses) {
             $customer->getResource()->getConnection()->update($customer->getResource()->getTable('customer_entity'), $changedAddresses, $customer->getResource()->getConnection()->quoteInto('entity_id = ?', $customer->getId()));
         }
     }
 }
 /**
  * @return bool|\Magento\Framework\DataObject
  */
 public function _getWishlist()
 {
     $customerId = $this->getRequest()->getParam('customer_id');
     if (!$customerId) {
         return false;
     }
     $customer = $this->customerFactory->create()->load($customerId);
     if (!$customer->getId()) {
         return false;
     }
     $collection = $this->wishlistFactory->create()->getCollection()->addFieldToFilter('customer_id', $customerId)->setOrder('updated_at', 'DESC')->setPageSize(1);
     if ($collection->getSize()) {
         //@codingStandardsIgnoreStart
         return $collection->getFirstItem();
         //@codingStandardsIgnoreEnd
     } else {
         return false;
     }
 }
Пример #19
0
 /**
  * @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;
 }
Пример #20
0
 /**
  * @param CustomerData $customer
  * @return $this
  */
 public function setCustomerDataAsLoggedIn($customer)
 {
     $this->_httpContext->setValue(Context::CONTEXT_AUTH, true, false);
     $this->setCustomerData($customer);
     $customerModel = $this->_customerFactory->create()->updateData($customer);
     $this->setCustomer($customerModel);
     $this->_eventManager->dispatch('customer_login', ['customer' => $customerModel]);
     $this->_eventManager->dispatch('customer_data_object_login', ['customer' => $customer]);
     return $this;
 }
 /**
  * Customer custom attributes.
  *
  * @return array
  */
 public function toOptionArray()
 {
     $options = [];
     //exclude attributes from mapping
     $excluded = ['created_at', 'created_in', 'dob', 'dotmailer_contact_id', 'email', 'firstname', 'lastname', 'gender', 'group_id', 'password_hash', 'prefix', 'rp_token', 'rp_token_create_at', 'website_id'];
     $attributes = $this->customerFactory->create()->getAttributes();
     foreach ($attributes as $attribute) {
         if ($attribute->getFrontendLabel()) {
             $code = $attribute->getAttributeCode();
             //escape the label in case of quotes
             //@codingStandardsIgnoreStart
             $label = addslashes($attribute->getFrontendLabel());
             //@codingStandardsIgnoreEnd
             if (!in_array($code, $excluded)) {
                 $options[] = ['value' => $attribute->getAttributeCode(), 'label' => $label];
             }
         }
     }
     return $options;
 }
 /**
  * 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)
 {
     $object = $observer->getEvent()->getDataObject();
     $customer = $this->customerFactory->create()->load($object->getCustomerId());
     $website = $this->storeManager->getStore($customer->getStoreId())->getWebsite();
     //sync enabled
     $syncEnabled = $this->helper->getWebsiteConfig(\Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_SYNC_WISHLIST_ENABLED, $website->getId());
     if ($this->helper->isEnabled($website->getId()) && $syncEnabled) {
         //Remove wishlist
         try {
             $item = $this->wishlistFactory->create()->getWishlist($object->getWishlistId());
             if ($item instanceof \Magento\Framework\DataObject && $item->getId()) {
                 //register in queue with importer
                 $this->importerFactory->create()->registerQueue(\Dotdigitalgroup\Email\Model\Importer::IMPORT_TYPE_WISHLIST, [$item->getId()], \Dotdigitalgroup\Email\Model\Importer::MODE_SINGLE_DELETE, $website->getId());
                 $item->delete();
             }
         } catch (\Exception $e) {
             $this->helper->debug((string) $e, []);
         }
     }
 }
 /**
  * After generate Xml
  *
  * @param \Magento\Framework\View\LayoutInterface $subject
  * @param \Magento\Framework\View\LayoutInterface $result
  * @return \Magento\Framework\View\LayoutInterface
  */
 public function afterGenerateXml(\Magento\Framework\View\LayoutInterface $subject, $result)
 {
     if ($this->depersonalizeChecker->checkIfDepersonalize($subject)) {
         $this->visitor->setSkipRequestLogging(true);
         $this->visitor->unsetData();
         $this->session->clearStorage();
         $this->customerSession->clearStorage();
         $this->session->setData(\Magento\Framework\Data\Form\FormKey::FORM_KEY, $this->formKey);
         $this->customerSession->setCustomerGroupId($this->customerGroupId);
         $this->customerSession->setCustomer($this->customerFactory->create()->setGroupId($this->customerGroupId));
     }
     return $result;
 }
Пример #24
0
 /**
  * {@inheritdoc}
  */
 public function validate(\Magento\Customer\Api\Data\CustomerInterface $customer)
 {
     $customerErrors = $this->validator->validateData($this->extensibleDataObjectConverter->toFlatArray($customer, [], '\\Magento\\Customer\\Api\\Data\\CustomerInterface'), [], 'customer');
     $validationResults = $this->validationResultsDataFactory->create();
     if ($customerErrors !== true) {
         return $validationResults->setIsValid(false)->setMessages($this->validator->getMessages());
     }
     $oldAddresses = $customer->getAddresses();
     $customerModel = $this->customerFactory->create()->updateData($customer->setAddresses([]));
     $customer->setAddresses($oldAddresses);
     $result = $customerModel->validate();
     if (true !== $result && is_array($result)) {
         return $validationResults->setIsValid(false)->setMessages($result);
     }
     return $validationResults->setIsValid(true)->setMessages([]);
 }
Пример #25
0
 /**
  * Creates a customer model from a customer entity.
  *
  * @param CustomerDataObject $customer
  * @return Customer
  */
 public function createCustomerModel(CustomerDataObject $customer)
 {
     $customerModel = $this->_customerFactory->create();
     $attributes = ExtensibleDataObjectConverter::toFlatArray($customer);
     foreach ($attributes as $attributeCode => $attributeValue) {
         // avoid setting password through set attribute
         if ($attributeCode == 'password') {
             continue;
         } else {
             $customerModel->setData($attributeCode, $attributeValue);
         }
     }
     $customerId = $customer->getId();
     if ($customerId) {
         $customerModel->setId($customerId);
     }
     // Need to use attribute set or future updates can cause data loss
     if (!$customerModel->getAttributeSetId()) {
         $customerModel->setAttributeSetId(CustomerMetadataServiceInterface::ATTRIBUTE_SET_ID_CUSTOMER);
     }
     return $customerModel;
 }
Пример #26
0
 /**
  * {@inheritdoc}
  */
 public function searchCustomers(SearchCriteria $searchCriteria)
 {
     $this->searchResultsBuilder->setSearchCriteria($searchCriteria);
     /** @var Collection $collection */
     $collection = $this->customerFactory->create()->getCollection();
     // This is needed to make sure all the attributes are properly loaded
     foreach ($this->customerMetadataService->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);
     }
     $this->searchResultsBuilder->setTotalCount($collection->getSize());
     $sortOrders = $searchCriteria->getSortOrders();
     /** @var SortOrder $sortOrder */
     if ($sortOrders) {
         foreach ($searchCriteria->getSortOrders() as $sortOrder) {
             $collection->addOrder($sortOrder->getField(), $sortOrder->getDirection() == SearchCriteria::SORT_ASC ? 'ASC' : 'DESC');
         }
     }
     $collection->setCurPage($searchCriteria->getCurrentPage());
     $collection->setPageSize($searchCriteria->getPageSize());
     $customersDetails = [];
     /** @var CustomerModel $customerModel */
     foreach ($collection as $customerModel) {
         $customer = $this->converter->createCustomerFromModel($customerModel);
         $addresses = $this->customerAddressService->getAddresses($customer->getId());
         $customerDetails = $this->customerDetailsBuilder->setCustomer($customer)->setAddresses($addresses)->create();
         $customersDetails[] = $customerDetails;
     }
     $this->searchResultsBuilder->setItems($customersDetails);
     return $this->searchResultsBuilder->create();
 }
Пример #27
0
 /**
  * Retrieve Customer Model from registry given an email
  *
  * @param string $customerEmail Customers email address
  * @param string|null $websiteId Optional website ID, if not set, will use the current websiteId
  * @return Customer
  * @throws NoSuchEntityException
  */
 public function retrieveByEmail($customerEmail, $websiteId = null)
 {
     if ($websiteId === null) {
         $websiteId = $this->storeManager->getStore()->getWebsiteId();
     }
     $emailKey = $this->getEmailKey($customerEmail, $websiteId);
     if (isset($this->customerRegistryByEmail[$emailKey])) {
         return $this->customerRegistryByEmail[$emailKey];
     }
     /** @var Customer $customer */
     $customer = $this->customerFactory->create();
     if (isset($websiteId)) {
         $customer->setWebsiteId($websiteId);
     }
     $customer->loadByEmail($customerEmail);
     if (!$customer->getEmail()) {
         // customer does not exist
         throw new NoSuchEntityException(__(NoSuchEntityException::MESSAGE_DOUBLE_FIELDS, ['fieldName' => 'email', 'fieldValue' => $customerEmail, 'field2Name' => 'websiteId', 'field2Value' => $websiteId]));
     } else {
         $this->customerRegistryById[$customer->getId()] = $customer;
         $this->customerRegistryByEmail[$emailKey] = $customer;
         return $customer;
     }
 }
Пример #28
0
 /**
  * @param \Magento\Core\Helper\Data $coreData
  * @param \Magento\Framework\Stdlib\String $string
  * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  * @param \Magento\ImportExport\Model\ImportFactory $importFactory
  * @param \Magento\ImportExport\Model\Resource\Helper $resourceHelper
  * @param \Magento\Framework\App\Resource $resource
  * @param \Magento\Framework\StoreManagerInterface $storeManager
  * @param \Magento\ImportExport\Model\Export\Factory $collectionFactory
  * @param \Magento\Eav\Model\Config $eavConfig
  * @param \Magento\CustomerImportExport\Model\Resource\Import\Customer\StorageFactory $storageFactory
  * @param \Magento\Customer\Model\Resource\Attribute\CollectionFactory $attrCollectionFactory
  * @param \Magento\Customer\Model\CustomerFactory $customerFactory
  * @param array $data
  */
 public function __construct(\Magento\Core\Helper\Data $coreData, \Magento\Framework\Stdlib\String $string, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\ImportExport\Model\ImportFactory $importFactory, \Magento\ImportExport\Model\Resource\Helper $resourceHelper, \Magento\Framework\App\Resource $resource, \Magento\Framework\StoreManagerInterface $storeManager, \Magento\ImportExport\Model\Export\Factory $collectionFactory, \Magento\Eav\Model\Config $eavConfig, \Magento\CustomerImportExport\Model\Resource\Import\Customer\StorageFactory $storageFactory, \Magento\Customer\Model\Resource\Attribute\CollectionFactory $attrCollectionFactory, \Magento\Customer\Model\CustomerFactory $customerFactory, array $data = array())
 {
     $this->_resourceHelper = $resourceHelper;
     if (isset($data['attribute_collection'])) {
         $this->_attributeCollection = $data['attribute_collection'];
         unset($data['attribute_collection']);
     } else {
         $this->_attributeCollection = $attrCollectionFactory->create();
         $this->_attributeCollection->addSystemHiddenFilterWithPasswordHash();
         $data['attribute_collection'] = $this->_attributeCollection;
     }
     parent::__construct($coreData, $string, $scopeConfig, $importFactory, $resourceHelper, $resource, $storeManager, $collectionFactory, $eavConfig, $storageFactory, $data);
     $this->_specialAttributes[] = self::COLUMN_WEBSITE;
     $this->_specialAttributes[] = self::COLUMN_STORE;
     $this->_permanentAttributes[] = self::COLUMN_EMAIL;
     $this->_permanentAttributes[] = self::COLUMN_WEBSITE;
     $this->_indexValueAttributes[] = 'group_id';
     $this->addMessageTemplate(self::ERROR_DUPLICATE_EMAIL_SITE, __('E-mail is duplicated in import file'));
     $this->addMessageTemplate(self::ERROR_ROW_IS_ORPHAN, __('Orphan rows that will be skipped due default row errors'));
     $this->addMessageTemplate(self::ERROR_INVALID_STORE, __('Invalid value in Store column (store does not exists?)'));
     $this->addMessageTemplate(self::ERROR_EMAIL_SITE_NOT_FOUND, __('E-mail and website combination is not found'));
     $this->addMessageTemplate(self::ERROR_PASSWORD_LENGTH, __('Invalid password length'));
     $this->_initStores(true)->_initAttributes();
     $this->_customerModel = $customerFactory->create();
     /** @var $customerResource \Magento\Customer\Model\Resource\Customer */
     $customerResource = $this->_customerModel->getResource();
     $this->_entityTable = $customerResource->getEntityTable();
 }
Пример #29
0
 /**
  * Set customer data object
  *
  * @param CustomerDataObject $customerData
  * @return $this
  */
 public function setCustomerData(CustomerDataObject $customerData)
 {
     /* @TODO: remove model usage in favor of Data Object in scope of MAGETWO-19930 */
     $customer = $this->_customerFactory->create();
     $customer->setData(\Magento\Framework\Service\EavDataObjectConverter::toFlatArray($customerData));
     $customer->setId($customerData->getId());
     $this->setCustomer($customer);
     return $this;
 }
Пример #30
0
 /**
  * @return \Magento\Customer\Model\Customer
  */
 protected function _createCustomer()
 {
     return $this->_customerFactory->create();
 }