setono/sylius-order-edit-plugin

Setono example plugin for Sylius.

Fund package maintenance!
Setono

Installs: 734

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 2

Forks: 1

Open Issues: 4

Type:sylius-plugin

v1.0.0-beta.3 2024-10-02 08:28 UTC

This package is auto-updated.

Last update: 2024-11-02 08:42:54 UTC


README

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 🎉