Skip to content

Instantly share code, notes, and snippets.

@druman
druman / demo.module
Created February 4, 2016 08:28 — forked from pascalduez/demo.module
Drupal 7 — Basic Ajax form submit (Ajax framework)
<?php
/**
* @file
* Demo module, Basic Ajax form submit (Ajax framework).
*/
/**
* Implements hook_menu().
*/
$product_array = array();
foreach ($vars['field_product'] as $product) {
$product_array[] = $product['product_id'];
}
$products = commerce_product_load_multiple(
$product_array,
array("status"=>1)
);
// testing...
echo "<pre>";
@druman
druman / Drupa7 Output URL large image
Created March 10, 2016 06:45 — forked from iledcom/Drupa7 Output URL large image
Drupa7 Output URL large image
<?php
foreach ($node->field_product['und'] as $key => $product_array) {
if ( !empty($product_array) ) {
$product = commerce_product_load($product_array['product_id']);
$largeimg = image_style_url('large', $product->field_image['und'][0]['uri']);
echo $largeimg;
}
}
?>
@druman
druman / migrate.php
Last active April 22, 2016 07:42
Migrate users: drupal 6 to 7
<?php
/*
Standalone PHP script to migrate users from Drupal 6 to Drupal 7 programatically.
*/
// set HTTP_HOST or drupal will refuse to bootstrap
$_SERVER['HTTP_HOST'] = 'SITENAME';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
//root of Drupal 7 site
$DRUPAL7_ROOT="/var/www/site.com";
define('DRUPAL_ROOT',$DRUPAL7_ROOT);
@druman
druman / gist:14b1ce50091f4859f8c467748a749288
Created May 13, 2016 08:06
DRUPAL bootstrap dropdown override
/*
* Bootstrap override
* make dropdown menus do dropdown on hover,
* and allow parent link to be clickable
*/
// place this in your styles
ul.nav li.dropdown:hover > ul.dropdown-menu{
display: block !important;
}
@druman
druman / dc_emw.php
Created August 1, 2016 13:22 — forked from BBGuy/dc_emw.php
Working with Drupal commerce entities using entity_metadata_wrapper. Just a bunch of exampled copied from the web or added by me. will keep adding over time.
<?php
// order.
$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
// Order id.
$order_id = order_wrapper->order_id->value();
// User detils.
@druman
druman / call_outside.php
Last active September 23, 2016 12:17
Call drupal function in outside php file
// define static var
define('DRUPAL_ROOT', getcwd());
// include bootstrap
include_once('./includes/bootstrap.inc');
// initialize stuff
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
//load user
@druman
druman / sort_combined.module
Created February 2, 2017 07:11
Exposed sort combined custom. Write module and rewrite views-exposed-form.tpl.php
<?php
/**
* Implements hook_form_alter().
*
* Alter exposed filter form in views
*/
function MODULE_form_views_exposed_form_alter(&$form, &$form_state, $form_id) {
if (isset($form['sort_by'])) {
// Combine sort drop-downs into one.
$form['sorting'] = array(
@druman
druman / requiredScroll.js
Created February 3, 2017 09:35
HTML5 input required, scroll to input with affix
$(document).ready(function() {
var delay = 0;
var offset = 100;
document.addEventListener('invalid', function(e){
$(e.target).addClass("invalid");
$('html, body').animate({scrollTop: $($(".invalid")[0]).offset().top - offset }, delay);
}, true);
document.addEventListener('change', function(e){
$(e.target).removeClass("invalid")
@druman
druman / myscript.js
Created February 7, 2017 13:13
Commerce Add To Cart and Views "Use Ajax"
/*** SHOW MORE FIX AJAX ADD TO CART ***/
Drupal.behaviors.commerceAjxCart = {
attach: function (context, settings) {
$('.commerce-add-to-cart .form-submit', context).once('ajax', function () {
var base = this.id;
Drupal.ajax[base] = new Drupal.ajax(base, this, {
event: 'mousedown',
url: Drupal.settings.basePath + 'system/ajax'
});
});