Skip to content

Commit e153d5f

Browse files
mnoconadriendupuis
andauthored
Removed indent from Product API samples (#3179)
* Removed indent from Product API samples * Fixed nested input * Apply suggestions from code review Co-authored-by: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com> --------- Co-authored-by: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com>
1 parent 367ffc5 commit e153d5f

1 file changed

Lines changed: 31 additions & 29 deletions

File tree

docs/product_catalog/product_api.md

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ month_change: false
2323
Get an individual product by using the `ProductServiceInterface::getProduct()` method:
2424

2525
``` php
26-
[[= include_file('code_samples/api/product_catalog/src/Command/ProductCommand.php', 54, 57) =]]
26+
[[= include_code('code_samples/api/product_catalog/src/Command/ProductCommand.php', 55, 57, remove_indent=True) =]]
2727
```
2828

2929
Find multiple products with `ProductServiceInterface::findProducts()`.
3030

3131
Provide the method with optional filter, query or Sort Clauses.
3232

3333
``` php
34-
[[= include_file('code_samples/api/product_catalog/src/Command/ProductCommand.php', 58, 68) =]]
34+
[[= include_code('code_samples/api/product_catalog/src/Command/ProductCommand.php', 59, 68, remove_indent=True) =]]
3535
```
3636

3737
See [Product Search Criteria](product_search_criteria.md) and [Product Sort Clauses](product_sort_clauses.md) references for more information about how to use the [`ProductQuery`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ProductCatalog-Values-Product-ProductQuery.html) class.
@@ -41,21 +41,21 @@ See [Product Search Criteria](product_search_criteria.md) and [Product Sort Clau
4141
To create, update and delete products, use the `LocalProductServiceInterface`.
4242

4343
``` php
44-
[[= include_file('code_samples/api/product_catalog/src/Command/ProductCommand.php', 79, 83) =]]
44+
[[= include_code('code_samples/api/product_catalog/src/Command/ProductCommand.php', 80, 83, remove_indent=True) =]]
4545
```
4646

4747
To create a product, use `LocalProductServiceInterface::newProductCreateStruct()` to get a [`ProductCreateStruct`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ProductCatalog-Local-Values-Product-ProductCreateStruct.html).
4848
Provide the method with the product type object and the main language code.
4949
You also need to set (at least) the code for the product and the required Field of the underlying content type, `name`:
5050

5151
``` php
52-
[[= include_file('code_samples/api/product_catalog/src/Command/ProductCommand.php', 69, 76) =]]
52+
[[= include_code('code_samples/api/product_catalog/src/Command/ProductCommand.php', 70, 76, remove_indent=True) =]]
5353
```
5454

5555
To delete a product, use `LocalProductServiceInterface::deleteProduct()`:
5656

5757
``` php
58-
[[= include_file('code_samples/api/product_catalog/src/Command/ProductCommand.php', 106, 107) =]]
58+
[[= include_code('code_samples/api/product_catalog/src/Command/ProductCommand.php', 107, 107, remove_indent=True) =]]
5959
```
6060

6161
### Product variants
@@ -70,21 +70,21 @@ You can filter variants by:
7070
- variant codes:
7171

7272
``` php
73-
[[= include_file('code_samples/api/product_catalog/src/Command/ProductVariantCommand.php', 50, 54) =]]
73+
[[= include_code('code_samples/api/product_catalog/src/Command/ProductVariantCommand.php', 51, 54, indent_level=1, remove_indent=True) =]]
7474
```
7575

7676
- product criteria:
7777

7878
To use [Product Search Criteria](product_search_criteria.md) with [`ProductVariantQuery`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ProductCatalog-Values-Product-ProductVariantQuery.html), wrap it with the [`ProductCriterionAdapter`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ProductCatalog-Values-Content-Query-Criterion-ProductCriterionAdapter.html) class, as in the example below:
7979

8080
``` php hl_lines="4"
81-
[[= include_file('code_samples/api/product_catalog/src/Command/ProductVariantCommand.php', 55, 66) =]]
81+
[[= include_code('code_samples/api/product_catalog/src/Command/ProductVariantCommand.php', 56, 66, indent_level=1, remove_indent=True) =]]
8282
```
8383

8484
From a variant ([`ProductVariantInterface`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ProductCatalog-Values-ProductVariantInterface.html)), you can access the attributes that are used to generate the variant by using the [`ProductVariantInterface::getDiscriminatorAttributes()`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ProductCatalog-Values-ProductVariantInterface.html#method_getDiscriminatorAttributes) method.
8585

8686
``` php
87-
[[= include_file('code_samples/api/product_catalog/src/Command/ProductVariantCommand.php', 69, 73) =]]
87+
[[= include_code('code_samples/api/product_catalog/src/Command/ProductVariantCommand.php', 70, 73, remove_indent=True) =]]
8888
```
8989

9090
#### Searching for variants across all products
@@ -99,15 +99,15 @@ You can filter variants by:
9999
- variant codes:
100100

101101
``` php
102-
[[= include_file('code_samples/api/product_catalog/src/Command/ProductVariantCommand.php', 83, 87) =]]
102+
[[= include_code('code_samples/api/product_catalog/src/Command/ProductVariantCommand.php', 84, 87, indent_level=1, remove_indent=True) =]]
103103
```
104104

105105
- product criteria:
106106

107107
To use [Product Search Criteria](product_search_criteria.md) with [`ProductVariantQuery`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ProductCatalog-Values-Product-ProductVariantQuery.html), wrap it with the [`ProductCriterionAdapter`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ProductCatalog-Values-Content-Query-Criterion-ProductCriterionAdapter.html) class, as in the example below:
108108

109109
``` php hl_lines="4"
110-
[[= include_file('code_samples/api/product_catalog/src/Command/ProductVariantCommand.php', 92, 100) =]]
110+
[[= include_code('code_samples/api/product_catalog/src/Command/ProductVariantCommand.php', 93, 100, indent_level=1, remove_indent=True) =]]
111111
```
112112

113113
#### Creating variants
@@ -117,7 +117,7 @@ This method takes the product and an array of [`ProductVariantCreateStruct`](/ap
117117
`ProductVariantCreateStruct` specifies the attribute values and the code for the new variant.
118118

119119
``` php
120-
[[= include_file('code_samples/api/product_catalog/src/Command/ProductVariantCommand.php', 85, 91) =]]
120+
[[= include_code('code_samples/api/product_catalog/src/Command/ProductVariantCommand.php', 86, 91, remove_indent=True) =]]
121121
```
122122

123123
### Product assets
@@ -127,14 +127,14 @@ You can get assets assigned to a product by using [`AssetServiceInterface`](/api
127127
Use `AssetServiceInterface` to get a single asset by providing the product object and the assets's ID as parameters:
128128

129129
``` php
130-
[[= include_file('code_samples/api/product_catalog/src/Command/ProductAssetCommand.php', 46, 48) =]]
130+
[[= include_code('code_samples/api/product_catalog/src/Command/ProductAssetCommand.php', 47, 48, remove_indent=True) =]]
131131
```
132132

133133
To get all assets assigned to a product, use `AssetServiceInterface::findAssets()`.
134134
You can retrieve the tags (corresponding to attribute values) of assets with the `AssetInterface::getTags()` method:
135135

136136
``` php
137-
[[= include_file('code_samples/api/product_catalog/src/Command/ProductAssetCommand.php', 49, 58) =]]
137+
[[= include_code('code_samples/api/product_catalog/src/Command/ProductAssetCommand.php', 50, 58, remove_indent=True) =]]
138138
```
139139

140140
## Product types
@@ -148,19 +148,19 @@ To create a product type, use [`LocalProductTypeServiceInterface`](/api/php_api/
148148
First, create a product type struct with `LocalProductTypeServiceInterface::newProductTypeCreateStruct()`, providing the identifier and main language code:
149149

150150
``` php
151-
[[= include_file('code_samples/api/product_catalog/src/Command/ProductTypeCommand.php', 48, 52) =]]
151+
[[= include_code('code_samples/api/product_catalog/src/Command/ProductTypeCommand.php', 49, 52, remove_indent=True) =]]
152152
```
153153

154154
You can set names in multiple languages by using `setNames()`:
155155

156156
``` php
157-
[[= include_file('code_samples/api/product_catalog/src/Command/ProductTypeCommand.php', 53, 57) =]]
157+
[[= include_code('code_samples/api/product_catalog/src/Command/ProductTypeCommand.php', 54, 57, remove_indent=True) =]]
158158
```
159159

160160
To create a virtual product type (for products that don't require shipping), use `setVirtual()`:
161161

162162
``` php
163-
[[= include_file('code_samples/api/product_catalog/src/Command/ProductTypeCommand.php', 58, 59) =]]
163+
[[= include_code('code_samples/api/product_catalog/src/Command/ProductTypeCommand.php', 59, 59, remove_indent=True) =]]
164164
```
165165

166166
#### Adding field definitions
@@ -169,7 +169,7 @@ To add custom field definitions to the product type, use `getContentTypeCreateSt
169169
For more information about working with content types, see [Adding content types](../content_management/content_api/managing_content.md#adding-content-types).
170170

171171
``` php
172-
[[= include_file('code_samples/api/product_catalog/src/Command/ProductTypeCommand.php', 62, 69) =]]
172+
[[= include_code('code_samples/api/product_catalog/src/Command/ProductTypeCommand.php', 63, 69, remove_indent=True) =]]
173173
```
174174

175175
#### Assigning attributes
@@ -179,13 +179,13 @@ To assign product attributes to the product type, use `setAssignedAttributesDefi
179179
First, retrieve the attribute definition by using [`AttributeDefinitionServiceInterface`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ProductCatalog-AttributeDefinitionServiceInterface.html):
180180

181181
``` php
182-
[[= include_file('code_samples/api/product_catalog/src/Command/ProductTypeCommand.php', 70, 71) =]]
182+
[[= include_code('code_samples/api/product_catalog/src/Command/ProductTypeCommand.php', 71, 71, remove_indent=True) =]]
183183
```
184184

185185
Then create the assignment struct with the attribute definition, and set whether it's required and whether it's a discriminator (used for product variants):
186186

187187
``` php
188-
[[= include_file('code_samples/api/product_catalog/src/Command/ProductTypeCommand.php', 72, 79) =]]
188+
[[= include_code('code_samples/api/product_catalog/src/Command/ProductTypeCommand.php', 73, 79, remove_indent=True) =]]
189189
```
190190

191191
For more information about working with attributes through PHP API, see [Attributes](#attributes).
@@ -195,21 +195,21 @@ For more information about working with attributes through PHP API, see [Attribu
195195
Finally, create the product type with `LocalProductTypeServiceInterface::createProductType()`:
196196

197197
``` php
198-
[[= include_file('code_samples/api/product_catalog/src/Command/ProductTypeCommand.php', 80, 81) =]]
198+
[[= include_code('code_samples/api/product_catalog/src/Command/ProductTypeCommand.php', 81, 81, remove_indent=True) =]]
199199
```
200200

201201
### Getting product types
202202

203203
Get a product type object by using `ProductTypeServiceInterface::getProductType()`:
204204

205205
``` php
206-
[[= include_file('code_samples/api/product_catalog/src/Command/ProductTypeCommand.php', 82, 83) =]]
206+
[[= include_code('code_samples/api/product_catalog/src/Command/ProductTypeCommand.php', 83, 83, remove_indent=True) =]]
207207
```
208208

209209
You can also get a list of product types with `ProductTypeServiceInterface::findProductTypes()`:
210210

211211
``` php
212-
[[= include_file('code_samples/api/product_catalog/src/Command/ProductTypeCommand.php', 86, 91) =]]
212+
[[= include_code('code_samples/api/product_catalog/src/Command/ProductTypeCommand.php', 87, 91, remove_indent=True) =]]
213213
```
214214

215215
## Product availability
@@ -223,14 +223,15 @@ Get the availability object with `ProductAvailabilityServiceInterface::getAvaila
223223
You can then use `ProductAvailabilityServiceInterface::getStock()` to get the stock number for the product:
224224

225225
```php
226-
[[= include_file('code_samples/api/product_catalog/src/Command/ProductCommand.php', 90, 95) =]][[= include_file('code_samples/api/product_catalog/src/Command/ProductCommand.php', 104, 105) =]]
226+
[[= include_code('code_samples/api/product_catalog/src/Command/ProductCommand.php', 91, 95, remove_indent=True) =]]
227+
[[= include_code('code_samples/api/product_catalog/src/Command/ProductCommand.php', 105, 105, remove_indent=True) =]]
227228
```
228229

229230
To change availability for a product, use `ProductAvailabilityServiceInterface::updateProductAvailability()` with a [`ProductAvailabilityUpdateStruct`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ProductCatalog-Values-Availability-ProductAvailabilityUpdateStruct.html) and provide it with the product object.
230231
The second parameter defines whether product is available, and the third whether its stock is infinite. The fourth parameter is the stock number:
231232

232233
``` php
233-
[[= include_file('code_samples/api/product_catalog/src/Command/ProductCommand.php', 98, 101) =]]
234+
[[= include_code('code_samples/api/product_catalog/src/Command/ProductCommand.php', 99, 101, remove_indent=True) =]]
234235
```
235236

236237
## Attributes
@@ -241,24 +242,25 @@ To get information about product attribute groups, use the [`AttributeGroupServi
241242
`AttributeGroupServiceInterface::findAttributeGroups()` gets attribute groups, all of them or filtered with an optional [`AttributeGroupQuery`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ProductCatalog-Values-AttributeGroup-AttributeGroupQuery.html) object:
242243

243244
``` php
244-
[[= include_file('code_samples/api/product_catalog/src/Command/AttributeCommand.php', 53, 54) =]]
245-
[[= include_file('code_samples/api/product_catalog/src/Command/AttributeCommand.php', 74, 79) =]]
245+
[[= include_code('code_samples/api/product_catalog/src/Command/AttributeCommand.php', 54, 54, remove_indent=True) =]]
246+
247+
[[= include_code('code_samples/api/product_catalog/src/Command/AttributeCommand.php', 75, 79, remove_indent=True) =]]
246248
```
247249

248250
To create an attribute group, use `LocalAttributeGroupServiceinterface::createAttributeGroup()` and provide it with an [`AttributeGroupCreateStruct`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ProductCatalog-Local-Values-AttributeGroup-AttributeGroupCreateStruct.html):
249251

250252
``` php
251-
[[= include_file('code_samples/api/product_catalog/src/Command/AttributeCommand.php', 48, 52) =]]
253+
[[= include_code('code_samples/api/product_catalog/src/Command/AttributeCommand.php', 49, 52, remove_indent=True) =]]
252254
```
253255

254256
To get information about product attributes, use the [`AttributeDefinitionServiceInterface`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ProductCatalog-AttributeDefinitionServiceInterface.html), or [`LocalAttributeDefinitionServiceInterface`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ProductCatalog-Local-LocalAttributeDefinitionServiceInterface.html) to modify attributes.
255257

256258
``` php
257-
[[= include_file('code_samples/api/product_catalog/src/Command/AttributeCommand.php', 60, 62) =]]
259+
[[= include_code('code_samples/api/product_catalog/src/Command/AttributeCommand.php', 61, 62, remove_indent=True) =]]
258260
```
259261

260262
To create an attribute, use `LocalAttributeGroupServiceinterface::createAttributeDefinition()` and provide it with an [`AttributeDefinitionCreateStruct`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ProductCatalog-Local-Values-AttributeDefinition-AttributeDefinitionCreateStruct.html):
261263

262264
``` php
263-
[[= include_file('code_samples/api/product_catalog/src/Command/AttributeCommand.php', 65, 71) =]]
265+
[[= include_code('code_samples/api/product_catalog/src/Command/AttributeCommand.php', 66, 71, remove_indent=True) =]]
264266
```

0 commit comments

Comments
 (0)