Skip to content

Edit your Sylius orders from the admin interface

License

Notifications You must be signed in to change notification settings

Setono/sylius-order-edit-plugin

Repository files navigation

Sylius Order Edit Plugin

Latest Version Software License Build Status Code Coverage Mutation testing

Edit orders inside your admin interface.

Install

composer require setono/sylius-order-edit-plugin

Import routing

# config/routes/setono_sylius_order_edit.yaml
setono_sylius_order_edit:
    resource: "@SetonoSyliusOrderEditPlugin/Resources/config/routes.yaml"

If you're using Sylius <=1.10, also import additional product variant routes:

setono_sylius_order_edit_product_variant:
    resource: "@SetonoSyliusOrderEditPlugin/Resources/config/routes/product_variant.yaml"

and remember to add the referenced ProductVariantRepository methods (findByCodes and findByPhrase).

Extend the Order entity

<?php

declare(strict_types=1);

namespace App\Entity\Order;

use Doctrine\ORM\Mapping as ORM;
use Setono\SyliusOrderEditPlugin\Entity\EditableOrderInterface;
use Setono\SyliusOrderEditPlugin\Entity\EditableOrderTrait;
use Sylius\Component\Core\Model\Order as BaseOrder;

#[ORM\Entity]
#[ORM\Table(name: 'sylius_order')]
class Order extends BaseOrder implements EditableOrderInterface
{
    use EditableOrderTrait;
}

Update your database schema

php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate

The plugin adds a new field to the Order entity named initialTotal which will contain the order total and is used when editing orders.

To set the initialTotal field for existing orders, you can add the following to your migration:

<?php
// ...

public function up(Schema $schema): void
{
    // ...
    $this->addSql('UPDATE sylius_order SET initial_total = total');
}

// ...

Done!

You should be able to edit orders in your admin interface. Enjoy 🎉