/**
  * @expectedException \Magento\Customer\Exception
  * @expectedExceptionMessage exception message
  */
 public function testCreateCustomerWithPasswordHashException()
 {
     $storeId = 5;
     $customerData = array('id' => self::ID, 'email' => self::EMAIL, 'firstname' => self::FIRSTNAME, 'lastname' => self::LASTNAME, 'store_id' => $storeId, 'website_id' => self::WEBSITE_ID);
     $this->_customerBuilder->populateWithArray($customerData);
     $customerEntity = $this->_customerBuilder->create();
     $customerDetails = $this->_customerDetailsBuilder->setCustomer($customerEntity)->create();
     $this->_storeManagerMock->expects($this->once())->method('getStores')->will($this->returnValue(array()));
     $this->_converter = $this->getMock('Magento\\Customer\\Model\\Converter', array('getCustomerModel', 'createCustomerModel'), array(), '', false);
     $this->_converter->expects($this->once())->method('getCustomerModel')->will($this->returnValue($this->_customerModelMock));
     $this->_converter->expects($this->once())->method('createCustomerModel')->will($this->throwException(new \Magento\Customer\Exception('exception message', 0)));
     $customerService = $this->_createService();
     $customerService->createCustomerWithPasswordHash($customerDetails, '', '');
 }
 public function connectByCreatingAccount($facebookId, $token, $email, $firstName, $lastName)
 {
     $customerDetails = array('firstname' => $firstName, 'lastname' => $lastName, 'email' => $email, 'sendemail' => 0, 'confirmation' => 0, 'custom_attributes' => array(array(\Magento\Framework\Service\Data\AttributeValue::ATTRIBUTE_CODE => 'inchoo_socialconnect_fid', \Magento\Framework\Service\Data\AttributeValue::VALUE => $facebookId), array(\Magento\Framework\Service\Data\AttributeValue::ATTRIBUTE_CODE => 'inchoo_socialconnect_ftoken', \Magento\Framework\Service\Data\AttributeValue::VALUE => serialize($token))));
     $customer = $this->_customerBuilder->populateWithArray($customerDetails)->create();
     // Save customer
     $customerDetails = $this->_customerDetailsBuilder->setCustomer($customer)->setAddresses(null)->create();
     $customerDataObject = $this->_customerAccountService->createCustomer($customerDetails);
     /* @var $customer \Magento\Customer\Service\V1\Data\Customer */
     // Convert data object to customer model
     $customer = $this->_converter->createCustomerModel($customerDataObject);
     /* @var $customer \Magento\Customer\Model\Customer */
     $customer->sendNewAccountEmail('confirmed', '');
     $this->_customerSession->setCustomerAsLoggedIn($customer);
 }
示例#3
0
 /**
  * Prepares and render result of composite product configuration request
  *
  * The $configureResult variable holds either:
  *  - 'ok' = true, and 'product_id', 'buy_request', 'current_store_id', 'current_customer_id'
  *  - 'error' = true, and 'message' to show
  *
  * @param \Magento\Framework\Object $configureResult
  * @return void
  */
 public function renderConfigureResult(\Magento\Framework\Object $configureResult)
 {
     try {
         if (!$configureResult->getOk()) {
             throw new \Magento\Framework\Model\Exception($configureResult->getMessage());
         }
         $currentStoreId = (int) $configureResult->getCurrentStoreId();
         if (!$currentStoreId) {
             $currentStoreId = $this->_storeManager->getStore()->getId();
         }
         $product = $this->_productFactory->create()->setStoreId($currentStoreId)->load($configureResult->getProductId());
         if (!$product->getId()) {
             throw new \Magento\Framework\Model\Exception(__('The product is not loaded.'));
         }
         $this->_coreRegistry->register('current_product', $product);
         $this->_coreRegistry->register('product', $product);
         // Register customer we're working with
         $customerId = (int) $configureResult->getCurrentCustomerId();
         // TODO: Remove the customer model from the registry once all readers are refactored
         $customerModel = $this->_converter->loadCustomerModel($customerId);
         $this->_coreRegistry->register(RegistryConstants::CURRENT_CUSTOMER, $customerModel);
         $this->_coreRegistry->register(RegistryConstants::CURRENT_CUSTOMER_ID, $customerId);
         // Prepare buy request values
         $buyRequest = $configureResult->getBuyRequest();
         if ($buyRequest) {
             $this->_catalogProduct->prepareProductOptions($product, $buyRequest);
         }
         $isOk = true;
         $productType = $product->getTypeId();
     } catch (\Exception $e) {
         $isOk = false;
         $productType = null;
         $this->_coreRegistry->register('composite_configure_result_error_message', $e->getMessage());
     }
     $this->_initConfigureResultLayout($isOk, $productType);
     $this->_view->renderLayout();
 }
示例#4
0
 /**
  * @param CustomerData $customer
  * @return $this
  */
 public function setCustomerDataAsLoggedIn($customer)
 {
     $this->_httpContext->setValue(\Magento\Customer\Helper\Data::CONTEXT_AUTH, true, false);
     $this->setCustomerData($customer);
     $customerModel = $this->_converter->createCustomerModel($customer);
     $this->setCustomer($customerModel);
     $this->_eventManager->dispatch('customer_login', array('customer' => $customerModel));
     $this->_eventManager->dispatch('customer_data_object_login', ['customer' => $customer]);
     return $this;
 }
示例#5
0
 /**
  * Update customer data object
  *
  * @param CustomerDataObject $customerData
  * @return $this
  */
 public function updateCustomerData(CustomerDataObject $customerData)
 {
     $customer = $this->getCustomer();
     /* @TODO: remove this code in favor of customer Data Object usage MAGETWO-19930 */
     $this->_converter->updateCustomerModel($customer, $customerData);
     $this->setCustomer($customer);
     return $this;
 }
 /**
  * {@inheritDoc}
  */
 public function getCustomerByEmail($customerEmail, $websiteId = null)
 {
     $customerModel = $this->customerRegistry->retrieveByEmail($customerEmail, $websiteId);
     return $this->converter->createCustomerFromModel($customerModel);
 }
 /**
  * @expectedException \Magento\Framework\Exception\NoSuchEntityException
  * @expectedExceptionMessage No such entity with email
  */
 public function testGetCustomerModelByEmailException()
 {
     $customerId = 0;
     $websiteId = 1;
     $customerEmail = '*****@*****.**';
     $this->prepareGetCustomerModelByEmail($websiteId, $customerEmail, $customerId);
     $this->storeManagerMock->expects($this->never())->method('getDefaultStoreView');
     $converter = new Converter($this->customerBuilderMock, $this->customerFactoryMock, $this->storeManagerMock);
     $this->assertInstanceOf('Magento\\Customer\\Model\\Customer', $converter->getCustomerModelByEmail('*****@*****.**', $websiteId));
 }