tomsgu/sylius-gift-plugin

Sylius plugin to mark orders as gifts when ordering products.

Installs: 2

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:sylius-plugin


README

This plugin adds an option to a customer to mark their orders as gifts to another person. This information is passed to an order through its notes field.

Installation

Step 1: Download the plugin

$ composer require tomsgu/sylius-gift-plugin

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Enable the plugin

Enable the plugin by adding it to the list of registered bundles:

<?php
# config/bundles.php

return [
    // ...
    
    Tomsgu\SyliusGiftPlugin\TomsguSyliusGiftPlugin::class => ['all' => true],
    
    // It is important to add plugin before the grid bundle
    Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true],
    
    // ...
];

Step 3: Import config

# config/packages/_sylius.yaml
imports:
    # ...
    - { resource: '@TomsguSyliusGiftPlugin/Resources/config/app/config.yaml' }
    # ...

Step 4: Import routing

# config/routes/tomsgu_sylius_gift.yaml

tomsgu_sylius_gift_admin:
    resource: "@TomsguSyliusGiftPlugin/Resources/config/routes/admin.yaml"
    prefix: /admin

Step 5: Update a database schema

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

Step 6: Override checkout complete form

Override the Sylius Form:

  • If you haven't override the templates/bundles/SyliusShopBundle/Checkout/Complete/_form.html.twig template yet, copy src/Resources/views/bundles/SyliusShopBundle/Checkout/Complete/_form.html.twig file to: templates/bundles/SyliusShopBundle/Checkout/Complete/_form.html.twig

    $ cp vendor/tomsgu/sylius-gift-plugin/src/Resources/views/bundles/SyliusShopBundle/Checkout/Complete/_form.html.twig \
    templates/bundles/SyliusShopBundle/Checkout/Complete/_form.html.twig
  • If you've already override it, add a following snippet to that template:

    {# templates/bundles/SyliusShopBundle/Checkout/Complete/_form.html.twig #}
    {% if form.gift_option is defined %}
        {{ form_row(form.gift_option) }}
    {% endif %}

Troubleshooting

  • If you get You have requested a non-existent parameter "tomsgu_sylius_gift.model.gift_option.class" exception, you must instantiate the plugin before the grid bundle. See Step 3: Import config section.