- 001
- 002
- 003
- 004
- 005
- 006
- 007
- 008
- 009
- 010
- 011
- 012
- 013
- 014
- 015
- 016
- 017
- 018
- 019
- 020
- 021
- 022
- 023
- 024
- 025
- 026
- 027
- 028
- 029
- 030
- 031
- 032
- 033
- 034
- 035
- 036
- 037
- 038
- 039
- 040
- 041
- 042
- 043
- 044
- 045
- 046
- 047
- 048
- 049
- 050
- 051
- 052
- 053
- 054
- 055
- 056
- 057
- 058
- 059
- 060
- 061
- 062
- 063
- 064
- 065
- 066
- 067
- 068
- 069
- 070
- 071
- 072
- 073
- 074
- 075
- 076
- 077
- 078
- 079
- 080
- 081
- 082
- 083
- 084
- 085
- 086
- 087
- 088
- 089
- 090
- 091
- 092
- 093
- 094
- 095
- 096
- 097
- 098
- 099
- 100
$output = '<div class="catalog catalog-category">';
$query = db_select('taxonomy_term_data','td');
$query->innerJoin('field_data_field_category', 'fc', "fc.field_category_tid = td.tid");
$query->innerJoin('taxonomy_term_hierarchy', 'tth', "tth.tid = td.tid");
$query->innerJoin('node', 'n', "n.nid = fc.entity_id");
$query->condition('td.vid', 4);
$query->condition('n.status', 1);
$query->condition('tth.parent', 0);
$query->fields('td', array('tid', 'name'));
$query->groupBy('td.tid');
$query->orderBy('td.weight', 'ASC');
$terms = $query->execute()->fetchAll();
foreach ($terms as $term) {
$prod_out = '';
$query = db_select('field_data_field_product', 'fp');
// Выбираем товары текущего типа
$query->innerJoin('node', 'n', "n.nid = fp.entity_id");
$query->innerJoin('field_data_field_category', 'fc', "fc.entity_id = n.nid");
$query->condition('n.status', 1);
$query->condition('fc.field_category_tid', $term->tid);
// Заголовок товара
$query->innerJoin('commerce_product', 'cp', "cp.product_id = fp.field_product_product_id");
$query->condition('cp.status', 1);
$query->fields('cp', array('title'));
// Цена без скидки
$query->innerJoin('field_data_commerce_price', 'dcp', "dcp.entity_id = fp.field_product_product_id");
$query->fields('dcp', array('commerce_price_amount'));
// Размер скидки
$query->leftJoin('field_data_field_discount', 'dcpd', "dcpd.entity_id = fp.field_product_product_id");
$query->fields('dcpd', array('field_discount_value'));
// Цена со скидкой
$query->leftJoin('field_data_field_price_new', 'dcpn', "dcpn.entity_id = fp.field_product_product_id");
$query->fields('dcpn', array('field_price_new_value'));
// Первое изображение
$query->innerJoin('field_data_field_image', 'dfi', "dfi.entity_id = fp.field_product_product_id");
$query->condition('dfi.delta', 0);
$query->fields('dfi', array('field_image_fid'));
$query->innerJoin('field_data_field_weight', 'fw', "fw.entity_id = fp.field_product_product_id");
$query->addExpression("(SELECT GROUP_CONCAT(td.name SEPARATOR ', ') FROM field_data_field_season AS dfs INNER JOIN taxonomy_term_data AS td ON td.tid=dfs.field_season_tid WHERE dfs.entity_id=n.nid)","name");
// Маркер
$query->leftJoin('field_data_field_marker', 'dfm', "dfm.entity_id = fp.field_product_product_id");
$query->fields('dfm', array('field_marker_value'));
// Товар
$query->fields('fp', array('field_product_product_id'));
// Связанная с товаром нода
$query->fields('n', array('nid'));
$query->range(0, 4);
$query->orderBy('fw.field_weight_value', 'ASC');
$products = $query->execute()->fetchAll();
// $output .= '<h2>' . l($term->name, 'taxonomy/term/'.$term->tid) . '</h2>';
$output .= '<div class="product_items">';
$output .= '<div class="catalog_item"><div style="width: 225px; height: 340px;"><h2>' . l($term->name, 'taxonomy/term/'.$term->tid) . '</h2></div></div>';
foreach ($products as $product) {
$fid = $product->field_image_fid;
if ($fid != 0 && is_numeric($fid)) {
$file_picture = file_load($fid);
$imageUrl = image_style_url('catalog', $file_picture->uri);
$title = $product->title;
$photo = "<img class='lazy-image' data-src='{$imageUrl}' alt='{$title}' title='{$title}'>";
}
else $photo = '';
$prod_out .= '<div class="catalog_item">';
$prod_out .= '<div class="title">' . l($product->title . '<br><span>' . $product->name . '</span><div>XS S M L XL</div>', 'node/'.$product->nid, array('html' => TRUE, 'query' => array('id' => $product->field_product_product_id))).'</div>';
$prod_out .= '<div class="image">' . $photo . '</div>';
if (!empty($product->field_discount_value)) {
$prod_out .= '<div class="views-field-field-discount"><div class="field-content">Sale ' . $product->field_discount_value . ' %</div></div>';
}
if (!empty($product->field_marker_value)) {
$prod_out .= '<div class="views-field-field-marker"><div class="field-content field-content field-content-' . $product->field_marker_value . '">' . ($product->field_marker_value == 'new'?'Новинка':'Бестселлер') . '</div></div>';
}
if (!empty($product->field_price_new_value)) {
$price = '<s>' . number_format($product->commerce_price_amount/100,0,'',' ') . '</s> ' . number_format($product->field_price_new_value,0,'',' ') . ' Р';
}
else {
$price = number_format($product->commerce_price_amount/100,0,'',' ') . ' Р';
}
$prod_out .= '<div class="views-field-field-price-new">' . $price . '</div>';
$prod_out .= '</div>';
}
}
$output .= $prod_out;
$output .= '<div class="catalog_item" style="position: absolute;">' . l('<img src="/sites/all/themes/base/img/strelka.png" style="width: 10px; height: 17px;">', 'taxonomy/term/'.$term->tid, array('html' => true)) . '</div>';
$output .= '</div>';