Skip to content

Instantly share code, notes, and snippets.

@doctorx32
doctorx32 / webcryptoapi.js
Created Apr 4, 2020
window.crypto.encode/decode Javascript example
View webcryptoapi.js
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;
@doctorx32
doctorx32 / InvoiceVoter.php
Created Apr 25, 2019
Adding link to invoice in Order completed email and making invoice available in public #Sylius #sylius/invoicing-plugin@0.8.3 #Symfony
View InvoiceVoter.php
<?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;
@doctorx32
doctorx32 / AddToCartCommand.php
Created Apr 9, 2019
[Sylius] page with product choice form
View AddToCartCommand.php
<?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;
@doctorx32
doctorx32 / nginx.conf
Created Sep 28, 2018
Ubuntu 16.04 default Nginx.conf
View 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;
}
@doctorx32
doctorx32 / ArticleFixture.php
Created May 21, 2018
[Sulu] Article fixture example
View ArticleFixture.php
<?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;
@doctorx32
doctorx32 / ShippingZoneConfigurationType.php
Created Apr 17, 2018
[Sylius] Zone based promotion rule
View ShippingZoneConfigurationType.php
<?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
{
@doctorx32
doctorx32 / DefaultCalculatorExtension.php
Created Apr 6, 2018
[Sylius] getting shippingmethod tax category amount for checkout stage
View DefaultCalculatorExtension.php
<?php
namespace AppBundle\Twig\Extension;
use Sylius\Component\Taxation\Calculator\DefaultCalculator;
use Sylius\Component\Taxation\Model\TaxRateInterface;
class DefaultCalculatorExtension extends \Twig_Extension
{
private $defaultCalculator;
@doctorx32
doctorx32 / ChannelBasedMinimumPriceConfigurationType.php
Created Mar 11, 2018
[Sylius] Order total amount promotion rule
View ChannelBasedMinimumPriceConfigurationType.php
<?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;
@doctorx32
doctorx32 / CustomAverageRatingUpdater.php
Created Oct 11, 2017
[Sylius] autoaccepting new reviews; disable accept state after creating a new review
View CustomAverageRatingUpdater.php
<?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;
@doctorx32
doctorx32 / RemainingAvailabilityChecker.php
Created Sep 4, 2017
Sylius remaining Twig helper. Returns remaining number of product variant.
View RemainingAvailabilityChecker.php
<?php
namespace AppBundle\Inventory;
use Sylius\Component\Inventory\Checker\AvailabilityCheckerInterface;
use Sylius\Component\Inventory\Model\StockableInterface;
/**