Skip to content

Instantly share code, notes, and snippets.

View cornobils's full-sized avatar

Dmitrijs Čornobiļs cornobils

View GitHub Profile
@cornobils
cornobils / TaxonsCheckboxType.php
Created July 22, 2017 12:54
Sylius product filter by taxons
<?php
namespace AppBundle\Form\Type\Filter;
use Sylius\Component\Core\Model\Taxon;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class TaxonsCheckboxType extends AbstractType {
@cornobils
cornobils / CustomBooleanToStringTransformer.php
Last active April 30, 2018 11:03
How to inject custom DataTransformer in Sylius/Symfony form
<?php
namespace AppBundle\DataTransformer;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\TransformationFailedException;
class CustomBooleanToStringTransformer implements DataTransformerInterface {
/**
@cornobils
cornobils / AdminOrderCreateType.php
Last active August 14, 2017 13:15
OrderItem attaching as Collection to Order problem
final class AdminOrderCreateType extends AbstractResourceType {
...
$builder
->add('items', CollectionType::class, [
'entry_type' => AdminOrderItemCollectionType::class,
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'block_name' => 'entry'
])
@cornobils
cornobils / RemainingAvailabilityChecker.php
Created September 4, 2017 17:33
Sylius remaining Twig helper. Returns remaining number of product variant.
<?php
namespace AppBundle\Inventory;
use Sylius\Component\Inventory\Checker\AvailabilityCheckerInterface;
use Sylius\Component\Inventory\Model\StockableInterface;
/**
@cornobils
cornobils / CustomAverageRatingUpdater.php
Created October 11, 2017 13:30
[Sylius] autoaccepting new reviews; disable accept state after creating a new review
<?php
namespace AppBundle\Resolver;
use Doctrine\Common\Persistence\ObjectManager;
use Sylius\Bundle\ReviewBundle\Updater\ReviewableRatingUpdaterInterface;
use Sylius\Component\Review\Calculator\ReviewableRatingCalculatorInterface;
use Sylius\Component\Review\Model\ReviewableInterface;
use Sylius\Component\Review\Model\ReviewInterface;
@cornobils
cornobils / ChannelBasedMinimumPriceConfigurationType.php
Created March 11, 2018 21:12
[Sylius] Order total amount promotion rule
<?php
declare(strict_types=1);
namespace AppBundle\Form\Admin;
use Sylius\Bundle\CoreBundle\Form\Type\ChannelCollectionType;
use Sylius\Component\Core\Model\ChannelInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
@cornobils
cornobils / DefaultCalculatorExtension.php
Created April 6, 2018 11:45
[Sylius] getting shippingmethod tax category amount for checkout stage
<?php
namespace AppBundle\Twig\Extension;
use Sylius\Component\Taxation\Calculator\DefaultCalculator;
use Sylius\Component\Taxation\Model\TaxRateInterface;
class DefaultCalculatorExtension extends \Twig_Extension
{
private $defaultCalculator;
@cornobils
cornobils / ShippingZoneConfigurationType.php
Created April 17, 2018 10:41
[Sylius] Zone based promotion rule
<?php
namespace AppBundle\Form\Admin\Promotion;
use Sylius\Bundle\AddressingBundle\Form\Type\ZoneCodeChoiceType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
final class ShippingZoneConfigurationType extends AbstractType
{
@cornobils
cornobils / ArticleFixture.php
Created May 21, 2018 08:02
[Sulu] Article fixture example
<?php
declare(strict_types=1);
namespace AppBundle\DataFixtures\Document;
use Sulu\Component\DocumentManager\DocumentManager;
use Sulu\Bundle\DocumentManagerBundle\DataFixtures\DocumentFixtureInterface;
use Sulu\Component\Content\Document\WorkflowStage;
@cornobils
cornobils / nginx.conf
Created September 28, 2018 07:14
Ubuntu 16.04 default Nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}