本文整理汇总了PHP中Magento\Customer\Helper\View::getCustomerName方法的典型用法代码示例。如果您正苦于以下问题:PHP View::getCustomerName方法的具体用法?PHP View::getCustomerName怎么用?PHP View::getCustomerName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Customer\Helper\View
的用法示例。
在下文中一共展示了View::getCustomerName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testEmulateWelcomeBlock
/**
* @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(Context::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->customerRepository->getById($this->_persistentSessionHelper->getSession()->getCustomerId())));
$translation = __('Welcome, %1!', $customerName);
$this->assertStringMatchesFormat('%A' . $translation . '%A', $block->getWelcome());
$this->_customerSession->logout();
}
示例2: emulateWelcomeBlock
/**
* 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->customerRepository->getById($this->_persistentSession->getSession()->getCustomerId())), null);
$this->_applyAccountLinksPersistentData();
$welcomeMessage = __('Welcome, %1!', $escapedName) . ' ' . $this->_layout->getBlock('header.additional')->toHtml();
$block->setWelcome($welcomeMessage);
return $this;
}
示例3: testGetCustomerName
/**
* @param \Magento\Customer\Api\Data\CustomerInterface $customerData
* @param string $expectedCustomerName
* @param bool $isPrefixAllowed
* @param bool $isMiddleNameAllowed
* @param bool $isSuffixAllowed
* @dataProvider getCustomerNameDataProvider
*/
public function testGetCustomerName($customerData, $expectedCustomerName, $isPrefixAllowed = false, $isMiddleNameAllowed = false, $isSuffixAllowed = false)
{
$visibleAttribute = $this->getMock('Magento\\Customer\\Api\\Data\\AttributeMetadataInterface');
$visibleAttribute->expects($this->any())->method('isVisible')->will($this->returnValue(true));
$invisibleAttribute = $this->getMock('Magento\\Customer\\Api\\Data\\AttributeMetadataInterface');
$invisibleAttribute->expects($this->any())->method('isVisible')->will($this->returnValue(false));
$this->_customerMetadataService->expects($this->any())->method('getAttributeMetadata')->will($this->returnValueMap([['prefix', $isPrefixAllowed ? $visibleAttribute : $invisibleAttribute], ['middlename', $isMiddleNameAllowed ? $visibleAttribute : $invisibleAttribute], ['suffix', $isSuffixAllowed ? $visibleAttribute : $invisibleAttribute]]));
$this->assertEquals($expectedCustomerName, $this->_helper->getCustomerName($customerData), 'Full customer name is invalid');
}
示例4: getCustomerName
/**
* Return the full name of the customer currently logged in
*
* @return string|null
*/
public function getCustomerName()
{
try {
$customer = $this->customerRepository->getById($this->currentCustomer->getCustomerId());
return $this->escapeHtml($this->_viewHelper->getCustomerName($customer));
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
return null;
}
}
示例5: testProcess
/**
* @magentoConfigFixture current_store catalog/productalert/allow_price 1
*
* @magentoDataFixture Magento/ProductAlert/_files/product_alert.php
*/
public function testProcess()
{
$this->_objectManager->configure(['Magento\\ProductAlert\\Model\\Observer' => ['arguments' => ['transportBuilder' => ['instance' => 'Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock']]], 'Magento\\ProductAlert\\Model\\Email' => ['arguments' => ['transportBuilder' => ['instance' => 'Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock']]], 'preferences' => ['Magento\\Framework\\Mail\\TransportInterface' => 'Magento\\TestFramework\\Mail\\TransportInterfaceMock', 'Magento\\TestFramework\\Mail\\Template\\TransportBuilder' => 'Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock']]);
\Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea(\Magento\Framework\App\Area::AREA_FRONTEND);
$observer = $this->_objectManager->get('Magento\\ProductAlert\\Model\\Observer');
$observer->process();
/** @var \Magento\TestFramework\Mail\Template\TransportBuilderMock $transportBuilder */
$transportBuilder = $this->_objectManager->get('Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock');
$this->assertStringMatchesFormat('%AHello %A' . $this->_customerViewHelper->getCustomerName($this->_customerSession->getCustomerDataObject()) . ',%A', $transportBuilder->getSentMessage()->getBodyHtml()->getContent());
}
示例6: testGetCustomerName
/**
* @dataProvider getCustomerServiceDataProvider
*/
public function testGetCustomerName($prefix, $firstName, $middleName, $lastName, $suffix, $result)
{
$customerData = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->disableOriginalConstructor()->getMock();
$customerData->expects($this->any())->method('getPrefix')->will($this->returnValue($prefix));
$customerData->expects($this->any())->method('getFirstname')->will($this->returnValue($firstName));
$customerData->expects($this->any())->method('getMiddlename')->will($this->returnValue($middleName));
$customerData->expects($this->any())->method('getLastname')->will($this->returnValue($lastName));
$customerData->expects($this->any())->method('getSuffix')->will($this->returnValue($suffix));
$this->assertEquals($result, $this->object->getCustomerName($customerData));
}
示例7: getUserName
/**
* Get user name
*
* @return string
*/
public function getUserName()
{
if (!$this->_customerSession->isLoggedIn()) {
return '';
}
/**
* @var \Magento\Customer\Api\Data\CustomerInterface $customer
*/
$customer = $this->_customerSession->getCustomerDataObject();
return trim($this->_customerViewHelper->getCustomerName($customer));
}
示例8: getWelcome
/**
* Retrieve welcome text
*
* @return string
*/
public function getWelcome()
{
if (empty($this->_data['welcome'])) {
if ($this->httpContext->getValue(Context::CONTEXT_AUTH)) {
$customerName = $this->_customerViewHelper->getCustomerName($this->_customerSession->getCustomerDataObject());
$this->_data['welcome'] = __('Welcome, %1!', $this->escapeHtml($customerName));
} else {
$this->_data['welcome'] = $this->_scopeConfig->getValue('design/header/welcome', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
}
}
return $this->_data['welcome'];
}
示例9: getUserName
/**
* Retrieve username for form field
*
* @return string
*/
public function getUserName()
{
$name = $this->getFormData()->getData('sender/name');
if (!empty($name)) {
return trim($name);
}
/* @var $session \Magento\Customer\Model\Session */
$session = $this->_customerSession;
if ($this->httpContext->getValue(Context::CONTEXT_AUTH)) {
return $this->_customerViewHelper->getCustomerName($session->getCustomerDataObject());
}
return '';
}
示例10: load
/**
* Load search results
*
* @return $this
*/
public function load()
{
$result = [];
if (!$this->hasStart() || !$this->hasLimit() || !$this->hasQuery()) {
$this->setResults($result);
return $this;
}
$this->searchCriteriaBuilder->setCurrentPage($this->getStart());
$this->searchCriteriaBuilder->setPageSize($this->getLimit());
$searchFields = ['firstname', 'lastname', 'company'];
$filters = [];
foreach ($searchFields as $field) {
$filters[] = $this->filterBuilder->setField($field)->setConditionType('like')->setValue($this->getQuery() . '%')->create();
}
$this->searchCriteriaBuilder->addFilters($filters);
$searchCriteria = $this->searchCriteriaBuilder->create();
$searchResults = $this->customerRepository->getList($searchCriteria);
foreach ($searchResults->getItems() as $customer) {
$customerAddresses = $customer->getAddresses();
/** Look for a company name defined in default billing address */
$company = null;
foreach ($customerAddresses as $customerAddress) {
if ($customerAddress->getId() == $customer->getDefaultBilling()) {
$company = $customerAddress->getCompany();
break;
}
}
$result[] = ['id' => 'customer/1/' . $customer->getId(), 'type' => __('Customer'), 'name' => $this->_customerViewHelper->getCustomerName($customer), 'description' => $company, 'url' => $this->_adminhtmlData->getUrl('customer/index/edit', ['id' => $customer->getId()])];
}
$this->setResults($result);
return $this;
}
示例11: getFullCustomerObject
/**
* Create an object with data merged from Customer and CustomerSecure
*
* @param CustomerInterface $customer
* @return \Magento\Customer\Model\Data\CustomerSecure
*/
private function getFullCustomerObject($customer)
{
// No need to flatten the custom attributes or nested objects since the only usage is for email templates and
// object passed for events
$mergedCustomerData = $this->customerRegistry->retrieveSecureData($customer->getId());
$customerData = $this->dataProcessor->buildOutputDataArray($customer, \Magento\Customer\Api\Data\CustomerInterface::class);
$mergedCustomerData->addData($customerData);
$mergedCustomerData->setData('name', $this->customerViewHelper->getCustomerName($customer));
return $mergedCustomerData;
}
示例12: getHeaderText
/**
* Retrieve the header text, either the name of an existing customer or 'New Customer'.
*
* @return \Magento\Framework\Phrase|string
*/
public function getHeaderText()
{
$customerId = $this->getCustomerId();
if ($customerId) {
$customerData = $this->customerRepository->getById($customerId);
return $this->escapeHtml($this->_viewHelper->getCustomerName($customerData));
} else {
return __('New Customer');
}
}
示例13: getHeaderText
/**
* 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');
}
}
示例14: getUserName
/**
* Get user name
*
* @return string
*/
public function getUserName()
{
if (!$this->_customerSession->isLoggedIn()) {
return '';
}
/**
* @var Customer $customer
*/
$customer = $this->_customerSession->getCustomerDataObject();
return trim($this->_customerViewHelper->getCustomerName($customer));
}
示例15: testSendAction
/**
* @magentoDataFixture Magento/Wishlist/_files/wishlist.php
*/
public function testSendAction()
{
\Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea(\Magento\Framework\App\Area::AREA_FRONTEND);
$request = ['form_key' => $this->_objectManager->get('Magento\\Framework\\Data\\Form\\FormKey')->getFormKey(), 'emails' => 'test@tosend.com', 'message' => 'message', 'rss_url' => null];
$this->getRequest()->setPostValue($request);
$this->_objectManager->get('Magento\\Framework\\Registry')->register('wishlist', $this->_objectManager->get('Magento\\Wishlist\\Model\\Wishlist')->loadByCustomerId(1));
$this->dispatch('wishlist/index/send');
/** @var \Magento\TestFramework\Mail\Template\TransportBuilderMock $transportBuilder */
$transportBuilder = $this->_objectManager->get('Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock');
$actualResult = \Zend_Mime_Decode::decodeQuotedPrintable($transportBuilder->getSentMessage()->getBodyHtml()->getContent());
$this->assertStringMatchesFormat('%A' . $this->_customerViewHelper->getCustomerName($this->_customerSession->getCustomerDataObject()) . ' wants to share this Wish List%A', $actualResult);
}