Use the WishlistAdder class

The WishlistAdder class allows you to easily add products and their variations to a desired wish list. To do this, you must perform the following:

  1. Get the catalog manager.
    Get an instance of the CatalogManager object.
  2. Get the product.
    Get the specified product that you want to add to the wish list.
    For more information, read For developers: Query products.
  3. Get the variation.
    Get the specified variation of the product.
    For more information, read For developers: Query product variations. If you do not want to add a variation, skip this step.
  4. Create an instance of the OptionDetails class.
    The OptionDetails class will wrap the information about the variation. If you are do not want to add a variation to the wish list, don’t set any of the properties of the OptionDetails instance. For more information about how to set the properties of the OptionDetails instance, refer to the code example at the end of the article.
  5. Get the default currency.
    Get the name of the default currency from the Ecommerce configuration.
  6. Create an instance of the WishlistAdder class.
  7. Add the item to the wish list.
    To add the specified product to the wish list, call the AddItemToWishlist of the WishlistAdder instance. As argument pass the product, the instance of the OptionDetails class, the desired quantity, the default currency name and the ID of the user that the wish list belongs to.

Use the following code sample:

Was this article helpful?