Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance examples #69

Merged
merged 3 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -8,4 +8,5 @@
.scannerwork
sonar-project.properties

PrestaShop/
PrestaShop/
vendor/
2 changes: 1 addition & 1 deletion examples/basic-example/README.md
Expand Up @@ -7,7 +7,7 @@ This example runs the latest available image of PrestaShop Flashlight, which is
The expected output of this example is:

```sh
docker compose up prestashop
docker compose up prestashop --force-recreate
[+] Building 0.0s (0/0) docker-container:thirsty_khorana
[+] Running 3/3
✔ Network basic-example_default Created 0.0s
Expand Down
1 change: 1 addition & 0 deletions examples/basic-example/docker-compose.yml
Expand Up @@ -7,6 +7,7 @@ services:
condition: service_healthy
environment:
- PS_DOMAIN=localhost:8000
# - DEBUG_MODE=true
ports:
- 8000:80

Expand Down
37 changes: 16 additions & 21 deletions examples/develop-a-module/README.md
Expand Up @@ -4,25 +4,20 @@ This example demonstrates how a local module can be mounted in your PrestaShop F

## Bind a local module to your instance in your manifest

Let's consider we have a `testmodule` PrestaShop Module.

Create a `modules/` directory, and drop in your `testmodule` directory.

Create a bind mount in your docker-compose.yml:

```yaml
...
prestashop:
container_name: prestashop
...
volumes:
- type: bind
source: ./modules/testmodule # local path to the module
target: /var/www/html/modules/testmodule # path to be mounted in the container
...
Install the module's dependencies:

```
cd ./modules/testmodule
composer install
```

And that's it: your module is available on the `prestashop` Docker container, and changes made in the local directory of the module are automatically synchronized on the `prestashop` Docker container.
Run flashlight with a RW bind mount (see ./docker-compose.yml)

```
docker compose up prestashop --force-recreate
```

And that's it: your module is available on the `prestashop` Docker container, and changes made in the local directory of the module are automatically synchronized on the `prestashop` Docker container.

## Install / test the module

Expand All @@ -31,16 +26,16 @@ You can access to PrestaShop in your browser:
- http://localhost:8000
- http://localhost:8000/admin-dev/ (back office, login/password described [here](../../README.md))

You can go to modules > install and install your module, or install it with cli:
You can go to modules > install and install your module, or install it with cli:

1. obtain container name:
1. obtain container name:

```sh
docker ps
```

2. execute the install module command in the container:
2. execute the install module command in the container:

```sh
docker exec -ti container_name php /var/www/html/bin/console prestashop:module install testmodule
```
```
2 changes: 2 additions & 0 deletions examples/develop-a-module/docker-compose.yml
Expand Up @@ -7,9 +7,11 @@ services:
condition: service_healthy
environment:
- PS_DOMAIN=localhost:8000
- INIT_SCRIPTS_DIR=/tmp/init-scripts
ports:
- 8000:80
volumes:
- ./init-scripts:/tmp/init-scripts:ro
- type: bind
source: ./modules/testmodule # local path to the module
target: /var/www/html/modules/testmodule # path to be mounted in the container
Expand Down
12 changes: 12 additions & 0 deletions examples/develop-a-module/init-scripts/module-install.sh
@@ -0,0 +1,12 @@
#!/bin/sh
#
# This is an init-script for prestashop-flashlight.
#
# Storing a folder in /var/www/html/modules is not enough to register the module
# into PrestaShop, hence why we have to call the console install CLI.
#
set -eu

cd "$PS_FOLDER"
echo "* [testmodule] installing the module..."
php -d memory_limit=-1 bin/console prestashop:module --no-interaction install "testmodule"
32 changes: 32 additions & 0 deletions examples/develop-a-module/modules/testmodule/composer.json
@@ -0,0 +1,32 @@
{
"name": "prestashopcorp/testmodule",
"description": "a simple module example",
"type": "prestashop-module",
"authors": [
{
"name": "Clément Désiles",
"email": "main@jokester.fr"
}
],
"license": "AFL-3.0",
"autoload": {
"classmap": [
"testmodule.php"
],
"psr-4": {
"PrestaShop\\Module\\TestModule\\": "src/"
}
},
"config": {
"preferred-install": "dist",
"platform": {
"php": "7.2.5"
},
"optimize-autoloader": true,
"prepend-autoloader": false,
"platform-check": false
},
"require": {
"php": ">=7.2.5"
}
}
23 changes: 23 additions & 0 deletions examples/develop-a-module/modules/testmodule/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions examples/develop-a-module/modules/testmodule/config.xml
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>
<module>
<name>testmodule</name>
<displayName><![CDATA[TestModule]]></displayName>
<name>modulea</name>
<displayName><![CDATA[Testmodule]]></displayName>
<version><![CDATA[1.0.0]]></version>
<description><![CDATA[TestModule module description]]></description>
<description><![CDATA[Test module description]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[]]></tab>
<is_configurable>0</is_configurable>
Expand Down
8 changes: 0 additions & 8 deletions examples/develop-a-module/modules/testmodule/index.php

This file was deleted.

70 changes: 21 additions & 49 deletions examples/develop-a-module/modules/testmodule/testmodule.php
@@ -1,75 +1,47 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

declare(strict_types=1);

if (!defined('_PS_VERSION_')) {
exit;
}

class TestModule extends Module
class Testmodule extends Module
{
/**
* @var string
*/
const VERSION = '1.0.0';

public function __construct()
{
$this->name = 'testmodule';
$this->author = 'PrestaShop';
$this->version = '1.0.0';
$this->ps_versions_compliancy = ['min' => '1.7.0', 'max' => _PS_VERSION_];
$this->ps_versions_compliancy = [
'min' => '1.7.0',
'max' => '99.99.99',
];
$this->bootstrap = false;

parent::__construct();
$this->displayName = $this->trans('Test Module', [], 'Modules.Mymodule.Admin');
$this->description = $this->trans('Test Module', [], 'Modules.Mymodule.Admin');
$this->confirmUninstall = $this->trans('Are you sure you want to quit ModuleA?', [], 'Modules.Mymodule.Admin');

$this->displayName = $this->trans('TestModule', [], 'Modules.TestModule.Config');
$this->description = $this->trans('TestModule module description', [], 'Modules.TestModule.Config');
require_once __DIR__ . '/vendor/autoload.php';
}

/**
* @return bool
*/
public function install()
{
if (!parent::install()) {
return false;
}

$this->registerHook('displayProductExtraContent');
return true;
}

/**
* @return bool
*/
public function uninstall()
{
if (!parent::uninstall()) {
return false;
}
return true;
}

/**
* Add extra content to the product page
*/
public function hookDisplayProductExtraContent($params) {
return [
(new PrestaShop\PrestaShop\Core\Product\ProductExtraContent())
->setTitle('my first field')
->setContent('my first content')
];
}

public function getFilePath()
{
return __FILE__;
}
}
2 changes: 1 addition & 1 deletion examples/develop-prestashop/README.md
Expand Up @@ -23,7 +23,7 @@ You are now ready to run PrestaShop within your Flashlight environment:

```
cd e2e-env
docker compose up prestashop
docker compose up prestashop --force-recreate
[+] Building 0.0s (0/0) docker-container:thirsty_khorana
[+] Running 3/3
✔ Network e2e-env_default Created 0.1s
Expand Down
6 changes: 3 additions & 3 deletions examples/ngrok-tunnel/README.md
Expand Up @@ -6,12 +6,12 @@

1. First you will have to Sign up to your ngrok account. For this simple use case the free plan is sufficient. Once it's done, on the left menu clic on "Getting Started > Your Authtoken".

3. Copy this token to the your own .env file (`mv .env.dist .env`)
2. Copy this token to the your own .env file (`mv .env.dist .env`)

4. Run PrestaShop Flashlight alongside with an Ngrok agent:
3. Run PrestaShop Flashlight alongside with an Ngrok agent:

```sh
docker compose up prestashop
docker compose up prestashop --force-recreate
ngrok-tunnel-prestashop-1 | * Auto-detecting domain with ngrok client api on http://ngrok:4040...
ngrok-tunnel-prestashop-1 | * ngrok tunnel found running on 4452-37-170-242-21.ngrok.app
ngrok-tunnel-prestashop-1 | * Applying PS_DOMAIN (4452-37-170-242-21.ngrok.app) to the dump...
Expand Down
2 changes: 1 addition & 1 deletion examples/with-init-scripts/README.md
Expand Up @@ -10,7 +10,7 @@ See [./init-scripts](./init-scripts).
The expected output of this example is:

```sh
docker compose up prestashop
docker compose up prestashop --force-recreate
[+] Building 0.0s (0/0)
[+] Running 3/2
✔ Network with-init-scripts_default Created 0.0s
Expand Down
2 changes: 1 addition & 1 deletion examples/with-post-scripts/README.md
Expand Up @@ -10,7 +10,7 @@ See [./post-scripts](./post-scripts).
The expected output of this example is:

```sh
docker compose up prestashop
docker compose up prestashop --force-recreate
[+] Building 0.0s (0/0)
[+] Running 2/2
✔ Container with-post-scripts-mysql-1 Running 0.0s
Expand Down