Commit 854c708f authored by jsacksick's avatar jsacksick Committed by Jonathan Sacksick

Issue #1811726 by jsacksick: Replace the colection taxonomy views by a Search...

Issue #1811726 by jsacksick: Replace the colection taxonomy views by a Search Api view based on the product display.

Change-Id: I209675f28ee4eeab8834a4038aa5a95b4d3435fc
Reviewed-on: https://code.drupalcommerce.org/487Tested-by: 's avatarJenkins <jenkins@commerceguys.com>
Reviewed-by: 's avatarJonathan Sacksick <jonathan.sacksick@gmail.com>
parent ce848f5e
......@@ -276,6 +276,7 @@ function commerce_kickstart_install_additional_modules() {
'commerce_kickstart_merchandising',
'commerce_kickstart_menus',
'commerce_kickstart_search',
'commerce_kickstart_taxonomy',
);
}
else {
......@@ -285,6 +286,7 @@ function commerce_kickstart_install_additional_modules() {
'commerce_kickstart_lite_product',
'commerce_kickstart_lite_product_ui',
'commerce_kickstart_search',
'commerce_kickstart_taxonomy',
);
$selected_extras = variable_get('commerce_kickstart_selected_extras', array());
if (empty($selected_extras['anonymous_checkout'])) {
......@@ -736,3 +738,87 @@ function commerce_kickstart_update_7204() {
drupal_flush_all_caches();
module_enable(array('commerce_backoffice_content'));
}
/**
* Replace the collection view by a view based on the product display index.
*/
function commerce_kickstart_update_7205(&$sandbox) {
// Enable commerce_kickstart_taxonomy.
module_enable(array('commerce_kickstart_taxonomy'));
menu_rebuild();
// Disable the old taxonomy/term/% view.
$view = views_get_view('collection_taxonomy_term');
if (isset($view->disabled) && $view->disabled === FALSE) {
views_export_status($view, TRUE);
}
$default_theme = variable_get('theme_default', 'omega_kickstart');
// Set the facets blocks only visibile on the "all products" view.
db_update('block')
->fields(array('pages' => 'products', 'visibility' => BLOCK_VISIBILITY_LISTED))
->condition('module', array('facetapi', 'search_api_sorts'))
->condition('theme', $default_theme)
->execute();
$install_demo_store = variable_get('commerce_kickstart_demo_store', FALSE);
// Set up taxonomy main menu..
if ($install_demo_store) {
$vocabulary_machine_name = 'collection';
}
else {
$vocabulary_machine_name = 'product_category';
}
if ($collection = taxonomy_vocabulary_machine_name_load($vocabulary_machine_name) && module_exists('taxonomy_menu')) {
drupal_load('module', 'taxonomy_menu');
$variable_name = _taxonomy_menu_build_variable('vocab_menu', $collection->vid);
variable_set($variable_name, 'main-menu');
$variable_name = _taxonomy_menu_build_variable('path', $collection->vid);
variable_set($variable_name, 'commerce_kickstart_taxonomy_term_path');
// Remove the previous menu entries.
_taxonomy_menu_delete_all($collection->vid);
// Taxonomy menu links
$terms = taxonomy_get_tree($collection->vid);
// Loop through $terms to process each term.
foreach ($terms as $term) {
$args = array(
'term' => $term,
'menu_name' => 'main-menu',
);
$mlid = taxonomy_menu_handler('insert', $args);
}
// Delete old pathauto aliases to regenerate the new ones.
db_delete('url_alias')
->condition('source', db_like('taxonomy/term/') . '%', 'LIKE')
->execute();
// Generate the url using the pathauto bulkupdate.
module_load_include('inc', 'pathauto', 'pathauto.pathauto');
taxonomy_pathauto_bulk_update_batch_process($sandbox);
}
// Add fields to the index (Needed for the new view).
drupal_load('module', 'search_api');
$index = search_api_index_load('product_display');
if (!empty($index)) {
$indexed_fields = $index->getFields();
$options = $index->options;
if ($index->hasStatus(ENTITY_OVERRIDDEN)) {
$options['fields'] += array(
'status' => array(
'type' => 'integer',
),
);
if ($install_demo_store) {
$options['fields'] += array(
'field_category:name' => array(
'type' => 'string',
),
);
}
if (!$index->update(array('options' => $options))) {
return '<strong style="color: red;">' . t("Important: We couldn't add the new fields to the index.") . '</strong>';
}
}
// Schedule the reindexing.
$index->clear();
search_api_index_items($index, 100);
}
}
......@@ -186,7 +186,7 @@ function _commerce_kickstart_taxonomy_menu($operation, &$context) {
$variable_name = _taxonomy_menu_build_variable('vocab_parent', $collection->vid);
variable_set($variable_name, '0');
$variable_name = _taxonomy_menu_build_variable('path', $collection->vid);
variable_set($variable_name, 'taxonomy_menu_path_default');
variable_set($variable_name, 'commerce_kickstart_taxonomy_term_path');
$variable_name = _taxonomy_menu_build_variable('rebuild', $collection->vid);
variable_set($variable_name, 1);
}
......@@ -327,8 +327,8 @@ function _commerce_kickstart_setup_blocks() {
'status' => 1,
'weight' => -30,
'region' => 'content',
'pages' => '',
'visibility' => 0,
'pages' => 'products',
'visibility' => BLOCK_VISIBILITY_LISTED,
'cache' => DRUPAL_NO_CACHE,
),
// Commerce checkout progress
......
......@@ -164,7 +164,7 @@ projects[i18n][subdir] = "contrib"
; Base theme.
projects[omega][version] = 3.1
projects[omega_kickstart][version] = 3.0-rc1
projects[omega_kickstart][version] = 3.x-dev
projects[shiny][version] = 1.0-rc1
; Libraries.
......
......@@ -142,6 +142,7 @@ function commerce_kickstart_lite_product_default_search_api_index() {
"cron_limit" : "50",
"fields" : {
"title" : { "type" : "string" },
"status" : { "type" : "integer" },
"created" : { "type" : "date" },
"field_product_category" : { "type" : "integer", "entity_type" : "taxonomy_term" },
"search_api_language" : { "type" : "string" },
......
......@@ -27,6 +27,5 @@ features[ctools][] = views:views_default:3.0
features[facetapi][] = search_api@product_display:block:field_product_category
features[features_api][] = api:1
features[rules_config][] = commerce_kickstart_add_to_cart_message
features[views_view][] = collection_taxonomy_term
features[views_view][] = confirm_message_product_display
features[views_view][] = shopping_cart
......@@ -60,6 +60,8 @@ function commerce_kickstart_lite_product_ui_enable() {
$collection = taxonomy_vocabulary_machine_name_load('product_category');
$variable_name = _taxonomy_menu_build_variable('vocab_menu', $collection->vid);
variable_set($variable_name, 'main-menu');
$variable_name = _taxonomy_menu_build_variable('path', $collection->vid);
variable_set($variable_name, 'commerce_kickstart_taxonomy_term_path');
// Set checkout panes order.
$pane_ids = array('cart_contents','account','customer_profile_billing','customer_profile_shipping');
......
......@@ -39,14 +39,7 @@ function commerce_kickstart_lite_product_ui_theme(&$existing) {
'path' => drupal_get_path('module', 'commerce_kickstart_lite_product_ui') . '/theme',
'template' => 'node--product--type--product--list',
),
'views_view__collection_taxonomy_term__page_1' => array(
'path' => drupal_get_path('module', 'commerce_kickstart_product_ui') . '/theme',
'template' => 'views-view--collection-taxonomy-term--page-1',
'arguments' => array('view' => NULL),
'base hook' => 'views_view',
),
);
return $themes;
}
......@@ -190,19 +183,3 @@ function commerce_kickstart_lite_product_ui_preprocess_entity(&$variables) {
$variables['url'] = "";
}
}
/**
* Implements hook_preprocess_views_view().
*
* Add collection term as view header.
*/
function commerce_kickstart_lite_product_ui_preprocess_views_view(&$vars) {
$view = $vars['view'];
if ($view->name == 'collection_taxonomy_term') {
if ($view->current_display == 'page_1') {
$tid = $view->args['0'];
$term = taxonomy_term_load($tid);
$vars['collection_title'] = $term->name;
}
}
}
<?php
/**
* @file
* Collection taxonomy term view template.
*
* Variables available:
* - $classes_array: An array of classes determined in
* template_preprocess_views_view(). Default classes are:
* .view
* .view-[css_name]
* .view-id-[view_name]
* .view-display-id-[display_name]
* .view-dom-id-[dom_id]
* - $classes: A string version of $classes_array for use in the class attribute
* - $css_name: A css-safe version of the view name.
* - $css_class: The user-specified classes names, if any
* - $header: The view header
* - $footer: The view footer
* - $rows: The results of the view query, if any
* - $empty: The empty text to display if the view is empty
* - $pager: The pager next/prev links to display, if any
* - $exposed: Exposed widget form/info to display
* - $feed_icon: Feed icon to display, if any
* - $more: A link to view more, if any
* - $collection_title: The collection term title
*
* @ingroup views_templates
*/
?>
<div class="<?php print $classes; ?>">
<?php print render($title_prefix); ?>
<?php if ($title): ?>
<?php print $title; ?>
<?php endif; ?>
<?php print render($title_suffix); ?>
<?php if ($header): ?>
<div class="view-header">
<div class="taxonomy-title" >
<?php if ($collection_title) : print $collection_title; endif;?>
</div>
<?php print $header; ?>
</div>
<?php endif; ?>
<?php if ($exposed): ?>
<div class="view-filters">
<?php print $exposed; ?>
</div>
<?php endif; ?>
<?php if ($attachment_before): ?>
<div class="attachment attachment-before">
<?php print $attachment_before; ?>
</div>
<?php endif; ?>
<?php if ($rows): ?>
<div class="view-content">
<?php print $rows; ?>
</div>
<?php elseif ($empty): ?>
<div class="view-empty">
<?php print $empty; ?>
</div>
<?php endif; ?>
<?php if ($pager): ?>
<?php print $pager; ?>
<?php endif; ?>
<?php if ($attachment_after): ?>
<div class="attachment attachment-after">
<?php print $attachment_after; ?>
</div>
<?php endif; ?>
<?php if ($more): ?>
<?php print $more; ?>
<?php endif; ?>
<?php if ($footer): ?>
<div class="view-footer">
<?php print $footer; ?>
</div>
<?php endif; ?>
<?php if ($feed_icon): ?>
<div class="feed-icon">
<?php print $feed_icon; ?>
</div>
<?php endif; ?>
</div><?php /* class view */ ?>
......@@ -301,6 +301,7 @@ function commerce_kickstart_product_default_search_api_index() {
"cron_limit" : "50",
"fields" : {
"title" : { "type" : "string" },
"status" : { "type" : "integer" },
"created" : { "type" : "date" },
"field_brand" : { "type" : "integer", "entity_type" : "taxonomy_term" },
"field_category" : { "type" : "integer", "entity_type" : "taxonomy_term" },
......@@ -313,6 +314,7 @@ function commerce_kickstart_product_default_search_api_index() {
"body:value" : { "type" : "text" },
"field_brand:name" : { "type" : "text" },
"field_brand:description" : { "type" : "text" },
"field_category:name" : { "type" : "string" },
"field_collection:name" : { "type" : "text" },
"field_collection:description" : { "type" : "text" },
"field_gender:name" : { "type" : "text" },
......
......@@ -39,6 +39,5 @@ features[facetapi][] = search_api@product_display:block:search_api_language
features[facetapi][] = search_api@product_display:block:title
features[features_api][] = api:1
features[rules_config][] = commerce_kickstart_add_to_cart_message
features[views_view][] = collection_taxonomy_term
features[views_view][] = confirm_message_product_display
features[views_view][] = shopping_cart
......@@ -43,14 +43,7 @@ function commerce_kickstart_product_ui_theme(&$existing) {
'path' => drupal_get_path('module', 'commerce_kickstart_product_ui') . '/theme',
'template' => 'commerce_product__product_in_cart',
),
'views_view__collection_taxonomy_term__page_1' => array(
'path' => drupal_get_path('module', 'commerce_kickstart_product_ui') . '/theme',
'template' => 'views-view--collection-taxonomy-term--page-1',
'arguments' => array('view' => NULL),
'base hook' => 'views_view',
),
);
return $themes;
}
......@@ -197,26 +190,6 @@ function commerce_kickstart_product_ui_field_create_instance($field) {
field_update_instance($instance);
}
/**
* Implements hook_preprocess_views_view().
*
* Add collection term as view header.
*/
function commerce_kickstart_product_ui_preprocess_views_view(&$vars) {
$view = $vars['view'];
if ($view->name == 'collection_taxonomy_term') {
if ($view->current_display == 'page_1') {
$tid = $view->args['0'];
$term = taxonomy_term_load($tid);
$vars['collection_title'] = $term->name;
$vars['collection_image_url'] = NULL;
if (!empty($term->field_image) && !empty($term->field_image[LANGUAGE_NONE][0]['uri'])) {
$vars['collection_image_url'] = file_create_url($term->field_image[LANGUAGE_NONE][0]['uri']);
}
}
}
}
/**
* Implements hook_block_info_alter().
*/
......
......@@ -38,6 +38,8 @@ function commerce_kickstart_search_install() {
db_update('block')
->fields(array(
'region' => 'sidebar_first',
'pages' => 'products',
'visibility' => BLOCK_VISIBILITY_LISTED,
'status' => (int) '1',
))
->condition('module', 'facetapi')
......@@ -49,4 +51,5 @@ function commerce_kickstart_search_install() {
watchdog_exception('block', $e);
throw $e;
}
}
name = Commerce Kickstart Taxonomy
description = Provides Kickstart-specific taxonomy customizations..
core = 7.x
package = Commerce Kickstart
php = 5.2.4
dependencies[] = taxonomy_menu
dependencies[] = commerce_kickstart_search
dependencies[] = views
; Views files
files[] = includes/views/handlers/commerce_kickstart_taxonomy_handler_field_text.inc
<?php
/**
* Implements hook_taxonomy_menu_path().
*/
function commerce_kickstart_taxonomy_taxonomy_menu_path() {
$output = array(
'commerce_kickstart_taxonomy_term_path' => t('Commerce Kickstart Taxonomy'),
);
return $output;
}
/**
* Implements hook_theme().
*/
function commerce_kickstart_taxonomy_theme(&$existing) {
$themes = array(
'views_view__collection_products__page' => array(
'path' => drupal_get_path('module', 'commerce_kickstart_taxonomy') . '/theme',
'template' => 'views-view--collection-products--page',
'arguments' => array('view' => NULL),
'base hook' => 'views_view',
),
);
return $themes;
}
/**
* Implements hook_preprocess_views_view().
*
* Add collection term as view header.
*/
function commerce_kickstart_taxonomy_preprocess_views_view(&$vars) {
$view = $vars['view'];
if ($view->name == 'collection_products') {
if ($view->current_display == 'page') {
// Keep the previous theming.
$vars['classes_array'][] = 'view-collection-taxonomy-term';
$tid = $view->args['0'];
$term = taxonomy_term_load($tid);
$vars['collection_title'] = $term->name;
$vars['collection_image_url'] = NULL;
if (!empty($term->field_image) && !empty($term->field_image[LANGUAGE_NONE][0]['uri'])) {
$vars['collection_image_url'] = file_create_url($term->field_image[LANGUAGE_NONE][0]['uri']);
}
}
}
}
/**
* Implements hook_entity_info_alter().
*/
function commerce_kickstart_taxonomy_entity_info_alter(&$entity_info) {
// Alter a URI callback to the taxonomy_term entity.
$entity_info['taxonomy_term']['uri callback'] = 'commerce_kickstart_taxonomy_term_uri';
}
/**
* Uri callback for the taxonomy terms.
*/
function commerce_kickstart_taxonomy_term_uri($taxonomy_term) {
$uri = 'taxonomy/term/' . $taxonomy_term->tid;
$machine_names = array(
'product_category',
'collection',
);
// Alter the default uri for those two vocabularies so that it point to our
// custom views.
if (in_array($taxonomy_term->vocabulary_machine_name, $machine_names)) {
$uri = $taxonomy_term->vocabulary_machine_name . '/' . $taxonomy_term->tid;
}
return array(
'path' => $uri,
);
}
/**
* Callback for hook_taxonomy_menu_path().
*/
function commerce_kickstart_taxonomy_term_path($vid, $tid) {
$vocabulary = taxonomy_vocabulary_load($vid);
if ($vocabulary) {
// if tid = 0 then we are creating the vocab menu item format will be taxonomy/term/$tid+$tid+$tid....
if ($tid == 0) {
// get all of the terms for the vocab
$vtids = _taxonomy_menu_get_terms($vid);
$end = implode(' ', $vtids);
$path = $vocabulary->machine_name . '/' . $end;
}
else {
$path = $vocabulary->machine_name . '/' . $tid;
if (variable_get(_taxonomy_menu_build_variable('display_decendants', $vid), FALSE)) {
// Use 'all' at the end of the path
if (variable_get(_taxonomy_menu_build_variable('end_all', $vid), FALSE)) {
$path .= '/all';
}
else {
// we wait to run this instead of during the if above
// because we only wan to run it once.
$terms = taxonomy_get_tree($vid, $tid);
foreach ($terms as $term) {
$tids[] = $term->tid;
}
if ($tids) {
$end = implode(' ', $tids);
$path .= ' ' . $end;
}
}
}
}
return $path;
}
else {
return taxonomy_menu_path_default($vid, $tid);
}
}
/**
* Implements hook_views_api().
*/
function commerce_kickstart_taxonomy_views_api() {
return array(
'api' => 3,
'path' => drupal_get_path('module', 'commerce_kickstart_taxonomy') . '/includes/views',
);
}
<?php
/**
* Implements hook_views_data_alter().
*/
function commerce_kickstart_taxonomy_views_data_alter(&$data) {
// Extend the default entity_views_handler_field_text for taxonomy.
if (isset($data['entity_taxonomy_term'])) {
foreach ($data['entity_taxonomy_term'] as $key => $field) {
if (isset($field['field']) && $field['field']['handler'] == 'entity_views_handler_field_text') {
$data['entity_taxonomy_term'][$key]['field']['handler'] = 'commerce_kickstart_taxonomy_handler_field_text';
}
}
}
}
<?php
/**
* @file
* Contains the commerce_kickstart_taxonomy_handler_field_text class.
*/
/**
* Extend the entity_views_handler_field_text to add needed enhancements.
*/
class commerce_kickstart_taxonomy_handler_field_text extends entity_views_handler_field_text {
/**
* Provide options for this handler.
*/
public function option_definition() {
return parent::option_definition() + array(
'replace_spaces' => array(
'default' => FALSE,
'bool' => TRUE,
),
);
}
/**
* Provide a options form for this handler.
*/
public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['replace_spaces'] = array(
'#type' => 'checkbox',
'#title' => t('Replace spaces with dashes'),
'#default_value' => $this->options['replace_spaces'],
);
}
/**
* Render a single field value.
*/
public function render_single_value($value, $values) {
$value = $this->sanitize_value($value, 'xss');
if (!empty($this->options['replace_spaces'])) {
$value = str_replace('-', '--', $value);
$value = str_replace(' ', '-', $value);
}
return $value;
}
}
......@@ -117,4 +117,4 @@
* Collection page
*/
.view-collection-taxonomy-term .view-content .item-list h3 span {
top: -70px; }
top: -90px; }
......@@ -126,7 +126,7 @@
.view-collection-taxonomy-term .view-content .item-list {
h3 {
span {
top: -70px;
top: -90px;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment