对象已移动

可在此处找到该文档 Get Customer Address in String format in Magento 2 – New Self New Life
New Self New Life
No Result
View All Result
  • Home
  • Entertainment
  • Celebrity
  • Cinema
  • Music
  • Digital Lifestyle
  • Social Media
  • Softwares
  • Devices
  • Home
  • Entertainment
  • Celebrity
  • Cinema
  • Music
  • Digital Lifestyle
  • Social Media
  • Softwares
  • Devices
New Self New Life
No Result
View All Result
Home Softwares

Get Customer Address in String format in Magento 2

by admin
4 years ago
in Softwares
Get Customer Address in String format in Magento 2
Share on FacebookShare on Twitter


Good day Mates!

On this weblog, we’re going to learn the way we will get an tackle in string format.

Within the following controller, we have now loaded an tackle by id and received the string format of that tackle.

<?php
/**
 * Vendor Desc.
 *
 * @class  Vendor
 * @package deal   Vendor_CustomModule
 * @creator    Vendor
 * @copyright Copyright (c) Vendor
 * @license   https://instance.com/license.html
 */
namespace VendorCustomModuleControllerDemo;

use MagentoFrameworkAppActionAction;
use MagentoFrameworkAppActionContext;
use MagentoFrameworkControllerResultFactory;

class GetAddressFormatString extends Motion
{
    /**
     * @var ResultFactory
     */
    protected $resultFactory;

    /**
     * initialization
     *
     * @param Context $context
     * @param ResultFactory $resultFactory
     * @param MagentoCustomerModelAddressConfig $addressConfig
     * @param MagentoCustomerModelAddressMapper $addressMapper
     * @param MagentoCustomerApiAddressRepositoryInterface $addressRepository
     * 
     * @return void
     */
    public operate __construct(
        Context $context,
        ResultFactory $resultFactory,
        MagentoCustomerModelAddressConfig $addressConfig,
        MagentoCustomerModelAddressMapper $addressMapper,
        MagentoCustomerApiAddressRepositoryInterface $addressRepository
    ) {
        $this->resultFactory     = $resultFactory;
        $this->addressRepository = $addressRepository;
        $this->addressConfig     = $addressConfig;
        $this->addressMapper     = $addressMapper;
        dad or mum::__construct($context);
    }
    
    /**
     * Execute methodology to get outcome
     */
    public operate execute()
    {
        $addressId = 1;
        $outcome = $this->resultFactory->create(MagentoFrameworkControllerResultFactory::TYPE_RAW);
        $addressString = $this->getFormattedAddressAsStringByAddressId($addressId);
        $result->setHeader('Content material-Kind','textual content/html')
            ->setContents('Deal with: '.$addressString);

        return $outcome;
    }

    /**
     * Get Formatted Deal with as String
     * 
     * @param int $addressId
     * @return string
     */
    public operate getFormattedAddressAsStringByAddressId($addressId)
    {
        $addressString = "";
        strive {
            $addressObject = $this->addressRepository->getById($addressId);
            /** @var MagentoCustomerBlockAddressRendererRendererInterface $renderer */
            $renderer = $this->addressConfig->getFormatByCode('html')->getRenderer();
            $addressString = $renderer->renderArray(
                $this->addressMapper->toFlatArray($addressObject)
            );
        } catch (MagentoFrameworkExceptionNoSuchEntityException $e) {
            return "";
        }
        return $addressString;
    }
}

Now, after we execute this controller on the browser. We are going to get the outcome as following picture:

AddressInStringFormat
author-thumb

Khushboo Sahu
5 Badges

5 October 2021



Source link

Tags: AddressCustomerformatMagentoString
Previous Post

Supermodel Chanel Iman & NFLer Sterling Shepard Allegedly SPLIT!!

Next Post

Twitter Removes Live Stream Guests Option in Order to Improve Broadcast Quality

Related Posts

Avoid these common platform engineering mistakes
Softwares

Avoid these common platform engineering mistakes

by admin
July 4, 2025
Meta slams ‘incorrect and unlawful’ EU DMA ruling
Softwares

Meta slams ‘incorrect and unlawful’ EU DMA ruling

by admin
July 3, 2025
Best Practices, Tools, xUnit, and NUnit Framework
Softwares

Best Practices, Tools, xUnit, and NUnit Framework

by admin
July 1, 2025
Start up crash fix – Vivaldi iOS Browser snapshot 3737.4
Softwares

Start up crash fix – Vivaldi iOS Browser snapshot 3737.4

by admin
June 30, 2025
Windows’ infamous ‘blue screen of death’ will soon turn black
Softwares

Windows’ infamous ‘blue screen of death’ will soon turn black

by admin
June 28, 2025
Next Post
Twitter Removes Live Stream Guests Option in Order to Improve Broadcast Quality

Twitter Removes Live Stream Guests Option in Order to Improve Broadcast Quality

Kelly Clarkson Shades Her Ex-Husband With Billie Eilish ‘Kellyoke’ Lyric Swap – Watch!

Kelly Clarkson Shades Her Ex-Husband With Billie Eilish 'Kellyoke' Lyric Swap - Watch!

  • Trending
  • Comments
  • Latest
‘America is back’: Foo Fighters show hits 100% capacity at Madison Square Garden – National

‘America is back’: Foo Fighters show hits 100% capacity at Madison Square Garden – National

June 22, 2021
Games teach kids climate action

Games teach kids climate action

January 23, 2024
Jane Withers, child actor and commercial star, dies at 95 – National

Jane Withers, child actor and commercial star, dies at 95 – National

August 10, 2021
How to integrate Odoo with ReactJs frontend

How to integrate Odoo with ReactJs frontend

October 7, 2024
All the glamorous celebrity looks from the Jeff Bezos, Lauren Sánchez wedding – National

All the glamorous celebrity looks from the Jeff Bezos, Lauren Sánchez wedding – National

June 28, 2025
Kanye West entry visa revoked by Australia after ‘Heil Hitler’ song release – National

Kanye West entry visa revoked by Australia after ‘Heil Hitler’ song release – National

July 3, 2025
Indiana Evans: What happened to the H2O Australian actress Indiana Evans and what is she doing now? | Explainer

Indiana Evans: What happened to the H2O Australian actress Indiana Evans and what is she doing now? | Explainer

December 7, 2024
Bones: All Of Brennan’s Interns, Ranked

Bones: All Of Brennan’s Interns, Ranked

June 15, 2021
Latest Sales Data Reveal Clear Winners And Losers in a Messy EV Market

Latest Sales Data Reveal Clear Winners And Losers in a Messy EV Market

July 5, 2025
Critics And Fans Disagree On Netflix’s Controversial Fantasy Show With Near-Perfect RT Score

Critics And Fans Disagree On Netflix’s Controversial Fantasy Show With Near-Perfect RT Score

July 5, 2025
Nip/Tuck Star Julian McMahon Dead at 56 After Private Cancer Battle

Nip/Tuck Star Julian McMahon Dead at 56 After Private Cancer Battle

July 5, 2025
Alesso and Sentinel Channel Raw Emotion on Thunderous New Single "Freedom"

Alesso and Sentinel Channel Raw Emotion on Thunderous New Single "Freedom"

July 5, 2025
The best early deals live before the sale, plus everything else you need to know

The best early deals live before the sale, plus everything else you need to know

July 4, 2025
Influencer Alix Earle Reveals The ONE Cosmetic Surgery She Regrets! (You'll Never Guess!)

Influencer Alix Earle Reveals The ONE Cosmetic Surgery She Regrets! (You'll Never Guess!)

July 5, 2025
The Rest Is Bulls*!t’ YouTube To Feature Prince Harry

The Rest Is Bulls*!t’ YouTube To Feature Prince Harry

July 4, 2025
Top 50 American Rock Songs

Top 50 American Rock Songs

July 4, 2025
New Self New Life

Your source for entertainment news, celebrities, celebrity news, and Music, Cinema, Digital Lifestyle and Social Media and More !

Categories

  • Celebrity
  • Cinema
  • Devices
  • Digital Lifestyle
  • Entertainment
  • Music
  • Social Media
  • Softwares
  • Uncategorized

Recent Posts

  • Latest Sales Data Reveal Clear Winners And Losers in a Messy EV Market
  • Critics And Fans Disagree On Netflix’s Controversial Fantasy Show With Near-Perfect RT Score
  • Nip/Tuck Star Julian McMahon Dead at 56 After Private Cancer Battle
  • Home
  • Disclaimer
  • DMCA
  • Privacy Policy
  • Cookie Privacy Policy
  • Terms and Conditions
  • Contact us

Copyright © 2021 New Self New Life.
New Self New Life is not responsible for the content of external sites. slotsfree  creator solana token

No Result
View All Result
  • Home
  • Entertainment
  • Celebrity
  • Cinema
  • Music
  • Digital Lifestyle
  • Social Media
  • Softwares
  • Devices

Copyright © 2021 New Self New Life.
New Self New Life is not responsible for the content of external sites.

New Self New Life