How it works
The workflow is the same for both display types. A click on the select list or the link of a dependent variant calls a JavaScript function. This function starts the AJAX communication and prevents the page from being rebuilt. Beforehand, a function of the design component runs, in which you, for example, show a layer with a waiting graphic. If no response is received, for example when the internet connection is broken, another function of the design component runs. There you hide the loading graphic again and show a notice instead. On success, WEBSALE V8s accepts the request and delivers the new content. So that the system library knows which parts of the page to replace, you define swap areas in the product template.WS-Ajax- and sits directly inside a div with the same ID. You choose the ID freely. On an AJAX call, the system library writes the content of each area into the div with the matching ID. This lets you swap out several places on the page at once.
The bracket ST-Ajax around the area markers ensures they are only output on an AJAX call. Otherwise, they would remain visible in the source code on a normal product call.
If you use the tracking interface together with this feature, follow the notes there on AJAX-based features. Since no full page build takes place, tracking calls otherwise do not fire.Guide: Description of the tracking interface
Integration
You extend the product template in six steps. Only the second step differs depending on whether you display the variants as select lists or as links.Step 1: include the system library
In the<head> of the template, include the system library along with the design component.
Step 2: add the trigger
Here the two display types differ. For select lists, in the<head> create the function SubmitSelection(), which is called by the select list via onchange. It passes the ID of the product form and the character set.
onClick to each variant link that calls ws_AJAXPRLink() with the link’s target and the character set.
href is preserved so that the link continues to work without JavaScript.
Step 3: create containers for messages
These three containers are shown and hidden via JavaScript and inform the customer about the state of their action. Place them withposition: fixed over the page so they are visible regardless of the scroll position.
Step 4: give the product form a unique ID
The function from step 2 addresses the form via its ID. Without it, it cannot find the selected values.Step 5: define the swap areas
Swap out the entire area in which the product is displayed, that is, the central area of the page.Step 6: populate functions in the design component
The system library calls four functions that live in the design component. There you place your show/hide logic or additional effects. The default looks like this:ws_AJAXPRResponseError applies when the shop responded and reported an error, for example because the chosen combination is no longer available. ws_AJAXPRError applies when no response came through at all.
Tags
Related topics
- Guide: Display dependent variants as select lists
- Guide: Display dependent variants as links
- Guide: AJAX functions
- Materials: WEBSALE JavaScript library
