Skip to content

Instantly share code, notes, and snippets.

View joshmiller83's full-sized avatar
🐢
Taking things one step at a time.

Josh Miller joshmiller83

🐢
Taking things one step at a time.
View GitHub Profile
@joshmiller83
joshmiller83 / commerce_2_order.php
Created September 28, 2016 15:12
Create an order programmatically for Drupal Commerce 2.x
<?php
$order_type = "default";
$store_id = 1;
$uid = 0;
$entity_type_manager = \Drupal::service('entity_type.manager');
$order_storage = $entity_type_manager->getStorage('commerce_order');
$new_order = $orderStorage->create([
'type' => $order_type,
'store_id' => $store_id,
@joshmiller83
joshmiller83 / ModulenameAddToCartForm.php
Last active May 31, 2019 15:53
Add to cart modifications for Commerce 2
<?php
// In folder `src/Form/`.
namespace Drupal\modulename\Form;
use Drupal\commerce\Context;
use Drupal\commerce_cart\Form\AddToCartForm;
use Drupal\commerce_product\Entity\ProductVariation;
use Drupal\Core\Form\FormStateInterface;
@joshmiller83
joshmiller83 / composer.json
Created January 31, 2018 01:17 — forked from andyshinn/composer.json
Docker Compose PHP Composer Example
{
"require": {
"mfacenet/hello-world": "v1.*"
}
}
<?php
/**
* Implements hook_form_FORM_ID_alter().
*
* This will work on all cart forms without running the global hook_form_alter().
*/
function MODULE_form_commerce_cart_add_to_cart_form_alter(&$form, &$form_state, $form_id) {
$product = $form_state['default_product'];
}
@joshmiller83
joshmiller83 / gist:5483972
Created April 29, 2013 19:14
Random Community Stats
// # of new committers
$commerce_module = "http://drupal.org/node/605898/committers";
echo return_new_committer_ul($commerce_module,'<a href="http://drupal.org/node/605898/committers">Drupal Commerce</a>');
$commerce_module = "http://drupal.org/node/1079066/committers";
echo return_new_committer_ul($commerce_module,'<a href="http://drupal.org/node/1079066/committers">Drupal Commerce Kickstart</a>');
function return_new_committer_ul ($url,$module) {
$doc = new DOMDocument();
@joshmiller83
joshmiller83 / gist:5033497
Created February 25, 2013 21:29
Tired of looking at the boring CSS for Drupalcon Portland comments? This will spice it up nicely:
.comments header {
width: 30%;
float: left;
margin-left: -210px;
}
.comments header p {
font-size: 12px;
color: #FFF;
margin-bottom: 0;
}
@joshmiller83
joshmiller83 / clone_drupal_blocks.php
Last active November 19, 2015 17:07
Using this function you can clone drupal blocks from one theme to another for Drupal 7 only.
<?php
/**
* Clones blocks from one theme to another.
*
* @param $original
* The machine name of the original theme.
*
* @param $new
* The machine name of the new theme.
*/
@joshmiller83
joshmiller83 / file.php
Created November 16, 2015 23:15
Quickly decouple a user's current cart from Drupal Commerce 7.x
<?php
// Only meant for quick development issues where the current order
// is somehow borked.
global $user;
$order_id = commerce_cart_order_id($user->uid);
db_query("UPDATE commerce_order SET uid = 0 WHERE order_id=".$order_id)->execute();
@joshmiller83
joshmiller83 / file.php
Last active October 30, 2015 16:35
Change Add to Cart on hook form alter when price is zero
<?php
/**
* Implements hook_form_alter()
*/
function MODULE_form_alter(&$form, &$form_state, $form_id) {
// Avoid bundle cart forms and other forms
if (strpos($form_id, 'commerce_cart_add_to_cart_form_') === 0) {
// Use the price calculation system
$price = commerce_product_calculate_sell_price($form_state['default_product']);
// Some products don't have a price, like bundles. In this case we get "NULL".
@joshmiller83
joshmiller83 / hideprice.info
Last active October 21, 2015 19:32
Quick example module of how to hide prices for anonymous users. This could be installed as is or could be a good starter to copy/paste into your own custom glue module.
name = View Price Permissions
description = Add a permission to view prices. Allows you to hide the price for anonymous or other roles.
core = 7.x
dependencies[] = commerce_product