Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Adding field to product table and updating from admin

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 06-11-2004, 09:56 AM
  adpboss's Avatar 
adpboss adpboss is offline
 

X-Man
  
Join Date: Feb 2003
Location: Ontario, Canada
Posts: 2,389
 

Default Adding field to product table and updating from admin

** SOLUTION is 6 posts or so below **

I'm trying to add a checkbox field to my products table and update it through the product modify in the backend.

I keep getting errors. So frustrated.

I'm trying to add a field called discontinued that would be a yes/no checkbox.

The problem is either in the product_modify.tpl or in the include/product_modify.php files. I could have swore that there is a post here that covers this but after searching for 2 hours, I give up.

HELP ME PLEASE.

here is where I added to my product_modify.php

Code:
# # Update product data # db_query("update $sql_tbl[products] set product='$product', categoryid='$categoryid', categoryid1='$categoryid1', categoryid2='$categoryid2', categoryid3='$categoryid3', brand='$brand', model='$model', descr='$descr', fulldescr='$fulldescr', avail='$avail', list_price='$list_price', weight='$weight', productcode='$productcode', forsale='$forsale', distribution='$distribution', free_shipping='$free_shipping', shipping_freight='$shipping_freight', discount_avail='$discount_avail', min_amount='$min_amount', param00='$param00', param01='$param01', param02='$param02', param03='$param03', param04='$param04', param05='$param05', param06='$param06', param07='$param07', param08='$param08', param09='$param09', low_avail_limit='$low_avail_limit', free_tax' $apply_canadian_taxes where productid='$productid' discontinued='$discontinued'");

and here is my .tpl

Code:
<TD class=ProductDetails height="11">{$lng.lbl_apply_global_discounts}</TD> <TD class=ProductDetails height="11"> <INPUT type=checkbox name=discount_avail value="Y" {if $product.discontinued ne ""}checked{elseif $product.discount_avail eq "Y"}checked{/if}> </TD> </TR> <TR> <TD class=ProductDetails height="11">{$lng.lbl_discontinued}</TD> <TD class=ProductDetails height="11"> <INPUT type=checkbox name=discontinued value="Y" {if $product.productid eq ""}checked{elseif $product.discontinued eq "Y"}checked{/if}> </TD> </TR>
Reply With Quote
  #2  
Old 06-11-2004, 11:21 AM
  TelaFirma's Avatar 
TelaFirma TelaFirma is offline
 

X-Adept
  
Join Date: Nov 2002
Location: North Carolina USA
Posts: 930
 

Default

What did you set that field as in MySQL? (data type, length...)
Reply With Quote
  #3  
Old 06-11-2004, 12:34 PM
  adpboss's Avatar 
adpboss adpboss is offline
 

X-Man
  
Join Date: Feb 2003
Location: Ontario, Canada
Posts: 2,389
 

Default

CHAR, 1, Not null, Default = N

I basically copied the field attributes from apply_pst/apply_gst.
Reply With Quote
  #4  
Old 06-11-2004, 01:14 PM
  BCSE's Avatar 
BCSE BCSE is online now
 

X-Guru
  
Join Date: Apr 2003
Location: Ohio - bcsengineering.com
Posts: 3,060
 

Default

I think you want it to be like this:

Code:
# # Update product data # db_query("update $sql_tbl[products] set product='$product', categoryid='$categoryid', categoryid1='$categoryid1', categoryid2='$categoryid2', categoryid3='$categoryid3', brand='$brand', model='$model', descr='$descr', fulldescr='$fulldescr', avail='$avail', list_price='$list_price', weight='$weight', productcode='$productcode', forsale='$forsale', distribution='$distribution', free_shipping='$free_shipping', shipping_freight='$shipping_freight', discount_avail='$discount_avail', min_amount='$min_amount', param00='$param00', param01='$param01', param02='$param02', param03='$param03', param04='$param04', param05='$param05', param06='$param06', param07='$param07', param08='$param08', param09='$param09', low_avail_limit='$low_avail_limit', free_tax' $apply_canadian_taxes discontinued='$discontinued' where productid='$productid' ");

See how I moved the discontinued= infront of the where. See if this helps.

Carrie
__________________
Custom Development, Custom Coding and Pre-built modules for X-cart since 2002!

We support X-cart versions 3.x through 5.x!

Home of the famous Authorize.net DPM & CIM Modules, Reward Points Module, Point of Sale module, Speed Booster modules and more!


Over 200 X-cart Mods available & Thousands of Customizations Since 2002 - bcsengineering.com

Please E-Mail us for questions/support!
Reply With Quote
  #5  
Old 06-12-2004, 06:55 AM
  adpboss's Avatar 
adpboss adpboss is offline
 

X-Man
  
Join Date: Feb 2003
Location: Ontario, Canada
Posts: 2,389
 

Default

I'm gonna fix that now, thanks so much Carrie. I feel like for not catching that. That was probably the problem.

My advice to anyone. If you are frustrated, walk away. Sometimes, you will not be able to see the answer in front of you.
Reply With Quote
  #6  
Old 06-12-2004, 07:06 AM
  BCSE's Avatar 
BCSE BCSE is online now
 

X-Guru
  
Join Date: Apr 2003
Location: Ohio - bcsengineering.com
Posts: 3,060
 

Default

No problem. I find the same thing. I get so burnt out and wraped up in code sometimes, it's just a simple semicolon or missordering of something that gets resolved by just walking away and taking a break!

Post the errors you're getting if that doesn't completely fix it. And maybe we can figure it out.

Carrie
__________________
Custom Development, Custom Coding and Pre-built modules for X-cart since 2002!

We support X-cart versions 3.x through 5.x!

Home of the famous Authorize.net DPM & CIM Modules, Reward Points Module, Point of Sale module, Speed Booster modules and more!


Over 200 X-cart Mods available & Thousands of Customizations Since 2002 - bcsengineering.com

Please E-Mail us for questions/support!
Reply With Quote
  #7  
Old 06-12-2004, 07:37 AM
  adpboss's Avatar 
adpboss adpboss is offline
 

X-Man
  
Join Date: Feb 2003
Location: Ontario, Canada
Posts: 2,389
 

Default

Well my code above was a complete mess but I got it working now.

To add a checkbox field to the xcart_products table and have it updateable in the admin here we go (3.5.7)

Edit skin1/main/product_modify.tpl and add

Code:
<TR> <TD class=ProductDetails height="11">{$lng.lbl_discontinued}</TD> <TD class=ProductDetails height="11"> <INPUT type=checkbox name=discontinued value="N" {if $product.discontinued eq "Y"}checked{/if}> </TD> </TR>

where you want it to appear, I added it after the </tr> for discount avail. You will need to create a language label tag (in my example I am using discontinued) to identify what the checkbox is for {$lng.lbl_discontinued}.

Be sure to add a field to the end of your xcart_products database table.

The attributes should be

Quote:
Field name (whatever you want), CHAR, 1, Not Null, and in my case default should = N.

Lastly you need to modify include/product_modify.php

Change this area

Code:
# # Update product data # db_query("update $sql_tbl[products] set product='$product', categoryid='$categoryid', categoryid1='$categoryid1', categoryid2='$categoryid2', categoryid3='$categoryid3', brand='$brand', model='$model', descr='$descr', fulldescr='$fulldescr', avail='$avail', list_price='$list_price', weight='$weight', productcode='$productcode', forsale='$forsale', distribution='$distribution', free_shipping='$free_shipping', shipping_freight='$shipping_freight', discount_avail='$discount_avail', min_amount='$min_amount', param00='$param00', param01='$param01', param02='$param02', param03='$param03', param04='$param04', param05='$param05', param06='$param06', param07='$param07', param08='$param08', param09='$param09', low_avail_limit='$low_avail_limit', $apply_vat free_tax='$free_tax' $apply_canadian_taxes where productid='$productid'");

to

Code:
# # Update product data # db_query("update $sql_tbl[products] set product='$product', categoryid='$categoryid', categoryid1='$categoryid1', categoryid2='$categoryid2', categoryid3='$categoryid3', brand='$brand', model='$model', descr='$descr', fulldescr='$fulldescr', avail='$avail', list_price='$list_price', weight='$weight', productcode='$productcode', forsale='$forsale', distribution='$distribution', free_shipping='$free_shipping', shipping_freight='$shipping_freight', discount_avail='$discount_avail', min_amount='$min_amount', param00='$param00', param01='$param01', param02='$param02', param03='$param03', param04='$param04', param05='$param05', param06='$param06', param07='$param07', param08='$param08', param09='$param09', low_avail_limit='$low_avail_limit', discontinued='$discontinued', $apply_vat free_tax='$free_tax' $apply_canadian_taxes where productid='$productid'");

You'll notice that everywhere in the above I am using discontinued. This is the name of the field I wanted to add and should make it easy for you to find all of my changes.

Thanks to BCSE and Telafirma for lending their ears.

Can we get this added to Custom mods? I spent two hour looking for this information before starting this thread.

Keywords: insert checkbox, insert field, add field, product modify
Reply With Quote
  #8  
Old 06-12-2004, 05:01 PM
  adpboss's Avatar 
adpboss adpboss is offline
 

X-Man
  
Join Date: Feb 2003
Location: Ontario, Canada
Posts: 2,389
 

Default

I should also add that you can now use this checkbox field in the skin1/customer/main/product.tpl such as

{if $product.discontinued eq "N"}DO THIS{/if}

Very handy for being able to turn on and off specific features in individual products.
Reply With Quote
  #9  
Old 09-16-2005, 11:35 AM
 
Lucent88 Lucent88 is offline
 

Senior Member
  
Join Date: Aug 2005
Posts: 147
 

Default

Hi, I'm on v4.0.15.

I am just wondering would this code still work? would it interfere with the standard extra field on xcart?

Just needed to make sure since this post is from 2years ago.
__________________
X-Cart Gold 4.0.17
Reply With Quote
  #10  
Old 09-16-2005, 02:49 PM
 
Lucent88 Lucent88 is offline
 

Senior Member
  
Join Date: Aug 2005
Posts: 147
 

Default

Hi,

I created fields in my SQL, and that went well.

Then, I edited include/product_modify.php , that went ok, too.

Then I edited my skin1/main/product_details.tpl
(here you listed product_modify.tpl but I guess v4. that changed to product_details.tpl)

well.. so far everything looks good, but when I went in to admin, all those field I added doesn't update to the database.

Is there anyother places I need to modify the code in order to get the value updated to the database?

any tips would be great, thank you.
__________________
X-Cart Gold 4.0.17
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 07:29 AM.

   

 
X-Cart forums © 2001-2020