If this is your first visit, check our documentation. To post, register or login.

SQL question

Started by timhersh on 12 Sep 2012, 10:03 PM · Views: 1,392

Results 1 to 15 of 15
12 Sep 2012, 10:03 PM
#1
timhersh avatar

timhersh

Zen Follower

Join Date:
Aug 2008
Posts:
274
Plugin Contributions:
0

Post #1 by timhersh

This is a dumb question but I'm trying to add a products manufacturer name to the end all the products.

For example if the product is "Blue earrings" and the manufacterer's names is "Tim's Gemstones" then I would like to switch the name of that product to "Blue Earrings - Tim's Gemstones". For seo purposes.

Can someone help me with the sql for this please. I have access to my database but can't figure out the correct syntax.

Here is basically what I'm trying to do

Set zen_products_description.products_name Where zen_products.manufacturers_id = 5 zen_products_description.products_name+zen_products.manufacturers_id

thank you

12 Sep 2012, 10:13 PM
#2
lhungil avatar

lhungil

Totally Zenned

Join Date:
Feb 2012
Location:
mostly harmless
Posts:
1,816
Plugin Contributions:
4

Post #2 by lhungil

Why not just modify your templates instead of the database? The templates are used to customize how content is displayed on your website.

Otherwise if you must do this directly in the database, take a look at http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat. You may need to use nested statements to accomplish your goal of doing this with one SQL command.

The glass is not half full. The glass is not half empty. The glass is simply too big!
Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
Zen Cart related projects maintained by lhûngîl : Plugin / Module Tracker

13 Sep 2012, 2:00 PM
#3
timhersh avatar

timhersh

Zen Follower

Join Date:
Aug 2008
Posts:
274
Plugin Contributions:
0

Post #3 by timhersh

Thanks, that is a great idea.

Any idea which file I would edit and how to make it add the manufacturer-id to the end of the product name?

I would need it on this page

http://kgfinegifts.com/shop/index.php?main_page=index&cPath=2_23

and this page

http://kgfinegifts.com/shop/index.php?main_page=product_info&cPath=2_23&products_id=846

Ideally would like to display as

Product Name - Manf Name

thank you

13 Sep 2012, 2:03 PM
#4
stevesh avatar

stevesh

Black Belt

Join Date:
Feb 2005
Location:
Lansing, Michigan USA
Posts:
19,793
Plugin Contributions:
2

Post #4 by stevesh

I don't know how many products you have, so I don't know if it wouldn't be easier to just add the manufacturers name to the product name when you create/edit the product.

p.s. Your header is all messed up in Internet Explorer 8 (and 7).

13 Sep 2012, 2:07 PM
#5
timhersh avatar

timhersh

Zen Follower

Join Date:
Aug 2008
Posts:
274
Plugin Contributions:
0

Post #5 by timhersh

Thank you, I'll check it out in IE 8

Yeah it would be much easier to edit the templates or run an SQL statement if possible, she has 1100 products

thanks

17 Sep 2012, 1:33 PM
#6
lhungil avatar

lhungil

Totally Zenned

Join Date:
Feb 2012
Location:
mostly harmless
Posts:
1,816
Plugin Contributions:
4

Post #6 by lhungil

timhersh:

Any idea which file I would edit and how to make it add the manufacturer-id to the end of the product name?

I would need it on this page

http://kgfinegifts.com/shop/index.php?main_page=index&cPath=2_23
Product_listing is used to list products in a category I believe. The module file puts the product information into an array which is then used by tpl_tabular_display.php to display product listings (At least in the default templates, yours may differ).

timhersh:

and this page

http://kgfinegifts.com/shop/index.php?main_page=product_info&cPath=2_23&products_id=846
Take a look at tpl_product_info_display. This is used to display product_info for most products. Product types (if you use any custom product types) typically use product_xxxx_info_display where xxxx is the name of the product type.

Don't Forget
Use the override system! This will save you a fair amount of time in the future when upgrading or changing to a different template (or if your client changes their mind and decides they no longer want the MFG to be displayed).

Other thoughts
If the MFG name is intended to always be a part of the product name or should only be present for some products... you may want to look into messing around some more with SQL, writing some code in PHP to read / write the changes, or messing around with custom product types.

The glass is not half full. The glass is not half empty. The glass is simply too big!
Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
Zen Cart related projects maintained by lhûngîl : Plugin / Module Tracker

19 Sep 2012, 12:13 AM
#7
timhersh avatar

timhersh

Zen Follower

Join Date:
Aug 2008
Posts:
274
Plugin Contributions:
0

Post #7 by timhersh

[QUOTE=lhungil;1150872]Product_listing is used to list products in a category I believe. The module file puts the product information into an array which is then used by tpl_tabular_display.php to display product listings (At least in the default templates, yours may differ).

Thank you. I think I follow, but where is this file located tpl_tabular_display.php

I can't find it, or what line of code is in it that you are recommending me to change. I can search for it with the toolbox that way.

I'm using zen cart 1.39

thanks

19 Sep 2012, 9:11 PM
#8
lhungil avatar

lhungil

Totally Zenned

Join Date:
Feb 2012
Location:
mostly harmless
Posts:
1,816
Plugin Contributions:
4

Post #8 by lhungil

Changing the template for displaying product info ("includes/templates/<your template>/templates/tpl_product_info_display.php") is relatively easy. The other part is not...

The files used by default to display all product listings are listed below. It may take some time to familiarize yourself with them. Keep in mind changing those files may affect the search results page (for the built-in search feature). Alternatively you may want to create your own module / template for displaying the product list inside category pages :)

tpl_modules_product_listing.php: Used to display product listings (such as a category with products). Found at "includes/templates/<your template>/templates/tpl_modules_product_listing.php".

tpl_tabular_display.php: Used to display the list of products in a "tabular" format. Your templates may use a different file. Look in "tpl_modules_product_listing.php" to see what your template calls. Found at "includes/templates/<your template>/common/tpl_tabular_display.php".

product_listing.php: Used to create an array containing product listing information. Your templates may use a different file. Look in the above file to see what your template calls. Found at "includes/modules/product_listing.php". Should be copied to "includes/modules/<your template>/product_listing.php" and the copy edited, not the original.

The glass is not half full. The glass is not half empty. The glass is simply too big!
Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
Zen Cart related projects maintained by lhûngîl : Plugin / Module Tracker

24 Sep 2012, 7:11 PM
#9
timhersh avatar

timhersh

Zen Follower

Join Date:
Aug 2008
Posts:
274
Plugin Contributions:
0

Post #9 by timhersh

Thank you, I have it somewhat nailed down now.

It is one of these two files /includes/modules/premium6c/product_listing.php
or
/includes/modules/premium6c/product_listing_original.php

I'm not sure what to edit to make it display both, here is the piece I think I need to edit in product_listing_original.php

for ($col=0, $n=sizeof($column_list); $col<$n; $col++) {
switch ($column_list[$col]) {
case 'PRODUCT_LIST_MODEL':
$lc_text = TABLE_HEADING_MODEL;
$lc_align = '';
$zc_col_count_description++;
break;
case 'PRODUCT_LIST_NAME':
$lc_text = TABLE_HEADING_PRODUCTS + TABLE_HEADING_PRODUCTS;
$lc_align = '';
$zc_col_count_description++;
break;
case 'PRODUCT_LIST_MANUFACTURER':
$lc_text = TABLE_HEADING_MANUFACTURER;
$lc_align = '';
$zc_col_count_description++;
break;
case 'PRODUCT_LIST_PRICE':
$lc_text = TABLE_HEADING_PRICE;
$lc_align = 'right' . (PRODUCTS_LIST_PRICE_WIDTH > 0 ? '" width="' . PRODUCTS_LIST_PRICE_WIDTH : '');
$zc_col_count_description++;
break;
case 'PRODUCT_LIST_QUANTITY':
$lc_text = TABLE_HEADING_QUANTITY;
$lc_align = 'right';
$zc_col_count_description++;
break;
case 'PRODUCT_LIST_WEIGHT':
$lc_text = TABLE_HEADING_WEIGHT;
$lc_align = 'right';
$zc_col_count_description++;
break;
case 'PRODUCT_LIST_IMAGE':
$lc_text = TABLE_HEADING_IMAGE;
$lc_align = 'center';
$zc_col_count_description++;
break;
}

24 Sep 2012, 7:12 PM
#10
timhersh avatar

timhersh

Zen Follower

Join Date:
Aug 2008
Posts:
274
Plugin Contributions:
0

Post #10 by timhersh

Ideally would like to display as

Product Name - Manf Name

28 Sep 2012, 5:38 PM
#11
timhersh avatar

timhersh

Zen Follower

Join Date:
Aug 2008
Posts:
274
Plugin Contributions:
0

Post #11 by timhersh

Any help would be great, just not sure what to change

thanks

28 Sep 2012, 11:48 PM
#12
lhungil avatar

lhungil

Totally Zenned

Join Date:
Feb 2012
Location:
mostly harmless
Posts:
1,816
Plugin Contributions:
4

Post #12 by lhungil

I'm not entirely sure as I am not familiar with the template you are using (and I believe it is a paid template, so probably best to not distribute).

I know when I changed things to display differently for categories containing products in my custom template I ended up modifying both of those files. The first to change the data sent to the second and the second to generate the desired HTML.

Looking at your site however, you might be able to just go to "Admin > Configuration > All Listing" and change the settings for "display name" and "display mfg". Then you could just change

case 'PRODUCT_LIST_MANUFACTURER':
$lc_text = TABLE_HEADING_MANUFACTURER;

to

case 'PRODUCT_LIST_MANUFACTURER':
$lc_text = '- ' . TABLE_HEADING_MANUFACTURER;

You will need to change this in the table headings and also in the code further down the file which operates on the list of products.

The glass is not half full. The glass is not half empty. The glass is simply too big!
Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
Zen Cart related projects maintained by lhûngîl : Plugin / Module Tracker

30 Sep 2012, 7:09 PM
#13
schoolboy avatar

schoolboy

Totally Zenned

Join Date:
Jun 2005
Location:
Cumbria, UK
Posts:
10,327
Plugin Contributions:
0

Post #13 by schoolboy

I think you are over-egging this whole issue.

There is a FIELD for manufacturers, which are very important for "SEO" which is what you seem to be trying to achieve.

Furthermore, this would be a REQUIRED bit of data if you ever considered using Google Merchant Center (Google Shopping).

You could achieve a safe and reliable data update through EasyPopulate or Apsona ShopAdmin, adding manufacturers names to all products, by importing that string into the appropriate dbase field.

Tinkering around with the code is not necessary, and risky.

20 years a Zencart User

30 Sep 2012, 7:13 PM
#14
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Post #14 by kobra

schoolboy:

Tinkering around with the code is not necessary, and risky
I second this statement

Zen-Venom Get Bitten

1 Oct 2012, 9:12 PM
#15
lhungil avatar

lhungil

Totally Zenned

Join Date:
Feb 2012
Location:
mostly harmless
Posts:
1,816
Plugin Contributions:
4

Post #15 by lhungil

schoolboy:

There is a FIELD for manufacturers, which are very important for "SEO" which is what you seem to be trying to achieve.

You could achieve a safe and reliable data update through EasyPopulate or Apsona ShopAdmin, adding manufacturers names to all products, by importing that string into the appropriate dbase field.
If he wants to actually update the product name to include the MFG in the database, I agree. However this will cause some additional overhead in the database (although not enough for most people to care).

schoolboy:

I think you are over-egging this whole issue.
Tinkering around with the code is not necessary, and risky.
:book: I wanted to give the original author an idea of how data flows through Zen Cart including how to use overrides and templates and yes my first responses were a bit much. Definately "over-egged". But the information should still be useful to others who might want to more heavily modify things.

After reviewing the existing options in my installations I posted a simpler solution. It has only 2 parts (but may require 1.5.x).

  1. Use "Admin > Configuration > All Listing". Changing these will tell the cart to show/hide the MFG (or product) name, what sort order to use, and the number of (line) breaks after the name.
  2. Small edit to one custom template file to add the " - " between the product name and mfg. Although one could use CSS for most modern browsers to add the " - ", I tend to prefer a server-side solution.

The glass is not half full. The glass is not half empty. The glass is simply too big!
Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
Zen Cart related projects maintained by lhûngîl : Plugin / Module Tracker