ecoco / sylius-base-price-plugin
Sylius base price plugin will show product base price next to its price and in cart
Installs: 219
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 5
Forks: 0
Open Issues: 0
Type:sylius-plugin
Requires
- php: ^7.3
- ext-bcmath: *
- ext-curl: *
- ext-exif: *
- ext-gd: *
- ext-intl: *
- ext-mbstring: *
- ext-simplexml: *
- friendsofsymfony/oauth-server-bundle: ^1.6 || >2.0.0-alpha.0 ^2.0@dev
- jordanbrauer/unit-converter: ^0.8
- sylius/sylius: ^1.8 || ^1.9
Requires (Dev)
- behat/behat: ^3.8.1
- behat/mink-selenium2-driver: ^1.4
- dmore/behat-chrome-extension: ^1.3
- dmore/chrome-mink-driver: ^2.7
- friends-of-behat/mink: ^1.9
- friends-of-behat/mink-browserkit-driver: ^1.5
- friends-of-behat/mink-extension: ^2.5
- friends-of-behat/page-object-extension: ^0.3
- friends-of-behat/suite-settings-extension: ^1.0
- friends-of-behat/symfony-extension: ^2.2
- friends-of-behat/variadic-extension: ^1.3
- lakion/mink-debug-extension: ^1.2.3
- phpspec/phpspec: ^6.3
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: 0.12.25
- phpstan/phpstan-doctrine: 0.12.13
- phpstan/phpstan-strict-rules: ^0.12.3
- phpstan/phpstan-webmozart-assert: 0.12.4
- phpunit/phpunit: ^8.5
- sensiolabs/security-checker: ^6.0
- sylius-labs/coding-standard: ^3.2
- symfony/browser-kit: ^4.4|^5.0
- symfony/debug-bundle: ^4.4|^5.0
- symfony/dotenv: ^4.4|^5.0
- symfony/intl: ^4.4|^5.0
- symfony/web-profiler-bundle: ^4.4|^5.0
- symfony/web-server-bundle: ^4.4|^5.0
- vimeo/psalm: 3.11.4
README
Plugin that calculates and shows product base price
Documentation
Sylius Base Price Plugin allows you to add extra information to your shop about product base price. After installation you will need to set up product variable mass or volume or other unit. This value will be used to calculate base unit price and will show up in product detail page and cart.
Features
- Installs base_price_unit and base_price_value columns in sylius_product_variant table.
- "Base Price" tab in admin product variant page
- Base price display in product detail page
- Base price display in cart for each product
Installation
Download and install
composer require ecoco/sylius-base-price-plugin
Enable plugin
*this step is done automatically by symfony.
Register the plugin by adding it to your config/bundles.php
file
return [ // ... Ecocode\SyliusBasePricePlugin\EcocodeSyliusBasePricePlugin::class => ['all' => true], ];
Configure
You need to copy config file to project:
config/packages/ecocode_sylius_base_price_plugin.yaml
cp vendor/ecoco/sylius-base-price-plugin/data/config/packages/ecocode_sylius_base_price_plugin.yaml config/packages/ecocode_sylius_base_price_plugin.yaml
Advanced configuration
If you want to have more control over what metrics are visible and how it will be converted then you should update:
ecocode_sylius_base_price:
(uncomment from above)
Its default values are defined in src/Resources/config/config.yaml
Extend ProductVariant
entity
Add trait and interface to existing entity.
src/Entity/Product/ProductVariant.php
cp vendor/ecoco/sylius-base-price-plugin/data/src/Entity/Product/ProductVariant.php src/Entity/Product/ProductVariant.php
Run migration
bin/console doctrine:migrations:diff bin/console doctrine:migrations:migrate
or update schema without defining migration
bin/console -e test doctrine:schema:update --dump-sql bin/console -e test doctrine:schema:update --dump-sql --force
Clear cache
bin/console cache:clear
Usage
1. Select product unit
2. Set product unit value
3. See it in product detail page
4. See it in cart
Testing
Using docker-compose (suggested)
First you will need to edit edit behat.yml.dist
and uncomment lines related to docker-compose.
Then you can boot it up. Prepare database and run tests.
docker-compose up -d
docker-compose exec php bash -c "XDEBUG_MODE=coverage composer test"
#docker-compose exec php console doctrine:database:drop --force
#docker-compose exec php console doctrine:database:create
docker-compose exec php console doctrine:schema:update --force
docker-compose exec php console sylius:fixtures:load
docker-compose exec php behat
docker-compose down
Using docker
Using this test method you will not be able to test behat so easily
docker build . -t sylius-base-price-plugin
docker run -v $(pwd)/build:/var/www/html/build -e XDEBUG_MODE=coverage sylius-base-price-plugin composer test
Locally (complex)
-
You will need to have database running. You can use locally installed one or run it using docker.
docker run -d --rm -p 3306:3306 -e MYSQL_ROOT_PASSWORD=test -e MYSQL_DATABASE=sylius -e MYSQL_USER=app -e MYSQL_PASSWORD=test mariadb:10.5.9
-
Then edit and make sure database configuration is correct:
Edit tests/Application/.env.test file. And add database configuration there
DATABASE_URL=mysql://root:root@127.0.0.1/sylius
# if you're running mariadb
DATABASE_URL=mysql://root:root@0.0.0.0/sylius?serverVersion=mariadb-10.3.25
- Export test env (then commands dont require
-e test
)
export APP_ENV=test
Installation
Continue with setup
composer install cd tests/Application yarn install yarn run gulp bin/console assets:install public -e test bin/console cache:clear -e test #bin/console doctrine:database:drop --force -e test #bin/console doctrine:database:create -e test bin/console doctrine:schema:create -e test bin/console sylius:fixtures:load -e test bin/console doctrine:schema:update --dump-sql --force -e test # If you want to develop something this is one way of starting dev server. # Later on we will use symfony server because it can handle https way easier. #bin/console server:run 127.0.0.1:8080 -d public -e test
Come back to root directory
cd ../../
Then you should be able to run phpunit and other static code analysis checks.
PhpUnit
vendor/bin/phpunit
Static code analysis
Psalm
vendor/bin/psalm
PHPStan
vendor/bin/phpstan analyse -c phpstan.neon -l max src/
Behat (JS scenarios)
1. [Install Symfony CLI command](https://symfony.com/download).
2. Start Chrome (all other chrome sessions needs to be closed first):
Headless
```bash
google-chrome-stable --enable-automation --disable-background-networking --no-default-browser-check --no-first-run --disable-popup-blocking --disable-default-apps --allow-insecure-localhost --disable-translate --disable-extensions --no-sandbox --enable-features=Metal --headless --remote-debugging-port=9222 --window-size=2880,1800 --proxy-server='direct://' --proxy-bypass-list='*' http://127.0.0.1
```
Normal
```bash
google-chrome-stable --enable-automation --disable-background-networking --no-default-browser-check --no-first-run --disable-popup-blocking --disable-default-apps --allow-insecure-localhost --disable-translate --disable-extensions --no-sandbox --enable-features=Metal --remote-debugging-port=9222 --window-size=2880,1800 --proxy-server='direct://' --proxy-bypass-list='*' http://127.0.0.1
```
3. Install SSL certificates (only once needed) and run test application's webserver on `127.0.0.1:8080`:
```bash
symfony server:ca:install
APP_ENV=test symfony server:start --port=8080 --dir=tests/Application/public --daemon
```
4. Run Behat:
Uncomment local configuration in `behat.yml.dist` (and comment out docker-compose one)
```bash
vendor/bin/behat --strict --tags="@javascript"
```