What do you think about the course so far?
Thank you for your feedback!
Explore more topics
How to create custom badges using a Multi-state box
Before you get started
For this example, we’ll be working on an Editor X online store. In this case, a flower shop. To follow the steps we’ve provided for this site, simply open the template in the editor from the link provided above.
Part 1: Prepare the product page
To display the product badge in a position relative to the product page, make these adjustments:
Navigate to the product page from the pages dropdown
Select the section that contains the product, then open the Inspector panel
Change the section’s padding to 120px on the top, left and right
Click Apply Grid in the floating action bar and add a 3 column grid
Click Advanced Mode, then click the top bar of the middle grid column
Change the middle column’s width property to min/max
Set the maximum width to 1440px and the minimum to auto
Click Done
Select the product element and open the Inspector panel again
Under Location in grid cells, click the middle cell
Scroll down in the Inspector panel and change all margins to zero
Part 2: Create the first state
Click Dev Mode at the top of the editor, then Turn on Dev Mode
Close the IDE by clicking the minimize icon in the top right of the panel
Open the Add panel, click Layout tools and drag the Multi-state box option onto the canvas
Delete one of the states by clicking Manage States. Then select one of the states, click the three dots beside it and hit Delete
Select the Multi-state box, open the Inspector panel and change its width to 160px
Select the state itself and change its height to 160px
Click on the design tab icon in the Inspector panel and remove the box’s background color by setting the background opacity to zero
Select the Multi-state box from the breadcrumbs and repeat step 7 to remove the background color of the box
Dock the Multi-state box to the top and left and set the top and left margins to -80px
From the Media menu in the Add panel, drag the “out of stock” vector image into the Multi-state box container
From the Inspector panel, center the image and set its width to 100%
Part 3: Create the remaining states.
Select the Multi-state box
Click Manage States
Select the existing state, and click the Duplicate State button twice to create two more states with the properties you created in Part 2
Select the second state in the list of states
Change the vector image to the “on sale” image
Select the third state in the list
Delete the vector from this state in order to add dynamic content to this state
Select the state container and open the Inspector panel
Change its background color to black from the design tab and create a circle by changing its corner sizes to 999px each
From the Assets menu, drag the stack into the state container
Open the Adjust section at the bottom of the Inspector panel and change the container’s rotation to -25%
Part 4: Customize the state IDs
Click Manage States
Click on the first state, click the three dots beside it and click Rename
Change its name to “outofstock” and click Done
Repeat step 2 for the second state
Change its name to “onsale” and click Done
Repeat step 2 for the third state
Change its name to “xleft” and click Done
Select the text element containing the X on the final state
Click the Properties and Events icon at the bottom of the screen to open the IDE
From this panel, rename the text element ID “quantity”
Part 5: Add conditions via code
Select the Product Page from the pages dropdown
Paste the following code into the code panel, after the onReady function:
$w(‘#productpage1’).getProduct().then((product)=>{
if (!product.InStock){
$w(‘#multistatebox1’).changeState(‘outofstock’);
$w(‘#multistatebox1’).expand();
}else if (product.quantityInStock < 6){
$w(‘quantity’).text = product.quantityInStock.toString();
$w(‘#multistatebox1’).changeState(‘xleft’);
$w(‘#multistatebox1’).expand();
} else if (product.discountedPrice < product.price){
$w(‘#multistatebox1’).changeState(‘onsale’);
$w(‘#multistatebox1’).expand();
Hit Publish in the top right of the editor to apply this code to the site
Part 6: Test the setup using your dashboard
Click Site in the top bar of the editor, then Dashboard
Click Store Products, then Products
Click on the Bliss Tulip product
Scroll down to the Manage variants section and click Edit
For both the large and small variants, click the Status dropdown and choose Out of stock
Click Apply, then click Save in the top right
Visit the live version of the product page to confirm that the “out of stock” badge is now displayed