In AnQi CMS, if you are managing document types for products and need to obtain the specific prices of these products (price) and stock quantities (stockInformation is actually very direct and convenient.The design of Anqi CMS considers such needs, treating these key data as one of the core attributes of the document, which you can easily obtain through several core interfaces.
Get the price and stock information of a single product document
When you need to view the price and stock of a specific product, Anqi CMS providesarchiveDetailan interface. This interface is specifically used for retrieving all the details of a single document.
You just need to pass the unique identifier of the product, which can be a document'sIDor itsURL 别名(filename)For example, if you want to get the details of the product with ID 123, you can call it like this:
{域名地址}/api/archive/detail?id=123
In the data returned by the interface, you will finddatadirectly included in the objectpriceandstockfields. These fields clearly show the pricing and current inventory of the product.
It is worth noting that,priceThe value returned by the field is an integer in "cents". This means that if the price of a product is 100 yuan,priceThe field value will be 10000.In your frontend application or any place where prices need to be displayed, please make sure to perform the corresponding division by 100 to display the price in the familiar unit of yuan.stockThe field directly indicates the inventory quantity of the product, which is an integer value.
Batch retrieval of the price and inventory information of product lists
If your scenario requires displaying multiple product prices and stock on a product list page, for example on a product category page or search results page,archiveListThe interface is your first choice. This interface can help you efficiently obtain data from a batch of documents.
When using this interface, it is usually recommended that you go throughmoduleIdThe parameter is used to specify the product model ID.The Auto CMS allows you to create different models for different types of content, products usually have their independent models.moduleId=2Thus, the interface will only return documents belonging to the product model.
The strength of this interface lies in its support for various filtering and sorting methods. You can use the following criteria tocategoryIdFilter products under specific categories, or throughlimitParameter limits to return the number of items, even throughtype=pageParameters to implement pagination display and obtain the total number of products. No matter how you filter,archiveListReturned by the interface.dataEach document object in the array will clearly containpriceandstockthese two fields.
For example, to get the list of the first 10 products with product model ID 2, you can make this request:
{域名地址}/api/archive/list?moduleId=2&type=page&limit=10
In the returneddataIn the array, you just need to iterate over each product object to easily obtain their respective prices and stock. Similarly, here thepriceThe fields are also in "units", and corresponding conversion is required when displayed.
In general, Anqi CMS provides an intuitive and easy-to-use interface design for handling the price and inventory information of product type documents. Whether you need to obtain detailed data for a single product or display a list of products in bulk, you can do so througharchiveDetailorarchiveListThe interface efficiently and accurately retrieves the required information and combines it with the characteristic of 'unit fraction' for reasonable display.
Common Questions and Answers (FAQ)
Q1:priceWhy is the returned value of the field 0 instead of the actual price I set?A1: Anqi CMSpriceThe field stores integer values in units of 'fen'.If you set the product price in the background, for example, entering "99" represents 99 yuan, the system may directly recognize it as 99 cents.Please check the way you set the price in the background, make sure you enter a value in units of 'fen' (for example, 9900 represents 99 yuan), or confirm that your product model is correctly configured with the price field.
Q2: How do I know the corresponding "Product Type" documentmoduleIdWhat is it?A2: You can callapi/module/listInterface to retrieve the list of all document models in AnQi CMS. Find your product model in the returned data (usuallytitle字段会是“Product Center”、“Product”或类似名称),其对应的id就是您需要的moduleId。在获取商品列表时,指定正确的moduleIdEnsure that you are getting product data.
Q3: If the product stock is 0,stockwhat field will it be? How can I judge whether the product is sold out?A3: Even if the product inventory is 0,stockthe field will still return its current value, that is,0. This means that you can determine the product inventory status by directly judgingstockthe value of the field. IfstockThe value equals 0, which usually means that the product is out of stock. You can display a prompt such as 'Out of Stock' or disable purchase on the front page according to this value.