Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Version History

« Previous Version 4 Current »

When integrating the Visualizer in full-screen mode, especially on mobile devices, it’s essential to ensure end users can comfortably add products to their shopping cart. The Visualizer provides shopping cart functionality with two synchronization options:
1. One-Way Sync

In this setup:

  • End users interact with the Visualizer’s shopping cart directly.

  • You cannot pre-populate the Visualizer cart with products from your website.

  • Whenever users add or remove items from the Visualizer cart, events are triggered, allowing you to synchronize these changes with your website’s cart.

Steps to enable the one-way shopping cart sync

  1. To enable the shopping cart functionality in your PIM account (Configuration → Web)

  2. Turn on shopping cart and one-way sync.

  1. Add integration code

<script>
    document.addEventListener('DOMContentLoaded', () => {
        const visualizer = WizartDeploymentKit.createVisualizer({
            token: 'YOUR_WEB_TOKEN',
            targetElement: document.getElementById('visualizer-container'),
        });
        
        visualizer.load().then(() => {
            visualizer.show();

            // Subscribe to "add to cart" events
            WizartDeploymentKit.EventBus.subscribe(
                (event) => { 
                    // Add item to your website cart
                },
                WizartDeploymentKit.VISUALIZER_EVENTS.ADD_TO_CART,
                visualizer
            );

            // Subscribe to "remove from cart" events
            WizartDeploymentKit.EventBus.subscribe(
                (event) => { 
                    // Remove item from your website cart
                },
                WizartDeploymentKit.VISUALIZER_EVENTS.REMOVE_FROM_CART,
                visualizer
            );
        });
    });
</script>
  1. Add shopping cart link.

When user clicks Proceed to checkout button in Visualizer it will redirect a user to your shopping cart URL.

https://example.com/cart?vendorCode[]=wallpaper_1&quantity[]=2&vendorCode[]=wallpaper_2&quantity[]=1

Note: The Visualizer saves the cart state between sessions, so the cart will retain its contents after a page reload.

2. Two-Way Sync

In this setup:

  • The Visualizer’s cart state is fully managed by your website.

  • You can pre-load the Visualizer cart with products already in your website cart.

  • Changes in either cart must be synchronized by pushing updates between your website and the Visualizer.

  1. Turn on shopping cart and two-way sync

  1. Add integration code.

<script>
    // Example initial website cart state
    const yourShoppingCartState = [
        { vendor_code: 'Wallpaper_01', quantity: 1 }
    ];

    document.addEventListener('DOMContentLoaded', () => {
        const visualizer = WizartDeploymentKit.createVisualizer({
            token: 'YOUR_WEB_TOKEN',
            targetElement: document.getElementById('visualizer-container'),
        });

        visualizer.load().then(() => {
            
            // Set initial cart state
            visualizer.setShoppingCartState(yourShoppingCartState);
            visualizer.show();

            WizartDeploymentKit.EventBus.subscribe(
                (event) => { 
                    /* Modify your cart state */
                    visualizer.setShoppingCartState(yourShoppingCartState);
                },
                WizartDeploymentKit.VISUALIZER_EVENTS.ADD_TO_CART,
                visualizer
            );

            WizartDeploymentKit.EventBus.subscribe(
                (event) => { 
                    /* Modify your cart state */
                    visualizer.setShoppingCartState(yourShoppingCartState);
                },
                WizartDeploymentKit.VISUALIZER_EVENTS.REMOVE_FROM_CART,
                visualizer
            );
            
            WizartDeploymentKit.EventBus.subscribe(
                (event) => { 
                    /* Modify your cart state */
                    visualizer.setShoppingCartState(yourShoppingCartState);
                },
                WizartDeploymentKit.VISUALIZER_EVENTS.CART_PRODUCT_COUNT_INCREASE,
                visualizer
            );

            WizartDeploymentKit.EventBus.subscribe(
                (event) => { 
                    /* Modify your cart state */
                    visualizer.setShoppingCartState(yourShoppingCartState);
                },
                WizartDeploymentKit.VISUALIZER_EVENTS.CART_PRODUCT_CART_DECREASE,
                visualizer
            );
        });
    });
</script>

Key Notes

  • One-Way Sync: Easier to implement but less flexible (no pre-loading products).

  • Two-Way Sync: More control but requires active state management.

  • Always ensure event handling and synchronization logic are optimized for real-time updates.

  • No labels