Skip to content

Instantly share code, notes, and snippets.

@AugustMiller
AugustMiller / FrequentBuyer.php
Last active January 26, 2021 23:09
Reduces the current Cart/Order's total by some percentage of the combined total of the previous 6 orders.
<?php
namespace dpdx\plugin\adjusters;
use Craft;
use craft\base\Component;
use craft\helpers\ArrayHelper;
use craft\commerce\Plugin as Commerce;
use craft\commerce\base\AdjusterInterface;
use craft\commerce\elements\Order;
@matt-adigital
matt-adigital / ProductEntrySearchService.php
Created December 10, 2018 11:25
Craftcms - Search both products and entries in a single search with custom pagination
<?php
/**
* Product & Entry Search plugin for Craft CMS 3.x
*
* Use site search across both products and entries allowing for pagination.
*
* @link https://adigital.agency
* @copyright Copyright (c) 2018 A Digital
*/
@cole007
cole007 / digitalocean.md
Last active November 22, 2023 16:54
Digital Ocean internal migration - moving files between droplets over SSH/SCP

If you need to move a lot of files between DO server you can move these through SCP over the internal private Digital Ocean network.

NB both droplets need to be within the same region

To do this you need:

  1. enable private network for each droplet (if not done at creation, note the droplet needs to be off for this to be enabled once live)
  2. ensure that eth1 is enabled for both droplets if not already - see https://www.digitalocean.com/community/tutorials/how-to-enable-digitalocean-private-networking-on-existing-droplets
  3. scp files from the source server to the destination server are sent like:
@brettburwell
brettburwell / img.html
Last active June 26, 2018 09:05
Craft macro to centralize the markup and config for responsive images
{# ================================================================== #}
{# Responsive Image Macro
{# ================================================================== #}
{#
Macro to centralize the markup and config for responsive images.
Based on an article by Marion Newlevant (@marionnewlevant) and
adapted for the Lazysizes plugin. Read more:
https://straightupcraft.com/articles/responsive-images-with-twig-macros
@nfourtythree
nfourtythree / Password Protect Serverpilot App.md
Last active December 10, 2020 17:20
Password Protect Serverpilot App

How to password protect your Serverpilot app

This is a quick (rough) guide on how to protect a Serverpilot pilot app with auth basic

1. SSH into your Serverpilot Server

ssh SERVERPILOTUSERNAME@your.server.ip.address

2. Create a htpasswd file in your app

@tomysmile
tomysmile / mac-setup-redis.md
Last active July 16, 2024 04:45
Brew install Redis on Mac

type below:

brew update
brew install redis

To have launchd start redis now and restart at login:

brew services start redis
server {
listen 80;
server_name {{ server_name }};
return 301 https://$server_name$request_uri;
}
server {
server_name www.{{ server_name }};
return 301 https://{{ server_name }}$request_uri;
}
@lukeholder
lukeholder / import.php
Last active January 10, 2018 09:58
Basic example to import Products and their variants into Craft Commerce
<?php
namespace Craft;
// This file could be placed into your public_html folder and visited to import a cheese product.
$craft = require '../craft/app/bootstrap.php';
$craft->plugins->loadPlugins();
$newProduct = new Commerce_ProductModel();
@lukeholder
lukeholder / nginxConfig
Created July 14, 2015 10:52
nginxConfig
server {
listen 80;
server_name tenina.com direct.tenina.com new.tenina.com;
# server_name .tenina.com;
root /home/forge/tenina.com/public;
rewrite /2013/12/brown-sugar-pavlova-summer-berries/ http://tenina.com/recipes/brown-sugar-pavlova-with-summer-berries permanent;
rewrite /2013/12/pomegranate-sangria/ http://tenina.com/recipes/pomegranate-sangria permanent;
rewrite /2013/12/tasmanian-salmon-pate/ http://tenina.com/recipes/tasmanian-salmon-pate permanent;
rewrite /2013/12/fruit-mince-baklava/ http://tenina.com/recipes/fruit-mince-baklava permanent;
@joshangell
joshangell / default.vcl
Last active January 5, 2022 11:35
Varnish config for Craft
# Varnish 4.0 configuration for Craft
#
# Based on the following:
# - https://github.com/mattiasgeniar/varnish-4.0-configuration-templates/blob/master/default.vcl
# - https://gist.github.com/aelvan/eba03969f91c1bd51c40
vcl 4.0;
import std;
import directors;