This topic describes the business flow for E-commerce scenarios. It also explains how to implement common features, such as product entry points, product cards, and product lists.
Prerequisites
You are familiar with Interactive Classroom scenarios. For more information, see Scenario overview.
You have completed the server-side integration for Interactive Classroom. For more information, see Server-side configuration and startup.
You have completed the client integration for Interactive Classroom. For more information, see Web client configuration and startup.
Overview
The E-commerce integration for Interactive Classroom adds E-commerce features to the basic classroom functionality.
Interactive behaviors
When E-commerce is integrated into Interactive Classroom, the following interactive behaviors are added:
Role | Interactive behavior |
Product operations staff |
|
Teacher |
|
Teaching assistant |
|
Student |
|
Product card
A product card in the classroom displays core information about a product recommended by the teacher. This typically includes a title, description, thumbnail, and purchase URL. The product card information is sent to the client using Instant Messaging (IM). To implement this, you must define a message type and a custom message struct for the product card.
Send product card message type
export enum CustomMessageTypes {
..., // Message types already defined by AUI Interactive Classroom are omitted here.
ShoppingProduct = 30011, // E-commerce card message
}Define the product card class
export interface ClassRoomProductConfig {
productId: string; // Product ID
title: string; // Product title
info: string; // Product description
coverUrl: string; // Product thumbnail URL
sellUrl: string; // Product purchase URL
}
// Define and implement the product card class
export class ClassRoomProduct {
productId: string; // Product ID
title: string; // Product title
info: string; // Product description
coverUrl: string; // Product thumbnail URL
sellUrl: string; // Product purchase URL
constructor(config: ClassRoomProductConfig) {
const { productId, title, info, coverUrl, sellUrl } = config;
this.productId = productId;
this.title = title;
this.info = info;
this.coverUrl = coverUrl;
this.sellUrl = sellUrl;
}
}Define the product management module
The teacher client and the teaching assistant client instantiate this module.
import { ClassRoomProductConfig } from 'path/to/ClassRoomProductConfig';
import { CustomMessageTypes } from 'path/to/CustomMessageTypes';
import AUIMessage from '@/BaseKits/AUIMessage';
export class ProductManager {
private productList: ClassRoomProductConfig[] = [];
private message: InstanceType<typeof AUIMessage>;
constructor(message: InstanceType<typeof AUIMessage>) {
this.message = message;
}
// Send a product card
public sendProduct(productId: string): Promise<void> {
const product = this.productList.find((item) => item.productId === productId);
if (product) {
this.message.sendGroupSignal({
type: CustomMessageTypes.ShoppingProduct,
data: {
product
},
});
}
}
...
}You can call the sendProduct method to send a product card. If you send the card from the operations console, the AppServer calls the Interactive Messages API. For more information, see Send messages to a group.
Receive product card messages
The student client must handle product card messages triggered by the teacher, teaching assistant, or operations staff. The following code shows how to implement a listener for product card messages, where CustomMessageTypes.ShoppingProduct is the custom message type for the product card.
Display the product card
const isShowProductCard = useMemo(() => {
// Business logic to determine whether to display the product card component.
}, [...]);
{isShowProductCard ? <ProductCard /> : null}Product list
Add an entry button
You can add a button to the bottom of the student client in the classroom to open the product list.
Open the product list
When a user clicks the entry button, a half-screen floating layer appears with an upward animation. The product list is then loaded onto this layer. You can develop the product information display and purchase flow based on your specific requirements.
import React, { useState } from 'react';
import { Popup } from 'antd-mobile';
import styles from './index.less';
const ProductList: React.FC = () => {
const [productListVisible, setProductListVisible] = useState<boolean>(false);
const closeProductList = () => {
setProductListVisible(false)
};
return (
<>
<Popup
onMaskClick={() => closeProductList()}
onClose={() => closeProductList()}
visible={productListVisible}
>
<div className={styles['shopping-list']}>
<div className={styles['shopping-title']}>
{/* The business logic implements the product list content. */}
</div>
</div>
</Popup>
setProductListVisible(true)}>
<span className="chat-btn">
<img src="https://img.alicdn.com/imgextra/i3/O1CN012R9g7P1F7ZCYy96rK_!!6000000000440-2-tps-108-108.png" />
</span>
</>
);
};
export default ProductList;