Hi,
suppose I'm using views to display product (not using display node)
1. I create product listing view page, supplying product link with: /product/[product-title]
example: /product/shirt5
2. I create individual product view page , with path: /product/%
accepting argument: product ID

How the product view page know the product ID , since the link I supply in the listing is [product-title]?
or how to transform product title argument to product ID ?
thanks

Comments

josephsergio’s picture

I am having a similar issue - I want to have a different view on seperate product pages (for examples) Tshirts / Vnecks / Tanks

How would I go about this?

rszrama’s picture

Status: Active » Fixed

To determine the product to display from the URL, you have to use what Views 3 calls a "Contextual Filter" (was an "Argument" in Views 2 and prior). The problem is that for products, the only argument Drupal Commerce provides at the moment is by Product ID. You actually can't use Product titles, because they're not unique, but an argument could be written that works based on Product SKUs, which could still contain search engine friendly terms.

Here's an example View that will get you part of the way there:


$view = new view;
$view->name = 'product';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'commerce_product';
$view->human_name = 'Product';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Product';
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Field: Commerce Product: Product ID */
$handler->display->display_options['fields']['product_id']['id'] = 'product_id';
$handler->display->display_options['fields']['product_id']['table'] = 'commerce_product';
$handler->display->display_options['fields']['product_id']['field'] = 'product_id';
/* Contextual filter: Commerce Product: SKU */
$handler->display->display_options['arguments']['sku']['id'] = 'sku';
$handler->display->display_options['arguments']['sku']['table'] = 'commerce_product';
$handler->display->display_options['arguments']['sku']['field'] = 'sku';
$handler->display->display_options['arguments']['sku']['default_action'] = 'not found';
$handler->display->display_options['arguments']['sku']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['sku']['default_argument_skip_url'] = 1;
$handler->display->display_options['arguments']['sku']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['sku']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['sku']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['arguments']['sku']['glossary'] = 0;
$handler->display->display_options['arguments']['sku']['limit'] = '0';
$handler->display->display_options['arguments']['sku']['transform_dash'] = 0;
$handler->display->display_options['arguments']['sku']['break_phrase'] = 0;

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'product/%';

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.