/**
  * 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;
 }
 /**
  * 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;
 }
Example #3
0
 /**
  * @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);
 }
 /**
  * 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, []);
     }
 }
 /**
  * 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;
 }
Example #6
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;
 }
Example #7
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;
 }
 /**
  * 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);
 }
 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;
 }
Example #11
0
 /**
  * SetUp
  */
 public 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->requestMock = $this->getMock('Magento\\Framework\\App\\Request\\Http', [], [], '', false);
     $this->customerMock = $this->getMock('Magento\\Customer\\Model\\Customer', ['setGroupId', '__wakeup'], [], '', false);
     $this->moduleManagerMock = $this->getMock('Magento\\Framework\\Module\\Manager', [], [], '', false);
     $this->visitorMock = $this->getMock('Magento\\Customer\\Model\\Visitor', [], [], '', false);
     $this->customerFactoryMock->expects($this->any())->method('create')->will($this->returnValue($this->customerMock));
     $this->cacheConfigMock = $this->getMock('Magento\\PageCache\\Model\\Config', [], [], '', false);
     $this->plugin = new DepersonalizePlugin($this->sessionMock, $this->customerSessionMock, $this->customerFactoryMock, $this->requestMock, $this->moduleManagerMock, $this->visitorMock, $this->cacheConfigMock);
 }
 /**
  * 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;
 }
Example #13
0
 public function testGetRssData()
 {
     $wishlistId = 1;
     $customerName = 'Customer Name';
     $title = "{$customerName}'s Wishlist";
     $wishlistModelMock = $this->getMock('Magento\\Wishlist\\Model\\Wishlist', ['getId', '__wakeup', 'getCustomerId', 'getItemCollection', 'getSharingCode'], [], '', false);
     $customerServiceMock = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false);
     $wishlistSharingUrl = 'wishlist/shared/index/1';
     $locale = 'en_US';
     $productUrl = 'http://product.url/';
     $productName = 'Product name';
     $customer = $this->getMockBuilder('Magento\\Customer\\Model\\Customer')->setMethods(['getName', '__wakeup', 'load'])->disableOriginalConstructor()->getMock();
     $customer->expects($this->once())->method('load')->will($this->returnSelf());
     $customer->expects($this->once())->method('getName')->will($this->returnValue('Customer Name'));
     $this->customerFactory->expects($this->once())->method('create')->will($this->returnValue($customer));
     $this->wishlistHelperMock->expects($this->any())->method('getWishlist')->will($this->returnValue($wishlistModelMock));
     $this->wishlistHelperMock->expects($this->any())->method('getCustomer')->will($this->returnValue($customerServiceMock));
     $wishlistModelMock->expects($this->once())->method('getId')->will($this->returnValue($wishlistId));
     $this->urlBuilderMock->expects($this->once())->method('getUrl')->will($this->returnValue($wishlistSharingUrl));
     $this->scopeConfig->expects($this->any())->method('getValue')->will($this->returnValueMap([['advanced/modules_disable_output/Magento_Rss', \Magento\Framework\Store\ScopeInterface::SCOPE_STORE, null, null], [\Magento\Core\Helper\Data::XML_PATH_DEFAULT_LOCALE, \Magento\Framework\Store\ScopeInterface::SCOPE_STORE, null, $locale]]));
     $staticArgs = ['productName' => $productName, 'productUrl' => $productUrl];
     $description = $this->processWishlistItemDescription($wishlistModelMock, $staticArgs);
     $expectedResult = ['title' => $title, 'description' => $title, 'link' => $wishlistSharingUrl, 'charset' => 'UTF-8', 'entries' => [0 => ['title' => $productName, 'link' => $productUrl, 'description' => $description]]];
     $this->assertEquals($expectedResult, $this->model->getRssData());
 }
 /**
  * {@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;
 }
Example #15
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;
 }
Example #16
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;
 }
 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();
                 }
             }
         }
     }
 }
 /**
  * {@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;
 }
Example #19
0
 /**
  * @param string $params
  * @dataProvider dataProcessNonce
  */
 public function testProcessNonceException($params = null, $exceptionMessage = null)
 {
     $this->customerSessionMock->expects($this->any())->method('getCustomerId')->willReturn($params['customerId']);
     $countryCollectionMock = $this->getMockBuilder('\\Magento\\Directory\\Model\\Resource\\Country\\Collection')->disableOriginalConstructor()->getMock();
     $countryCollectionMock->expects($this->any())->method('addCountryCodeFilter')->willReturn($countryCollectionMock);
     $this->countryFactoryMock->expects($this->any())->method('create')->willReturn($countryCollectionMock);
     $this->configMock->expects($this->any())->method('canUseForCountry')->willReturn($params['canUseForCountry']);
     $this->configMock->expects($this->any())->method('canUseCcTypeForCountry')->willReturn($params['canUseCcTypeForCountry']);
     $this->helperMock->expects($this->any())->method('generateCustomerId')->willReturn($params['customerId']);
     $this->customerMock->expects($this->any())->method('load')->willReturn($this->customerMock);
     $this->customerFactoryMock->expects($this->any())->method('create')->willReturn($this->customerMock);
     if (is_object($params['paymentMethodObj'])) {
         if (!$params['optionsArray']['update']) {
             $this->braintreePaymentMethodMock->expects($this->once())->method('create')->willReturn($params['paymentMethodObj']);
         } else {
             $this->braintreePaymentMethodMock->expects($this->once())->method('update')->willReturn($params['paymentMethodObj']);
         }
         if (!$params['paymentMethodObj']->success) {
             $this->errorHelperMock->expects($this->once())->method('parseBraintreeError')->willReturn(new \Magento\Framework\Phrase($exceptionMessage));
         } else {
             $this->errorHelperMock->expects($this->never())->method('parseBraintreeError');
         }
     }
     try {
         $this->model->processNonce($params['nonce'], $params['optionsArray'], $params['billingAddress']);
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $this->assertEquals($exceptionMessage, $e->getMessage());
     }
 }
 /**
  * @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'])];
 }
Example #21
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'];
 }
 /**
  * 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;
 }
Example #23
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;
     }
 }
Example #25
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, []);
         }
     }
 }
Example #28
0
 /**
  * @param $customerId
  * @return \PHPUnit_Framework_MockObject_MockObject
  */
 protected function prepareLoginDataMock($customerId)
 {
     $customerDataMock = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false);
     $customerDataMock->expects($this->once())->method('getId')->will($this->returnValue($customerId));
     $customerMock = $this->getMock('Magento\\Customer\\Model\\Customer', [], [], '', false);
     $customerMock->expects($this->once())->method('getId')->will($this->returnValue($customerId));
     $customerMock->expects($this->once())->method('isConfirmationRequired')->will($this->returnValue(true));
     $customerMock->expects($this->never())->method('getConfirmation')->will($this->returnValue($customerId));
     $this->customerFactoryMock->expects($this->once())->method('create')->will($this->returnValue($customerMock));
     $customerMock->expects($this->once())->method('updateData')->with($customerDataMock)->will($this->returnSelf());
     $this->_httpContextMock->expects($this->exactly(3))->method('setValue');
     return $customerDataMock;
 }
 /**
  * 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;
 }
 /**
  * @return void
  */
 public function testAuthenticate()
 {
     $username = '******';
     $password = '******';
     $customerData = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock();
     $customerModel = $this->getMockBuilder('Magento\\Customer\\Model\\Customer')->disableOriginalConstructor()->getMock();
     $customerModel->expects($this->once())->method('updateData')->willReturn($customerModel);
     $this->customerRepository->expects($this->once())->method('get')->with($username)->willReturn($customerData);
     $this->accountManagementHelper->expects($this->once())->method('checkIfLocked')->with($customerData);
     $this->accountManagementHelper->expects($this->once())->method('validatePasswordAndLockStatus')->with($customerData, $password);
     $this->customerFactory->expects($this->once())->method('create')->willReturn($customerModel);
     $this->manager->expects($this->exactly(2))->method('dispatch')->withConsecutive(['customer_customer_authenticated', ['model' => $customerModel, 'password' => $password]], ['customer_data_object_login', ['customer' => $customerData]]);
     $this->assertEquals($customerData, $this->accountManagement->authenticate($username, $password));
 }