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 request object. | |
$request = \Drupal::request(); | |
// Query - get all parameter. | |
$q = $request->query->all(); | |
// Check if a query parameter exists. | |
if ($request->query->has('commerce_product_v_id')) { | |
// Get the query parameter. | |
$pvid = $request->query->get('commerce_product_v_id'); |
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
/** | |
* 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'; | |
} | |
} |
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); |
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
// 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 | |
// 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
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 | |
// 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
<?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
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 |