ps_eventbus
is a module companion for CloudSync.
PrestaShop platform | PHP | PS EventBus |
---|---|---|
8.0 | 7.1+ | From 2.x - to latest |
1.7.3-1.7.8 | 7.1+ | From 2.x - to latest |
1.6.1.11 - 1.7.2.5 | 5.6+ | From 3.1 - to latest |
PS Accounts compatibility matrix can be viewed here.
Please note that starting from PHP 8.1, product images may be missing due to a known issue. This is a recognized problem and is being tracked in the PrestaShop repository. You can follow the progress and find more details about the resolution here.
Since version 4.0, all API endpoints are grouped under a single controller "apiShopContent.php" (except for the healthcheck). The route to call is now unique, and the shopContent is no longer a specific endpoint but a query parameter of the request:
http://localhost:8000/index.php?fc=module&module=ps_eventbus&controller=apiShopContent&shop_content=products
make help # get help on how to use the awesome Makefile features
make # bundle all vendors required for the module to run
make zip # make a zip ready to be tested in PrestaShop (see ./dist)
Pro-tip: prefix all you make commands with the variables you want to override. Ie:
VERSION=v1.2.3-rc4 make zip-prod
to set the zip package to the desired version.
make lint # linting the code with vendor/bin/php-cs-fixer
make lint-fix # linting and fixing the code with vendor/bin/php-cs-fixer
make php-lint # linting with php
make phpunit # unit testing with vendor/bin/phpunit
make phpunit-cov # unit testing as above but with code coverage
make phpstan # linting the code with PrestaShop and vendor/bin/phpstan
make docker-<stuff> # same as above, but in a docker container
Note: you will need xdebug if you want to generate the code-coverage of this project. You may install it with:
pecl install -f xdebug
.
To check the module healthiness (authenticated route):
BASE_URL="http://localhost:8000"
curl -s -L "$BASE_URL/index.php?fc=module&module=ps_eventbus&controller=apiHealthCheck&job_id=valid-job-stuff" | jq .
{
"prestashop_version": "1.6.1.24",
"ps_eventbus_version": "0.0.0",
"ps_accounts_version": "5.6.2",
"php_version": "7.1.33",
"ps_account": true,
"is_valid_jwt": true,
"ps_eventbus": true,
"env": {
"EVENT_BUS_PROXY_API_URL": "http://reverse-proxy/collector",
"EVENT_BUS_SYNC_API_URL": "http://reverse-proxy/sync-api"
},
"httpCode": 200
}
To check the fallback route (unauthenticated):
BASE_URL="http://localhost:8000"
curl -s -L "$BASE_URL/index.php?fc=module&module=ps_eventbus&controller=apiHealthCheck" | jq .
{
"ps_account": true,
"is_valid_jwt": true,
"ps_eventbus": true,
"env": {
"EVENT_BUS_PROXY_API_URL": "http://reverse-proxy/collector",
"EVENT_BUS_SYNC_API_URL": "http://reverse-proxy/sync-api",
"EVENT_BUS_LIVE_SYNC_API_URL": "http://reverse-proxy/live-sync-api/v1"
},
"httpCode": 200
}
Dev requirements:
Or an up-to-date Docker engine.
Let's take the example of adding a shopContent named "plane".
Add the shop content in the Config.php file (create a constant, and add it to the SHOP_CONTENTS array).
const COLLECTION_PLANES = 'planes';
const SHOP_CONTENTS = [
...
self::COLLECTION_PLANES
...
];
Create a service "planesService.php" (in plural) in the shop content services folder that extends the ShopContentAbstractService and implements the ShopContentServiceInterface.php interface. For the method structure, use the existing base on all other shop content services to maintain consistency.
class PlanesService extends ShopContentAbstractService implements ShopContentServiceInterface
{
...
}
Don't missing to declare this new service to service.yml file.
Then create a repository PlaneRepository.php (in singular) in the Repository folder that extends the AbstractRepository.php class and implements the RepositoryInterface.php interface. Similarly, maintain consistency with other shop content repositories.
class PlaneRepository extends AbstractRepository implements RepositoryInterface
{
...
}
Don't missing to declare this new repository to repository.yml file.
Add your shop content in the e2e config file.
export const shopContentMapping = {
...
planes: 'planes'
...
}
Run the tests once to generate the necessary dumps (they will be present in the dump folder). Once the test is performed (and failed), copy the planes.json file, and paste it into the fixture folder for your given version. Do the same for each version (if the versions return different results).
You can run the tests again and ensure everything is green.
In case your shopContent cannot return results (missing data in the tables), please add a planes.json file in the folders of each version containing an empty array.
Object content | Reason | Added in PS version | Link with more info |
---|---|---|---|
currency.precision | row missing in table | 1.7.6.0 | github |
employee.has_enabled_gravatar | row missing in table | 1.7.8.0 | github |
product.additional_delivery_time | row missing in table | 1.7.3.0 | github |
product.delivery_in_stock | row missing in table | 1.7.3.0 | github |
product.delivery_out_stock | row missing in table | 1.7.3.0 | github |
stock.location | row missing in table | 1.7.5.0 | github |
store_lang | table missing | 1.7.3.0 | github |
wishlist¹ | table missing | n/a | Prestashop Addons |
taxonomy² | table missing | n/a | Prestashop Addons |
stock_available. physical_quantity | row missing in table | 1.7.2.0 | github |
stock_available. reserved_quantity | row missing in table | 1.7.2.0 | github |
languages.locale | row missing in table | 1.7.0.0 | github |
products.mpn | row missing in table | 1.7.7.0 | github |
¹ Feature enabled only with PsWishlist module
² Feature enabled only with PsFacebook module
There are 3 variables that are passed globally from the apiShopContent file to the end of the chain (repositories and errorHandler):
- PS_EVENTBUS_EXPLAIN_SQL_ENABLED
- PS_EVENTBUS_VERBOSE_ENABLED
- PS_EVENTBUS_LOGS_ENABLED
These variables are defined via the PHP function define() and reused in the files mentioned above. The reason for this usage is to avoid having to pass these variables through the entire execution chain to retrieve them at the end of the chain (e.g., apiShopContent => frontService => shopContentService => shopContentRepository).