top of page

Turning Your Wix Store App into a Marketplace Using Wix Velo - Part1: Vendor Dashboard

Updated: Oct 10

creative for Wix MArketplace using Velo

In today's digital age, the e-commerce landscape is evolving rapidly. One of the emerging trends is the marketplace model, where multiple vendors can sell their products on a single platform. If you have a Wix store and want to transform it into a fully functional marketplace, Wix Velo provides the tools and flexibility needed to make this transition smooth and efficient. This blog will guide you through the essential steps to turn your Wix store app into a thriving marketplace using Wix Velo.


Step 1: Setting Up the Foundation


Before diving into the technical aspects, it’s crucial to plan the structure of your marketplace. Consider the following:

  • Vendor Registration: How vendors will sign up and manage their profiles.

  • Product Listings: How vendors will add and manage their products.

  • Order Management: How orders will be processed and managed by vendors.

  • Commission Structure: How you will earn from each sale (commissions, listing fees, etc.).


Once you have a clear plan, you can start setting up your Wix store to accommodate multiple vendors.


Step 2: Creating Vendor Registration and Management


Creating an efficient and user-friendly vendor registration and management system is crucial for the success of your marketplace. This step involves setting up a seamless process for vendors to sign up, manage their profiles, and access their sales data. Here's a detailed breakdown of how to achieve this using Wix Velo.


1. Creating a Vendor Signup Form

To start, you need a registration form that captures all necessary details about the vendors. This form can be created using Wix Forms or custom input elements with Velo for more control.


Fields to Include:

  • Business Name

  • Contact Person Name

  • Email Address

  • Phone Number

  • Business Address

  • Product Categories

  • Business Logo


Example Code for Vendor Signup Form

First, create a new page for vendor registration. Add input elements (e.g., text boxes, email inputs) and a submit button. Then, use the following code to handle form submission:



// Backend file: backend/vendorRegistration.jsw
import wixData from 'wix-data';

export function registerVendor(vendorData) {
    return wixData.insert('Vendors', vendorData);
}

import { registerVendor } from 'backend/vendorRegistration';

$w.onReady(function () {
    $w('#submitBtn').onClick(async () => {
        const vendorData = {
            businessName: $w('#businessNameInput').value,
            contactName: $w('#contactNameInput').value,
            email: $w('#emailInput').value,
            phone: $w('#phoneInput').value,
            address: $w('#addressInput').value,
            categories: $w('#categoriesInput').value,
            logo: $w('#logoInput').value
        };

        try {
            const result = await registerVendor(vendorData);
            $w('#statusText').text = "Registration successful!";
        } catch (error) {
            console.error("Error registering vendor:", error);
            $w('#statusText').text = "Registration failed. Please try again.";
        }
    });
});

2. Setting Up the Vendor Dashboard

Screenshot of Dashboard on Wix

The vendor dashboard is where vendors will manage their profiles, products, and view sales data. Create a new dynamic page for the vendor dashboard. This page will use dynamic datasets to fetch and display vendor-specific data.


Example Structure for Vendor Dashboard:
  • Vendor Profile Management:

    • Display current vendor information.

    • Allow vendors to update their profile details.

  • Product Management:

    • List of products added by the vendor.

    • Options to add, edit, or delete products.

  • Sales Overview:

    • Display sales statistics, recent orders, and earnings.


Example Code for Vendor Dashboard:

Create a dynamic dataset linked to the Vendors collection. Use this dataset to fetch the current vendor's data and display it on the dashboard.




import wixData from 'wix-data';
import { authentication,currentMember  } from 'wix-members-frontend';


$w.onReady(function () {
    // Get the logged-in member's data
    const member = await currentMember.getMember();
    const memberId = member._id;

// Query the Vendors collection to get the vendor data 
//based on the member ID

wixData.query('Vendors').eq('_owner', memberId).find()
    .then((results) => {
  if (results.items.length > 0) {
        const vendor = results.items[0];
        $w('#businessNameText').text = vendor.businessName;
        $w('#contactNameText').text = vendor.contactName;
        $w('#emailText').text = vendor.email;
        // Set other fields similarly

        // Fetch and display vendor's products
        wixData.query('Products')
        .eq('vendorId', vendorId)
        .find()
        .then((results) => {
            $w('#productsRepeater').data = results.items;
        });
 } else {
         console.error("No vendor found for the logged-in member");
         $w('#statusText').text = "No vendor data found.";
         }
    })
    .catch((error) => {
        console.error("Error fetching vendor data:", error);
    });
});

// Code for updating vendor profile
$w('#updateProfileBtn').onClick(() => {
    const updatedVendorData = {
        _id: vendorId,
        businessName: $w('#businessNameInput').value,
        contactName: $w('#contactNameInput').value,
        email: $w('#emailInput').value,
        // other fields
    };

    wixData.update('Vendors', updatedVendorData)
    .then(() => {
        $w('#statusText').text = "Profile updated successfully!";
    })
    .catch((error) => {
        console.error("Error updating profile:", error);
        $w('#statusText').text = "Update failed. Please try again.";
    });
});

3. Differentiating Vendor Authentication from Regular Client Members

To ensure that only registered vendors can access their dashboards and differentiate them from regular client members, implement a robust authentication system. Use Wix Members area with additional custom logic to distinguish between vendors and regular members.


Member Area Setup:

  • Create a members area and customize the signup/login forms to suit vendors.

  • Restrict the vendor dashboard to logged-in members only.


Tagging Vendors:

  • Use member roles or custom fields to tag users as vendors during registration.

  • Use this tag to control access to the vendor-specific pages.


Example of Tagging Vendors During Registration

Add a custom field to the member profile to indicate the user is a vendor.



// Backend file: backend/vendorRegistration.jsw

import wixData from 'wix-data';
import { authentication } from 'wix-members-backend';

export function registerVendor(vendorData) {
    return wixData.insert('Vendors', vendorData)
    .then((vendor) => {
        return authentication.register(vendorData.email, vendorData.password, {
            contactInfo: {
                firstName: vendorData.contactName,
                lastName: vendorData.businessName
            },
            customFields: {
                isVendor: true // Custom field to tag the user as a vendor
            }
        });
    });
}

Example of Protecting Vendor Dashboard


import { authentication,currentMember  } from 'wix-members-frontend';
import wixLocation from 'wix-location';

$w.onReady(async function () {
    const member = await currentMember.getMember();
    if (!member) {
        authentication.promptLogin();
    } else {
        const isVendor = member.customFields.isVendor;
        if (!isVendor) {
            wixLocation.to("/not-authorized");
        } else {
            // Load vendor dashboard data
        }
    }
});

4. Editing Vendor Information

To allow vendors to edit their profile information, you need to provide an interface within the vendor dashboard where they can update their details. Here's how you can set up the editing functionality:


  • Edit Form:

  • Add input elements to your vendor dashboard page for fields that can be edited, such as business name, contact name, email, etc.

  • Include a submit button to save changes.

  • Fetch Existing Vendor Data: Populate the input fields with the current vendor data when the page loads.

  • Save Changes: Implement a function to handle the form submission and update the vendor data in the database.



Example Code for Editing Vendor Information Using Code

Add the following elements to your vendor dashboard page:


  • Input fields for businessName, contactName, email, etc.

  • A submit button with the ID #updateProfileBtn.




import wixData from 'wix-data';
import wixLocation from 'wix-location';
import { authentication, currentMember  } from 'wix-members-frontend';

$w.onReady(async function () {
    // Get the logged-in member's data
    const member = await currentMember.getMember();
    
    // Check if the member is logged in
    if (member) {
        const memberId = member._id;

        // Query the Vendors collection to get the vendor data based on the member ID
        wixData.query('Vendors')
        .eq('memberId', memberId)
        .find()
        .then((results) => {
            if (results.items.length > 0) {
                const vendor = results.items[0];
                // Populate the form with current vendor data
                $w('#businessNameInput').value = vendor.businessName;
                $w('#contactNameInput').value = vendor.contactName;
                $w('#emailInput').value = vendor.email;
                // Populate other fields similarly

                // Set a click event on the update button
                $w('#updateProfileBtn').onClick(() => {
                    const updatedVendorData = {
                        _id: vendor._id,
                        businessName: $w('#businessNameInput').value,
                        contactName: $w('#contactNameInput').value,
                        email: $w('#emailInput').value,
                        // other fields
                    };

                    wixData.update('Vendors', updatedVendorData)
                    .then(() => {
           $w('#statusText').text = "Profile updated successfully!";
                    })
                    .catch((error) => {
                        console.error("Error updating profile:", error);
           $w('#statusText').text = "Update failed. Please try again.";
                    });
                });
            } else {
                console.error("No vendor found for the logged-in member");
                $w('#statusText').text = "No vendor data found.";
            }
        })
        .catch((error) => {
            console.error("Error fetching vendor data:", error);
        });
    } else {
        // Redirect to login page if the member is not logged in
        authentication.promptLogin();
    }
});

Using Dataset Connections


Alternatively, you can achieve the same functionality using dataset connections, which can simplify the process by binding UI elements directly to the data collection. Make sure Dataset is set as Read and Write.


  • Add a Dataset:

    • Add a dataset to the page and connect it to the Vendors collection.

    • Set the dataset to filter by the logged-in member's ID.

  • Bind Input Elements: Bind the input elements to the corresponding fields in the dataset.

  • Save Changes: Use the built-in dataset save functionality to update the vendor data.



Step 3: Product Listings

Allowing vendors to add and manage their products is a core functionality of any marketplace. This step involves creating an intuitive interface for vendors to list their products, ensuring the data is stored correctly, and providing a way for vendors to edit or delete their listings. Here’s a comprehensive guide on how to integrate your custom product management system with the Wix Stores app using Wix Velo.



1. Creating a Product Submission Form

Vendors need an easy-to-use form to add their products. This form should capture all necessary product details such as title, description, price, category, and images.


Fields to Include:

  • Product Title

  • Description

  • Price

  • Category

  • Images

  • Stock Quantity

  • SKU (Stock Keeping Unit)


Example Code for Product Submission Form

Create a new page or section within the vendor dashboard for product submission. Add input elements for each product attribute and a submit button. Modify the product submission function to use the Wix Stores API to add products to the Wix Stores collection.


Backend Code


// Backend file: backend/productManagement.jsw
import { products } from 'wix-stores-backend';

export async function addProductToStore(productData) {
    const newProduct = await products.insertProduct(productData);
    return newProduct;
}

export async function addProductMedia(productId, mediaItems) {
    return await products.addProductMedia(productId, mediaItems);
}


Explanation of backend Code

  • addProductToStore(productData): Inserts a new product into the Wix Store.

  • addProductMedia(productId, mediaItems): Adds media (e.g., images) to a product.


Frontend Code

Create a new page or section within the vendor dashboard for product submission, display, and management. Use the following code for the frontend.


import { addProductToStore, addProductMedia } from 'backend/productManagement';
import { authentication, currentMember  } from 'wix-members-frontend';

$w.onReady(async function () {
    const member = await currentMember.getMember();

    if (member) {
        const vendorId = member._id;

        // Handle new product submission
        $w('#submitProductBtn').onClick(async () => {
            const productData = {
                name: $w('#productTitleInput').value,
                description: $w('#productDescriptionInput').value,
                price: {
                    currency: "USD",
                    amount: Number($w('#productPriceInput').value)
                },
                productType: 'physical', // or 'digital' depending on your product type
                sku: $w('#productSKUInput').value,
                inventory: {
                    inStock: Number($w('#productStockInput').value)
                },
                customTextFields: [{ title: "Vendor ID", value: vendorId }] // Link the product to the current vendor
                // Add other necessary fields
            };

            try {
                const newProduct = await addProductToStore(productData);
                const productId = newProduct._id;

                // Handle product images
                const imageUrl = $w('#productImageInput').value; // Assuming this is a URL or you can use a file uploader
                const mediaItems = [{
                    mediaType: 'image',
                    src: imageUrl,
                    title: 'Product Image',
                    alt: 'Image of ' + $w('#productTitleInput').value
                }];

                await addProductMedia(productId, mediaItems);

                $w('#statusText').text = "Product added successfully!";
                $w('#productsDataset').refresh(); // Refresh dataset to show the new product
            } catch (error) {
                console.error("Error adding product:", error);
                $w('#statusText').text = "Failed to add product. Please try again.";
            }
        });

    } else {
        authentication.promptLogin();
    }
});


Explanation of Frontend Code

On Page Load:

  • currentMember.getMember(): Fetches the current logged-in member.

  • Checks if a member is logged in. If not, it prompts the login using authentication.promptLogin().


Product Submission:

  • Form Elements: Input fields for title, description, price, category, image URL, stock quantity, and SKU.

  • Submit Button (#submitProductBtn): On click, gathers input values and creates a productData object.

  • addProductToStore: Calls the backend function to add the product to the store.

  • addProductMedia: Adds the product image to the product.


2. Displaying and Managing Products on Vendor Dashboard


Once vendors add products, they need a way to view and manage these listings. This involves creating a section in the vendor dashboard where they can see their products, edit them, or delete them.



Example Code for Displaying and Managing Products

Create a repeater on the vendor dashboard to display the list of products added by the vendor.


Backend Code

// Backend file: backend/productManagement.jsw
import { products } from 'wix-stores-backend';

export async function updateStoreProduct(productId, productData) {
    return await products.updateProduct(productId, productData);
}

export async function updateProductMedia(productId, mediaItems) {
    return await products.addProductMedia(productId, mediaItems);
}


Explanation of backend Code

  • updateStoreProduct(productId, productData): Updates an existing product in the Wix Store with new data.

  • updateProductMedia(productId, mediaItems): Adds or updates media (e.g., images) for a product.


Frontend Code


import { updateStoreProduct, updateProductMedia } from 'backend/productManagement';
import { authentication, currentMember  } from 'wix-members-frontend';

$w.onReady(async function () {
    const member = await currentMember.getMember();

    if (member) {
        const vendorId = member._id;

        // Set the dataset filter to only show the logged-in vendor's products
        $w("#productsDataset").setFilter(wixData.filter().contains("customTextFields.value", vendorId));

        // Set up the repeater to display product details
        $w('#productsRepeater').onItemReady(($item, itemData, index) => {
            $item('#productTitle').text = itemData.name;
            $item('#productPrice').text = `$${itemData.price.amount.toFixed(2)}`;
            // Set other product fields similarly

            // Handle product edit
            $item('#editProductBtn').onClick(() => {
                // Bind the dataset to the form elements for editing
                $w('#productTitleInput').value = itemData.name;
                $w('#productDescriptionInput').value = itemData.description;
                $w('#productPriceInput').value = itemData.price.amount.toFixed(2);
                $w('#productCategoryInput').value = itemData.customField.category; // Assuming category is a custom field

                $w('#updateProductBtn').onClick(async () => {
                    $w('#productsDataset').setFieldValue('name', $w('#productTitleInput').value);
                    $w('#productsDataset').setFieldValue('description', $w('#productDescriptionInput').value);
                    $w('#productsDataset').setFieldValue('price.amount', Number($w('#productPriceInput').value));
                    $w('#productsDataset').setFieldValue('customField.category', $w('#productCategoryInput').value);
                    // Update other fields similarly

                    try {
                        await $w('#productsDataset').save();
                        $w('#statusText').text = "Product updated successfully!";
                        $w('#productsDataset').refresh(); // Refresh dataset to show the updated product
                    } catch (error) {
                        console.error("Error updating product:", error);
                        $w('#statusText').text = "Failed to update product. Please try again.";
                    }
                });
            });

            // Handle product delete
            $item('#deleteProductBtn').onClick(async () => {
                try {
                    await $w('#productsDataset').remove(itemData._id);
                    $w('#statusText').text = "Product deleted successfully!";
                    $w('#productsDataset').refresh(); // Refresh dataset to remove the deleted product
                } catch (error) {
                    console.error("Error deleting product:", error);
                    $w('#statusText').text = "Failed to delete product. Please try again.";
                }
            });
        });

    } else {
        authentication.promptLogin();
    }
});

Explanation of the Code


1. Setting Up the Dataset Filter

  • currentMember.getMember(): Fetches the current logged-in member.

  • $w("#productsDataset").setFilter(wixData.filter().contains("customTextFields.value", vendorId)): Filters the dataset to only show products that belong to the logged-in vendor using the vendor's ID stored in a custom field.

2. Creating Products

  • Product Submission Form:

  • Collects product data from the form fields.

  • addProductToStore(productData): Adds the product to the Wix Stores collection.

  • addProductMedia(productId, mediaItems): Adds images to the product.

  • Refreshes the dataset to display the newly added product.

3. Displaying and Managing Products

  • Repeater Setup (#productsRepeater):

  • Uses onItemReady to set up each item in the repeater to display product details.

  • Edit Button (#editProductBtn): On click, binds the product data to the form fields for editing. Updates the dataset fields with the new values when the update button is clicked and saves the changes.

  • Delete Button (#deleteProductBtn): On click, removes the product from the dataset and refreshes it to update the repeater.


Page Elements Setup

Ensure you have the following elements on your page:

  • Dataset: A dataset with the ID #productsDataset connected to the Wix Stores Products collection.

  • Product Submission Form:

    • Input fields for product title, description, price, category, image URL, stock quantity, SKU.

    • A submit button with the ID #submitProductBtn.

  • Product Edit Form:

    • Input fields for product title, description, price, category, image URL, stock quantity, SKU (same as submission form).

    • An update button with the ID #updateProductBtn.

  • Products Repeater:

  • Status Text: A text element with the ID #statusText to display status messages.



Conclusion: Turning Your Wix Store App into a Marketplace

Turning your Wix Store app into a marketplace using Wix Velo provides a powerful way to expand your e-commerce platform. In this first part, we focused on setting up the vendor dashboard, which includes creating products, displaying, and managing product listings. By following the steps outlined, you can ensure a seamless experience for your vendors, allowing them to efficiently manage their product offerings.


Key takeaways from this part include:


  • Vendor Authentication: Ensuring only registered vendors can access their dashboards.

  • Product Submission: Allowing vendors to add products with all necessary details and media.

  • Displaying Products: Using datasets to filter and display products specific to each vendor.

  • Managing Products: Providing an interface for vendors to edit and delete their products.


This setup lays a solid foundation for a multi-vendor marketplace on Wix.


What's Next?

In Part 2, we will cover:


  • Order Management: How orders will be processed and managed by vendors.

  • Commission Structure: How you will earn from each sale through commissions, listing fees, etc.


Stay tuned for the next part to complete the transformation of your Wix Store into a fully functional marketplace!


Ready to take your Wix Store to the next level? Start implementing these steps today and watch your marketplace thrive. If you have any questions or need further assistance, feel free to contact us at CodeMasters. Don't forget to subscribe to our blog to get notified when Part 2 is released!


Sign up for free and unlock over $300 in exclusive deals on top SaaS tools like LinkedIn credits, QuickBooks, SEMrush, and more! Explore Deals


bottom of page