25
votes
Magento 2: How to add customer address programmatically?
Using Magento\Customer\Api\AddressRepositoryInterface; you can create customer address.
namespace {NameSpace};
/**
* Description of Address
*/
class Address {
/**
* @var Magento\Customer\Api\...
20
votes
“We can't save the customer” Alert on Magento 2
You most probably have an error somewhere.
In order to find out what the problem is you can add this code.
$this->messageManager->addException($e, $e->getMessage());
Instead of the line
$...
13
votes
Accepted
Programatically load default billing and shipping address
This is an example of getting default customer's billing and shipping address if you have the customerId and using the customerRepository Magento\Customer\Api\CustomerRepositoryInterface and the ...
12
votes
Accepted
How to get customer address by customer ID?
You cannot retrieve an address based on the customer id so this code will never work:
$address = $this->_addressRepository->getByCustomerId($customerId);//error
Because the getByCustomerId ...
10
votes
How to add a customer custom-attribute in the customer address edit form?
Custom customer attributes will never just 'appear' on the frontend like they do in the backend. The code that displays them on the frontend is located in a custom phtml file.
Magento EE has this ...
10
votes
Accepted
Limit country drop down input field Magento 2
Please allow only that need from Admin > Stores > Configuration > General >
Country Options > Allow Countries
9
votes
Accepted
How to add a new address (shipping or billing or another) via Magento 2 REST API?
I was having a similar problem and was digging into the AccountManagement class to find the proper payload. I noticed that the createAccount function checks if a customer ID exists and loads the ...
8
votes
Accepted
Update customer address using address id in magento 2
If you know the address id ($addressId) you can use the address repository to load and save updated addresses:
/**
* @var \Magento\Customer\Api\AddressRepositoryInterface
*/
protected $...
8
votes
Accepted
Magento 2 Customer Listing action: get customer's telephone
The telephone number is related to the customer's addresses and not to the customer's account. So a solution will be to get the customer's default billing or shipping and get the telephone number ...
8
votes
Accepted
Multiselect attribute not saving in Magento 2.3.0
When creating the customer attribute, please take care about following things:
Attribute is added to the attribute set, group
customer_eav_attribute
eav_entity_attribute
Attribute is assigned ...
7
votes
Programatically update customer address by its entity id
Replace this $address->setData($addressCode, $addressData[$addressValue]); with $address->setData($addressCode, $addressValue);
<?php
$addressId = '5';
$addressData = array(
...
7
votes
How to get customer address by customer ID?
For get customer adderess using order id in .phtml file
$customerId = 3;
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerObj = $objectManager->create('Magento\...
7
votes
Accepted
how to display the address fields in the registration form
Create customer_account_create.xml file your current active theme
For eg.
app/design/frontend/{YOUR_PACKAGE}/{YOUR_THEME}/Magento_Customer/layout/customer_account_create.xml
After add below ...
7
votes
Accepted
Magento 2.X - "Invalid Customer Address Id" comes randomly for the customers on checkout
I've checked it further and fixed this issue by overriding Magento's validateForCart function.
/**
* Validate address to be used for cart.
*
* @param CartInterface $cart
* @param AddressInterface $...
6
votes
Check if customer has address?
$customer->getAddresses() should return all customer addresses so count($customer->getAddresses()) should return quantity of addresses of customer.
you can check like
if(count($customer->...
6
votes
How to add a new address (shipping or billing or another) via Magento 2 REST API?
It should be possible to add/update customer addresses using customer repository API:
PUT /V1/customers/:id (for admin)
PUT /V1/customers/me (for customer)
6
votes
Magento 2 checkout address buttons are missing and the developer console shows a customAttributes error
For this kind of issue, it's really hard to find the root cause. Magento is hard, Js is hard.
My suggestion is to use Debugger.
Chrome Devtools: https://developers.google.com/web/tools/chrome-...
5
votes
Magento 2 Get shipping and billing address of customer after order placed?
You can add this piece of code in the file:
<?php /** @var $_order \Magento\Sales\Model\Order */ ?>
<?php $_order = $block->getOrder() ?>
<?php $billingAddress = $_order->...
5
votes
Accepted
How to Make First and Last Name Optional for addresses?
Here's a simple method that can be used to make any required address field optional.
First create a plugin for Magento\Checkout\Block\Checkout\LayoutProcessor. Define the class as follow:
<?php
...
5
votes
Accepted
Customer Address custom attribute not showing front end in Magento 2
Customer Address edit form won't automatically generate custom attribute.
You have to override template file vendor/magento/module-customer/view/frontend/templates/address/edit.phtml to show it in ...
5
votes
Magento 2 : From where and how does knockout retrieve data on checkout
Here are answers to your query:
What/Where is this persistence storage:
If we look at dependancy injection of current model, "storage" is an alias of "Magento_Customer/js/customer-data" js model. By ...
5
votes
How to update customer address using custom Api in magento2?
You need to call below api for customer address update
API : xyz.com/rest/V1/customers/2
Header:
Authorization :"Bearer ishamls4xu7pnwhlvup141502tjm3cl2"
Content-Type :"application/json"
Method : ...
5
votes
Magento 2: How to add customer address programmatically?
Please try with following code.
$customerId = 10
$addresss = $objectManager->get('\Magento\Customer\Model\AddressFactory');
$address = $addresss->create();
$address->setCustomerId($...
5
votes
Accepted
How to get Region text from address id (Magento 2)
You can try following code to get the region from the address id.
$address = $this->addressRepository->getById($addressId);
$address->getRegion()->getRegion();
where $this->...
5
votes
Accepted
Magento 2 How to get Customer address after registration?
As $customer is an object of service contact data interface \Magento\Customer\Api\Data\CustomerInterface .So you cannot get default address using $customer->getDefaultShippingAddress().
This ...
5
votes
Magento 2.X - "Invalid Customer Address Id" comes randomly for the customers on checkout
I had same issue, used plugin to solve this.
In di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation=&...
5
votes
Accepted
How to get Customer Address in formated way and print it - Magento2.3
create Model
app/code/VendoreName/ModuleName/Model
CustomerAddress.php
<?php
namespace VendoreName\ModuleName\Model;
use Magento\Framework\Model\AbstractModel;
use VendoreName\ModuleName\Model\...
4
votes
How do I add a customer's email to the sales invoice?
There is an easier way to add it to all customer configuration emails. Just rewrite Mage_Customer_Helper_Address and it to the customer address attribute list. So open up
System > Configuration > ...
4
votes
How to check IF getOrigData() has changed using Observer?
Before the after load events are dispatched, _origData and therefore _hasDataChanges are reset.
What you can do: Make your checks in an observer for customer_address_save_before, set a flag in your ...
4
votes
Adding button in Magento 2
Sorry that this is not a complete answer but more a pointing in the "right" direction.
There are a set of elements that can be called inside the Magento/Ui system. These can be found under app/code/...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
customer-address × 342magento2 × 145
customer × 67
magento-1.9 × 51
shipping-address × 42
checkout × 27
address × 24
billing-address × 23
custom-attributes × 21
customer-account × 19
customer-attribute × 18
attributes × 15
event-observer × 15
magento-2.1 × 13
admin × 13
magento2.3 × 12
collection × 10
sales-order × 10
onepage-checkout × 10
magento-1.7 × 9
address-attribute × 9
magento-1.8 × 8
adminhtml × 8
database × 7
validation × 7