Skip to content

Commit

Permalink
Updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Oct 11, 2019
1 parent f076c10 commit cf4138b
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 165 deletions.
228 changes: 64 additions & 164 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,10 @@

## Screenshots

Menu:

![Screenshot showing admin menu](docs/images/admin-menu.png)

Gift card admin pages:

![Screenshot showing gift card admin index page](docs/images/admin-gift-card-code-index.png)
![Screenshot showing admin menu and index](docs/images/admin-menu.png)

![Screenshot showing gift card admin create page](docs/images/admin-gift-card-code-create.png)

Products admin pages:

![Screenshot showing admin product create menu options](docs/images/admin-product-menu-create-gift-card.png)

## Installation

### Require plugin with composer:
Expand All @@ -40,8 +30,7 @@ imports:
### (Optional) Import fixtures
If you wish to have some gift cards to play with in your application
during development.
If you wish to have some gift cards to play with in your application during development.
```yaml
# config/packages/_sylius.yaml
Expand All @@ -50,8 +39,6 @@ imports:
- { resource: "@SetonoSyliusGiftCardPlugin/Resources/config/app/fixtures.yaml" }
```
Or write your own ones.
### Import routing:
```yaml
Expand All @@ -63,7 +50,7 @@ setono_sylius_gift_card:
### Add plugin class to your `bundles.php`:

Make sure you add it before `SyliusGridBundle`, otherwise you'll get
`You have requested a non-existent parameter "setono_sylius_gift_card.model.gift_card_code.class".` exception.
`You have requested a non-existent parameter "setono_sylius_gift_card.model.gift_card.class".` exception.

```php
<?php
Expand All @@ -86,165 +73,81 @@ $ bin/console doctrine:migrations:migrate

- For `SyliusShopBundle`:

```bash
mkdir -p templates/bundles/SyliusShopBundle
cp -r vendor/setono/sylius-gift-card-plugin/tests/Application/templates/bundles/SyliusShopBundle/ \
templates/bundles/SyliusShopBundle/
```
```bash
mkdir -p templates/bundles/SyliusShopBundle
cp -r vendor/setono/sylius-gift-card-plugin/tests/Application/templates/bundles/SyliusShopBundle/ \
templates/bundles/SyliusShopBundle/
```

- For `SyliusAdminBundle`:

```bash
mkdir -p templates/bundles/SyliusAdminBundle
cp -r vendor/setono/sylius-gift-card-plugin/tests/Application/templates/bundles/SyliusAdminBundle/ \
templates/bundles/SyliusAdminBundle/
```
```bash
mkdir -p templates/bundles/SyliusAdminBundle
cp -r vendor/setono/sylius-gift-card-plugin/tests/Application/templates/bundles/SyliusAdminBundle/ \
templates/bundles/SyliusAdminBundle/
```

### Override core `Order` and `OrderRepository`
### Override `Order` and `OrderRepository`

- Override `Order`:
**Override `Order`**

- If you use `annotations` mapping:
```php
<?php
```php
<?php
# src/Entity/Order.php
declare(strict_types=1);
namespace App\Entity;
use Setono\SyliusGiftCardPlugin\Model\OrderInterface as SetonoSyliusGiftCardPluginOrderInterface;
use Setono\SyliusGiftCardPlugin\Model\OrderTrait as SetonoSyliusGiftCardPluginOrderTrait;
use Sylius\Component\Core\Model\Order as BaseOrder;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="sylius_order")
*/
class Order extends BaseOrder implements SetonoSyliusGiftCardPluginOrderInterface
{
use SetonoSyliusGiftCardPluginOrderTrait;
}
```

- If you use `xml` mapping:

```php
<?php
# src/Model/Order.php
# src/Entity/Order.php
declare(strict_types=1);
namespace App\Model;
use Setono\SyliusGiftCardPlugin\Model\OrderInterface as SetonoSyliusGiftCardPluginOrderInterface;
use Setono\SyliusGiftCardPlugin\Model\OrderTrait as SetonoSyliusGiftCardPluginOrderTrait;
use Sylius\Component\Core\Model\Order as BaseOrder;
class Order extends BaseOrder implements SetonoSyliusGiftCardPluginOrderInterface
{
use SetonoSyliusGiftCardPluginOrderTrait;
}
```

```xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- config/doctrine/model/Order.orm.xml -->
<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">
<mapped-superclass name="App\Model\Order" table="sylius_order">
<many-to-many field="payedByGiftCardCodes" target-entity="Setono\SyliusGiftCardPlugin\Model\GiftCardCodeInterface" mapped-by="usedInOrders" />
</mapped-superclass>
</doctrine-mapping>
```

- Override `OrderRepository`:

```php
<?php
# src/Doctrine/ORM/OrderRepository.php
declare(strict_types=1);
namespace App\Doctrine\ORM;
use Setono\SyliusGiftCardPlugin\Doctrine\ORM\OrderRepositoryInterface as SetonoSyliusGiftCardPluginOrderRepositoryInterface;
use Setono\SyliusGiftCardPlugin\Doctrine\ORM\OrderRepositoryTrait as SetonoSyliusGiftCardPluginOrderRepositoryTrait;
use Sylius\Bundle\CoreBundle\Doctrine\ORM\OrderRepository as BaseOrderRepository;
class OrderRepository extends BaseOrderRepository implements SetonoSyliusGiftCardPluginOrderRepositoryInterface
{
use SetonoSyliusGiftCardPluginOrderRepositoryTrait;
}
```
declare(strict_types=1);
- Add configuration:
namespace App\Entity;
```yaml
# config/services.yaml
sylius_order:
resources:
order:
classes:
model: App\Entity\Order
repository: App\Doctrine\ORM\OrderRepository
use Setono\SyliusGiftCardPlugin\Model\OrderInterface as SetonoSyliusGiftCardPluginOrderInterface;
use Setono\SyliusGiftCardPlugin\Model\OrderTrait as SetonoSyliusGiftCardPluginOrderTrait;
use Sylius\Component\Core\Model\Order as BaseOrder;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="sylius_order")
*/
class Order extends BaseOrder implements SetonoSyliusGiftCardPluginOrderInterface
{
use SetonoSyliusGiftCardPluginOrderTrait;
}
```

```
**Override `OrderRepository`:*

### Override the grid `sylius_admin_product`:
```php
<?php
# src/Doctrine/ORM/OrderRepository.php
declare(strict_types=1);
- If you haven't override it in your app before - you can just import
ready-to-go grid configuration:
namespace App\Doctrine\ORM;
```yaml
# config/packages/_sylius.yaml
imports:
- { resource: "@SetonoSyliusGiftCardPlugin/Resources/config/grids/sylius_admin_product.yaml" }
```
use Setono\SyliusGiftCardPlugin\Repository\OrderRepositoryInterface as SetonoSyliusGiftCardPluginOrderRepositoryInterface;
use Setono\SyliusGiftCardPlugin\Doctrine\ORM\OrderRepositoryTrait as SetonoSyliusGiftCardPluginOrderRepositoryTrait;
use Sylius\Bundle\CoreBundle\Doctrine\ORM\OrderRepository as BaseOrderRepository;
- But if you override it before - make sure you have next changes in place:
class OrderRepository extends BaseOrderRepository implements SetonoSyliusGiftCardPluginOrderRepositoryInterface
{
use SetonoSyliusGiftCardPluginOrderRepositoryTrait;
}
```

- Add configuration:

```yaml
sylius_grid:
grids:
sylius_admin_product:
actions:
main:
create:
type: links
label: sylius.ui.create
options:
class: primary
icon: plus
header:
icon: cube
label: sylius.ui.type
links:
simple:
label: sylius.ui.simple_product
icon: plus
route: sylius_admin_product_create_simple
configurable:
label: sylius.ui.configurable_product
icon: plus
route: sylius_admin_product_create
# This is what should be added:
gift_card:
label: setono_sylius_gift_card.ui.gift_card
icon: plus
route: setono_sylius_gift_card_admin_product_create_gift_card
# config/services.yaml
sylius_order:
resources:
order:
classes:
model: App\Entity\Order
repository: App\Doctrine\ORM\OrderRepository
```

### Install assets:
Expand All @@ -271,12 +174,9 @@ $ composer tests

- To run built-in application showing plugin at work, just run:

```bash
$ composer try
```

- Open browser on page:
http://localhost:8000/admin/products/?criteria%5Bsearch%5D%5Btype%5D=contains&criteria%5Bsearch%5D%5Bvalue%5D=gift
```bash
$ composer try
```

## Contribution

Expand Down
Binary file modified docs/images/admin-gift-card-code-create.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/images/admin-gift-card-code-index.png
Binary file not shown.
Binary file modified docs/images/admin-menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/images/admin-product-menu-create-gift-card.png
Binary file not shown.
2 changes: 1 addition & 1 deletion src/Menu/AdminMenuListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function addAdminMenuItems(MenuBuilderEvent $event): void
{
$menu = $event->getMenu();

$submenu = $menu->getChild('marketing');
$submenu = $menu->getChild('catalog');
if ($submenu instanceof ItemInterface) {
$this->addChild($submenu);
} else {
Expand Down

0 comments on commit cf4138b

Please sign in to comment.