2

I am building an extension for Magento 2. I am trying to get the collection (origin) address of the store.

2 Answers 2

3

Here what I tried and it's working:

    $this->scopeConfig->getValue(
            "general/store_information/street_line1",
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE
        );
-2

Please use below code it will give you address customer id wise.

$customerId = $_POST["customer_id"];
$customer = $this->_customerRepository->getById($customerId);
$addresses = $customer->getAddresses();

Please note that getAddresses will return an array of Magento\Customer\Api\Data\AddressInterface.

If you need the default billing address you can call:

$billingAddress = $customer->getDefaultBilling();

Thanks and Happy Coding.

2
  • Thank you, this will return the address of the customer, but I need the shipping address of the store.
    – Majd Alhaj
    Oct 28, 2020 at 16:42
  • Then you need to change getDefaultShipping(). Other code is same. Oct 29, 2020 at 3:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.