custom product field

Locked

Started by chronicsys on 16 Jun 2008, 11:38 AM · Views: 6,758

Results 1 to 15 of 15
This thread is locked. New replies are disabled.
16 Jun 2008, 11:38 AM
#1
chronicsys avatar

chronicsys

New Zenner

Join Date:
Jun 2008
Posts:
2
Plugin Contributions:
0

custom product field

hi,

i have added a new product field to me products table by following this great post from crazy_chris: http://www.zen-cart.com/forum/showthread.php?t=57924

everything works fine. i am able to edit values from admin and see results on product info page. http://www.zen-cart.com/forum/images/smilies/cool.gif

i need to output this field on the product listing page - have been tryin in vain for a couple of days and have hit a brick wall it seems. must be missing something.

in my custom product_listing.php template i can output any existing product fields with " $listing->fields['products_id']) "

as soon as i try to reference my new field " $listing->fields['products_image_orientation']) " - it fails and outputs nothing. the same syntax works on product info page - no problem.

can anyone point out what i am missing .... a thousand thank you's in advance .....

[as you can see - i wish to store the orientation of my artwork / prints .... i tried initially to just calulate (width divided by height) but could not figure that out so opted to hard code it as a product attribute]

http://www.zen-cart.com/forum/images/smilies/blink.gif

19 Nov 2008, 4:47 AM
#2
stevecollins avatar

stevecollins

New Zenner

Join Date:
Aug 2005
Location:
Southampton
Posts:
80
Plugin Contributions:
0

Re: custom product field

I too have followed the instructions as found in the link above, and I would like it to show in my product listing. Has anyone found the answer to this question as I really need to get this onto the listing page as soon as possible. No-one seems to be answering any of the questions concerning this issue.

19 Nov 2008, 5:25 AM
#3
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,874
Plugin Contributions:
8

Re: custom product field

Does the SQL query for the product listing retrieve the new field's value? You would probably need to edit that before you can use it in the listing.

19 Nov 2008, 12:56 PM
#4
stevecollins avatar

stevecollins

New Zenner

Join Date:
Aug 2005
Location:
Southampton
Posts:
80
Plugin Contributions:
0

Re: custom product field

What I have done so far is add a field on the product info page called products_delivery which is editable through admin. The database has been altered to allow for the extra field and all shows up on the product info page. I now need this field to be shown on the product listing page in order for the information to be seen by all customers so that they do not complain about delivery dates.

I have downloaded product_listing.php to see if there is anything that is obvious for me to customise but I cannot see where to start. I know that I must pull the information from the database in order for this to be shown, but not quite sure how to do it.

20 Nov 2008, 8:36 AM
#5
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,874
Plugin Contributions:
8

Re: custom product field

At the top of product_listing.php, this gets the data to be used: ```php
$listing_split = new splitPageResults($listing_sql, MAX_DISPLAY_PRODUCTS_LISTING, 'p.products_id', 'page');

so you would have to find the file where splitPageResults is built (in a /functions/ or /classes/ folder, most likely) and add to the SQL query there.
21 Nov 2008, 12:51 AM
#6
stevecollins avatar

stevecollins

New Zenner

Join Date:
Aug 2005
Location:
Southampton
Posts:
80
Plugin Contributions:
0

Re: custom product field

Me no understand!!! Am I to edit the product_listing.php file or some other file? If so where do I find this other file and what do I add?

21 Nov 2008, 1:00 AM
#7
stevecollins avatar

stevecollins

New Zenner

Join Date:
Aug 2005
Location:
Southampton
Posts:
80
Plugin Contributions:
0

Re: custom product field

I currently have a field set up in my database and the product info page called products_delivery that works well. But I need to be able to display this in the product listing page. Do I add this to the product listing page and how?

21 Nov 2008, 10:40 AM
#8
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,874
Plugin Contributions:
8

Re: custom product field

Use the Developers Toolkit in admin > Tools to find the file where splitPageResults is built (see the tutorials if you don't know how to use it yet). That file is most likely the place to modify the SQL query to also retrieve your products_delivery field.

Once you have retrieved it, you can use it in product_listing.php the same way as in the product info page.

23 Nov 2008, 3:09 PM
#9
stevecollins avatar

stevecollins

New Zenner

Join Date:
Aug 2005
Location:
Southampton
Posts:
80
Plugin Contributions:
0

Re: custom product field

There are lots of places where splitPageResults is found but I cannot see where or what I am supposed to put the info that is needed. There is also a splitPageResults.php file in /includes/classes. Where am I supposed to place products_delivery? Am I also to edit the product_listing.php file with the same info in the splitPageResults section? Is there anywhere else that I am supposed to edit and what am I meant to change?

I appreciate your time and effort in replying to my enquiry, but there are so many questions that are being raised by the answers given that I am not really acheiving anything. I need more specific information in order to get to the results that are needed. I am okish with PHP, good with HTML and useless with SQL, JAVASCRIPT and most other scripts. It is important that any info given doesn't just point me in the right direction, but gives me accurate and precise information about how to include the field that I require in the product_listing page.

If you have not the time or the info please just say and I will appreciate your efforts in helping me.

23 Nov 2008, 4:22 PM
#10
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,874
Plugin Contributions:
8

Re: custom product field

I believe /includes/classes/splitPageResults.php will be the file to edit, but I can't tell you definitively how to edit the SQL query.

If you know what you did to get the new field into the product info page, the addition to the SQL should be quite similar if not the same. Be careful about this, as splitPageResults may also be used in other situations where you don't want to change. It may make no difference to other locations if the new field is available and unused there.

23 Nov 2008, 4:34 PM
#11
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,874
Plugin Contributions:
8

Re: custom product field

Just looked at it and the splitPageResults function takes the SQL query as one of its arguments, so in your case you would have to modify the $listing_sql variable used in product_listing.php:```php
$listing_split = new splitPageResults($listing_sql, MAX_DISPLAY_PRODUCTS_LISTING, 'p.products_id', 'page');


/includes/index_filters/default_filter.php

looks like the place. There are a number of different versions of $listing_sql built there, so we'll have to find the right one.
23 Nov 2008, 5:58 PM
#12
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,874
Plugin Contributions:
8

Re: custom product field

In default_filter.php
it looks like you would add your
p.products_delivery (assuming it is in the products table)
to the "select" list in line 27:php // We are asked to show only a specific category $listing_sql = "select " . $select_column_list . " p.products_id, p.products_type, p.master_categories_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, pd.products_description, if(s.status = 1, s.specials_new_products_price, NULL) AS specials_new_products_price, IF(s.status = 1, s.specials_new_products_price, p.products_price) as final_price, p.products_sort_order, p.product_is_call, p.product_is_always_free_shipping, p.products_qty_box_status and the same way in line 42:```php
// We show them all
$listing_sql = "select " . $select_column_list . " p.products_id, p.products_type, p.master_categories_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, pd.products_description, IF(s.status = 1, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status = 1, s.specials_new_products_price, p.products_price) as final_price, p.products_sort_order, p.product_is_call, p.product_is_always_free_shipping, p.products_qty_box_status


Alternatively, you might need to add your field to the $select_column_list variable built in 
/includes/modules/pages/index/main_template_vars.php around line 157. This looks like it also requires some prep work, adding to $define_list above it:```php
  // create column list
  $define_list = array('PRODUCT_LIST_MODEL' => PRODUCT_LIST_MODEL,
  'PRODUCT_LIST_NAME' => PRODUCT_LIST_NAME,
  'PRODUCT_LIST_MANUFACTURER' => PRODUCT_LIST_MANUFACTURER,
  'PRODUCT_LIST_PRICE' => PRODUCT_LIST_PRICE,
  'PRODUCT_LIST_QUANTITY' => PRODUCT_LIST_QUANTITY,
  'PRODUCT_LIST_WEIGHT' => PRODUCT_LIST_WEIGHT,
  'PRODUCT_LIST_IMAGE' => PRODUCT_LIST_IMAGE);

  /*                         ,
  'PRODUCT_LIST_BUY_NOW' => PRODUCT_LIST_BUY_NOW);
  */
  asort($define_list);
  reset($define_list);
  $column_list = array();
  foreach ($define_list as $key => $value)
  {
    if ($value > 0) $column_list[] = $key;
  }

  $select_column_list = '';

  for ($i=0, $n=sizeof($column_list); $i<$n; $i++)
  {
    switch ($column_list[$i])
    {
      case 'PRODUCT_LIST_MODEL':
      $select_column_list .= 'p.products_model, ';
      break;
      case 'PRODUCT_LIST_NAME':
      $select_column_list .= 'pd.products_name, ';
      break;
      case 'PRODUCT_LIST_MANUFACTURER':
      $select_column_list .= 'm.manufacturers_name, ';
      break;
      case 'PRODUCT_LIST_QUANTITY':
      $select_column_list .= 'p.products_quantity, ';
      break;
      case 'PRODUCT_LIST_IMAGE':
      $select_column_list .= 'p.products_image, ';
      break;
      case 'PRODUCT_LIST_WEIGHT':
      $select_column_list .= 'p.products_weight, ';
      break;
    }
  }
```Something like


  'PRODUCT_LIST_DELIVERY' => PRODUCT_LIST_DELIVERY

where PRODUCT_LIST_DELIVERY is a constant defined by you in a similar way as the other constants in that list. This will require some research to find where those constants are defined and what they say. It probably also gets deeper into setting up a switch in admin to set the sort/display order of the new field, assuming you want to be able to control the behavior of the new field in the product listing. 

If you can just piggyback the new field onto another field so it always displays with it, you can probably avoid this work. 
Something like```php
      case 'PRODUCT_LIST_WEIGHT':
      $select_column_list .= 'p.products_weight, ';
      $select_column_list .= 'p.products_delivery, ';
      break;
```if you want the weight and delivery to show together.

I'm sure there is more involved in this whole process, but that's all I have time to look into right now.
27 Nov 2008, 5:45 PM
#13
stevecollins avatar

stevecollins

New Zenner

Join Date:
Aug 2005
Location:
Southampton
Posts:
80
Plugin Contributions:
0

Re: custom product field

Thank you very much for your assistance. Your help is greatly appreciated.

3 Feb 2009, 1:16 AM
#14
marcopolo avatar

marcopolo

Totally Zenned

Join Date:
May 2008
Location:
United States
Posts:
525
Plugin Contributions:
2

Re: custom product field

I'm having this same issue, the below quote was a perfect explanation! However no solution was ever posted? Can someone from development please point me in the right direction to solve this issue? I added a new product field in the products table called: products_review_id

I need to call the field contents from the product_listing.php page. I can get the product id field to populate using this code: '.$listing->fields['products_id'].' ** However is I change it to: '.$listing->fields['products_review_id'].'** it is now working?

chronicsys:

hi,

i have added a new product field to me products table by following this great post from crazy_chris: http://www.zen-cart.com/forum/showthread.php?t=57924

everything works fine. i am able to edit values from admin and see results on product info page. http://www.zen-cart.com/forum/images/smilies/cool.gif

i need to output this field on the product listing page - have been tryin in vain for a couple of days and have hit a brick wall it seems. must be missing something.

in my custom product_listing.php template i can output any existing product fields with " $listing->fields['products_id']) "

as soon as i try to reference my new field " $listing->fields['products_image_orientation']) " - it fails and outputs nothing. the same syntax works on product info page - no problem.

can anyone point out what i am missing .... a thousand thank you's in advance .....

[as you can see - i wish to store the orientation of my artwork / prints .... i tried initially to just calulate (width divided by height) but could not figure that out so opted to hard code it as a product attribute]

http://www.zen-cart.com/forum/images/smilies/blink.gif

marcopolo
Zen Cart 2.2.2 | PHP 8.5.12 | MariaDB 10.11.14

3 Feb 2009, 1:42 AM
#15
marcopolo avatar

marcopolo

Totally Zenned

Join Date:
May 2008
Location:
United States
Posts:
525
Plugin Contributions:
2

Re: custom product field

Ok I figured it out :) If someone can just verify this is the correct solution, that would be nice!

I added:

Original:
$select_column_list = '';

Modified:
$select_column_list = 'p.products_review_id,';

to this file:
\includes\modules\pages\index*main_template_vars.php*

marcopolo
Zen Cart 2.2.2 | PHP 8.5.12 | MariaDB 10.11.14