Today we're going to take a brief look into how we can implement wishlist functionality in our Marketcloud driven store.

Due to the Marketcloud's flexible data model we can simply append a new property to a user and push product ids into it. Let's take a look at how that can be achieved.

NOTE: We're assuming that you are using an existing project and have installed and configured the the Marketcloud javascript SDK.


​Updating the Registration logic

// Registering a new user
mc.users.create({
  email: "someone@foobar.com",
  password: "supersecret",
  wishlist: []
})
.then(function(response) {
  // Log in the newly created user
  return mc.users.authenticate("someone@foobar.com", "supersecret");
}) 
.catch(function(error) {
  console.log("An error has occurred", error);
});

We have added a custom "wishlist" array to the newly registered user.


Adding a product to the logged in user's wishlist:

// The product was fetched from the Marketcloud API and displayed to the user
mc.currentUser.wishlist.push(product.id); // Update the local cached version of the user

mc.users.update(mc.currentUser.id, {
  wishlist: mc.currentUser.wishlist
}).then(function(response) {
  // User wishlist was successfully persisted to the API
});

We updated the SDKs local user information and then used the same property to update the data on the Marketcloud API.


Removing a product from the logged in user's wishlist:

var index = mc.currentUser.wishlist.indexOf(product.id);
mc.currentUser.wishlist.splice(index, 1);

mc.users.update(mc.currentUser.id, {
  wishlist: mc.currentUser.wishlist
});

We updated the SDKs local user information and then used the same property to update the data on the Marketcloud API.


Clearing the logged in user's wishlist:

mc.currentUser.wishlist = [];

mc.users.update(mc.currentUser.id, {
  wishlist: []
});



We hope this quick tutorial successfully demonstrated how you can use Marketcloud's flexible data model to persist custom data and add your own functionality to a store.


If you have any feedback or questions feel free to add a comment below!