Skip to content

Commit

Permalink
Merge pull request #32 from etienne-monsieurbiz/feature/add-twig-func…
Browse files Browse the repository at this point in the history
…tion

Twig function to know if no commerce is enabled
  • Loading branch information
etienne-monsieurbiz authored Dec 14, 2023
2 parents 6c1d991 + ed710dd commit 69f92d9
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
40 changes: 40 additions & 0 deletions dist/src/Migrations/Version20231214131617.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/*
* This file is part of Monsieur Biz' No Commerce plugin for Sylius.
*
* (c) Monsieur Biz <sylius@monsieurbiz.com>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20231214131617 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE mbiz_settings_setting CHANGE json_value json_value JSON DEFAULT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE mbiz_settings_setting CHANGE json_value json_value JSON DEFAULT NULL');
}
}
41 changes: 41 additions & 0 deletions src/Twig/Extension/NoCommerceExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/*
* This file is part of Monsieur Biz' No Commerce plugin for Sylius.
*
* (c) Monsieur Biz <sylius@monsieurbiz.com>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace MonsieurBiz\SyliusNoCommercePlugin\Twig\Extension;

use MonsieurBiz\SyliusNoCommercePlugin\Provider\FeaturesProviderInterface;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

final class NoCommerceExtension extends AbstractExtension
{
private FeaturesProviderInterface $featuresProvider;

public function __construct(
FeaturesProviderInterface $featuresProvider
) {
$this->featuresProvider = $featuresProvider;
}

public function getFunctions(): array
{
return [
new TwigFunction('is_no_commerce_enabled', [$this, 'isNoCommerceEnabled']),
];
}

public function isNoCommerceEnabled(): bool
{
return $this->featuresProvider->isNoCommerceEnabledForChannel();
}
}

0 comments on commit 69f92d9

Please sign in to comment.