Skip to content

Commit

Permalink
Merge pull request #70 from BitBagCommerce/OP-520
Browse files Browse the repository at this point in the history
OP-520 - installation.md - new standard
  • Loading branch information
senghe authored Sep 9, 2024
2 parents 226c20f + 7abf816 commit 782324e
Show file tree
Hide file tree
Showing 4 changed files with 364 additions and 257 deletions.
269 changes: 12 additions & 257 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,268 +42,23 @@ This **open-source plugin was developed to help the Sylius community**. If you h
[![](https://bitbag.io/wp-content/uploads/2020/10/button-contact.png)](https://bitbag.io/contact-us/?utm_source=github&utm_medium=referral&utm_campaign=plugins_blacklist)

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

Add plugin dependencies to your `config/bundles.php` file:
```php
return [
...

BitBag\SyliusBlacklistPlugin\BitBagSyliusBlacklistPlugin::class => ['all' => true],
];
```

Import required config in your `config/packages/_sylius.yaml` file:
```yaml
# config/packages/_sylius.yaml

imports:
...

- { resource: "@BitBagSyliusBlacklistPlugin/Resources/config/config.yaml" }
```
Import routing in your `config/routes.yaml` file:

```
# config/routes.yaml

bitbag_sylius_blacklist_plugin:
resource: "@BitBagSyliusBlacklistPlugin/Resources/config/routing.yaml"
```
Add traits to your Customer entity class, when You don't use annotation.
```php
<?php
declare(strict_types=1);
namespace App\Entity\Customer;
use BitBag\SyliusBlacklistPlugin\Model\FraudStatusTrait;
use Sylius\Component\Core\Model\Customer as BaseCustomer;
class Customer extends BaseCustomer implements CustomerInterface
{
use FraudStatusTrait;
}
```

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

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
{
/**
* @var string
* @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;
}
}
```

Create also interface, which is implemented by customer entity

```php
<?php

namespace App\Entity\Customer;

use BitBag\SyliusBlacklistPlugin\Entity\Customer\FraudStatusInterface;
use Sylius\Component\Core\Model\CustomerInterface as BaseCustomerInterface;

interface CustomerInterface extends BaseCustomerInterface, FraudStatusInterface
{
}
```
Override Customer resource:

```yaml
# config/packages/_sylius.yaml
...

sylius_customer:
resources:
customer:
classes:
model: App\Entity\Customer\Customer
repository: App\Repository\Customer\CustomerRepository
```
Create or edit `CustomerRepository.php` file:
```php
<?php
declare(strict_types=1);
namespace App\Repository\Customer;
use BitBag\SyliusBlacklistPlugin\Repository\CustomerRepositoryTrait;
use Sylius\Bundle\CoreBundle\Doctrine\ORM\CustomerRepository as BaseCustomerRepository;
class CustomerRepository extends BaseCustomerRepository
{
use CustomerRepositoryTrait;
}
```

Override Customer grid:

```yaml
# config/packages/_sylius.yaml
...
sylius_grid:
grids:
sylius_admin_customer:
fields:
...
fraudStatus:
type: twig
label: bitbag_sylius_blacklist_plugin.ui.fraud_status
options:
template: "@BitBagSyliusBlacklistPlugin/Customer/Grid/Field/fraudStatus.html.twig"
filters:
...
fraudStatus:
type: select
label: bitbag_sylius_blacklist_plugin.ui.fraud_status
form_options:
choices:
bitbag_sylius_blacklist_plugin.ui.neutral: Neutral
bitbag_sylius_blacklist_plugin.ui.blacklisted: Blacklisted
```

```yaml
# config/packages/twig.yaml
...
twig:
paths: ['%kernel.project_dir%/templates']
debug: '%kernel.debug%'
strict_variables: '%kernel.debug%'
form_themes:
- '@BitBagSyliusBlacklistPlugin/Form/theme.html.twig'
- '@SyliusUi/Form/theme.html.twig'
services:
_defaults:
public: false
autowire: true
autoconfigure: true
Twig\Extra\Intl\IntlExtension: ~
when@test_cached:
twig:
strict_variables: true
```

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">
<h4 class="ui dividing header">{{ 'bitbag_sylius_blacklist_plugin.ui.fraud_status'|trans }}</h4>
{{ form_row(form.fraudStatus) }}
</div>
```

Update your database

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

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

Update your database schema:
We work on stable, supported and up-to-date versions of packages. We recommend you to do the same.

```bash
bin/console doctrine:schema:update --dump-sql
```
| Package | Version |
|---------------|-----------------|
| PHP | \>=8.0 |
| sylius/sylius | 1.12.x - 1.13.x |
| MySQL | \>= 5.7 |
| NodeJS | \>= 18.x |

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

```bash
bin/console doctrine:schema:update -f
```
----

If there are another changes, please make sure they will not destroy your database schema.
### Full installation guide
- [See the full installation guide](doc/installation.md)

## Functionalities

Expand Down
Loading

0 comments on commit 782324e

Please sign in to comment.