If the document is a product type, how can you get its `price` (price) and `stock` (stock) information?

Calendar 👁️ 76

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.

Related articles

The value of the `status` field in the document details, for example 1, specifically indicates which display status the document has?

When using AnQi CMS to manage website content, you may encounter various technical parameters, one of which seems simple but is crucial is the `status` field in the document details.It acts like a 'switch' for the content, quietly controlling whether your article, product, or other information can be seen by visitors. Then, what does this `status` field specifically represent?In simple terms, it is an integer value used to mark the current display state of the document.

2025-11-09

Is the `created_time` and `updated_time` field of the document in Unix timestamp, how to perform time format conversion?

In AnQiCMS (AnQiCMS), when you obtain various information such as documents, categories, attachments, and users through the API interface, you will find that fields like `created_time` (creation time) and `updated_time` (update time) are usually presented in integer form.This is indeed the Unix timestamp format commonly used by many systems, including AnQiCMS.### What is Unix timestamp? Unix timestamp, also known as POSIX time or Epoch time, is a way to represent time

2025-11-09

What is the role of `canonical_url` and `fixed_link` in document details for SEO and link management?

In website operation, the health status of links and the friendliness to search engines are the foundation for the success of the website.AnQi CMS provides us with two key fields: `canonical_url` and `fixed_link`, which play a crucial role in document details and help us optimize the search engine performance of the website and effectively manage links. ### canonical_url: Define the "main version" of the content Imagine that your website might have multiple URLs pointing to the same or highly similar content for various reasons.

2025-11-09

How to interpret the `flag` recommended attribute in the document details, for example, what do `h`, `c`, `f`, and others represent?

In AnQi CMS, the recommended attribute `flag` is a very practical feature in content operations. It allows us to classify and label document content, thereby enabling personalized display and filtering in different areas of the website.Understanding the meaning of these brief letter codes can help us manage and present website content more efficiently.Where can I find the `Flag` attribute? This important `flag` attribute appears in several key interfaces, it is both the characteristic of the document itself, and the important basis for querying and filtering documents. First

2025-11-09

What detailed information will the nested `category` object return?

When we explore the mysteries of content in AnQi CMS, we often need to obtain detailed information about the documents.The `archiveDetail` interface provides us with rich document data, and the nested `category` object is a frequently overlooked but extremely important repository of information.It is not just a simple classification ID, but a complete entity containing all the metadata of the classification, which provides great convenience for us to deeply understand the context of the document and to carry out refined content display.

2025-11-09

How to display the `extra` object, how to access its `name` and `value`?

When using AnQiCMS to manage website content, the flexibility of custom fields in the document model is one of its highlights.These custom fields allow us to add unique properties for different types of documents (such as articles, products, etc.), greatly enriching the content dimensions.When obtaining document details or lists through the API, the information of these custom fields is cleverly encapsulated in the `extra` object of the returned data.

2025-11-09

How to get the value of a specific custom field (such as "author") through the `extra` field?

In Anqi CMS, the custom fields of documents are a reflection of its powerful flexibility, allowing us to add various unique attributes to content, thereby enabling more precise management and display of information.But for many developers and operations personnel, how to accurately obtain the values of these custom fields through the API is often a clear issue.Don't worry, Anqi CMS provides clear paths in API design, through the `extra` field, you can easily handle these additional data.### Understand the `extra` field

2025-11-09

What does it mean if an error code 1001 or 1002 occurs when getting the document details, and how to solve it?

When using AnQi CMS for website content management and development, we often use API interfaces to obtain various data, among which obtaining document details (`/api/archive/detail`) is very commonly used.When you call this interface, if you encounter system return codes 1001 or 1002, it usually indicates that the request was not successfully processed and a specific reason is given.Understanding the meaning and solutions of these error codes can help us more efficiently troubleshoot problems and ensure the normal display of website content.### Error Code 1001

2025-11-09