When a user adds a file to the cart, a message will appear to show the file was added. With the cart panel open, no message will show, as the user will see the file appear in the cart. The number of items is also updated in the menu. On certain websites, you may want to display a dialog to clearly indicate that the user successfully added the file. There’s a default dialog and you can also create a custom version. The default dialog has buttons “Go to checkout” and “Continue shopping”. There’s also a checkbox that the user can select if they don’t want to display the dialog anymore.

Enabling the dialog

To enable the “File added to cart” dialog, go to Site configuration in Back office and click on Cart page in the side bar. Then open the section General settings. Check the box in front of display cart dialog with “go to cart” and “continue shopping” when a user adds a file. Scroll to the bottom of the page and click Save. To try the dialog go to a search results page and click on an Add to cart button underneath a thumbnail.

Styling the dialog

If you want to change the look and feel of the default dialog, you can do so by adding CSS in the code editor. How to add CSS is explained in the article Using Custom CSS.

Note that you can change the label Cart, to something else if you wish. E.g. Basket or Order. You can change the label either via Back office, Site configuration, Pages and menu, and then open the section Website menu. Or you can leave this field blank and change the default in the constants file defaults.txt. For further information about changing constants, read Website constants.

Creating a custom dialog

If you want to create a custom version of the dialog, then open the code editor and select the template Added to cart dialog (64) in the group Page fragments. You can load the example HTML to use as a starting point. Click on Load example in the toolbar to open the dialog, select the code example and click Use code. For more information about using the code editor and about customisation, read the articles Using the code editor and Infradox XS customisation.

HTML code example

The class names that are used are essential for the script to function. You can however create your own script if you want. This is explained in the next paragraph. The above example uses constants to output the text. The advantage is that the output will automatically in the selected user interface language. You can however also use normal text if you don’t need localisation, or you can use the xs print() function.

Creating custom Javascript for the dialog

If you want complete control over how the dialog functions, then you can add your own script for it. You can do this regardless of using a custom dialog. This is an advanced feature that requires an understanding of Javascript and JQuery. Read the article about Using Javascript in your pages first as it explains the client object that you will need to add or edit.

The example below shows the function showcartdialog added to the client object. If this function exists, then the standard Infradox script will call it instead of the built-in function used to show the dialog.

The data variable (above) is a JSON object returned by the software as a result of updating the cart.
Next, you’ll need to add your own function. In the above example we’ve called it addtocartdialog but it can have any name you want to use. The complete object is below. It checks if the dialog HTML is already loaded, and if not it will load the HTML with $.get(). This is an asynchronous call so you must handle its result in a callback as shown below.