You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This commit standardizes whitespace, removes trailing spaces, and improves formatting across multiple documentation files for consistency and readability. No content changes were made.
Copy file name to clipboardExpand all lines: development/coding-standards/_index.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -86,7 +86,7 @@ class MyClass
86
86
{
87
87
public function doStuff(string $foo, array $bar): void
88
88
{
89
-
}
89
+
}
90
90
}
91
91
```
92
92
@@ -149,7 +149,7 @@ You can run the linter to help you comply with these coding standards:
149
149
150
150
## TypeScript
151
151
152
-
All `admin-dev/themes/new-theme/js` files are coded in TypeScript. Classes and functions in .ts files must be strictly typed.
152
+
All `admin-dev/themes/new-theme/js` files are coded in TypeScript. Classes and functions in .ts files must be strictly typed.
153
153
154
154
You are able to get global types in the `admin-dev/themes/new-theme/js/types` folder using the `@PSTypes` relative path and some types library are imported from npm using the `@types` namespace and automatically imported by TypeScript.
Copy file name to clipboardExpand all lines: development/compile-assets.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ Some components in PrestaShop, like Javascript or SCSS files, need to be compile
11
11
12
12
We use [Webpack](https://webpack.js.org/) to compile assets. PrestaShop is using NodeJS ([get it here](https://nodejs.org/)), NPM will take care of it all.
-[Active record pattern](https://en.wikipedia.org/wiki/Active_record_pattern)
20
20
21
-
A class extending the ObjectModel class is tied to a database table. Its static attribute (`$definition`) represents the model.
21
+
A class extending the ObjectModel class is tied to a database table. Its static attribute (`$definition`) represents the model.
22
22
23
-
Its instances are tied to database records.
23
+
Its instances are tied to database records.
24
24
25
-
When instantiated with an `$id` in the class constructor, the attributes are retrieved from the related database record (using the `$id` as the primary key to find the table record).
25
+
When instantiated with an `$id` in the class constructor, the attributes are retrieved from the related database record (using the `$id` as the primary key to find the table record).
26
26
27
27
{{% notice info %}}
28
-
You can override classes that extend ObjectModel, but with extreme precaution, e.g., defining a wrong `$definition` model can break the entire system or lead to data loss.
28
+
You can override classes that extend ObjectModel, but with extreme precaution, e.g., defining a wrong `$definition` model can break the entire system or lead to data loss.
29
29
{{% /notice %}}
30
30
31
31
## Create a new entity managed by ObjectModel
32
32
33
-
You can create a new entity (in a module for example), with its own database table, managed by ObjectModel.
33
+
You can create a new entity (in a module for example), with its own database table, managed by ObjectModel.
34
34
35
35
To do this, create class extending the ObjectModel:
36
36
@@ -122,14 +122,14 @@ public static $definition = [
122
122
'fields' => array(
123
123
```
124
124
125
-
-`table` is the related database table name (without the database table `PREFIX`),
125
+
-`table` is the related database table name (without the database table `PREFIX`),
126
126
-`primary` is the name of the `PRIMARY KEY` field in the database table, which will be used as `$id` in the ObjectModel
127
127
-`multilang` is a boolean value indicating that the entity is available in multiple langages, see [Multiple languages]({{< ref "#multiple-languages" >}})
128
128
-`fields` is an array containing all other of the fields from the database table.
129
129
130
130
### Fields description
131
131
132
-
A field is defined by a key (its name in the database table) and an array of its settings.
132
+
A field is defined by a key (its name in the database table) and an array of its settings.
133
133
134
134
```php
135
135
'meta_description' => [
@@ -165,13 +165,13 @@ Field type is an important setting, it determines how ObjectModel will format yo
165
165
166
166
#### Validation rules reference
167
167
168
-
Several validation rules are available for your ObjectModel fields.
168
+
Several validation rules are available for your ObjectModel fields.
169
169
[Please refer to the Validate class of PrestaShop](https://github.com/PrestaShop/PrestaShop/blob/8.0.x/classes/Validate.php) for a complete list.
170
170
171
171
### Add timestamps to your entity (date_add and date_upd)
172
172
173
-
ObjectModel has a mechanism to handle creation/modification timestamps.
174
-
To use this feature, you have to define those two properties of your entity and set them up in the model definition.
173
+
ObjectModel has a mechanism to handle creation/modification timestamps.
174
+
To use this feature, you have to define those two properties of your entity and set them up in the model definition.
175
175
176
176
```php
177
177
class Cms extends ObjectModel
@@ -215,7 +215,7 @@ If the insert is successful, the ObjectModel class will set the entity's id (ret
215
215
216
216
```php
217
217
$id = 2; // id of the object in database
218
-
$cms = new Cms($id);
218
+
$cms = new Cms($id);
219
219
$cms->position = 3;
220
220
...
221
221
$cms->save();
@@ -225,7 +225,7 @@ In this example, we retrieve an entity from the database with its id. Then, we c
225
225
226
226
### Hard or soft delete an object
227
227
228
-
Two delete mechanisms are available with ObjectModel: hard delete and soft delete.
228
+
Two delete mechanisms are available with ObjectModel: hard delete and soft delete.
229
229
Hard-delete deletes the record from the database, while soft-delete sets a flag in the table's field indicating that this record is deleted.
230
230
231
231
{{% notice info %}}
@@ -242,13 +242,13 @@ Soft deleting an object does not trigger **Delete** related hooks, but will trig
242
242
243
243
```php
244
244
$id = 2; // id of the object in database
245
-
$cms = new Cms($id);
245
+
$cms = new Cms($id);
246
246
$cms->softDelete(); // sets the deleted property to true, and triggers an update() call
247
247
...
248
248
$cms->delete(); // triggers a DELETE statement to the DBAL
249
249
```
250
250
251
-
## Advanced usage
251
+
## Advanced usage
252
252
253
253
### Multiple languages objects{#multiple-languages}
254
254
@@ -257,7 +257,7 @@ PrestaShop's ObjectModel can handle translations (also called internationalizati
257
257
#### Under the hood: how does it work?
258
258
259
259
When declaring a multi-language ObjectModel, PrestaShop will fetch another database table named like your base database table, but with a suffix `_lang`
260
-
This table references the id of the base Object (`id_cms`), the id of the language (`id_lang`), and each translatable field.
260
+
This table references the id of the base Object (`id_cms`), the id of the language (`id_lang`), and each translatable field.
261
261
262
262
In our previous example, for `Cms` ObjectModel:
263
263
@@ -308,7 +308,7 @@ And then, you must declare which fields are available for translations:
308
308
309
309
#### Accessors for translatable ObjectModels{#multiple-language-accessors}
310
310
311
-
Translatable fields are available in your ObjectModel as `array`.
311
+
Translatable fields are available in your ObjectModel as `array`.
312
312
In our example, to update the attributes `meta_title` for languages EN (`$lang_id=1`) and FR (`$lang_id=2`), use the following method :
313
313
314
314
```php
@@ -333,7 +333,7 @@ PrestaShop's ObjectModel can handle multiple stores (or multi shop) ObjectModels
333
333
#### Under the hood: how does it work?
334
334
335
335
When declaring a multi-store ObjectModel, PrestaShop will fetch another database table named like your base database table, with a suffix `_shop`
336
-
This table is a pivot table referencing at least the id of the base Object (`id_cms`) and the id of the shop (`id_shop`).
336
+
This table is a pivot table referencing at least the id of the base Object (`id_cms`) and the id of the shop (`id_shop`).
337
337
338
338
In our previous example, for `Cms` ObjectModel:
339
339
@@ -382,7 +382,7 @@ PrestaShop's ObjectModel can handle both multiple languages and multiple shop en
382
382
#### Under the hood: how does it work?
383
383
384
384
When declaring a multi-store ObjectModel, PrestaShop will fetch another database table named like your base database table, with a suffix `_shop`
385
-
This table is a pivot table referencing at least the id of the base Object (`id_cms`) and the id of the shop (`id_shop`).
385
+
This table is a pivot table referencing at least the id of the base Object (`id_cms`) and the id of the shop (`id_shop`).
386
386
387
387
In our previous example, for `Category` ObjectModel :
388
388
@@ -458,7 +458,7 @@ $category->save();
458
458
To duplicate an object, use the following method : `duplicateObject()`
459
459
460
460
```php
461
-
$cms = new Cms(2);
461
+
$cms = new Cms(2);
462
462
$duplicatedCms = $cms->duplicateObject();
463
463
```
464
464
@@ -470,14 +470,14 @@ Please note that the `duplicateObject()` method will instantly save the duplicat
470
470
471
471
### Partial update of an object
472
472
473
-
Since {{< minver v="8.x" >}}, a partial update mechanism is available in ObjectModel. This mechanism allows you to choose which attributes you want to update during the `update()` method call.
473
+
Since {{< minver v="8.x" >}}, a partial update mechanism is available in ObjectModel. This mechanism allows you to choose which attributes you want to update during the `update()` method call.
474
474
475
475
On previous versions ({{< minver v="1.7.x" >}}, {{< minver v="1.6.x" >}}, ...), this method was already available but was not working properly.
476
476
477
477
Example:
478
478
479
479
```php
480
-
$cms = new Cms(2);
480
+
$cms = new Cms(2);
481
481
$cms->position = 4;
482
482
$cms->active = 0;
483
483
$cms->setFieldsToUpdate(["position" => true]);
@@ -491,7 +491,7 @@ In this example, only the `position` is updated, `active` (and all other fields)
491
491
You need to specify the language Ids you want to update, as an array :
492
492
493
493
```php
494
-
$cms = new Cms(2);
494
+
$cms = new Cms(2);
495
495
$cms->meta_title[1] = "My awesome title"; // language id #1
496
496
$cms->meta_title[2] = "Mon fabuleux titre"; // language id #2
497
497
$cms->setFieldsToUpdate(
@@ -507,8 +507,8 @@ $cms->save(); // only meta_title for language id #1 will be updated
507
507
508
508
### Toggle status
509
509
510
-
A mecanism of state is available with ObjectModel : active / inactive state.
511
-
When triggered, this mecanism allows your entities to be enabled / disabled.
510
+
A mecanism of state is available with ObjectModel : active / inactive state.
511
+
When triggered, this mecanism allows your entities to be enabled / disabled.
512
512
513
513
{{% notice info %}}
514
514
**Status is not always available.**
@@ -518,15 +518,15 @@ If the model object has no `active` property or no `active` definition field, a
518
518
519
519
```php
520
520
$id = 2; // id of the entity in database
521
-
$cms = new Cms($id);
521
+
$cms = new Cms($id);
522
522
$cms->toggleStatus(); // sets the active property to true or false (depending on its current value), and triggers an update() call
523
523
```
524
524
525
525
### Delete multiple entities
526
526
527
-
You can delete multiple object at once with the `deleteSelection` method. Pass an array of IDs to delete to this method, and they will be deleted.
527
+
You can delete multiple object at once with the `deleteSelection` method. Pass an array of IDs to delete to this method, and they will be deleted.
528
528
529
-
Usage :
529
+
Usage :
530
530
531
531
```php
532
532
$cmsIdsToDelete = [1, 2, 3, 8, 10];
@@ -564,7 +564,7 @@ public function hookActionObjectProductDeleteAfter(Product $product)
564
564
{
565
565
PrestaShopLogger::addLog(
566
566
sprintf('Product with id %s was deleted with success', $product->id_product)
0 commit comments