This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Custom IT Shop cart check

Hi,

I would like to put some custom checks when the user clicks "Check Shopping Cart". Furthermore, these checks are specific to certain products.

For instance - for Product A I would like the check to fail if the Valid Until date is more than 1 year in the future. Similarly for Product B I would like to check some value in one of the custom property to make sure its valid by running a query against the database. 

Is it possible to implement customised product specific shopping cart checks, and if so, where can this be done?

Thanks

  • The short answer is yes this is likely possible.

    What version of D1 are you running? I can post how I did a custom check for data in 6.1.2 and can probably adapt it to what you are trying to accomplish.

  • Thanks Aaron

    I'm on v6.1.3 - any script etc will be very helpful

    Thanks

  • OK. First what I did for my situation:

    We added a new box when approving an item with a compliance conflict where the approver was forced to provide mitigating controls. 

    How I forced it was:

    On the appropriate module, under the Save button, I added a server action that executed when the variable for that box was null. That action shows a popup telling the user what's wrong and then canceling the action.

    Below I will try to piece together how to do the same for what you want to do.

    So you want to limit the Valid Until on a certain product when the cart is checked. 

    The Module that control this is 'VI_ITShop_ShoppingCart' so to start you need to copy this so that it can be edited.

    The button itself in in the form. You might want to add the appropriate items to both the 'check and submit' and the 'check only' buttons. I'll let you decide.

    Under the button is a server action node. Under this node is where we want to add the item. Start with assing a Control Structure -> Action to it. You will need to right click the new action and move it up to an appropriate place in the tree (they execute top down) I chose for it to be the first action just to make screenshots easy. Under that new action add a  Component reference -> Call action, and choose VI_MessageBox, and am Interface Action -> Cancel Action Here. Edit the VI_MessageBox contents to what you need. See the 3rd screen below for my example.

    All that's left now is to write an execution condition for the added action node. This will be the tricky part and where I can't direct you. Hopefully, I can at least give you enough clues that you will be able to solve it. 

    You want the Valid until Date. Depending on where this is entered it can be in different collections. If it is entered through the 'edit shopping cart' task then it will be in the container collection. If it is on teh item it is likely in the ShoppingCartItem collection (note you may need to add 'ValidUntil to this collection to use it in this manner). Also you want the product being ordered and your likely best bet here is 'DisplayProduct' in the ShoppingCartItem collection.

     

    So you will need a WebSQL query something like (see note below):


    (From ShoppingCartItem select DisplayProduct = 'the product name')
    and
    ((From Container Select IsNull(ValidUntil,'') = '')
    Or
    (From Container Select ValidUntil < DateAdd(y,1,GetUTCDate())))

    Note: Apparently DateAdd is not a valid function in webSQL. I will try to come up with a valid way to query this. Maybe someone who speaks WebSQL better can help out. Also in teh screenshot I have "greater than 1 year" instead of less than

    Hopefully this st least gets you most of the way to your goal. I will post again if I come up with a way to help further. 

  • Aaron you sir are a legend! Thank you so very much, I can work with this.