Skip to content

Instantly share code, notes, and snippets.

View chornobils's full-sized avatar

Dmitrijs Čornobiļs chornobils

View GitHub Profile
@chornobils
chornobils / 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;
@chornobils
chornobils / 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;
@chornobils
chornobils / 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;
@chornobils
chornobils / 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;
}
@chornobils
chornobils / 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;
@chornobils
chornobils / 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
{
@chornobils
chornobils / 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;
@chornobils
chornobils / 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;
@chornobils
chornobils / 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;
@chornobils
chornobils / 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;
/**