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

PrestaShop Free Gift Products | Add Free Products to Cart
Softwares

PrestaShop Free Gift Products | Add Free Products to Cart

by admin
May 22, 2025
The emperors of AI coding tools have no clothes – and it’s creating a productivity delusion
Softwares

The emperors of AI coding tools have no clothes – and it’s creating a productivity delusion

by admin
May 20, 2025
Land Your First Programming Job in 7 Steps
Softwares

Land Your First Programming Job in 7 Steps

by admin
May 21, 2025
Blockchain gaming is ‘growing up’
Softwares

Blockchain gaming is ‘growing up’

by admin
May 19, 2025
DeFi Staking Platform Development | DeFi Staking Platforms Company
Softwares

DeFi Staking Platform Development | DeFi Staking Platforms Company

by admin
May 17, 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
barnacle boi Releases Thumping ‘Introspect’ EP

barnacle boi Releases Thumping ‘Introspect’ EP

November 15, 2023
Spiritbox Drop New 3-Track Single ‘Rotoscope’ + Videos

Spiritbox Drop New 3-Track Single ‘Rotoscope’ + Videos

June 23, 2022
Australian Music Festival Forced to Cancel Due to 529% Government-Imposed Price Hike: Report

Australian Music Festival Forced to Cancel Due to 529% Government-Imposed Price Hike: Report

May 9, 2024
Most Useful Gadgets in 2021 – Nogentech.org

Most Useful Gadgets in 2021 – Nogentech.org

July 29, 2021
How to Build a JavaScript Search [Article]

How to Build a JavaScript Search [Article]

August 30, 2022
I Tried Calocurb For 90 Days. Here’s My Review.

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

January 8, 2025
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
The Comprehensive Multivitamin for Everyday Glow

The Comprehensive Multivitamin for Everyday Glow

April 24, 2022
How to Buy Nike Us Force 1 Sneakers Online

How to Buy Nike Us Force 1 Sneakers Online

May 22, 2025
PrestaShop Free Gift Products | Add Free Products to Cart

PrestaShop Free Gift Products | Add Free Products to Cart

May 22, 2025
The 11 Best Swimsuits for Long Torsos That *Actually* Fit Perfectly

The 11 Best Swimsuits for Long Torsos That *Actually* Fit Perfectly

May 22, 2025
Travis Kelce Accidentally Hints He & Taylor Swift Are Living Together!

Travis Kelce Accidentally Hints He & Taylor Swift Are Living Together!

May 22, 2025
Meta Launches Ray Ban AI Glasses in More Regions

Meta Launches Ray Ban AI Glasses in More Regions

May 22, 2025
The Armed announce new album The Future Is Here And Everything Needs To Be Destroyed

The Armed announce new album The Future Is Here And Everything Needs To Be Destroyed

May 21, 2025
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
Taylor Swift: Look What You Made Me Do (Taylor’s Version) in Handmaid’s Tale

Taylor Swift: Look What You Made Me Do (Taylor’s Version) in Handmaid’s Tale

May 21, 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

  • How to Buy Nike Us Force 1 Sneakers Online
  • PrestaShop Free Gift Products | Add Free Products to Cart
  • The 11 Best Swimsuits for Long Torsos That *Actually* Fit Perfectly
  • 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.

5jl