This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
drush vset comment_maintain_node_statistics TRUE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Basics | |
// Get a value. | |
$value = $wrapper->field_x->value(); | |
// If the field is a reference field you will get the field object | |
// To get the wrapper back use: | |
$wrapper_b = $wrapper->field_ref; | |
// To set a value. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 ); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// some examples on | |
// https://docs.drupalcommerce.org/commerce2/developer-guide/products/product-architecture/code-recipes | |
// https://docs.drupalcommerce.org/commerce2/developer-guide/products/product-management/code-recipes | |
// https://docs.drupalcommerce.org/commerce2/developer-guide/products/displaying-products/code-recipes | |
// Work with orders. | |
/** @var \Drupal\commerce_order\Entity\OrderInterface $order */ | |
$order = \Drupal::entityTypeManager()->getStorage('commerce_order')->load($order_id); |
OlderNewer