Currently, I am working on a project that involves utilizing an API for data retrieval, updates, and deletions. The API in question is the prestashop API. While I have managed to retrieve data and update certain items successfully, I encountered an issue. According to the documentation, all data transmitted through the API is in either `json` or `xml` format. However, some data within the API has different levels in the JSON return, such as the @attributes and @associations levels, leading me to the following query.
I aim to access this data and display it using AngularJS. To demonstrate what I intend to achieve, let me provide a quick example.
Here is a simplified version of the JSON return:
{"products": {"product":[{"id: "1", name: "Product Name", category: "Category"
...
]
With the use of the AngularJS `$http.get()` function, along with ng-repeat and binding, I can display the product names efficiently. However, accessing the @attribute values poses a challenge. Is there a specific method to accomplish this, or is it based solely on navigating through the JSON object's depth level?
The AngularJS function snippet for retrieving products is as follows:
$http.get('config/get/getProducts.php', {cache: true}).then(function (response) {
$scope.products = response.data.products.product
});
Including the corresponding HTML:
<div ng-if="product.active == 1" class="productimg col-4" ng-repeat="product in products | filter : {id_category_default: catFilter.id}: true | filter:productSearch | filter:product.name | orderBy: 'name'">
<p ng-bind="product.name.language"></p>
</div>
UPDATE: 01/02/2018 After reviewing comments and conducting tests, I have devised a viable solution to access the @attributes and associations values. However, a new obstacle has emerged. The result from each filter includes multiple "id" values, which are not suitable for comparison with corresponding id values from other tables. Here is an illustration:
<div class="col-lg-3" ng-repeat="value in products">
<p ng-bind="value.associations.categories.category"></p>
</div>
This results in:
[{"id":"2"},{"id":"3"},{"id":"4"},{"id":"5"}]
...
My objective is to extract these values as simple numbers for accurate comparisons. An ideal outcome would be:
2, 3, 4, 5
Hence, how can I achieve this desired output?
If you are curious about the motive behind this endeavor, I am striving to retrieve option_values IDs and category IDs from products in a PrestaShop installation using the PrestaShop webservice.