X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Adding field to product table and updating from admin (https://forum.x-cart.com/showthread.php?t=8048)

adpboss 06-11-2004 09:56 AM

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. :D

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>


TelaFirma 06-11-2004 11:21 AM

What did you set that field as in MySQL? (data type, length...)

adpboss 06-11-2004 12:34 PM

CHAR, 1, Not null, Default = N

I basically copied the field attributes from apply_pst/apply_gst.

BCSE 06-11-2004 01:14 PM

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

adpboss 06-12-2004 06:55 AM

I'm gonna fix that now, thanks so much Carrie. I feel like :? 8O :roll: :cry: 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.

BCSE 06-12-2004 07:06 AM

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

adpboss 06-12-2004 07:37 AM

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

adpboss 06-12-2004 05:01 PM

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.

Lucent88 09-16-2005 11:35 AM

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.

Lucent88 09-16-2005 02:49 PM

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.


All times are GMT -8. The time now is 03:08 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.