Git Product home page Git Product logo

adminordercreationplugin's Introduction

Sylius Logo.

Admin Order Creation Plugin

This plugin allows to create an order in admin panel.

Screenshot showing the order creation page, Shipments&Payments section

Business value

So far it was up to the Customer to place an order using available product variants as well as payment and shipping methods.

The whole process of placing an order is not that obvious, however. For some reason a Customer may feel a little bit confused when a promotion is no longer available or shipping method is not eligible for given area. Here comes Admin Order Creation Plugin.

Briefly speaking, it allows an Administrator to place or reorder an order in the name of a Customer. It helps them solve even more of Customers' fundamental problems and equips an Administrator with basic tools making creating an order possible.

Admin Order Creation Plugin processes are strongly based on standard Order model taken from SyliusCoreBundle. The only things that differ are order creation context and business requirements. Right now it is up to the Administrator to provide a channel, locale and currency in which an Order is created. What's more, the Administrator is able to add a discount for any item or the whole Order, which is, technically speaking, a new type of Sylius Adjustments.

After creating an Order via Admin panel, this new Order is listed like any other order placed via Sylius.

Installation

Beware!

This installation instruction assumes that you're using Symfony Flex. If you don't, take a look at the legacy installation instruction. However, we strongly encourage you to use Symfony Flex, it's much quicker! :)

  1. Require plugin with composer:

    composer require sylius/admin-order-creation-plugin

    Remember to allow community recipes with composer config extra.symfony.allow-contrib true or during plugin installation process

  2. Copy Sylius templates overridden in plugin to your templates directory (e.g templates/bundles/):

    mkdir -p templates/bundles/SyliusAdminBundle/
    cp -R vendor/sylius/admin-order-creation-plugin/src/Resources/views/SyliusAdminBundle/* templates/bundles/SyliusAdminBundle/
  3. Override repositories

    1. Create repository classes
      mkdir src/Repository
      touch src/Repository/CustomerRepository.php
      touch src/Repository/ProductVariantRepository.php
    2. Paste the following content to the src/Repository/CustomerRepository.php:
      <?php
      
      declare(strict_types=1);
      
      namespace App\Repository;
      
      use Sylius\AdminOrderCreationPlugin\Doctrine\ORM\CustomerRepositoryInterface;
      use Sylius\AdminOrderCreationPlugin\Doctrine\ORM\CustomerRepositoryTrait;
      use Sylius\Bundle\CoreBundle\Doctrine\ORM\CustomerRepository as BaseCustomerRepository;
      
      final class CustomerRepository extends BaseCustomerRepository implements CustomerRepositoryInterface
      {
          use CustomerRepositoryTrait;
      }
    3. Paste the following content to the src/Repository/ProductVariantRepository.php:
      <?php
      
      declare(strict_types=1);
      
      namespace App\Repository;
      
      use Sylius\AdminOrderCreationPlugin\Doctrine\ORM\ProductVariantRepositoryInterface;
      use Sylius\AdminOrderCreationPlugin\Doctrine\ORM\ProductVariantRepositoryTrait;
      use Sylius\Bundle\CoreBundle\Doctrine\ORM\ProductVariantRepository as BaseProductVariantRepository;
      
      final class ProductVariantRepository extends BaseProductVariantRepository implements ProductVariantRepositoryInterface
      {
          use ProductVariantRepositoryTrait;
      }
    4. Configure repositories in config/packages/_sylius.yaml:
     sylius_customer:
         resources:
             customer:
                 classes:
                     model: App\Entity\Customer\Customer
    +                repository: App\Repository\CustomerRepository
    
     sylius_product:
         resources:
             product_variant:
                 classes:
                     model: App\Entity\Product\ProductVariant
    +                repository: App\Repository\ProductVariantRepository

Extension points

Admin Order Creation Plugin makes it possible to add custom discount during order creation - thus some of Order Show templates need to be replaced with those placed in Resources/views package.

Payment link generation and sending process is based on logic placed in the PaymentLinkCreationListener class. Thus, it can be easily replaced with suitable implementation.

Adjustments set is not closed and strictly defined - adding custom adjustment means defining a new constant in the AdjustmentType class.

Significant part of Reorder Processing is inspired by official Sylius Customer Reorder Plugin. In case of the need for more processors, just add new class implementing ReorderProcessor interface, declare it in reorder_processing.xml file and match it with a proper tag.

Admin Order Creation process is based on Symfony Forms. To find out more about Symfony Forms extension possibilities, check out Symfony Docs.

Security issues

If you think that you have found a security issue, please do not use the issue tracker and do not post it publicly. Instead, all security issues must be sent to [email protected].

adminordercreationplugin's People

Contributors

adamkasp avatar arminek avatar bartoszpietrzak1994 avatar clem21 avatar codermaggie avatar coldic3 avatar damonsson avatar dunglas avatar gsadee avatar herveemagma avatar igormukhingmailcom avatar jacquesbh avatar kayue avatar konafets avatar lchrusciel avatar maciekpaprocki avatar mamazu avatar pamil avatar peterukena avatar pierre-h avatar pogorivan avatar roshyo avatar themilek avatar zales0123 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adminordercreationplugin's Issues

Routes not existing

Hi,

I'm using Sylius v1.7.4 on Symfony 4.48. The installation worked well but when i'm trying to create a new customer or a new order for a customer i got the following errors :

Uncaught Error: The route "sylius_admin_order_creation_customer_create" does not exist.
Uncaught Error: The route "sylius_admin_order_creation_order_create" does not exist

Could you help me with that ? I'm going crazy!!

Thx

Missing discount amount

After adding discount per item, discount isn't filled. But total looks correct.

Added 22.00$ Discount:
untitled

Order creation refactoring

Not saving order during creation and before preview does more harm than good. During the current changing of custom discounts functionality, it's a real nightmare.
My idea is to refactor it this way:

  1. Provide new state for order in_creation (or sth similar), that would be an equivalent of cart state in Admin panel
  2. Save order with this state immediately after the first step of creation (before preview)
  3. Applying discount on preview page could be done with some custom actions (with commands and everything that is beautiful)
  4. After pressing Cancel button order would be removed from database (we have the ID, as it's already saved)
  5. If Admin would abandon order we could have a command clear_abandoned_admin_order (we have something similar for customer orders)
    5*. In the future, we could even listen to the event of leaving a page and display a modal

Transition "select_shipping" cannot be applied on state "shipping_skipped" of object "App\Entity\Order\Order" with graph "sylius_order_checkout"

When I create an order from admin, I have this error :

Transition "select_shipping" cannot be applied on state "shipping_skipped" of object "App\Entity\Order\Order" with graph "sylius_order_checkout"

I create an order with product without shipping (virtual products).
I think this is why I have this exception, I don't need shipping for this order and something in the code try to select it.

Here is the stacktrace :

SM\SMException:
Transition "select_shipping" cannot be applied on state "shipping_skipped" of object "App\Entity\Order\Order" with graph "sylius_order_checkout"

  at vendor/winzou/state-machine/src/SM/StateMachine/StateMachine.php:122
  at SM\StateMachine\StateMachine->apply('select_shipping')
     (vendor/sylius/admin-order-creation-plugin/src/EventListener/OrderCreationListener.php:44)
  at Sylius\AdminOrderCreationPlugin\EventListener\OrderCreationListener->completeOrderBeforeCreation(object(ResourceControllerEvent), 'sylius.order.pre_admin_create', object(TraceableEventDispatcher))
     (vendor/symfony/event-dispatcher/Debug/WrappedListener.php:115)
  at Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke(object(ResourceControllerEvent), 'sylius.order.pre_admin_create', object(TraceableEventDispatcher))
     (vendor/symfony/event-dispatcher/EventDispatcher.php:212)
  at Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(array(object(WrappedListener), object(WrappedListener)), 'sylius.order.pre_admin_create', object(ResourceControllerEvent))
     (vendor/symfony/event-dispatcher/EventDispatcher.php:44)
  at Symfony\Component\EventDispatcher\EventDispatcher->dispatch('sylius.order.pre_admin_create', object(ResourceControllerEvent))
     (vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:145)
  at Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch('sylius.order.pre_admin_create', object(ResourceControllerEvent))
     (vendor/sylius/resource-bundle/src/Bundle/Controller/EventDispatcher.php:76)
  at Sylius\Bundle\ResourceBundle\Controller\EventDispatcher->dispatchPreEvent('admin_create', object(RequestConfiguration), object(Order))
     (vendor/sylius/resource-bundle/src/Bundle/Controller/ResourceController.php:191)
  at Sylius\Bundle\ResourceBundle\Controller\ResourceController->createAction(object(Request))
     (vendor/symfony/http-kernel/HttpKernel.php:150)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (vendor/symfony/http-kernel/HttpKernel.php:67)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor/symfony/http-kernel/Kernel.php:198)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (public/index.php:25)

[Reorder] Todo scenarios

Some scenarios are disabled after changing logic associated with adjustment:

  • reordering_placed_order_with_modified_total_price.feature
  • reordering_placed_order_with_modified_unit_price.feature

The payments contraint breaks the cart

vendor/sylius/admin-order-creation-plugin/src/Resources/config/validation.xml has a declaration of min/max count of 1 payment in the Order resource. That being said, at the cart stage where there are no payments at all it throws the Violation error and breaks the cart usability. Screenshot:

Screenshot 2019-06-12 at 22 19 09

Extract repository methods to traits

If you extract the concrete methods in the repositories to traits it would be easier to use the plugin, i.e. you could just use the trait and implement the interface and you would be good to go. Now you have to copy the method manually.

Customer Reorder Integration

Steps to reproduce:

  • Create a customer
  • Create an order with discounts on the order or the order items
  • Try to reorder this order and the order does not have the discount applied.

I don't know if that is expected behavior.

Endless spinner on setting the shipment

Problem:
Order item validation is kicked off when the available shipments are loaded. Then the request runs into a validation issue and throws an error which breaks the request and the spinner keeps loading.

Steps to reproduce:

  • Create an order with the plugin where you add one item with an amount greater than what you have in stock
  • Fill in the Shipping and billing information
  • Add a shipment (loads)

Filter products that are sufficiently stocked

In the product selection it should not show products that have no stock to ship, as it will cause problems in the next step. Alternatively you could also add some kind of visual indicator of it being sold out.

[FEATURE] Allow Doctrine\ORM\*Repository to be embeddable

I don't know if it the right word to use here : "embeddable" but if we have several plugins or src/Repository/* classes we can have some troubles.
So we are force to decorate the service or to copy/paste the repository methods.

Is there any other way to make this to work, if for exemple we have another ProductVariantRepository ?

Possible features about plugin [ROADMAP]

Hello, today I tried this plugin, and I want to congratulate, I see this plugin very interesting.

But I have some suggestions to share with community.. If some feature is interesting we can create an issue specific

  1. Create an order for a specific user

Now when you visit a customer and click in create an order, we navigate to main page of plugin, and we must select the customer into list ALL customers.... It is very inneficient.... with a list big, the select is very lazy.
And now I cannot write the email directly.

It create the second point.

  1. To have a Select with all customers, in a big ecommerce it is crazy...

I think this pull request can help to this problem
Sylius/Sylius#8778

Maybe the select would to be an autocomplete, and write three characteres by example... or to have possibility to write the customer`s email directly.

  1. Discount 100%
    If you create a order with discount of 100%, ie the value order equals zero... I get the error...

What do you think about these things?

Error when searching customer

As I want create an order for a customer, I start typing the email address but got the error

{
    code: 500,
    message: "Notice: Undefined index: customer"
}

Address selection/creation not required

Apparently its not a required form component to fill out the address of a created order. If you dont do it, it redirects you to the preview page and crashes with an error "return value must be of type string, null returned" in Sylius\Bundle\AddressingBundle\Twig\CountryNameExtension due to the template trying to render the uninitiated address.

The migrations doesn't make sense

Am I missing something or does the two migration files leave the database unchanged?

The first one adds to fields and the second one removes them?

If that's the case, why not remove these files? :)

Migration error

After I copied the migration files, I issued the command bin/console doctrine:migrations:migrate which led me to the following error:

[Doctrine\DBAL\Migrations\MigrationException]
  Migration class "DoctrineMigrations\Version20180626065141" was not found. Is it placed in "DoctrineMigrations" namespace?

I had to change the namespace of the migration files from Sylius\Migrations; -> DoctrineMigrations;.

Not sure if this is a documentation or a code issue.

Proper Order fields values

We need to validate following properties while creating order in Admin panel:

  1. Shipping method - select with available shipping methods should display only shipping methods that are eligible for creating order (should be probably reloaded after each significant order change, like adding a product or changing shipping address)
  2. Payment method - pretty much the same as 1.
  3. Items
    3.1. Validate if there is at least one item
    3.2. Merge order items if there are few of them added with the same variant
  4. Customer
    4.1. Validate if new Customer email is an email
    4.2. Validate if new Customer email is already used (now it just uses an existing customer)

Related with #7

Validate item and order discount inputs

Steps to reproduce

  1. Create new order in Admin panel
  2. Add item discount greater than item's total
  3. Greater amount is accepted

screen shot 2018-09-19 at 09 52 27

  1. Create new order in Admin panel
  2. Add order discount greater than order's total
  3. 500 error

plugin installation issue

help me for installation plugin i did try php 7.0 with sylius so i can use all plugins installation
i am getting error at 7.0 php version incompatibility

anyone can help me or suggestion me ? i would like to install all plugins and library with sylius

as 7.0 result here

/opt/rh/rh-php70/root/bin/php -d memory_limit=-1 /usr/bin/composer require sylius/admin-order-creation-plugin

[InvalidArgumentException]
Package sylius/admin-order-creation-plugin at version has a PHP requirement incompatible with your PHP version (7.0.27)

require [--dev] [--prefer-source] [--prefer-dist] [--no-progress] [--no-suggest] [--no-update] [--no-scripts] [--update-no-dev] [--update-with-dependencies] [--update-with-all-dependencies] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--] []...

Infinite loading circle when country does not have a shipping method

The problem occurs when selecting a country with no shipping method possible.

Steps to reproduce:

  • Create a country (zone) with no shipments defined.
  • Create a new order
  • Select the created country in the shipping address
  • When trying to add a shipment the loader tries to load but gets a 500

The problem could be fixed by checking if the shipment is null:

public function __invoke(Request $request): Response
{
    $order = $this->orderPreparator->prepareFromRequest($request);
    $shipment = $order->getShipments()->get((int) $request->attributes->get('shipmentNumber'));
    $availableShippingMethods = [];
    if ($shippment !== null) {
        $availableShippingMethods = $this->availableShippingMethodsListProvider->__invoke($shipment);
    }
    return new JsonResponse($availableShippingMethods);
}

in

$shipment = $order->getShipments()->get((int) $request->attributes->get('shipmentNumber'));

Useless migration

If you check and compare 2 migration files which you copy and run in your project you will notice that one cancels another:
Version20180626065141.php
Version20180709120541.php

So up method in first migration creates fields, and up in another field deletes fields. In the end 2 migrations dont do any change. So they could be deleted? Or there is some error in one of them?

Unknown locale filter

in vendor/sylius/admin-order-creation-plugin/src/Resources/views/Order/preview.html.twig:31
{{ flags.fromLocaleCode(order.localeCode) }}{{ order.localeCode|locale }}
there is an error when creating an order (on order preview page /admin/orders/new/24/DE_SHOP/preview)

Text of the error: Uncaught PHP Exception Twig\Error\SyntaxError: "Unknown "locale" filter. Did you mean "locale_name", "sylius_locale_name", "sylius_locale_country"?" at /srv/sylius/vendor/sylius/admin-order-creation-plugin/src/Resources/views/Order/preview.html.twig line 31

Should use ApiPlatform's CustomerProvider

I noticed AdminOrderCreationPlugin has its own CustomerProvider

public function provideNewCustomer(string $email): CustomerInterface
{
/** @var CustomerInterface $customer */
$customer = $this->customerFactory->createNew();
$customer->setEmail($email);
$this->customerRepository->add($customer);
return $customer;
}

It should use the one from \Sylius\Bundle\ApiBundle\Provider\CustomerProviderInterface so that it can support Sylius Plus properly.

Validation Order Payments

The validation to check if there is only one payment should have another group to avoid blocking checkout validation in shop if there is multiple payments

<class name="Sylius\Component\Core\Model\Order"> <property name="payments"> <constraint name="Count"> <option name="min">1</option> <option name="max">1</option> <option name="groups">sylius_admin_order</option> </constraint> </property> </class>

Move admin as a prefix out of the plugin

Move route name admin as a prefix out of the plugin.

The way it's done in AdminBundle

sylius_admin:
    resource: "@SyliusAdminBundle/Resources/config/routing.yml"
    prefix: /admin

The way it's done in the plugin
now:

sylius_admin_order_creation:
    resource: "@SyliusAdminOrderCreationPlugin/Resources/config/app/routing.yml"

change to:

sylius_admin_order_creation:
    resource: "@SyliusAdminOrderCreationPlugin/Resources/config/app/routing.yml"
    prefix: /admin

and remove admin from SyliusAdminOrderCreationPlugin/Resources/config/app/routing.yml

if it's okay I can commit changes

State machine error on order creation

When creating an order on Sylius 1.7.4 an error is made by Winzou State machine:

Transition "select_payment" cannot be applied on state "payment_skipped" of object "App\Entity\Order\Order" with graph "sylius_order_checkout"

This occurs when the channel flag skipping_shipping_step_allowed or skipping_payment_step_allowed are enabled and only one payment/shipping provider is available.

Missing form error messages

In the order creation form there is no check for quantities of products. So when creating the order and getting to the review step, there is a form validation error saying not enough quantity in stock. However, this only shows up in the debug toolbar. And the fact that the price of the product is 0.

Steps to reproduce:

  • Create a product in a low quantity
  • Create an order in the admin panel with this product
  • Set the quantity higher than it is available for.
  • Submit the form
  • When reviewing the created order and clicking confirm nothing happens because the form validation error is not shown

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.