Skip to content

Instantly share code, notes, and snippets.

View iledcom's full-sized avatar

Konstantyn iledcom

View GitHub Profile
@iledcom
iledcom / Drupal 7 foreach node one type of material
Created September 14, 2015 15:16
Drupal 7 foreach node one type of material
<?php
// for example node type = product_display
$type = 'product_display';
$nodes = node_load_multiple(array(), array('type' => $type));
foreach ($nodes as $node){
$title = $node->title;
print $title;
}
?>
@iledcom
iledcom / Drupal7 concluded the "add to cart"
Created September 7, 2015 11:05
Drupal7 concluded the "add to cart"
<?php
$form_id
= commerce_cart_add_to_cart_form_id(array($product->product_id));
$line_item = commerce_product_line_item_new($product);
$line_item->data['context']['product_ids'] = array($product->product_id);
$form = drupal_get_form($form_id, $line_item);
// render your $form somewhere
?>
@iledcom
iledcom / Drupal 7 The software checks the address of the page
Last active February 12, 2016 16:42
Drupal 7 The software checks the address of the page
$current_url = 'http://' .$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
@iledcom
iledcom / From JavaScript in PHP (method GET)
Created August 21, 2015 08:14
From JavaScript in PHP (method GET)
<script type="text/javascript">
var userName2 = 'Переменная';
</script>
<?php
if (isset($_GET['u_name']))
{
echo "Значение JavaScript-переменной: ". $_GET['u_name'];
@iledcom
iledcom / Drupal 7 commerce_cart_add_to_cart_form
Last active August 29, 2015 14:27
Drupal 7 commerce_cart_add_to_cart_form
$form_idp= commerce_cart_add_to_cart_form_id(array(7));
//in this case product_id of 7 corresponds to a silver level
$productp = commerce_product_load(7);
$line_itemp = commerce_product_line_item_new($productp, 1); // 1 is quantity
$line_itemp->data['context']['product_ids'] = array(7);
$formp = drupal_get_form($form_idp, $line_itemp);
<?print drupal_render($formp);?>
?>
@iledcom
iledcom / Drupal7 get product_id
Created August 18, 2015 12:05
Drupal7 get product_id
<?php
foreach ($node->field_product['und'] as $key => $product_array) {
if ( !empty($product_array) ) {
$product = commerce_product_load($product_array['product_id']);
}
}
?>
@iledcom
iledcom / Drupa7 Output URL large image
Created August 18, 2015 12:03
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;
}
}
?>
@iledcom
iledcom / Drupal 7 display node id
Created August 18, 2015 11:00
Drupal 7 display node id
<?php print $node->nid; ?>
@iledcom
iledcom / Drupal7 image_style_url
Created August 12, 2015 10:38
Drupal7 image_style_url
<?php
$node = node_load(49);
$largeimg = image_style_url('medium', $node->field_image['und'][0]['uri']);
echo $largeimg;
?>">
@iledcom
iledcom / Drupal 7 Commerce entity_load
Last active August 29, 2015 14:27
Drupal 7 Commerce entity_load
<?php
$products = entity_load('commerce_product');
foreach ($products as $product) {
$title = $product->title;
$cokol = field_get_items('commerce_product', $product, 'field_cokol');
$cokolname = field_view_value('commerce_product', $product, 'field_cokol', $cokol[0], array(
'type' => 'text',
));
?>
<?php print render($cokolname);?>