pathauto hook for uc_product

Project:Ubercart Contributions
Component:Code
Category:
Priority:normal
Assigned:Unassigned
Status:patch (needs review)
Description
Project: 
Ubercart

Hook for pathauto that allows product SKU to be used in the URL.

It would be easy to add other fields (eg, weight, price), but I couldn't see the purpose.

--- uc_product.module.orig      2007-10-04 10:48:25.000000000 -0400
+++ uc_product.module   2007-10-21 20:24:54.000000000 -0400
@@ -2341,3 +2341,20 @@
   return 'node/'. $data['nid'] .'/edit/features';
}

+/** Implementation of hook_pathauto_node()
+ */
+function uc_product_pathauto_node($op, $node = false) {
+  switch ($op) {
+    case 'placeholders':
+      $placeholders = array(
+        '[uc_model]' => t('Ubercart Product Model/SKU'),
+      );
+      return $placeholders;
+    case 'values':
+      $values = array();
+      if ($node) {
+        $values['[uc_model]'] = (isset($node->model) ? $node->model : '');
+      }
+      return $values;
+  }
+}

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: pathauto hook for uc_product

What version of pathauto are you using? I got the latest version, and this doesn't work. I looked into it, and I can't find any place where this hook is being called. Of course, Pathauto 2.0 is still in beta, so I don't know how much people want to use it.

I think if you want to support the newest pathauto, you need to implement hook_token_list and hook_token_values.

gregmac's picture
Offline
Getting busy with the Ubercode.
Joined: 09/25/2007
Juice: 87
I have pathauto 5.x-1.2 I
Assigned to:Lyle» gregmac

I have pathauto 5.x-1.2

I didn't realize that 2.0 was different.. if they've actually changed the hook name it is probably trivial to support both (eg, just add hook_token_* in addition to hook_pathauto_node)

milesenglish's picture
Offline
Joined: 12/26/2008
Juice: 55
Re: I have pathauto 5.x-1.2 I
Assigned to:gregmac» milesenglish

I'd like to try this; are there instructions on what to do with the code above?

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: Re: I have pathauto 5.x-1.2
Assigned to:milesenglish» Lyle

The code above is in patch format, and instructions for applying patches is found at http://drupal.org/patch/apply.

Since it's a simple patch, I can tell you how to do it manually.
The first line tells you the name of the file that's being changed. The line with the @@ tells you the line number where the code block starts, followed by the number of lines to look at after it. For any lines with a - in the first column, delete them. For +, add them.

This patch adds an entire function to the uc_product.module, so you can add it wherever you like. Just be sure to remove the + column from the actual code.