Hide & Refresh iframe using jQuery

/* Hide iframe using jQuery */
jQuery(‘#iframe’, window.parent.document).hide();
/* Refresh iframe using jQuery */
jQuery(‘#iframe’,window.parent.document).attr(‘src’,jQuery(‘#iframe’,window.parent.document).attr(‘src’));

Node vs. entity in drupal

Please find below given clear explanation…..

  • To me, the concept of “node” is fairly clear: It is an “instantiation” of a content-type. When you add content, you choose the type, e.g. “Article”, and the content that you add (e.g. the article text, title, images, etc.) is stored as one unit in the database, and is also often assigned its own URL path. A node is then retrieved, upon user request (i.e. the appropriate HTTP GET), by the node module and passed on to the template which places in on its appropriate place in the layout and generates and returns the webpage (the actual final markup that is served to the browser) by adding in other components of the page (e.g. menus, blocks, etc.). What I find a bit fuzzy however is the concept of entity. A user is an entity, so is a node? How about a role, or a block? How about a comment or a menu? Are those entities too?I can’t yet quite see its place in the overall scheme.
  • To me, “entity” is just a fancy synonym for “thingie”, which is about as vague (or general/abstract) as you could get. Indeed, if knew what is NOT an entity, it might become clearer.

Menu code for drupal 7

/* Menu code for drupal 7 */
<?php
$main_menu_tree = menu_tree(‘main-menu’);
foreach ($main_menu_tree as $key => &$main_menu_item) {
if (is_numeric($key)) {
$main_menu_item[‘#below’][‘#theme_wrappers’][0] = ‘some_other_theme_wrapper’;
}
}
print drupal_render($main_menu_tree);
?>

Backbone.js basics

/* Create Model */
var MessageModel = Backbone.Model.extend();

/* Create Collection with URL */
var MessageCollection = Backbone.Collection.extend({
model: MessageModel,
url: “../api/example_2.php”
});

/* Sent value within URL using collection */
var MessageCollectionNew = Backbone.Collection.extend({
model: MessageModel,
initialize: function(models, options) {
this.url = ‘../api/example_3.php?id=’ + options.id;
},
});

/* Display Message using View */

<!– Templates –>

var MessageView = Backbone.View.extend({
template:_.template($(‘#tpl-hello-backbone’).html()),
render:function (eventName) {
$(this.el).html(this.template(this.model.toJSON()));
return this;
}
});

/* Router in Backbone.js */
var MessageRouter = Backbone.Router.extend({
/* Display message */
displayMessages: function() {
var messageCollection = new MessageCollection();
var messageListView = new MessageListView({model:messageCollection});
messageCollection.fetch({
success: function () {
$(‘#msg’).html(messageListView.render().el);
}
});
}

/* Send id to collection */
getMsgData: function(id){
var messageCollectionNew = new MessageCollectionNew([], { id: id });
var messageListViewNew = new MessageListViewNew({model:messageCollectionNew});
messageCollectionNew.fetch({
success: function () {
$(‘#data_show’).html(messageListViewNew.render().el);
}
});
},
});

Woo-Commerce change product price in cart

/*Update below code in functions.php it will change cart page and checkout page*/

add_action( ‘woocommerce_before_calculate_totals’, ‘add_custom_price’ );
function add_custom_price( $cart_object ) {
$custom_price = 0.0;

foreach ( $cart_object->cart_contents as $value ) {
if ( $value[‘product_id’] == $free_id ) {

//Woo-Commerce version below 2.7.0
$value[‘data’]->price = $custom_price;

//Woo-Commerce version above 3.0.0
$value[‘data’]->set_price($custom_price);
}
}
}