Skip to content

Instantly share code, notes, and snippets.

View clrockwell's full-sized avatar
🏠
Working from home

Chris Rockwell clrockwell

🏠
Working from home
  • Vanderbilt University Medical Center
View GitHub Profile
# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh
source "$HOME/.console/console.rc" 2>/dev/null
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME=agnoster
Random PHP fixes
- Scenario: php running out of memory with only 2MB
- I checked every php.ini configuration file with no luck, all had .ini files with memory_limit plenty high or set to -1
- Occurred after a `brew upgrade`
- Fix: link php to a brew
-- echo 'export PATH="/usr/local/opt/php@7.2/bin:$PATH"' >> ~/.zshrc
-- echo 'export PATH="/usr/local/opt/php@7.2/sbin:$PATH"' >> ~/.zshrc
-- source ~/.zshrc
@clrockwell
clrockwell / README.MD
Last active April 9, 2019 18:32
Use PHP CodeSniffer on only changed files
  • Follow instructions at https://www.drupal.org/node/1419988 to install PHPCS using composer (do it globally)
  • Save git-cs to a location in your current path (echo $PATH); I used /usr/local/sbin
  • Update permissions: chmod u+x /usr/local/sbin/git-cs
  • From your project directory, run git-cs to test changed files against Drupal coding standard

@todo - It would be nice to have this in a pre-commit hook so it's automatically run before a commit is made.

@clrockwell
clrockwell / OrderComments.php
Created June 27, 2018 20:53
Allow GETing and POSTing D8 order comments
<?php
namespace Drupal\scholarrx_api\Plugin\rest\resource;
use Drupal\commerce_log\Entity\Log;
use Drupal\commerce_order\Entity\Order;
use Drupal\Component\Serialization\Json;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\openid_connect\Authmap;
@clrockwell
clrockwell / PromotionAdvanced.php
Created December 6, 2017 21:50
commerce_order_report plugin
<?php
namespace Drupal\scholarrx_reports\Plugin\Commerce\ReportType;
use Drupal\commerce_order\Adjustment;
use Drupal\commerce_order\Entity\OrderInterface;
use Drupal\commerce_order\Entity\OrderItemInterface;
use Drupal\commerce_promotion\Entity\CouponInterface;
use Drupal\commerce_promotion\Entity\Promotion;
use Drupal\commerce_reports\Annotation\CommerceReportType;
@clrockwell
clrockwell / GaltOrderItemProduct.php
Created November 16, 2017 01:39 — forked from lisastreeter/GaltOrderItemProduct.php
Limit by product commerce condition plugin with add another
<?php
namespace Drupal\galt\Plugin\Commerce\Condition;
use Drupal\commerce\Plugin\Commerce\Condition\ConditionBase;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
<?php
namespace Drupal\commerce_form_customizations\Plugin\Commerce\ReportType;
use Drupal\commerce_order\Adjustment;
use Drupal\commerce_order\Entity\Order;
use Drupal\commerce_order\Entity\OrderInterface;
use Drupal\commerce_order\Entity\OrderItemInterface;
use Drupal\commerce_price\Price;
use Drupal\commerce_promotion\Entity\CouponInterface;
@clrockwell
clrockwell / CreatePluginInstance.php
Created October 1, 2017 14:57
Example of creating a plugin instance with the default configuration
<?php
// using PayPal EC as example
/** @var PaymentGatewayManager $plugin */
$plugin = \Drupal::service('plugin.manager.commerce_payment_gateway');
// Get the id of config from `drupal debug:config | grep paypal`
/** @var Config $config */
$config = \Drupal::service('config.factory')
@clrockwell
clrockwell / RefundPayment.php
Created September 21, 2017 13:43
A sample endpoint for refunding a payment in Commerce 2.x
<?php
namespace Drupal\module\Plugin\rest\resource;
use Drupal\commerce_order\Entity\Order;
use Drupal\commerce_payment\Entity\Payment;
use Drupal\commerce_payment\Exception\PaymentGatewayException;
use Drupal\commerce_payment\PaymentGatewayManager;
use Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\PaymentGatewayBase;
use Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\SupportsRefundsInterface;
@clrockwell
clrockwell / LicenseProrated.php
Last active June 27, 2018 20:50
Provide a prorated discount for license roles; useful in upsells when someone already has purchased role, they will receive a discount equal to the amount of time left.
<?php
namespace Drupal\commerce_promotion_prorated\Plugin\Commerce\PromotionOffer;
use Drupal\commerce_license\Entity\License;
use Drupal\commerce_order\Adjustment;
use Drupal\commerce_order\Entity\Order;
use Drupal\commerce_order\Entity\OrderItem;
use Drupal\commerce_order\Entity\OrderItemInterface;
use Drupal\commerce_price\Price;