Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • David Conlisk 432 posts 1008 karma points
    Jan 19, 2017 @ 11:11
    David Conlisk
    0

    Merchello FastTrack: collecting extra user information per-product

    Hi all.

    I'm trying to create products in Merchello which can be sent as e-cards. This means that when a user chooses to buy a product, they need to provide extra information such as email address, the message text and the date to send the card. I'm struggling to work out the best way to achieve this.

    I've installed Merchello v2.3.1 and I've downloaded the corresponding code from github. I've installed the FastTrack site, and I've overridden the StoreBasketController, and created my own MVC area. I've created my own implementation of IAddItemModel with the extra fields required. This all works so far.

    My plan is to use the AddBasketItem method in my custom StoreBasketController to add the extra data (extended data?) to my product. Later I'll need to retrieve these details from Merchello using a scheduled task of some sort to actually send the e-card.

    Am I going about this in a sensible way, or am I missing something simpler? I have never used Merchello before. Any help or advice would be much appreciated.

    Thanks,

    David

  • Lee 1130 posts 3088 karma points
    Jan 20, 2017 @ 10:05
    Lee
    100

    It looks like you are going in the right direction. Storing the values in the extended data. I noticed in the Merchello source Rusty has put a comment about this too. So that might be a way to go.

    https://github.com/Merchello/Merchello/blob/merchello-dev/src/Merchello.Web/Controllers/BasketControllerBase%7BT%7D.cs#L123

    In a project I'm currently working on with Rusty (It's not based on top of FastTrack), we have some custom fields that need to get added to the basket lineitems too. We also need to adjust lineitems based on values the user selected on the product and added to cart (Stored in extendedData)

    There is an event on the Basket called 'AddingItem' which we call in the AddToCart. It's called like so

            // Add an event handler to adjust the sku in instances where an optional delivery service is selected
            ((Basket)Basket).AddingItem += OnAddingBasketItem;
    

    Where we use this to change the price of the line item based on what is stored in the extendedData. This might also be something you could use.

        /// <summary>
        /// Handles the Basket Adding event.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The event arguments.
        /// </param>
        private void OnAddingBasketItem(CustomerItemCacheBase sender, NewEventArgs<ILineItem> e)
        {
            var deliveryServiceFee = e.Entity.ExtendedData.GetDeliveryServiceFee();
            // Other Code here removed for forum post
            e.Entity.Price = e.Entity.Price + deliveryServiceFee.Total();
        }
    

    And the event handler is then removed further down the same action

            // remove the event handler.
            ((Basket)Basket).AddingItem -= OnAddingBasketItem;
    

    Hope that helps...

  • David Conlisk 432 posts 1008 karma points
    Jan 26, 2017 @ 10:49
    David Conlisk
    0

    Hi Lee,

    That's great, thanks. I had to use the AddingItem event as you described for the scenario when a user adds multiples of the same product to their cart. With that event I can manually check if a user already has that product in their cart, and if so I can add the new e-card data to the existing extended data. So now if a user adds the same product to the cart 3 times, for example, the extended data contains a list of 3 e-cards. Perfect.

    Thanks again!

    David

Please Sign in or register to post replies

Write your reply to:

Draft