Giter VIP home page Giter VIP logo

wix-code's Introduction

Add a Related Products Section to a Wix Store Product Page with Wix Code

This repository helps you set up a Related Products section in a Wix Store Product page, using Wix Code. It gives you two methods for relating products to each other. You can either relate products by price range or using a custom relationship you define.

Setup

This code assumes the following setup. It includes code that is added to the Products page as well as a collection that stores the custom relationships you define between products. If you have a similar setup on your site and you want to use this code, you'll need to change the IDs listed here to match the ones on your site. You'll also need to make sure to change the name of the related products collection to match your collection's name.

You can see a site with this code in action here: http://code-examples.wixsite.com/shop-related-item

Page setup

Page Setup

  1. A Wix Site with Wix Stores.

  2. A strip on the Products page with the ID: relatedItems. This is the container for the related products.

  3. A title in the strip indcating it is a Related Products section.

  4. A horizontal repeater in the strip with the ID relatedItemsRepeater. This displays the related products.

  5. The repeater designed to display related products. The repeater item has the following elements with their corresponding IDs:

    Element ID
    text productName
    image productImage
    text productPrice
  6. The Product Page element with the ID: productPage.

Database setup

When you work with Wix Code, your Store's products are automatically included in a read-only Products collection in your site.

Product collection

To create custom product relationships you'll need another collection called relatedProducts on your site with two reference fields: ProductA and ProductB. For each item, ProductA values reference an item in the Products collection. ProductB values then reference the product related to the item in ProductA. Here's what it looks like in our site:

relatedProducts collection

Code Overview

Related products by price range (related-products-1-strategy)

  1. Get the ID of the currently displayed product.
  2. Query the Products collection for items whose price falls within a specific range, relative to the current item's price.
  3. Use the repeater to display the first four results of the query.
  4. If there are no results, hide the repeater.

Custom related products (related-products-2-strategies)

  1. Get the ID of the currently displayed product.
  2. Run two parallel queries on the relatedProducts collection. Each query returns the value in the productA or productB columns that relate to the currently displayed product.
  3. Use the results of both queries to create a list of related products.
  4. Display the custom related products. If there are none then display related products by price.
  5. If there are no results, hide the repeater.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.