diff --git a/.gitignore b/.gitignore index 6704566..6183f2b 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ lerna-debug.log* report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json # Runtime data +.DS_Store pids *.pid *.seed diff --git a/README.md b/README.md index 9708910..0e8e9e8 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,29 @@ -# Salesforce B2C Commerce Developer 101 : ISMLs +# Salesforce B2C Commerce Developer 101 : Controllers -This branch has the changes required to support the DIY's requirements. We will implement the following parts of the overall approach: +This branch has the changes required to support the following DIY's requirements. We will implement the following parts of the overall approach: -* Make changes to the required ISMLs, Forms, Models, Resource Properties. +* Extend the profile object to accommodate the weather preference, create a custom attribute. +* Extend the Account controller to persist & retrieve this preference. # Implementation Changes to be done: -> First complete the [tasks](https://github.com/pravngaur/Dev_101/blob/DIY_Controllers/README.md#implementation-changes-to-be-done) mentioned in DIY_Controllers branch. +* Create a custom cartridge custom_app_dev101 +* Update the cartridge path to: custom_app_dev101:app_storefront_base +* Extended the Profile System Object to have an additional attribute which holds the value for product's preferred season of usage. Enum of Strings: WINTER, SUMMER, RAIN. +* Inherit the Account.js controller in the new cartridge. -* Override the editProfileForm.isml & profileCard.isml in your custom cartridge -- this is to accomodate the additional custom attribute to be persisted & shown. -* Add the required properties(for the new attribute) in the resource bundles. -* Update account.js model to accommodate the new attribute -- this is to show the value of the attribute on profile page. -* Update the profile.xml form to persist the customer's selection in Profile's custom attribute. Remember the possible values a customer can choose should match to the values of enum-of-string in the profile metadata. +_Please try doing these changes yourself first & then compare with this branch._ + +# Configuration changes required: + +#### Adding custom profile attribute: + +* You can do that by importing the profile_extension.xml file in sites folder. +* Or do that manually by updating the profile system object to add a custom attribute named 'weather_preference' as enum of strings type: + +![Attribute config](https://github.com/pravngaur/Dev_101/blob/DIY_Controllers/custom_app_dev101/docs/profile_attr_1.png) + +Values: + +![Attribute values](https://github.com/pravngaur/Dev_101/blob/DIY_Controllers/custom_app_dev101/docs/profile_attr_2.png) -_Please try doing these changes yourself first & then compare with this branch. No config changes required for this task._ diff --git a/custom_app_dev101/cartridge/controllers/Account.js b/custom_app_dev101/cartridge/controllers/Account.js index 48e54e2..933d476 100644 --- a/custom_app_dev101/cartridge/controllers/Account.js +++ b/custom_app_dev101/cartridge/controllers/Account.js @@ -86,7 +86,7 @@ function (req, res, next) { profile.setPhoneHome(formInfo.phone); // TODO: In productionize code, you ideally should store 'WINTER' in custom preferences(or someehere else as config). // Should not hard code it - profile.custom.weather_preference = formInfo.weatherPref; + profile.custom.weather_preference = 'WINTER'; }); // Send account edited email diff --git a/custom_app_dev101/cartridge/forms/default/profile.xml b/custom_app_dev101/cartridge/forms/default/profile.xml deleted file mode 100644 index 701675e..0000000 --- a/custom_app_dev101/cartridge/forms/default/profile.xml +++ /dev/null @@ -1,109 +0,0 @@ - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/custom_app_dev101/cartridge/models/account.js b/custom_app_dev101/cartridge/models/account.js deleted file mode 100644 index c946985..0000000 --- a/custom_app_dev101/cartridge/models/account.js +++ /dev/null @@ -1,50 +0,0 @@ -/* eslint-disable spaced-comment */ -'use strict'; - -var baseModule = module.superModule; - -/** - * Creates a plain object that contains profile information - * @param {Object} profile - current customer's profile - * @param {Object} rawProfile - current customer's raw profile - * @returns {Object} an object that contains information about the current customer's profile - */ -function getProfileWithWeather(profile, rawProfile) { - var result; - if (profile) { - result = { - firstName: profile.firstName, - lastName: profile.lastName, - email: profile.email, - phone: profile.phone, - password: '********', - weatherPreference: rawProfile.custom.weather_preference - }; - } else { - result = null; - } - return result; -} - -/** - * Account class that represents the current customer's profile dashboard - * @param {Object} currentCustomer - Current customer - * @param {Object} addressModel - The current customer's preferred address - * @param {Object} orderModel - The current customer's order history - * @constructor - */ -function account(currentCustomer, addressModel, orderModel) { - var baseModelObject = new baseModule(currentCustomer, addressModel, orderModel); - this.profile = getProfileWithWeather(currentCustomer.profile, currentCustomer.raw.profile); - this.addresses = baseModelObject.addresses; - this.preferredAddress = baseModelObject.preferredAddress; - this.orderHistory = baseModelObject.orderHistory; - this.payment = baseModelObject.payment; - this.registeredUser = baseModelObject.registeredUser; - this.isExternallyAuthenticated = baseModelObject.isExternallyAuthenticated; - this.customerPaymentInstruments = baseModelObject.customerPaymentInstruments; -} - -//testing.getCustomerPaymentInstruments = baseModule.getCustomerPaymentInstruments; - -module.exports = account; diff --git a/custom_app_dev101/cartridge/templates/default/account/editProfileForm.isml b/custom_app_dev101/cartridge/templates/default/account/editProfileForm.isml deleted file mode 100644 index dee424f..0000000 --- a/custom_app_dev101/cartridge/templates/default/account/editProfileForm.isml +++ /dev/null @@ -1,101 +0,0 @@ -
> - -
required"> - - > -
-
- -
required"> - - > -
-
- -
required"> - - - -
-
- -
required"> - - > -
-
- -
required"> - - > -
-
- -
required"> - - > -
-
- -
required"> - - > -
-
- - -
-
- - ${Resource.msg('link.tracking.consent','account',null)} - -
-
-
- - -
- -
-
-
diff --git a/custom_app_dev101/cartridge/templates/default/account/profileCard.isml b/custom_app_dev101/cartridge/templates/default/account/profileCard.isml deleted file mode 100644 index a4770ac..0000000 --- a/custom_app_dev101/cartridge/templates/default/account/profileCard.isml +++ /dev/null @@ -1,33 +0,0 @@ -
-
-

${Resource.msg('label.profile','account',null)}

- - ${Resource.msg('link.edit','account',null)} - -
-
-
-
${Resource.msg('label.profile.firstname','account',null)}
-
${pdict.account.profile.firstName}
-
-
-
${Resource.msg('label.profile.weatherPreference','account',null)}
-
${pdict.account.profile.weatherPreference}
-
-
-
${Resource.msg('label.profile.lastname','account',null)}
-
${pdict.account.profile.lastName}
-
-
-
${Resource.msg('label.profile.email','account',null)}
-
${pdict.account.profile.email}
-
- -
-
${Resource.msg('label.profile.phone','account',null)}
-
${pdict.account.profile.phone}
-
-
- -
-
diff --git a/custom_app_dev101/cartridge/templates/resources/account.properties b/custom_app_dev101/cartridge/templates/resources/account.properties deleted file mode 100644 index 5073eb9..0000000 --- a/custom_app_dev101/cartridge/templates/resources/account.properties +++ /dev/null @@ -1 +0,0 @@ -label.profile.weatherPreference=Weather Preference \ No newline at end of file diff --git a/custom_app_dev101/cartridge/templates/resources/forms.properties b/custom_app_dev101/cartridge/templates/resources/forms.properties deleted file mode 100644 index 8d218b0..0000000 --- a/custom_app_dev101/cartridge/templates/resources/forms.properties +++ /dev/null @@ -1,6 +0,0 @@ -## Adding new properties for handling the weatherPreference changes -- only the additional properties -## For the existing properties, systems checks in the file first, if not found then goes to file in parent cartridge -label.input.weatherPref.profile=Weather Preference -select.option.weatherPref.winter=Winter -select.option.weatherPref.summer=Summer -select.option.weatherPref.rain=Rain \ No newline at end of file diff --git a/custom_app_dev101/docs/profile_attr_1.png b/custom_app_dev101/docs/profile_attr_1.png new file mode 100644 index 0000000..7fd236b Binary files /dev/null and b/custom_app_dev101/docs/profile_attr_1.png differ diff --git a/custom_app_dev101/docs/profile_attr_2.png b/custom_app_dev101/docs/profile_attr_2.png new file mode 100644 index 0000000..53f9812 Binary files /dev/null and b/custom_app_dev101/docs/profile_attr_2.png differ