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

Apple debuts Liquid Glass interface at design-focused WWDC event
Softwares

Apple debuts Liquid Glass interface at design-focused WWDC event

by admin
June 10, 2025
Learn How to Build a WordPress Block Theme Style Variation — Speckyboy
Softwares

Learn How to Build a WordPress Block Theme Style Variation — Speckyboy

by admin
June 11, 2025
User Guide for Odoo Website SSLCommerz Payment Acquirer
Softwares

User Guide for Odoo Website SSLCommerz Payment Acquirer

by admin
June 9, 2025
Bug Fixes and Enhancements – Vivaldi Android Browser snapshot 3718.4
Softwares

Bug Fixes and Enhancements – Vivaldi Android Browser snapshot 3718.4

by admin
June 12, 2025
AI updates from the past week: OpenAI Codex adds internet access, Mistral releases coding assistant, and more — June 6, 2025
Softwares

AI updates from the past week: OpenAI Codex adds internet access, Mistral releases coding assistant, and more — June 6, 2025

by admin
June 7, 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
Jada Pinkett Smith reveals what Chris Rock said to her after Oscars slap – National

Jada Pinkett Smith reveals what Chris Rock said to her after Oscars slap – National

October 13, 2023
12 Parts That Make No Sense

12 Parts That Make No Sense

November 10, 2023
The Comprehensive Multivitamin for Everyday Glow

The Comprehensive Multivitamin for Everyday Glow

April 24, 2022
The Top Java IDEs for 2021

Java Math Operators | Developer.com

November 9, 2022
The Mood Benefits of Saffron—and How to Get More of It

The Mood Benefits of Saffron—and How to Get More of It

October 13, 2021
New Python and Data Analysis Workshops [Article]

New Python and Data Analysis Workshops [Article]

August 27, 2021
The Definitive 30-Step Basic SEO Checklist for 2022

The Definitive 30-Step Basic SEO Checklist for 2022

January 3, 2022
The Data Lake Security Checklist: IT Leader Essentials

The Data Lake Security Checklist: IT Leader Essentials

August 1, 2022
Kendrick Lamar Performs in Toronto, Drake Streams With Kai Cenat

Kendrick Lamar Performs in Toronto, Drake Streams With Kai Cenat

June 12, 2025
FIFA Rivals Launches Worldwide, Bringing Non-Simulation Arcade Football Action to Mobile Devices

FIFA Rivals Launches Worldwide, Bringing Non-Simulation Arcade Football Action to Mobile Devices

June 12, 2025
What Happened To Regina & How Charlie Set Up John Cho’s Con Man Character

What Happened To Regina & How Charlie Set Up John Cho’s Con Man Character

June 12, 2025
Pedro Pascal’s NSFW Response To Dakota Johnson Nickname

Pedro Pascal’s NSFW Response To Dakota Johnson Nickname

June 12, 2025
Meta Takes Next Steps Towards the Development of True Artificial Intelligence

Meta Takes Next Steps Towards the Development of True Artificial Intelligence

June 12, 2025
VINGUYS Smart Bird Feeder V-Feeder Bamboo review

VINGUYS Smart Bird Feeder V-Feeder Bamboo review

June 11, 2025
Club Space Invites Dads to Groove on the Terrace for Special Father's Day 2025 Celebration

Club Space Invites Dads to Groove on the Terrace for Special Father's Day 2025 Celebration

June 11, 2025
P2istheName’s Cause of Death Revealed

P2istheName’s Cause of Death Revealed

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

  • Kendrick Lamar Performs in Toronto, Drake Streams With Kai Cenat
  • FIFA Rivals Launches Worldwide, Bringing Non-Simulation Arcade Football Action to Mobile Devices
  • What Happened To Regina & How Charlie Set Up John Cho’s Con Man Character
  • 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