In Anqi CMS, if you are managing documents of the product type and need to obtain the specific prices of these products (price) and stock quantities (stockThis information is actually very direct and convenient. AnQi CMS takes these needs into account in its design, making these key data as one of the core attributes of the document, and you can easily obtain them through several core interfaces.

Get the price and stock information of a single product document

When you need to view the price and inventory of a specific product, AnQi CMS providesarchiveDetailan interface. This interface is specifically used to retrieve all 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 product details for ID 123, you can call it like this:

{域名地址}/api/archive/detail?id=123

In the data returned by the interface, you will finddataThe object directly containspriceandstockfields. These fields clearly show the pricing and current inventory of the product.

It is worth noting that,priceThe field returns the integer value in 'cents'. This means that if the price of a product is 100 yuan, thenpriceThe value will be 10000. Be sure to divide by 100 in your frontend application or any place where you need to display prices, so that it shows as a familiar price in units of yuan.stockThe field directly represents the product's stock quantity, which is an integer value.

Batch retrieval of the price and stock information of the product list.

If your scenario is to display multiple product prices and inventory on a product list page, for example on a product category page or in search results, thenarchiveListThe interface is your first choice. This interface can help you efficiently retrieve a batch of document data.

When using this interface, it is usually recommended to go throughmoduleIdSpecify the product model ID. Anqi CMS allows you to create different models for different types of content, and products usually have their own independent models.For example, if your product model ID is 2, then setmoduleId=2. This 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 sort according tocategoryIdFilter products under a specific category, or throughlimitParameter limit the number of returned results, and even throughtype=pageParameters to implement pagination display and obtain the total number of products. No matter how you filter,archiveListThe interface returnsdataEach document object in the array will clearly containpriceandstockthese fields.

For example, to get the top 10 product lists with product model ID 2, you can request as follows:

{域名地址}/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 get their respective prices and stock. Similarly, here we get thepriceThe fields are also in "cents" units and need to be converted when displayed.

In general, Anqi CMS provides an intuitive and user-friendly interface design for handling the price and inventory information of product type documents. Whether it is to obtain detailed data of a single product or to display a list of products in bulk, you can do so byarchiveDetailorarchiveListThe interface efficiently and accurately retrieves the required information and reasonably displays it in combination with the "unit fraction" feature.


Frequently Asked Questions (FAQ)

Q1:priceWhy is the returned value of the field 0 instead of the actual price I set?A1: Anqi CMS'priceThe field stores integers in units of 'fen'. For example, if you enter '99' in the background to set the product price, the system may directly recognize it as 99 fen.Please check the way you set the price in the background, make sure you enter a value in "cents" (for example, 9900 represents 99 yuan), or confirm that your product model is correctly configured with the price field.

Q2: How do I know which document corresponds to my "product type"?moduleIdare?A2: You can callapi/module/listAn interface to retrieve the list of all document models in AnQi CMS. In the returned data, find your product model (usuallytitleThe field will be "Product Center", "Product" or similar names, corresponding toidThat is what you needmoduleIdSpecify the correct one when getting the product listmoduleIdCan ensure that you get is product data.

Q3: If the product inventory is 0,stockwhat field will it be? How can I judge whether the product is sold out?A3: Even if the product stock is 0,stockthe field will still return its current value, that is,0. This means you can directly determine the product stock status by checking thestockvalue of the field. IfstockThe value is 0, which usually means that the product is out of stock. You can use this value on the frontend page to display a 'sold out' message or to prevent purchase.