对象已移动

可在此处找到该文档 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

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
User Guide for Unopim Odoo Connector
Softwares

User Guide for Unopim Odoo Connector

by admin
June 27, 2025
Warp 2.0 evolves its terminal experience into an Agentic Development Environment
Softwares

Warp 2.0 evolves its terminal experience into an Agentic Development Environment

by admin
June 25, 2025
10+ Best Text Animation Presets & Templates for Premiere Pro — Speckyboy
Softwares

10+ Best Text Animation Presets & Templates for Premiere Pro — Speckyboy

by admin
June 29, 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
Torras Ostand O3 Air iPhone case review – It runs rings around other cases

Torras Ostand O3 Air iPhone case review – It runs rings around other cases

May 21, 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
I Tried Calocurb For 90 Days. Here’s My Review.

I Tried Calocurb For 90 Days. Here’s My Review.

January 8, 2025
Aaron Rodgers returns to ‘Pat McAfee Show’ 1 day after being axed by host – National

Aaron Rodgers returns to ‘Pat McAfee Show’ 1 day after being axed by host – National

January 11, 2024
18 Best Political Series on Netflix, Ranked

18 Best Political Series on Netflix, Ranked

March 25, 2025
Bones: All Of Brennan’s Interns, Ranked

Bones: All Of Brennan’s Interns, Ranked

June 15, 2021
Xu Kai’s Upcoming Chinese Dramas List

Xu Kai’s Upcoming Chinese Dramas List

August 14, 2024
How to Build a DIY Spotify Music Player with Raspberry Pi Pico

How to Build a DIY Spotify Music Player with Raspberry Pi Pico

May 13, 2025
M3GAN 2.0 Is a Glitchy, Goofy Upgrade That Has a Few Fun Moments — GeekTyrant

M3GAN 2.0 Is a Glitchy, Goofy Upgrade That Has a Few Fun Moments — GeekTyrant

July 1, 2025
On the road with Saya Gray

On the road with Saya Gray

June 30, 2025
Microscopic Simulation in Transportation: A Clear Guide

Microscopic Simulation in Transportation: A Clear Guide

June 30, 2025
Rihanna’s sheer baby doll lingerie look is bang on trend for SS25

Rihanna’s sheer baby doll lingerie look is bang on trend for SS25

June 30, 2025
X Will Soon Charge for Ads Based on the Size of Your Visuals

X Will Soon Charge for Ads Based on the Size of Your Visuals

June 30, 2025
Family’s ‘Shock and Horror’ After Son’s Body at Funeral Infested with ‘Moving and Visible Maggots’: Suit

Family’s ‘Shock and Horror’ After Son’s Body at Funeral Infested with ‘Moving and Visible Maggots’: Suit

June 30, 2025
Korean & Spanish Shows Win Big At Italian Global Series Festival

Korean & Spanish Shows Win Big At Italian Global Series Festival

June 29, 2025
‘Ironheart’ Makes a Major Pivot From the Comics With This One Change

‘Ironheart’ Makes a Major Pivot From the Comics With This One Change

June 29, 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

  • M3GAN 2.0 Is a Glitchy, Goofy Upgrade That Has a Few Fun Moments — GeekTyrant
  • On the road with Saya Gray
  • Microscopic Simulation in Transportation: A Clear Guide
  • 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