# Quable API

As Quable products are represented as Ibexa DXP products, you can use the existing [Product APIs](https://doc.ibexa.co/en/latest/product_catalog/product_api/index.md) to retrieve the product information.

Quable is the source of truth about products and categories and you should only use the Ibexa DXP APIs to read the information coming from Quable, but you can't use them to modify it. To modify the information, use the [Quable interface](https://quable.com) or the dedicated [Quable APIs](https://developers.quable.com/quable-api/).

## REST API Usage

To learn how to work with Ibexa DXP REST API, see [REST API reference](https://doc.ibexa.co/en/latest/api/rest_api/rest_api_usage/rest_api_usage/index.md).

You can use the following endpoints to retrieve product and category information:

- [Product REST API](https://doc.ibexa.co/en/latest/api/rest_api/rest_api_reference/rest_api_reference.html#tag/Product)
- [Taxonomy REST API](https://doc.ibexa.co/en/latest/api/rest_api/rest_api_reference/rest_api_reference.html#tag/Taxonomy)

## PHP API Usage

### Retrieve products

To retrieve product information coming from Quable, use the same APIs as described in [Product API](https://doc.ibexa.co/en/latest/product_catalog/product_api/index.md).

The following example shows how you can retrieve a single product:

```
$product = $this->productService->getProduct($productCode);

$output->writeln('Product with code ' . $product->getCode() . ' is ' . $product->getName());
```

### Search for products

Use [`ProductQuery`](https://doc.ibexa.co/en/latest/product_catalog/product_api/#getting-product-information) to search for mulitple products:

```
$criteria = new Criterion\ProductType([$productType]);
$sortClauses = [new SortClause\ProductName(ProductQuery::SORT_ASC)];

$productQuery = new ProductQuery(null, $criteria, $sortClauses);

$products = $this->productService->findProducts($productQuery);

foreach ($products as $product) {
    $output->writeln($product->getName() . ' of type ' . $product->getProductType()->getName());
}
```

When working with Quable products, the following search criteria are supported:

| Search Criterion                                                                                                             | Search based on                                          |
| ---------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------- |
| [CreatedAt](https://doc.ibexa.co/en/latest/search/criteria_reference/createdat_criterion/index.md)                           | Date and time when product was created                   |
| [LogicalAnd](https://doc.ibexa.co/en/latest/search/criteria_reference/logicaland_criterion/index.md)                         | Composite criterion combining multiple criteria with AND |
| [MatchAll](https://doc.ibexa.co/en/latest/search/criteria_reference/matchall_criterion/index.md)                             | All products                                             |
| [ProductCategory](https://doc.ibexa.co/en/latest/search/criteria_reference/productcategory_criterion/index.md)               | Product category assigned to product                     |
| [ProductCategorySubtree](https://doc.ibexa.co/en/latest/search/criteria_reference/productcategorysubtree_criterion/index.md) | Product category subtree                                 |
| [ProductCode](https://doc.ibexa.co/en/latest/search/criteria_reference/productcode_criterion/index.md)                       | Product's code                                           |
| [ProductName](https://doc.ibexa.co/en/latest/search/criteria_reference/productname_criterion/index.md)                       | Product's name                                           |
| [ProductType](https://doc.ibexa.co/en/latest/search/criteria_reference/producttype_criterion/index.md)                       | Product type                                             |
| [UpdatedAt](https://doc.ibexa.co/en/latest/search/criteria_reference/updated_at_criterion/index.md)                          | Date and time when product was last updated              |

The following sort clauses are supported:

| Sort Clause                                                                                                 | Sorting based on                           |
| ----------------------------------------------------------------------------------------------------------- | ------------------------------------------ |
| [CreatedAt](https://doc.ibexa.co/en/latest/search/sort_clause_reference/createdat_sort_clause/index.md)     | Date and time of the creation of a product |
| [ProductCode](https://doc.ibexa.co/en/latest/search/sort_clause_reference/productcode_sort_clause/index.md) | Product's code                             |
| [ProductName](https://doc.ibexa.co/en/latest/search/sort_clause_reference/productname_sort_clause/index.md) | Product's name                             |

### Manage stock and pricing

For information stored outside of Quable, such as [product availability](https://doc.ibexa.co/en/latest/product_catalog/product_api/#product-availability) or [pricing](https://doc.ibexa.co/en/latest/product_catalog/price_api/index.md), you can use the existing services to manage them:

```
// Manage availability
$product = $this->productService->getProduct('NEWMODIFIEDPRODUCT');

$productAvailabilityCreateStruct = new ProductAvailabilityCreateStruct($product, true, true);

$this->productAvailabilityService->createProductAvailability($productAvailabilityCreateStruct);

// Manage prices
$newCurrency = $this->currencyService->getCurrencyByCode($newCurrencyCode);

$money = new Money\Money(50000, new Money\Currency($newCurrencyCode));
$priceCreateStruct = new ProductPriceCreateStruct($product, $newCurrency, $money, null, null);

$this->productPriceService->createProductPrice($priceCreateStruct);
```

For advanced pricing strategies, use the [Discounts API](https://doc.ibexa.co/en/latest/discounts/discounts_api/index.md) to specify prices for Quable's products.
