Skip to content

Instantly share code, notes, and snippets.

View cornobils's full-sized avatar

Dmitrijs Čornobiļs cornobils

View GitHub Profile
@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 / webcryptoapi.js
Created April 4, 2020 22:35
window.crypto.encode/decode Javascript example
var secretmessage = "";
var password = "";
var key_object = null;
var promise_key = null;
var encrypted_data = null;
var encrypt_promise = null;
var vector = window.crypto.getRandomValues(new Uint8Array(16));
var decrypt_promise = null;
var decrypted_data = null;
@cornobils
cornobils / InvoiceVoter.php
Created April 25, 2019 12:22
Adding link to invoice in Order completed email and making invoice available in public #Sylius #sylius/invoicing-plugin@0.8.3 #Symfony
<?php
declare(strict_types=1);
namespace App\Voter;
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
use Sylius\InvoicingPlugin\Entity\InvoiceInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
@cornobils
cornobils / AddToCartCommand.php
Created April 9, 2019 08:37
[Sylius] page with product choice form
<?php
declare(strict_types=1);
namespace App\Model;
use Sylius\Bundle\OrderBundle\Controller\AddToCartCommandInterface;
use Sylius\Component\Order\Model\OrderInterface;
use Sylius\Component\Order\Model\OrderItemInterface;
@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;
}
@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 / 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 / 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 / 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 / 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;