Skip to content

Instantly share code, notes, and snippets.

View BBGuy's full-sized avatar

Guy Schneerson BBGuy

View GitHub Profile
@BBGuy
BBGuy / drupal_commerce_order_total_components_1.php
Last active August 29, 2015 14:00
Drupal Commerce Order Total components
<?php
// Get a nicely formatted amount for Ex VAT & Vat order totals.
// Get the order wrapper
$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
// Order total.
$order_total = $order_wrapper->commerce_order_total->value();
// Get ex vat amount.
@BBGuy
BBGuy / drush
Created August 14, 2014 09:00
Sort out Drupal 7: Notice: Undefined property: stdClass::$comment_count in comment_node_page_additions()
drush vset comment_maintain_node_statistics TRUE
@BBGuy
BBGuy / gist:592f191e2ab120f75df0
Last active August 29, 2015 14:20
Working with Images in Drupal
// Using the Entity API
$image = $MY_ENITIY->field_image->value();
$variables = array(
'style_name' => 'my_style__img',
'path' => $centre['image']['uri'],
'width' => $centre['image']['width'],
'height' => $centre['image']['height'],
);
$img = theme('image_style', $variables );
@BBGuy
BBGuy / i18n_get_menu.php
Created November 28, 2012 13:41
Drupal - Build a localized menu programmatically using i18n menu
<?php
function i18n_get_menu_get_localized_menu($menu_name) {
// Get the menu tree
$menu_links = menu_tree($menu_name);
// reform the array to be i18n_menu compatible
$l_menu_links = array();
foreach ($menu_links as $key => $value) {
$l_menu_links[$key]['link'] = $value['#original_link'];
}
// localize the menu
@BBGuy
BBGuy / amazons3_mpfu.php
Created November 29, 2012 09:46
Drupal Amazon S3 multipart file upload
<?php
function amazons3_upload($file, bucket)
if(!libraries_load('awssdk')) {
print t('Unable to load the AWS SDK. Please check you have installed the library correctly and configured your S3 credentials.</br>');
return;
}
else if(!class_exists('AmazonS3')) {
print t('Cannot load AmazonS3 class. Please check the awssdk is installed correctly.</br>');
return;
}
@BBGuy
BBGuy / drupal_commerce_localization.sh
Last active December 19, 2015 11:48
The following is a script to download and install Drupal Commerce localization modules
drush dl entity_translation
drush en entity_translation -y
drush dl title
drush en title -y
drush dl variable
drush en variable -y
drush dl i18n
drush en i18n, i18n_translation, i18n_field, i18n_menu -y
@BBGuy
BBGuy / gist:7875084
Created December 9, 2013 16:23
Drupal Commerce Localization - translate the currency symbol
<?php
/**
* Implementation of hook_commerce_currency_info_alter().
*/
function MyModule_commerce_currency_info_alter(&$currencies, $langcode) {
// Add a curreny format callback so we can take over formating.
$currencies['RUB']['format_callback'] = 'MyModule_commerce_currency_format';
}
@BBGuy
BBGuy / dc_add_default_product.module
Created August 8, 2016 14:40
Create a default producr if one was not set.
/**
* Implements hook_form_alter().
*/
function dwwcommerce_form_alter(&$form, &$form_state, $form_id) {
// The style edit form.
if ($form_id == 'product_style_node_form') {
// Add a custom submit.
$form['actions']['submit']['#submit'][] = 'mymodule_node_prod_display_form_submit';
}
}
### Keybase proof
I hereby claim:
* I am BBGuy on github.
* I am guy_schneerson (https://keybase.io/guy_schneerson) on keybase.
* I have a public key whose fingerprint is E0F9 7435 1C0D 3783 458E 5F99 CE91 6F6F 7690 BF49
To claim this, I am signing this object:
@BBGuy
BBGuy / commerce_tools.php
Last active January 11, 2018 17:33
Drupal 7 commerce utility functionality
<?php
/**
* Get the node ID for a commerce product using it's product ID.
*
* Asumes only one. If not will return the first node referencing the product.
* If the commerce product has no product display will return FALSE.
*/
function _get_product_referencing_nid($product_id) {
$query = new EntityFieldQuery();