/**
  * @magentoDataFixture Magento/Customer/_files/customer.php
  */
 public function testGetCustomerAttributeMetadata()
 {
     // Expect these attributes to exist but do not check the value
     $expectAttrsWOutVals = array('created_at');
     // Expect these attributes to exist and check the value - values come from _files/customer.php
     $expectAttrsWithVals = array('id' => '1', 'website_id' => '1', 'store_id' => '1', 'group_id' => '1', 'firstname' => 'Firstname', 'lastname' => 'Lastname', 'email' => '*****@*****.**', 'default_billing' => '1', 'default_shipping' => '1', 'disable_auto_group_change' => '0');
     $customer = $this->_customerAccountService->getCustomer(1);
     $this->assertNotNull($customer);
     $attributes = \Magento\Framework\Service\ExtensibleDataObjectConverter::toFlatArray($customer);
     $this->assertNotEmpty($attributes);
     foreach ($attributes as $attributeCode => $attributeValue) {
         $this->assertNotNull($attributeCode);
         $this->assertNotNull($attributeValue);
         $attributeMetadata = $this->_service->getAttributeMetadata($attributeCode);
         $attrMetadataCode = $attributeMetadata->getAttributeCode();
         $this->assertSame($attributeCode, $attrMetadataCode);
         if (($key = array_search($attrMetadataCode, $expectAttrsWOutVals)) !== false) {
             unset($expectAttrsWOutVals[$key]);
         } else {
             $this->assertArrayHasKey($attrMetadataCode, $expectAttrsWithVals);
             $this->assertSame($expectAttrsWithVals[$attrMetadataCode], $attributeValue, "Failed for {$attrMetadataCode}");
             unset($expectAttrsWithVals[$attrMetadataCode]);
         }
     }
     $this->assertEmpty($expectAttrsWOutVals);
     $this->assertEmpty($expectAttrsWithVals);
 }
Exemple #2
0
 /**
  * Retrieve Shared Wishlist Customer instance
  *
  * @return \Magento\Customer\Service\V1\Data\Customer
  */
 public function getWishlistCustomer()
 {
     if (is_null($this->_customer)) {
         $this->_customer = $this->_customerAccountService->getCustomer($this->_getWishlist()->getCustomerId());
     }
     return $this->_customer;
 }
Exemple #3
0
 /**
  * Make sure customer is valid, if logged in
  *
  * By default will add error messages and redirect to customer edit form
  *
  * @param bool $redirect - stop dispatch and redirect?
  * @param bool $addErrors - add error messages?
  * @return bool
  */
 protected function _preDispatchValidateCustomer($redirect = true, $addErrors = true)
 {
     try {
         $customerId = $this->_customerSession->getCustomerId();
         $customer = $this->_customerAccountService->getCustomer($customerId);
     } catch (NoSuchEntityException $e) {
         return true;
     }
     if (isset($customer)) {
         $validationResult = $this->_customerAccountService->validateCustomerData($customer, $this->_customerMetadataService->getAllCustomerAttributeMetadata());
         if (!$validationResult->isValid()) {
             if ($addErrors) {
                 foreach ($validationResult->getMessages() as $error) {
                     $this->messageManager->addError($error);
                 }
             }
             if ($redirect) {
                 $this->_redirect('customer/account/edit');
                 $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
             }
             return false;
         }
     }
     return true;
 }
Exemple #4
0
 /**
  * Return the full name of the customer currently logged in
  *
  * @return string|null
  */
 public function getCustomerName()
 {
     try {
         $customer = $this->_customerAccountService->getCustomer($this->currentCustomer->getCustomerId());
         return $this->escapeHtml($this->_viewHelper->getCustomerName($customer));
     } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
         return null;
     }
 }
 /**
  * Set persistent data to customer session
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute($observer)
 {
     if (!$this->_persistentData->canProcess($observer) || !$this->_persistentData->isShoppingCartPersist()) {
         return $this;
     }
     if ($this->_persistentSession->isPersistent() && !$this->_customerSession->isLoggedIn()) {
         $customer = $this->_customerAccountService->getCustomer($this->_persistentSession->getSession()->getCustomerId());
         $this->_customerSession->setCustomerId($customer->getId())->setCustomerGroupId($customer->getGroupId());
     }
     return $this;
 }
 /**
  * Update customer id and customer group id if user is in persistent session
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if (!$this->_persistentSession->isPersistent()) {
         return;
     }
     $customerCookies = $observer->getEvent()->getCustomerCookies();
     if ($customerCookies instanceof \Magento\Framework\Object) {
         $persistentCustomer = $this->_customerAccountService->getCustomer($this->_persistentSession->getSession()->getCustomerId());
         $customerCookies->setCustomerId($persistentCustomer->getId());
         $customerCookies->setCustomerGroupId($persistentCustomer->getGroupId());
     }
 }
Exemple #7
0
 /**
  * @magentoDataFixture Magento/Customer/_files/customer.php
  * @magentoDataFixture Magento/Core/_files/second_third_store.php
  * @magentoConfigFixture current_store customer/account_share/scope 0
  */
 public function testToHtmlEmptyGlobalShareAndSessionData()
 {
     $this->registry->register(RegistryConstants::CURRENT_CUSTOMER_ID, 1);
     $customer = $this->customerAccountService->getCustomer(1);
     $this->backendSession->setCustomerData(array('account' => $customer->__toArray()));
     $block = $this->layout->createBlock('Magento\\Customer\\Block\\Adminhtml\\Edit\\Tab\\View\\Accordion');
     $html = $block->toHtml();
     $this->assertContains('Wishlist - 0 item(s)', $html);
     $this->assertContains('Shopping Cart of Main Website - 0 item(s)', $html);
     $this->assertContains('Shopping Cart of Second Website - 0 item(s)', $html);
     $this->assertContains('Shopping Cart of Third Website - 0 item(s)', $html);
 }
 /**
  * @magentoAppArea frontend
  * @magentoConfigFixture current_store persistent/options/shopping_cart 1
  * @magentoConfigFixture current_store persistent/options/logout_clear 0
  * @magentoConfigFixture current_store persistent/options/enabled 1
  */
 public function testEmulateCustomer()
 {
     $observer = new \Magento\Framework\Event\Observer();
     $this->_customerSession->loginById(1);
     $this->_customerSession->logout();
     $this->assertNull($this->_customerSession->getCustomerId());
     $this->assertEquals(\Magento\Customer\Service\V1\CustomerGroupServiceInterface::NOT_LOGGED_IN_ID, $this->_customerSession->getCustomerGroupId());
     $this->_observer->execute($observer);
     $customer = $this->_customerAccountService->getCustomer($this->_persistentSessionHelper->getSession()->getCustomerId());
     $this->assertEquals($customer->getId(), $this->_customerSession->getCustomerId());
     $this->assertEquals($customer->getGroupId(), $this->_customerSession->getCustomerGroupId());
 }
Exemple #9
0
 /**
  * @magentoDataFixture Magento/Customer/_files/customer.php
  */
 public function testGetHtml()
 {
     $customer = $this->_customerAccountService->getCustomer(1);
     $data = array('account' => $customer->__toArray());
     $this->_context->getBackendSession()->setCustomerData($data);
     $this->_block = $this->_objectManager->get('Magento\\Framework\\View\\LayoutInterface')->createBlock('Magento\\Customer\\Block\\Adminhtml\\Edit\\Tab\\Carts', '', array('context' => $this->_context));
     $html = $this->_block->toHtml();
     $this->assertContains("<div id=\"customer_cart_grid1\">", $html);
     $this->assertContains("<div class=\"grid-actions\">", $html);
     $this->assertContains("customer_cart_grid1JsObject = new varienGrid('customer_cart_grid1',", $html);
     $this->assertContains("backend/customer/cart_product_composite_cart/configure/website_id/1", $html);
 }
 /**
  * @magentoConfigFixture current_store persistent/options/enabled 1
  * @magentoConfigFixture current_store persistent/options/remember_enabled 1
  * @magentoConfigFixture current_store persistent/options/remember_default 1
  * @magentoAppArea frontend
  * @magentoConfigFixture current_store persistent/options/shopping_cart 1
  * @magentoConfigFixture current_store persistent/options/logout_clear 0
  */
 public function testEmulateQuote()
 {
     $requestMock = $this->getMockBuilder('Magento\\Framework\\App\\Request\\Http')->disableOriginalConstructor()->setMethods([])->getMock();
     $requestMock->expects($this->once())->method('getFullActionName')->will($this->returnValue('valid_action'));
     $event = new \Magento\Framework\Event(['request' => $requestMock]);
     $observer = new \Magento\Framework\Event\Observer();
     $observer->setEvent($event);
     $this->_customerSession->loginById(1);
     $customer = $this->_customerAccountService->getCustomer($this->_persistentSessionHelper->getSession()->getCustomerId());
     $this->_checkoutSession->expects($this->once())->method('setCustomerData')->with($customer);
     $this->_customerSession->logout();
     $this->_observer->execute($observer);
 }
Exemple #11
0
 /**
  * Prepare the form.
  *
  * @return $this
  */
 protected function _prepareForm()
 {
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create(array('data' => array('id' => 'edit_form', 'action' => $this->getUrl('customer/*/save'), 'method' => 'post', 'enctype' => 'multipart/form-data')));
     $customerId = $this->_coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID);
     if ($customerId) {
         $form->addField('id', 'hidden', array('name' => 'customer_id'));
         $customer = $this->_customerAccountService->getCustomer($customerId);
         $form->setValues(\Magento\Framework\Service\ExtensibleDataObjectConverter::toFlatArray($customer))->addValues(array('customer_id' => $customerId));
     }
     $form->setUseContainer(true);
     $this->setForm($form);
     return parent::_prepareForm();
 }
Exemple #12
0
 /**
  * Get logged in customer
  *
  * @return \Magento\Customer\Service\V1\Data\Customer
  */
 protected function _getCustomerData()
 {
     if (empty($this->_customer)) {
         $this->_customer = $this->_customerAccountService->getCustomer($this->_customerSession->getCustomerId());
     }
     return $this->_customer;
 }
 /**
  * @return Customer
  */
 private function _loadCustomer()
 {
     $customer = $this->_customerAccountService->getCustomer(1);
     $data = array('account' => $customer->__toArray());
     $this->_context->getBackendSession()->setCustomerData($data);
     $this->_coreRegistry->register(RegistryConstants::CURRENT_CUSTOMER_ID, $customer->getId());
     return $customer;
 }
Exemple #14
0
 /**
  * Emulate 'welcome' block with persistent data
  *
  * @param \Magento\Framework\View\Element\AbstractBlock $block
  * @return $this
  */
 public function emulateWelcomeBlock($block)
 {
     $escapedName = $this->_escaper->escapeHtml($this->_customerViewHelper->getCustomerName($this->_customerAccountService->getCustomer($this->_persistentSession->getSession()->getCustomerId())), null);
     $this->_applyAccountLinksPersistentData();
     $welcomeMessage = __('Welcome, %1!', $escapedName) . ' ' . $this->_layout->getBlock('header.additional')->toHtml();
     $block->setWelcome($welcomeMessage);
     return $this;
 }
Exemple #15
0
 /**
  * @magentoDataFixture Magento/Customer/_files/customer.php
  */
 public function testNotReadOnly()
 {
     $this->backendSession->setCustomerData(array('customer_id' => 1, 'account' => $this->customerAccountService->getCustomer(1)->__toArray()));
     $this->accountBlock->initForm()->toHtml();
     $element = $this->accountBlock->getForm()->getElement('firstname');
     // Make sure readonly has not been set (is null) or set to false
     $this->assertTrue(is_null($element->getReadonly()) || !$element->getReadonly());
 }
 /**
  * @magentoAppArea adminhtml
  * @magentoDataFixture Magento/Customer/_files/customer.php
  * @magentoAppIsolation enabled
  */
 public function testDeleteCustomer()
 {
     // _files/customer.php sets the customer id to 1
     $this->_customerAccountService->deleteCustomer(1);
     //Verify if the customer is deleted
     $this->setExpectedException('Magento\\Framework\\Exception\\NoSuchEntityException', 'No such entity with customerId = 1');
     $this->_customerAccountService->getCustomer(1);
 }
Exemple #17
0
 /**
  * Authorization customer by identifier
  *
  * @param   int $customerId
  * @return  bool
  */
 public function loginById($customerId)
 {
     try {
         $customer = $this->_customerAccountService->getCustomer($customerId);
         $this->setCustomerDataAsLoggedIn($customer);
         return true;
     } catch (\Exception $e) {
         return false;
     }
 }
Exemple #18
0
 /**
  * Retrieve the header text, either the name of an existing customer or 'New Customer'.
  *
  * @return string
  */
 public function getHeaderText()
 {
     $customerId = $this->getCustomerId();
     if ($customerId) {
         $customerData = $this->_customerAccountService->getCustomer($customerId);
         return $this->escapeHtml($this->_viewHelper->getCustomerName($customerData));
     } else {
         return __('New Customer');
     }
 }
Exemple #19
0
 /**
  * Get customer data from session or service.
  *
  * @param int|null $customerId possible customer ID from DB
  * @return Customer
  * @throws NoSuchEntityException
  */
 protected function getCustomer($customerId)
 {
     $customerData = $this->_backendSession->getCustomerData();
     if (!empty($customerData['account'])) {
         return $this->_customerBuilder->populateWithArray($customerData['account'])->create();
     } elseif ($customerId) {
         return $this->_customerAccountService->getCustomer($customerId);
     } else {
         return $this->_customerBuilder->create();
     }
 }
Exemple #20
0
 /**
  * Verify that the specified customer has the same default billing and shipping address.
  *
  * @magentoDataFixture Magento/Customer/_files/customer.php
  * @magentoDataFixture Magento/Customer/_files/customer_address.php
  */
 public function testGetPrimaryAddressesBillingShippingSame()
 {
     $customer = $this->customerAccountService->getCustomer(1);
     $this->customerSession->setCustomerId(1);
     $addresses = $this->block->getPrimaryAddresses();
     $this->assertCount(1, $addresses);
     $address = $addresses[0];
     $this->assertInstanceOf('Magento\\Customer\\Service\\V1\\Data\\Address', $address);
     $this->assertEquals($customer->getDefaultBilling(), $address->getId());
     $this->assertEquals($customer->getDefaultShipping(), $address->getId());
 }
Exemple #21
0
 /**
  * @magentoDataFixture Magento/Customer/_files/two_customers.php
  */
 public function testMassAssignGroupActionPartialUpdate()
 {
     $this->assertEquals(1, $this->customerAccountService->getCustomer(1)->getGroupId());
     $this->assertEquals(1, $this->customerAccountService->getCustomer(2)->getGroupId());
     $this->getRequest()->setParam('group', 0)->setPost('customer', array(1, 4200, 2));
     $this->dispatch('backend/customer/index/massAssignGroup');
     $this->assertSessionMessages($this->equalTo(array('A total of 2 record(s) were updated.')), \Magento\Framework\Message\MessageInterface::TYPE_SUCCESS);
     $this->assertSessionMessages($this->equalTo(array('No such entity with customerId = 4200')), \Magento\Framework\Message\MessageInterface::TYPE_ERROR);
     $this->assertEquals(0, $this->customerAccountService->getCustomer(1)->getGroupId());
     $this->assertEquals(0, $this->customerAccountService->getCustomer(2)->getGroupId());
 }
Exemple #22
0
 /**
  * @magentoDataFixture Magento/Customer/_files/customer.php
  * @magentoDataFixture Magento/Catalog/_files/product_simple.php
  */
 public function testSend()
 {
     $this->_objectManager->configure(['Magento\\ProductAlert\\Model\\Email' => ['arguments' => ['transportBuilder' => ['instance' => 'Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock']]], 'preferences' => ['Magento\\Framework\\Mail\\TransportInterface' => 'Magento\\TestFramework\\Mail\\TransportInterfaceMock']]);
     \Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea(\Magento\Framework\App\Area::AREA_FRONTEND);
     $this->_emailModel = $this->_objectManager->create('Magento\\ProductAlert\\Model\\Email');
     /** @var \Magento\Store\Model\Website $website */
     $website = $this->_objectManager->create('Magento\\Store\\Model\\Website');
     $website->load(1);
     $this->_emailModel->setWebsite($website);
     /** @var \Magento\Customer\Service\V1\Data\Customer $customer */
     $customer = $this->_customerAccountService->getCustomer(1);
     $this->_emailModel->setCustomerData($customer);
     /** @var \Magento\Catalog\Model\Product $product */
     $product = $this->_objectManager->create('Magento\\Catalog\\Model\\Product');
     $product->load(1);
     $this->_emailModel->addPriceProduct($product);
     $this->_emailModel->send();
     /** @var \Magento\TestFramework\Mail\Template\TransportBuilderMock $transportBuilder */
     $transportBuilder = $this->_objectManager->get('Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock');
     $this->assertStringMatchesFormat('%AHello ' . $this->_customerViewHelper->getCustomerName($customer) . '%A', $transportBuilder->getSentMessage()->getBodyHtml()->getContent());
 }
 /**
  * @magentoConfigFixture current_store persistent/options/enabled 1
  * @magentoConfigFixture current_store persistent/options/remember_enabled 1
  * @magentoConfigFixture current_store persistent/options/remember_default 1
  * @magentoAppArea frontend
  * @magentoAppIsolation enabled
  */
 public function testEmulateWelcomeBlock()
 {
     $this->_customerSession->loginById(1);
     $httpContext = new \Magento\Framework\App\Http\Context();
     $httpContext->setValue(\Magento\Customer\Helper\Data::CONTEXT_AUTH, 1, 1);
     $block = $this->_objectManager->create('Magento\\Sales\\Block\\Reorder\\Sidebar', ['httpContext' => $httpContext]);
     $this->_observer->emulateWelcomeBlock($block);
     $customerName = $this->_escaper->escapeHtml($this->_customerViewHelper->getCustomerName($this->_customerAccountService->getCustomer($this->_persistentSessionHelper->getSession()->getCustomerId())));
     $translation = __('Welcome, %1!', $customerName);
     $this->assertStringMatchesFormat('%A' . $translation . '%A', $block->getWelcome());
     $this->_customerSession->logout();
 }
Exemple #24
0
 /**
  * Set data to block
  *
  * @return string
  */
 protected function _toHtml()
 {
     $agreement = $this->_getBillingAgreement();
     $this->setReferenceId($agreement->getReferenceId());
     $customerId = $agreement->getCustomerId();
     $customer = $this->_customerAccountService->getCustomer($customerId);
     $this->setCustomerEmail($customer->getEmail());
     $this->setCustomerUrl($this->getUrl('customer/index/edit', array('id' => $customerId)));
     $this->setStatus($agreement->getStatusLabel());
     $this->setCreatedAt($this->formatDate($agreement->getCreatedAt(), 'short', true));
     $this->setUpdatedAt($agreement->getUpdatedAt() ? $this->formatDate($agreement->getUpdatedAt(), 'short', true) : __('N/A'));
     return parent::_toHtml();
 }
Exemple #25
0
 /**
  * @return \Magento\Customer\Service\V1\Data\Customer|null
  */
 public function getCustomer()
 {
     $customer = $this->getData('customer');
     if (is_null($customer)) {
         try {
             $customer = $this->_customerAccountService->getCustomer($this->currentCustomer->getCustomerId());
         } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
             return null;
         }
         $this->setData('customer', $customer);
     }
     return $customer;
 }
Exemple #26
0
 /**
  * Prepare edit review form
  *
  * @return $this
  */
 protected function _prepareForm()
 {
     $review = $this->_coreRegistry->registry('review_data');
     $product = $this->_productFactory->create()->load($review->getEntityPkValue());
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create(array('data' => array('id' => 'edit_form', 'action' => $this->getUrl('review/*/save', array('id' => $this->getRequest()->getParam('id'), 'ret' => $this->_coreRegistry->registry('ret'))), 'method' => 'post')));
     $fieldset = $form->addFieldset('review_details', array('legend' => __('Review Details'), 'class' => 'fieldset-wide'));
     $fieldset->addField('product_name', 'note', array('label' => __('Product'), 'text' => '<a href="' . $this->getUrl('catalog/product/edit', array('id' => $product->getId())) . '" onclick="this.target=\'blank\'">' . $this->escapeHtml($product->getName()) . '</a>'));
     try {
         $customer = $this->customerAccount->getCustomer($review->getCustomerId());
         $customerText = __('<a href="%1" onclick="this.target=\'blank\'">%2 %3</a> <a href="mailto:%4">(%4)</a>', $this->getUrl('customer/index/edit', array('id' => $customer->getId(), 'active_tab' => 'review')), $this->escapeHtml($customer->getFirstname()), $this->escapeHtml($customer->getLastname()), $this->escapeHtml($customer->getEmail()));
     } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
         $customerText = $review->getStoreId() == \Magento\Store\Model\Store::DEFAULT_STORE_ID ? __('Administrator') : __('Guest');
     }
     $fieldset->addField('customer', 'note', array('label' => __('Posted By'), 'text' => $customerText));
     $fieldset->addField('summary_rating', 'note', array('label' => __('Summary Rating'), 'text' => $this->getLayout()->createBlock('Magento\\Review\\Block\\Adminhtml\\Rating\\Summary')->toHtml()));
     $fieldset->addField('detailed_rating', 'note', array('label' => __('Detailed Rating'), 'required' => true, 'text' => '<div id="rating_detail">' . $this->getLayout()->createBlock('Magento\\Review\\Block\\Adminhtml\\Rating\\Detailed')->toHtml() . '</div>'));
     $fieldset->addField('status_id', 'select', array('label' => __('Status'), 'required' => true, 'name' => 'status_id', 'values' => $this->_reviewData->getReviewStatusesOptionArray()));
     /**
      * Check is single store mode
      */
     if (!$this->_storeManager->hasSingleStore()) {
         $field = $fieldset->addField('select_stores', 'multiselect', array('label' => __('Visible In'), 'required' => true, 'name' => 'stores[]', 'values' => $this->_systemStore->getStoreValuesForForm()));
         $renderer = $this->getLayout()->createBlock('Magento\\Backend\\Block\\Store\\Switcher\\Form\\Renderer\\Fieldset\\Element');
         $field->setRenderer($renderer);
         $review->setSelectStores($review->getStores());
     } else {
         $fieldset->addField('select_stores', 'hidden', array('name' => 'stores[]', 'value' => $this->_storeManager->getStore(true)->getId()));
         $review->setSelectStores($this->_storeManager->getStore(true)->getId());
     }
     $fieldset->addField('nickname', 'text', array('label' => __('Nickname'), 'required' => true, 'name' => 'nickname'));
     $fieldset->addField('title', 'text', array('label' => __('Summary of Review'), 'required' => true, 'name' => 'title'));
     $fieldset->addField('detail', 'textarea', array('label' => __('Review'), 'required' => true, 'name' => 'detail', 'style' => 'height:24em;'));
     $form->setUseContainer(true);
     $form->setValues($review->getData());
     $this->setForm($form);
     return parent::_prepareForm();
 }
Exemple #27
0
 /**
  * Put existing customer data into the backend session
  */
 protected function setupExistingCustomerData()
 {
     /** @var Customer $customer */
     $customer = $this->_customerAccountService->getCustomer(1);
     $this->_customerData = array('customer_id' => $customer->getId(), 'account' => \Magento\Framework\Service\ExtensibleDataObjectConverter::toFlatArray($customer));
     $this->_customerData['account']['id'] = $customer->getId();
     /** @var Address[] $addresses */
     $addresses = $this->_addressService->getAddresses(1);
     foreach ($addresses as $addressData) {
         $this->_customerData['address'][$addressData->getId()] = AddressConverter::toFlatArray($addressData);
         $this->_customerData['address'][$addressData->getId()]['id'] = $addressData->getId();
     }
     $this->_backendSession->setCustomerData($this->_customerData);
 }
Exemple #28
0
 /**
  * @magentoDataFixture Magento/Customer/_files/customer.php
  */
 public function testToHtml()
 {
     $customer = $this->customerAccountService->getCustomer($this->coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID));
     $customerData['customer_id'] = $customer->getId();
     $customerData['account'] = $customer->__toArray();
     $customerData['address'] = array();
     $this->context->getBackendSession()->setCustomerData($customerData);
     $html = $this->block->toHtml();
     $this->assertContains('name="cart" title="Shopping Cart"', $html);
     $this->assertContains('name="wishlist" title="Wishlist"', $html);
     $this->assertStringMatchesFormat('%a name="account[firstname]" %s value="Firstname" %a', $html);
     $this->assertStringMatchesFormat('%a name="account[lastname]" %s value="Lastname" %a', $html);
     $this->assertStringMatchesFormat('%a name="account[email]" %s value="*****@*****.**" %a', $html);
 }
Exemple #29
0
 /**
  * Initialize add new review
  *
  * @return void
  */
 protected function _construct()
 {
     $this->_addButtonLabel = __('Add New Review');
     parent::_construct();
     $this->_blockGroup = 'Magento_Review';
     $this->_controller = 'adminhtml';
     // lookup customer, if id is specified
     $customerId = $this->getRequest()->getParam('customerId', false);
     $customerName = '';
     if ($customerId) {
         $customer = $this->customerAccount->getCustomer($customerId);
         $customerName = $customer->getFirstname() . ' ' . $customer->getLastname();
         $customerName = $this->escapeHtml($customerName);
     }
     $productId = $this->getRequest()->getParam('productId', false);
     $productName = null;
     if ($productId) {
         $product = $this->_productFactory->create()->load($productId);
         $productName = $this->escapeHtml($product->getName());
     }
     if ($this->_coreRegistry->registry('usePendingFilter') === true) {
         if ($customerName) {
             $this->_headerText = __('Pending Reviews of Customer `%1`', $customerName);
         } else {
             $this->_headerText = __('Pending Reviews');
         }
         $this->buttonList->remove('add');
     } else {
         if ($customerName) {
             $this->_headerText = __('All Reviews of Customer `%1`', $customerName);
         } elseif ($productName) {
             $this->_headerText = __('All Reviews of Product `%1`', $productName);
         } else {
             $this->_headerText = __('All Reviews');
         }
     }
 }
Exemple #30
0
 /**
  * Retrieve default value for giftmessage sender
  *
  * @return string
  */
 public function getDefaultSender()
 {
     if (!$this->getEntity()) {
         return '';
     }
     if ($this->_getSession()->hasCustomerId() && $this->_getSession()->getCustomerId()) {
         $customerData = $this->_customerService->getCustomer($this->_getSession()->getCustomerId());
         return $this->_customerViewHelper->getCustomerName($customerData);
     }
     $object = $this->getEntity();
     if ($this->getEntity()->getQuote()) {
         $object = $this->getEntity()->getQuote();
     }
     return $object->getBillingAddress()->getName();
 }