Custom card layout for e-commerce app

Custom card layout for e-commerce app

Requirement

Display products in a card layout with a button to add required products to a cart.

Use Case

An e-commerce business uses an order management app to process orders. Products need to be displayed in a card layout with product images, and customers can add required products to their cart to make an order.

Steps to follow

1. Create the forms with the following details:

Form

Form Link Name

Field Type

Field Name

Field Link Name

Products

Products

Single Line

Product

Product

Image

Image

Image

Currency

Price

Price

Items

Items

 

Lookup

Product

Product

Number

Quantity

Quantity

Currency

Price

Price

Currency

Total

Total

Email

Email

Email

Order

Order

Name

Name

Name

Address

Address

Address

Phone

Phone

Phone_Number

SubForm

Items
(Existing Form)

Items

Currency

Total

Total


2. Set the initial value of email field in Items form to ${zoho.loginuserid}.

3. Rename the Items Report to My Cart, and set the following Layout to it under Quick View > Layout.


4. Navigate to QuickView > Actions, and rename the Delete action to Remove form Cart, and remove the additional actions like Edit, and Duplicate.



5. Set a filter in Report Properties of My Cart report as shown below. This is to ensure that customers see only their products in the report.


6. Create a page named Product Listing.

7. Add a button named Raise Order and set the following parameters under Action tab.


The URL should redirect to the Orders form. It will be in the following format:
https://creatorapp.zoho.com/<app-owner-name>/<app-linkname>/#Form:Order
8. Add an HTML snippet and paste the below HTML code.

  1. <%{
  2. %>

  3. /* class to define font length*/

  4. <style>
  5.         .product-link {
  6. text-decoration: none;
  7. font-size: 1rem;
  8. }

  9. /* class to define Card Layout */

  10. .product-cards {
  11. display: grid;
  12. grid-template-columns: repeat(3, 1fr);
  13. grid-auto-rows: auto;
  14. gap: 0.5rem;
  15. }

  16. /* will get back */

  17. .no_record_wrapper {
  18.     display: none;
  19. }

  20. /* to remove text No Records Added */

  21. .row.reportfullwidth.custom-report.zc-card-report
  22. {
  23. background-color: white;
  24. }

  25. /* class to define details in individual Card */

  26. .product-card {
  27. box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
  28. transition: 0.3s;
  29. width: 70%;
  30. height: fit-content;
  31. text-align: center;
  32. padding: 1rem;
  33. float: left;
  34. margin: 25px;
  35. }

  36. /* class to add space between product name and Add to Cart text */

  37. .product-card .product-container-card {
  38. padding: 1rem;
  39. }

  40. /* class to define Image dimensions*/

  41. .product-header-image {
  42. display: block;
  43. margin: auto;
  44. max-width: 150px;
  45. height: 60%;
  46. }
  47. </style>

  48. /* class to fetch images from report */

  49. <div class="product-cards">
  50. <%
  51. for each  product in Products[ID != null]
  52. {
  53. var = product.Image.getprefix("\" lowqual").getsuffix("<img src = \"").replaceAll("/sharedBy/appLinkName/viewLinkName/fieldName",zoho.appuri + "All_Products/Image");
  54. %>

  55. /* class to display product image in each card fetched in above snippet*/

  56. <div class="product-card">
  57.    <img src=<%=var%> class="product-header-image" alt=<%=product.Product%>/>
  58.    <div class="product-container-card">
  59.     <h4><b><%=product.Product%></b></h4>
  60.     /* action to open form on click of Add to Cart*/

  61. <p><a class="product-link" href="#Form:Items?zc_LoadIn=dialog&Product=<%=product.ID%>">Add To Cart</a></p>
  62.    </div>
  63.   </div>
  64. <%
  65. }
  66. %>
  67. </div>
  68. <% 
  69. }%>
9. Embed the My Cart report on the page and position it in parallel to the HTML snippet as displayed below.


10. Create a workflow to populate quantity with value "1" and price of the product when the Items form loads.


11. Click Add New Action and add the following snippet in the deluge editor:
  1. // fetch details of the selected Product
  2. productDetails = Products[ID == input.Product];
  3. // Assign the product details to the form fields
  4. input.Price = productDetails.Price;
  5. input.Quantity = 1;
  6. input.Total = productDetails.Price;
  7. // hide email field as it is used only to track the current user's products
  8. hide Email;
  9. // disable Price and Total fields from manual updation
  10. disable Price;
  11. disable Total;
12. Now set a condition so that the above script executes only when Product value is not null.


13. Let's add another workflow to calculate the Total when the Quantity is updated.


14. Click Add New Action and add the following snippet.
  1. input.Total = input.Quantity * input.Price;
15. Now create a workflow to redirect users to the Product Listing page after an item has been added to the cart.


16. Click Add New Action > Deluge Script and add the following script to the editor:
  1. openUrl("https://creatorapp.zoho.com/<owner-name>/<app-linkname>/#Product_Listing","same window");
  2. reload;
17. Now let's add a workflow in the Orders form to add subform rows with the selected items.


18. Click Add New Action and add the following snippet:
  1. // hide the email field
  2. hide Items.Email;
  3. // insert subform rows with selected Items
  4. rows = Collection();
  5. // declare initial value to calculate the sum later
  6. sum = 0.0;
  7. // iterate though records of current user in Items form to fetch values and insert in subform
  8. for each  rec in Items[Email == zoho.loginuserid]
  9. {
  10. row1 = Order.Items();
  11. row1.Product=rec.Product;
  12. row1.Price=rec.Price;
  13. row1.Quantity=rec.Quantity;
  14. row1.Total=rec.Total;
  15. rows.insert(row1);
  16. sum = sum + rec.Total;
  17. }
  18. input.Items.insert(rows);
  19. input.Total = sum;
19. Let's add a workflow to update the price if the selected product is changed in the Orders form.


20. Click Add New Action and add the following snippet:
  1. row.Price=row.Products.Price;
21. Let's add a workflow to update the price if the selected quantity is changed in the Orders form, and to calculate the total cost of the selected items.


22. Click Add New Action and add the following snippet:
  1. if(row.Quantity != 0 && row.Quantity != null)
  2. {
  3. row.Cost=row.Quantity * row.Price;
  4. }
  5. input.Total = input.Items.sum(Cost);
23. Lastly, let's add a workflow to remove the records from Items form after the order has been placed.


24. Click Add New Action > Deluge Script and add the following script to the editor:
  1. delete from Items[ID != 0];
  2. openUrl("https://creatorapp.zoho.com/<app-owner>/<app-linkname>/#Product_Listing","parent window");

See how it works


Points to Note

  1. Custom card layout could also be implemented with ZML snippet in a similar way.
  2. The Items form can be hidden from customers to restrict it from appearing as a standalone component.
  1. Pages
  2. Deluge