Giter Site home page Giter Site logo

monsieurbiz / syliussettingsplugin Goto Github PK

View Code? Open in Web Editor NEW
23.0 7.0 17.0 688 KB

Provide some custom settings to your favorite Sylius shop!

License: MIT License

JavaScript 1.38% PHP 86.55% Makefile 5.37% Twig 6.69%
sylius sylius-plugin hacktoberfest

syliussettingsplugin's Introduction

Banner of Sylius Settings plugin

Settings for Sylius

Settings Plugin license Tests Security

This plugin gives you the ability to have Plugins oriented settings in your favorite e-commerce platform, Sylius.

Screenshot of the admin panel in Settings section

Installation

Install the plugin via composer:

composer require monsieurbiz/sylius-settings-plugin
For the installation without flex, follow these additional steps

Change your config/bundles.php file to add this line for the plugin declaration:

<?php

return [
    //..
    MonsieurBiz\SyliusSettingsPlugin\MonsieurBizSyliusSettingsPlugin::class => ['all' => true],
];  

Copy the plugin configuration files in your config folder:

cp -Rv vendor/monsieurbiz/sylius-settings-plugin/recipes/1.0-dev/config/ config

Update your database:

bin/console doctrine:migration:migrate

Continue to "How it works" to add your first setting for your store.

Note: you may encounter an error during the installation via composer if you let it run the scripts.
Copy the configuration files and rerun the composer require, it should work. This is due to the use of other plugins in the DI. The configuration is then required to run any console command.

How it works

As a good start you can have a look at:

Then you can get your settings using a twig function: setting().
Have a look at this example.

You can also use the DI to get your Settings, as example with the settings in the test Application app.default:

$ ./bin/console debug:container | grep app.settings.default
  MonsieurBiz\SyliusSettingsPlugin\Settings\Settings $defaultSettings                    alias for "app.settings.default"
  MonsieurBiz\SyliusSettingsPlugin\Settings\SettingsInterface $defaultSettings           alias for "app.settings.default"
  app.settings.default                                                                   MonsieurBiz\SyliusSettingsPlugin\Settings\Settings

Note: the "Settings" menu won't appear until you have at least one setting.

Fetch settings

use MonsieurBiz\SyliusSettingsPlugin\Provider\SettingsProviderInterface;
//...

    private SettingsProviderInterface $settingsProvider;

    public function __construct(SettingsProviderInterface $settingsProvider)
    {
            $this->settingsProvider = $settingsProvider;
    }
    
    public function myAwesomeMethod()
    {
        return $this->settingsProvider->getSettingValue('app.default', 'demo_message')
    }

Use fixtures

We've implemented a fixtures loader to help you to create your settings if you need to have different settings for your tests or project (by channel, by locale…).

You need to create a yaml file with your fixtures, like explained in the documentation of Sylius.
You can find our own example in the source code, section sylius_fixtures: configuration file.

It's also possible to run test fixtures with a local suite in development: make sylius.fixtures.local.

By default, a fixture will replace the value of a setting if it already exists. If you want to keep a value as it is in the database when running this fixture, you can use the flag ignore_if_exists: true for each element that you want to be kept.

Extends existing settings form

If you want to add a field to an existing settings form (like in another plugin), you can check the example in the test app

Use CLI

You can use a CLI command to set a value for a setting directly from the console: $ ./bin/console monsieurbiz:settings:set {alias} {path} {value} --channel="FASHION_WEB" --locale="en_US" --type="text"

Examples:

$ ./bin/console monsieurbiz:settings:set app.default demo_message 'fashion message' --channel="FASHION_WEB" --locale="en_US"
$ ./bin/console monsieurbiz:settings:set app.default demo_json '{"foo":"baz"}' --channel="FASHION_WEB" --locale="en_US" --type="json"
$ ./bin/console monsieurbiz:settings:set app.default demo_datetime '2023-07-24 01:02:03' --channel="FASHION_WEB" --locale="en_US" --type="datetime"
$ ./bin/console monsieurbiz:settings:set app.default enabled 0

The options channel and locale can be omitted if you want to set the value for a global scope. If a value exists for the given scope the type can be omitted as it will be the same as the existing one unless you want to change the type. For a new value you need to specify the type.

⚠️ When specifying the type, be sure to know what you are doing as it should be coherent with the Form Type of the field.

Use cache

Settings use cache.adapter.array adapter by default. If you want to increase performance, you can use cache.adapter.apcu, cache.adapter.redis or any adapters instead.

You had to add the following lines to your config file:

monsieurbiz_sylius_settings:
    cache_adapter: cache.adapter.apcu

Contributing

You can find a way to run the plugin without effort in the file DEVELOPMENT.md.

Then you can open an issue or a Pull Request if you want! 😘
Thank you!

License

This plugin is completely free and released under the MIT License.

syliussettingsplugin's People

Contributors

delyriand avatar etienne-monsieurbiz avatar htaoufikallah avatar jacquesbh avatar kocal avatar lanfisis avatar mamazu avatar maximehuran avatar vvasiloi 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

syliussettingsplugin's Issues

is it possible to use entitytype

Is it possible to use an entityType, to set a collection of other entity in the configuration ?

I am looking a way to do that but can't find any exemple

[PHP] Compatibility with php 7.3

Hello,

Thank you for this great plugin which will surely help all the developers who work with Sylius. 🚀

I see in composer.json "php": "~7.4", do you think we can make this plugin PHP 7.3 compatible?

Thanks !

Problem when I check "use default value"

Hello.

When i check "use default value" on my setting of my channel, its impossible to set "true" the default values ​​for search and instant search limits, only the checkbox for the activation of instant search is working :

image

Do you know how to solve this problem ?

Thanks !

Sylius 1.11 + PHP 8 release

It seems not possible to install SyliusSettingsPlugin on Sylius 1.11 + PHP 8 as the composer.json explicitely defines "~1.8.0 || ~1.9.0 || ~1.10.0" sylius version only.
Could you provide an updated release ?
Thanks for your work !

Having to pass the channel and the locale is annoying

It could be great to have a method which uses the ChannelContext and LocaleContext to get the channel and the locale.

It will simplify a lot of code actually in the applications by avoiding to autowire the channel and locale contexts.

Be able to set default value on the channel

It could be nice to set default values on the channel scope.

monsieurbiz_sylius_settings:
    plugins:
        app.my_plugin:
            vendor_name: Monsieur Biz
            vendor_url:
            plugin_name: My Plugin
            description: My amazing plugin
            icon: rocket
            use_locales: false
            classes:
                form: App\Form\Type\SettingsType
            default_values:
                value_1: 'value_1'
                value_2: 'value_2'
            MY_CHANNEL_CODE_values:
                value_1: 'value_1_1'
                value_2: 'value_2_2'

Update for compatibility for Sylius 1.12

I update my Sylius project to 1.12 and I can't install your plugins with this last version.
Could you make the compatibility please or tell me when you think make it ?

Hierarchy of default values is incorrect

It should always do :

  1. Channel + Locale
  2. Channel + Default
  3. Default + Locale
  4. Default + Default

But it does:

  • If I have a Default + Locale value:
    1. Channel + Locale
    2. Default + Locale
    3. Channel + Default
    4. Default + Default
  • If I don't have a Default + Locale value: (correct order)
    1. Channel + Locale
    2. Channel + Default
    3. Default + Locale
    4. Default + Default

Use multiple option in ChoiceType with default value

There is a bug in the Configuration definition when using a Choice Type with multiple option = true, we cannot use array

$this->addWithDefaultCheckbox(
    $builder, 'my_field', ChoiceType::class, [
    'required' => true,
    'multiple' => true,
    'choices'  => [
       'option1' => 'option1'
       'option2' => 'option2'
    ],
]);
app.common:
          ...
          default_values:
              my_field:
                - option1

Then the error occurs:

In ScalarNode.php line 36:
                                                                                                                                               
  Invalid type for path "monsieurbiz_sylius_settings.plugins.app.common.default_values.my_field". Expected "scalar", but got "array".                                                                                                                                                

A PR will follow

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.