Product API¶
Products¶
Ibexa DXP's Product API provides two services for handling product information, which differ in function:
ProductServiceInterface
is used to request product dataLocalProductServiceInterface
is used to modify products
Product REST API
To learn how to load products using the REST API, see REST API reference.
Getting product information¶
Get an individual product by using the ProductServiceInterface::getProduct()
method:
1 2 3 |
|
Find multiple products with ProductServiceInterface::findProducts()
.
Provide the method with optional filter, query or Sort Clauses.
1 2 3 4 5 6 7 8 9 10 |
|
See Product Search Criteria and Product Sort Clauses references for more information about how to use the ProductQuery
class.
Modifying products¶
To create, update and delete products, use the LocalProductServiceInterface
.
1 2 3 4 |
|
To create a product, use LocalProductServiceInterface::newProductCreateStruct()
to get a ProductCreateStruct
.
Provide the method with the product type object and the main language code.
You also need to set (at least) the code for the product and the required Field of the underlying content type, name
:
1 2 3 4 5 6 7 |
|
To delete a product, use LocalProductServiceInterface::deleteProduct()
:
1 |
|
Product variants¶
You can access the variants of a product by using ProductServiceInterface::findProductVariants()
.
The method takes the product object and a ProductVariantQuery
object as parameters.
A ProductVariantQuery
lets you define the offset and limit of the variant query.
The default offset is 0, and limit is 25.
1 2 3 |
|
From a variant (ProductVariantInterface
), you can access the attributes that are used to generate the variant by using ProductVariantInterface::getDiscriminatorAttributes()
.
1 2 3 4 5 6 7 |
|
Creating variants¶
To create a product variant, use LocalProductServiceInterface::createProductVariants()
.
This method takes the product and an array of ProductVariantCreateStruct
objects as parameters.
ProductVariantCreateStruct
specifies the attribute values and the code for the new variant.
1 2 3 4 5 6 |
|
Product assets¶
You can get assets assigned to a product by using AssetServiceInterface
.
Use AssetServiceInterface
to get a single asset by providing the product object and the assets's ID as parameters:
1 2 |
|
To get all assets assigned to a product, use AssetServiceInterface::findAssets()
.
You can retrieve the tags (corresponding to attribute values) of assets with the AssetInterface::getTags()
method:
1 2 3 4 5 6 7 8 9 |
|
Product types¶
To work with product types, use ProductTypeServiceInterface
.
Get a product type object by using ProductTypeServiceInterface::getProductType()
:
1 |
|
You can also get a list of product types with ProductTypeServiceInterface::findProductTypes()
:
1 2 3 4 5 |
|
Product availability¶
Product availability is an object which defines whether a product is available, and if so, in what stock.
To manage it, use ProductAvailabilityServiceInterface
.
To check whether a product is available (with or without stock defined), use ProductAvailabilityServiceInterface::hasAvailability()
.
Get the availability object with ProductAvailabilityServiceInterface::getAvailability()
.
You can then use ProductAvailabilityServiceInterface::getStock()
to get the stock number for the product:
1 2 3 4 5 6 |
|
To change availability for a product, use ProductAvailabilityServiceInterface::updateProductAvailability()
with a ProductAvailabilityUpdateStruct
and provide it with the product object.
The second parameter defines whether product is available, and the third whether its stock is infinite. The fourth parameter is the stock number:
1 2 3 |
|
Attributes¶
To get information about product attribute groups, use the AttributeGroupServiceInterface
, or LocalAttributeGroupServiceInterface
to modify attribute groups.
AttributeGroupServiceInterface::getAttributeGroup()
enables you to get a single attribute group by its identifier.
AttributeGroupServiceInterface::findAttributeGroups()
gets attribute groups, all of them or filtered with an optional AttributeGroupQuery
object:
1 2 3 4 5 6 7 |
|
To create an attribute group, use LocalAttributeGroupServiceinterface::createAttributeGroup()
and provide it with an AttributeGroupCreateStruct
:
1 2 3 4 |
|
To get information about product attributes, use the AttributeDefinitionServiceInterface
, or LocalAttributeDefinitionServiceInterface
to modify attributes.
1 2 |
|
To create an attribute, use LocalAttributeGroupServiceinterface::createAttributeDefinition()
and provide it with an AttributeDefinitionCreateStruct
:
1 2 3 4 5 6 |
|