Skip to content

Commit

Permalink
Merge pull request #67 from JanPalen/feature/OP-453-upgrade-plugin-to…
Browse files Browse the repository at this point in the history
…-sylius-1.13-support

Upgrade plugin to Sylius 1.13 compatibility
  • Loading branch information
senghe authored Aug 11, 2024
2 parents 8cf6e96 + 266d9c9 commit 0b4552d
Show file tree
Hide file tree
Showing 119 changed files with 854 additions and 698 deletions.
32 changes: 17 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,32 @@ on:

jobs:
tests:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest

name: "Sylius ${{ matrix.sylius }}, PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}, MySQL ${{ matrix.mysql }}"

strategy:
fail-fast: false
matrix:
php: ["8.0"]
symfony: ["^5.4", "^6.0"]
sylius: ["~1.11.0", "~1.12.0"]
node: ["^14.17.x"]
mysql: ["5.7", "8.0"]
php: ["8.0", "8.1", "8.2", "8.3"]
symfony: ["^5.4", "^6.4"]
sylius: ["~1.12.0", "~1.13.0"]
node: ["^18.0", "^20.0"]
mysql: ["8.0"]

exclude:
- sylius: ~1.11.0
symfony: ^6.0
- sylius: "~1.13.0"
php: "8.0"
- symfony: "^6.4"
php: "8.0"

env:
APP_ENV: test
DATABASE_URL: "mysql://root:[email protected]/sylius?serverVersion=${{ matrix.mysql }}"

steps:
-
uses: actions/checkout@v2
uses: actions/checkout@v3

-
name: Setup PHP
Expand All @@ -50,7 +52,7 @@ jobs:

-
name: Setup Node
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: "${{ matrix.node }}"

Expand Down Expand Up @@ -96,7 +98,7 @@ jobs:

-
name: Cache Composer
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json **/composer.lock') }}
Expand All @@ -123,7 +125,7 @@ jobs:
-
name: Get Yarn cache directory
id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT

-
name: Cache Yarn
Expand All @@ -147,8 +149,8 @@ jobs:
-
name: Prepare test application assets
run: |
(cd tests/Application && yarn encore dev)
(cd tests/Application && bin/console assets:install public -vvv)
(cd tests/Application && yarn prod)
-
name: Prepare test application cache
Expand Down Expand Up @@ -186,8 +188,8 @@ jobs:
name: Behat logs
path: etc/build/
if-no-files-found: ignore
-

-
name: Failed build Slack notification
uses: rtCamp/action-slack-notify@v2
if: ${{ failure() && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') }}
Expand Down
135 changes: 97 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ This **open-source plugin was developed to help the Sylius community**. If you h

## Installation
```bash
$ composer require bitbag/blacklist-plugin
composer require bitbag/blacklist-plugin --no-scripts
```

Add plugin dependencies to your `config/bundles.php` file:
```php
return [
Expand Down Expand Up @@ -92,7 +92,56 @@ class Customer extends BaseCustomer implements CustomerInterface
}
```

Or this way if you use annotations:
Define new Entity mapping inside your src/Resources/config/doctrine directory.

```xml
<?xml version="1.0" encoding="UTF-8"?>

<doctrine-mapping
xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"
>
<entity name="App\Entity\Customer\Customer" table="sylius_customer">
<field name="fraudStatus" column="fraud_status" type="string" />
</entity>
</doctrine-mapping>
```

Or edit Customer Entity this way if you use attributes:

```php
<?php

declare(strict_types=1);

namespace App\Entity\Customer;

use Doctrine\ORM\Mapping as ORM;
use Sylius\Component\Core\Model\Customer as BaseCustomer;

#[ORM\Entity]
#[ORM\Table(name: 'sylius_customer')]
class Customer extends BaseCustomer implements CustomerInterface
{
#[ORM\Column(type: 'string', nullable: false)]
protected $fraudStatus = FraudStatusInterface::FRAUD_STATUS_NEUTRAL;

public function getFraudStatus(): ?string
{
return $this->fraudStatus;
}

public function setFraudStatus(?string $fraudStatus): void
{
$this->fraudStatus = $fraudStatus;
}
}

```

Or edit Customer Entity this way if you use annotations:

```php
<?php
Expand All @@ -102,7 +151,6 @@ declare(strict_types=1);
namespace App\Entity\Customer;

use Doctrine\ORM\Mapping as ORM;
use BitBag\SyliusBlacklistPlugin\Entity\Customer\FraudStatusInterface;use BitBag\SyliusBlacklistPlugin\Model\FraudStatusTrait;
use Sylius\Component\Core\Model\Customer as BaseCustomer;

/**
Expand All @@ -112,28 +160,21 @@ use Sylius\Component\Core\Model\Customer as BaseCustomer;
class Customer extends BaseCustomer implements CustomerInterface
{
/**
* @var string
* @ORM\Column(type="string", nullable=false)
*/
* @var string
* @ORM\Column(type="string", nullable=false)
*/
protected $fraudStatus = FraudStatusInterface::FRAUD_STATUS_NEUTRAL;
}
```

If you don't use annotations, define new Entity mapping inside your src/Resources/config/doctrine directory.

```xml
<?xml version="1.0" encoding="UTF-8"?>
public function getFraudStatus(): ?string
{
return $this->fraudStatus;
}

<doctrine-mapping
xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"
>
<entity name="App\Entity\Customer\Customer" table="sylius_customer">
<field name="fraudStatus" column="fraud_status" type="string" />
</entity>
</doctrine-mapping>
public function setFraudStatus(?string $fraudStatus): void
{
$this->fraudStatus = $fraudStatus;
}
}
```

Create also interface, which is implemented by customer entity
Expand Down Expand Up @@ -189,7 +230,7 @@ sylius_grid:
bitbag_sylius_blacklist_plugin.ui.blacklisted: Blacklisted
```
Override Customer form template (`@SyliusAdminBundle\Customer\_form.html.twig`) by adding lines below
Override Customer form template (`@SyliusAdminBundle\Customer\_form.html.twig` or `@SyliusAdminBundle/Customer/Form/_firstColumn.html.twig`) by adding lines below

```html
<div class="ui segment">
Expand All @@ -200,34 +241,52 @@ Override Customer form template (`@SyliusAdminBundle\Customer\_form.html.twig`)

Update your database

```
$ bin/console doctrine:migrations:migrate
```bash
bin/console doctrine:migrations:migrate
```

**Note:** If you are running it on production, add the `-e prod` flag to this command.

Update your database schema:

```bash
doctrine:schema:update --dump-sql
```

If the list includes only changes for updating the database by adding 'fraud_status' you can use:

```bash
doctrine:schema:update -f
```

If there are another changes, please make sure they will not destroy your database schema.

## Functionalities

All main functionalities of the plugin are described [here.](doc/functionalities.md)

## Customization

### Available services you can [decorate](https://symfony.com/doc/current/service_container/service_decoration.html) and forms you can [extend](http://symfony.com/doc/current/form/create_form_type_extension.html)

Run the below command to see what Symfony services are shared with this plugin:
```bash
$ bin/console debug:container | grep bitbag_sylius_blacklist_plugin
bin/console debug:container | grep bitbag_sylius_blacklist_plugin
```

## Testing
```bash
$ composer install
$ cd tests/Application
$ yarn install
$ yarn build
$ bin/console assets:install public -e test
$ bin/console doctrine:schema:create -e test
$ bin/console server:run 127.0.0.1:8080 -d public -e test
$ open http://localhost:8080
$ cd ../..
$ vendor/bin/behat
$ vendor/bin/phpspec run
composer install
cd tests/Application
yarn install
yarn build
bin/console assets:install public -e test
bin/console doctrine:schema:create -e test
bin/console server:run 127.0.0.1:8080 -d public -e test
open http://localhost:8080
cd ../..
vendor/bin/behat
vendor/bin/phpspec run
```

# About us
Expand Down
33 changes: 17 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
"description": "Blacklist plugin for Sylius.",
"license": "MIT",
"require": {
"php": "^8.0",
"sylius/sylius": "~1.11.0 || ~1.12.0"
"php": "^8.0 || ^8.1 || ^8.2 || ^8.3",
"sylius/sylius": "~1.12.0 || ~1.13.0",
"doctrine/annotations": "^2.0.0"
},
"require-dev": {
"behat/behat": "^3.7",
"behat/behat": "^3.7.0",
"behat/mink": "^1.8",
"behat/mink-selenium2-driver": "^1.4",
"bitbag/coding-standard": "^1.0.1",
"behat/mink-selenium2-driver": "~1.6.0",
"bitbag/coding-standard": "^3.0.0",
"dmore/behat-chrome-extension": "^1.3",
"dmore/chrome-mink-driver": "^2.7",
"friends-of-behat/mink": "^1.8",
Expand All @@ -26,19 +27,19 @@
"lchrusciel/api-test-case": "^4.1||^5.0",
"phpspec/phpspec": "^7.0",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "0.12.82",
"phpstan/phpstan-doctrine": "0.12.33",
"phpstan/phpstan-strict-rules": "^0.12.0",
"phpstan/phpstan-webmozart-assert": "0.12.12",
"phpstan/phpstan": "^1.4",
"phpstan/phpstan-doctrine": "^1.0",
"phpstan/phpstan-strict-rules": "^1.0",
"phpstan/phpstan-webmozart-assert": "^1.0",
"phpunit/phpunit": "^9.5",
"polishsymfonycommunity/symfony-mocker-container": "^1.0",
"symfony/browser-kit": "^5.4 || ^6.0",
"symfony/debug-bundle": "^5.4 || ^6.0",
"symfony/dotenv": "^5.4 || ^6.0",
"symfony/intl": "^5.4 || ^6.0",
"symfony/web-profiler-bundle": "^5.4 || ^6.0",
"symfony/webpack-encore-bundle": "^1.14",
"vimeo/psalm": "4.12"
"symfony/browser-kit": "^5.4 || 6.4",
"symfony/debug-bundle": "^5.4 || ^6.4",
"symfony/dotenv": "^5.4 || ^6.4",
"symfony/intl": "^5.4 || ^6.4",
"symfony/web-profiler-bundle": "^5.4 || ^6.4",
"vimeo/psalm": "^4.7 || ^5.0",
"symfony/webpack-encore-bundle": "^1.17"
},
"autoload": {
"psr-4": {
Expand Down
Loading

0 comments on commit 0b4552d

Please sign in to comment.