Jump to content

Including Product Identifiers in Search Results (UPC, ISBN, JAN, MPN, etc).


traylor23

Recommended Posts

Let's look at Advanced Search. This page gets populated and rendered in the CubeCart->_search() private function. This function gathers certain information, prepares it if necessary, and assigns it to respective template variables. Currently, the only info that needs to be prepared is the list of manufacturers (and maybe a list of sort choices). There is a hook allowing to gather and process more info to be shown on a customized template.

The search parameters get POSTed to the CubeCart->_category() private function. The search term(s) get logged in the Search Log. (See in Admin, Statistics.) In this function, the search parameters are passed to the Catalogue->searchCatalogue() function.

Right at the start of searchCatalogue() is a hook allowing to add more search parameters. For example, a new search parameter might be:
$where[]="I.isbn='978-1-890774-44-8'";

One needs to figure out how to get a search term and the database table and column identified. One suggestion is to enter a term that looks like:
"ISBN::978-1-890774-44-8"

The code would explode() the string on the '::' to an array, list() the array elements to $custom_key and $custom_value, and finally:
$where[] = "I." . strtolower($custom_key) . "=" . $custom_value;

Looking at columns in another table is a bit more involved by pushing strings onto the $join array.

The search code should continue with appropriate results retrieved from the database.

The mentioned hooks are the tools you use to get CubeCart to do what you want. And in Admin, Manage Hooks, Code Snippets tab is where these tools are created.

Link to comment
Share on other sites

Hmm. I appreciate the reply, but I'm not really following what I need to do.

I'll give an example of a product, and in turn, I'm hoping I can get some guidance on how specifically to add what I'm trying to allow customers to search for in the easiest terms possible:

Here is a link:

https://www.ballcardz.com/2018-panini-playoff-42-geno-atkins-football-card

Under the "Product Specifications" tab, I have changed the GTIN Code language, to Team, and this player happens to play for the Cincinnati Bengals. I would like for a customer to be able search for all Cincinnati Bengals players by either typing in the whole team name, the city, or just the team name, understanding that if just Cincinnati is typed in, that any other team from Cincinnati will populate, and that's ok.

Thanks, as always, for your amazing assistance, BSmither.

Link to comment
Share on other sites

So, if the product's description made mention that this card/player is associated with the Cincinnati Bengals, how would CubeCart's search not find this?

I assume, then, that for good reason, the description will not or cannot make this mention. Maybe using GTIN is a more broadly appropriate solution?

I am also thinking of a different solution -- changing the columns that CubeCart searches in. The first search looks in the aggregate of the product code, product name, and description. If a (rather weird) search fails to find results, a second search is made against whole words that might be found in any of these columns. If that fails, a third search is made using the given string of characters that might be found as a part of any word in any of those columns.

The current problem is that the first search uses the columns declared as a group (fulltext), but the second and third search uses hard-coded names of columns.

The idea is to change the FULLTEXT search group to include GTIN. This action must be performed directly against the database. To solve the problem mentioned above, there must be some edits to the code.

Creating a Code Snippet is better than this solution. I will be back later with a suggested snippet.

 

Link to comment
Share on other sites

9 hours ago, bsmither said:

So, if the product's description made mention that this card/player is associated with the Cincinnati Bengals, how would CubeCart's search not find this?

I assume, then, that for good reason, the description will not or cannot make this mention. Maybe using GTIN is a more broadly appropriate solution?

 

Cubecart does a decent enough job with search if it’s keywords in the title or description. The problem for me is workflow efficiency. With as many products as I envision adding, I need the team name to be its own field. Cutting and pasting whole columns of data is way easier than splicing data into existing fields (titles/descriptions). 
 

Instead of trying to create a new database item, I figured I’d utilize one that I have no other use for. Just seems easier to me. That being said, I would just like this data to appear in search.

Thanks, again, for helping all of us with our rather trivial requests.

Link to comment
Share on other sites

If so, then using a programmer's text editor, in the file /classes/catalogue.class.php:

Near line 1990, find:

$indexes = $GLOBALS['db']->getFulltextIndex('CubeCart_inventory', 'I');

Change to:

// $indexes = $GLOBALS['db']->getFulltextIndex('CubeCart_inventory', 'I');

Near line 1786, find:

$original_search_data = $search_data;

After that line, add this:

$indexes = $GLOBALS['db']->getFulltextIndex('CubeCart_inventory', 'I');

This edit just moves the statement to a place above the hook call. A Code Snippet will be used to add a column of the Inventory database table to search for keywords.

In admin, Manage Hooks, Code Snippets tab, click the Add Snippet link. When the Snippet form appears, enter:

Enabled: checked
Unique ID: add_search_columns@CC6
Execution Order: 1
Description: Adds more text columns to search on the CubeCart_inventory table.
Trigger: class.catalogue.pre_search
Version: 1.0
Author: https://forums.cubecart.com/topic/58751-including-product-identifiers-in-search-results-upc-isbn-jan-mpn-etc/
PHP Code:
<?php
/* Specify the name of the column,
 * with 'I' table identifier,
 * of the CubeCart_inventory table
 * to search for keywords.
 */
$indexes[] = 'I.gtin';

Save.

Test.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...