Last active
June 20, 2024 02:11
-
-
Save guilhermemarconi/2af015a8c3528cdb5cc4f50b7b3170a3 to your computer and use it in GitHub Desktop.
Deal with User Profile and User Addresses in VTEX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fetch(`/no-cache/postalcode/address/delete/${addressName}`, { | |
credentials: 'same-origin', | |
}) | |
.then(res => res.json()) | |
.then(addressData => { | |
// ... | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fetch(`/no-cache/postalcode/address/${postalCode /* e.g.:24310-090 */}`, { | |
credentials: 'same-origin', | |
}) | |
.then(res => res.json()) | |
.then(addressData => { | |
// ... | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fetch(`/no-cache/account/address/detail/${addressName}`, { | |
credentials: 'same-origin', | |
}) | |
.then(res => res.json()) | |
.then(addressData => { | |
// ... | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Pre-requisites | |
* | |
* 1) This fields should be public to read in AD data entity: | |
* addressName, addressType, city, complement, country, neighborhood, number, postalCode, | |
* receiverName, reference, state, street | |
* | |
* 2) userId need to be a filter and also public to filter. | |
* | |
* 3) For security reasons, the AD data entity must not allow requests without filter. | |
*/ | |
vtexjs.checkout.getOrderForm(['userProfileId']) | |
.done(orderForm => { | |
let fields = ['addressName', 'addressType', 'city', 'complement', 'country', 'neighborhood', 'number', 'postalCode', 'receiverName', 'reference', 'state', 'street'] | |
fetch(`/api/dataentities/AD/search/?_fields=${fields.join(',')}&userId=${orderForm.userProfileId}`) | |
.then(res => res.json()) | |
.then(addressesData => { | |
// ... | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Pre-requisites | |
* | |
* 1) This fields should be public to read in CL data entity: | |
* firstName, lastName, nickName, document, birthDate, gender, corporateName, businessDocument, | |
* stateRegistration, homePhone, phone, businessPhone, isCorporate | |
* | |
* 2) userId need to be a filter and also public to filter. | |
* | |
* 3) For security reasons, the CL data entity must not allow requests without filter. | |
*/ | |
vtexjs.checkout.getOrderForm(['userProfileId']) | |
.done(orderForm => { | |
let fields = ['firstName', 'lastName', 'nickName', 'document', 'birthDate', 'gender', 'corporateName', 'businessDocument', 'stateRegistration', 'homePhone', 'phone', 'businessPhone', 'isCorporate'] | |
fetch(`/api/dataentities/CL/search/?_fields=${fields.join(',')}&userId=${orderForm.userProfileId}`) | |
.then(res => res.json()) | |
.then(userData => { | |
// ... | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let formData = $('#form-profile-address').serialize() | |
fetch('/no-cache/account/address/save', { | |
credentials: 'same-origin', | |
method: 'POST', | |
headers: { | |
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8', | |
}, | |
body: formData, | |
}) | |
.then(res => { | |
// ... | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let formData = $('#form-profile-data').serialize() | |
fetch('/no-cache/account/profile/save', { | |
credentials: 'same-origin', | |
method: 'POST', | |
headers: { | |
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8', | |
}, | |
body: formData, | |
}) | |
.then(res => { | |
// ... | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment