Jump to content

How to Add Fields to a CC3 Database


Guest disneyalumni

Recommended Posts

Guest disneyalumni

So far, CubeCart looks like a great, easy way to run my client's storefront, but I need to find out how to add some fields to the database. I found out in the CC2 forums how to do it there, but I would like to use CC3 and the procedure seems to be different.

The site will be a bookstore, so I need to add fields like AuthorLastName, AuthorFirstName, ISBN, Number of Pages, Hardback or Paperback, and such. The client also wants to be able to have author biographies and be able to search for authors and find their books in the store. So I guess I need an authors table to do that?

I am new to php and mySQL, but am trying to learn what I can.

Can anyone help?

Thanks.

--disneyalumni

Link to comment
Share on other sites

Easiest way if you don't know php and mysql is just to put all the data you want in the description field. As long as the author's name is there, someone could search on it. You can use html so you can format it in columns if you want, with bold for the heading, etc.

You can do an author biographies section thru documents or as external pages you link to from links in the description.

Link to comment
Share on other sites

  • 3 weeks later...
Guest rkdnsam

same problem/question here... :)

I also found jbdancer's awesome tutorial for adding fields in CC2.

and just before i started hacking away on my db and php files i read your last post disneyalumni... i owe you a big THANK YOU!

it wasnt until i read your post at the very bottom of that very long thread that i woke up and realized i was still browsing in the CubeCartâ„¢ Version 2 Forums!!!

WHEW! that could have been a bit ugly...

does anyone know how to do this in CC3.0.2? or is there already a link somewhere i have overlooked?

Link to comment
Share on other sites

I haven't read the cc2 tutorial, real programmers don't eat quiche or read tutorials :blink:.

While programming my product compare mod for cc3, I've added several new fields to the database. The concept of adding fields is not that much different in cc3 from what it is in cc2. It is actually a lot easier in cc3.

A simple overview:

Using phpadmin add the new fields to the cuberat_inventory table

Edit admin/products/index.php to add new text boxes to edit the new fields.

Add new fields to the viewProd.tpl and you're done.

I may have oversimplified this, but you should get the picture.

PM me if you would like me to setup the new fields for you and configure cc3 to use them.

Thanks

Goober

Link to comment
Share on other sites

Guest rkdnsam

perfect!

that is the the start i was looking for

knowing exactly which files need work is half the battle

thanks goober i'll give this a try tonight

Link to comment
Share on other sites

The only thing i will add to that is remember to change the details in viewProd.tpl to the skin you are using or safer bet to all 3 skins in case u wanna change look at later stage.

Link to comment
Share on other sites

Guest rkdnsam

ok, i gave this a shot.

Using simple overview (3 basic steps) from goober's post above

1. Using phpadmin add the new fields to the cuberCaRt_inventory table.

no problems here, pretty straight forward. just make sure fields have correct properties, etc.

2. Edit admin/products/index.php to add new text boxes to edit the new fields.

ok, i admit it. i tried to take a shortcut here. ;) am i incorrect in assuming i can skip this step if i dont ever want to add products via the admin interface? (i.e. if i choose to add all my products via an import directly into mysql db as i usually do)

3. Add new fields to the viewProd.tpl and you're done.

i ran into a bit of a snag here, so i tried 2 different approaches with no luck... B)

FIRST ATTEMPT - i tried simply adding {TXT_DESCRIPTION3} on the very next line right after {TXT_DESCRIPTION} in the viewProd.tpl file (all 3 skin dirs just for the sake of being consistent for future) note: DESCRIPTION3 is the name of one of my newly added fields in mysql. no go here... my sample dummy data in DESCRIPTION3 field wouldnt show up at all and and for that matter my original data from DESCRIPTION field wouldnt show up anymore either after adding this line, so i removed the line from viewProd.tpl - back to square one again

SECOND ATTEMPT - since ADDING a field seemed to have more potential for problems, i simply tried RENAMING an existing field as a test just to see if any of this would work for me at all. seemed like an easier approach to me at the time. no go here either! to clarify, i renamed the original DESCRIPTION field in mysql db to DESCRIPTION2, and i did a search and replace in viewProd.tpl and replaced every occurence of {TXT_DESCRIPTION} with {TXT_DESCRIPTION2} after this complete renaming of the DESCRIPTION field (and known references in viewProd.tpl) to DESCRIPTION2 once again my product data wouldnt show up anymore, so i changed it all back and now i'm back to where i started ;))

OK, so with all that said, i now have 2 questions before i proceed.

Question # 1. Is step 2 mandatory? i'll come clean - index.php also looked a bit ugly so i avoided it like the plague :whistle:

Question # 2. What is the TXT_DESCRIPTION variable referenced in viewProd.tpl and how does viewProd.tpl know what to do with this line of code? i.e. is it a global variable referenced somewhere else first - in an #include or global.inc file somewhere that i need to go and add the same type of reference for my new fields TXT_DESCRIPTION2, TXT_DESCRIPTION3, etc?

btw, i'm currently looking at the admin/products/index.php just to see where i would add text boxes if it is indeed necessary...

Link to comment
Share on other sites

  • 2 weeks later...
Guest hartmurmur

I don't think the question should be "Can this be done." Of course it can (if you have time and know PHP and MySQL). The real question is *should* it be done?

I'm afraid if I modify existing tables and a new version of CubeCart is released, then my table modifications can/may be erased.

Does it make more sense to create a second database and join the two? Please share your experiences with modifying existing tables and what happens when new CC releases come out.

Thanks.

Link to comment
Share on other sites

Don't add a new database, but simply a new table or two. That way it will NOT be changed by new software updates. Also, HEAVILY comment and document all your changes. So if you have to re-add them to new file versions later, you can without exessive troubles.

Link to comment
Share on other sites

Guest hartmurmur

Why not add the second database? It adds some greater flexibility.

You can drop the CubeCart database and reload as necessary without worrying about your extra tables. You should back up often, but who knows if the newer version of software drops the database as part of the update (create new database/insert into from../drop database).

I guess the bigger concern is modifications to your SQL queries.

Link to comment
Share on other sites

  • 1 year later...
Guest renzanzan

I haven't read the cc2 tutorial, real programmers don't eat quiche or read tutorials :(.

While programming my product compare mod for cc3, I've added several new fields to the database. The concept of adding fields is not that much different in cc3 from what it is in cc2. It is actually a lot easier in cc3.

A simple overview:

Using phpadmin add the new fields to the cuberat_inventory table

Edit admin/products/index.php to add new text boxes to edit the new fields.

Add new fields to the viewProd.tpl and you're done.

I may have oversimplified this, but you should get the picture.

PM me if you would like me to setup the new fields for you and configure cc3 to use them.

Thanks

Goober

sorry i see that u have mention about phpadmin to add fields to cubecar_inventory table,where can i get this program??

Link to comment
Share on other sites

I don't think the question should be "Can this be done." Of course it can (if you have time and know PHP and MySQL). The real question is *should* it be done?

I'm afraid if I modify existing tables and a new version of CubeCart is released, then my table modifications can/may be erased.

Does it make more sense to create a second database and join the two? Please share your experiences with modifying existing tables and what happens when new CC releases come out.

Thanks.

It is highly unlikely that the CubeCart database upgrader would drop your manually added fields or tables by name. And it's also highly unlikely that the upgrader would delete and recreate it's own database tables as the content would be gone.

Creating a different database would cause problems if you wanted to link information with their IDs. SQL queries, to my knowledge, to not work across different databases.

If you install phpmyadmin, be sure to secure it otherwise it's a direct access path to your data by anyone who can find it... and it can be found :dizzy:

Link to comment
Share on other sites

A really old thread resurrected :)

It can also be a really helpful thread, I think Goober's original overview could be dusted off and improved so here goes:

Disclaimer! Only you yourself are responsible for any damages done to your store by attempting modifications. These are not step-by-step instructions, but meant to be helpful hints. Backup your store files and database and proceed with caution!

1. Create New Database Fields

The fields should be created in the CubeCart_inventory table of your db, also if you use more than one language in the store, create the same fields in CubeCart_inv_lang table.

You may create the fields manually, using phpMyAdmin, or you can write a script to create the fields by using the upgrade.php scripts that come with CubeCart as a basis.

2. Edit admin/product/index.php

First, edit it to record the data from your new fields, as it is coded to record data from existing fields, then edit the html section of the file to create the text boxes or other inputs where you input the data.

3. Edit includes/viewProd.inc.php

First, edit the SQL query to pull the data from your new fields. Then, add some assignments, to assign this new data to tags that can be used like {THIS} in the .tpl skin template file.

4. Edit skins/xx/styleTemplates/content/viewProd.tpl to use the assignment codes and show your new data in the webpage.

Optional

To make the new data searchable, or to add it to the product list on the viewCat page, you will also need to edit includes/content/viewCat.inc.php, there are SQL queries there and code for the search strings as well as for the product lists. You will need to edit these areas, and if you want to use the data on the viewCat product list shown in your store you would also edit the skins/xx/styleTemplates/content/viewCat.tpl as well.

Have fun :)

Link to comment
Share on other sites

Guest rongrong

A really old thread resurrected :)

It can also be a really helpful thread, I think Goober's original overview could be dusted off and improved so here goes:

Disclaimer! Only you yourself are responsible for any damages done to your store by attempting modifications. These are not step-by-step instructions, but meant to be helpful hints. Backup your store files and database and proceed with caution!

1. Create New Database Fields

The fields should be created in the CubeCart_inventory table of your db, also if you use more than one language in the store, create the same fields in CubeCart_inv_lang table.

You may create the fields manually, using phpMyAdmin, or you can write a script to create the fields by using the upgrade.php scripts that come with CubeCart as a basis.

2. Edit admin/product/index.php

First, edit it to record the data from your new fields, as it is coded to record data from existing fields, then edit the html section of the file to create the text boxes or other inputs where you input the data.

3. Edit includes/viewProd.inc.php

First, edit the SQL query to pull the data from your new fields. Then, add some assignments, to assign this new data to tags that can be used like {THIS} in the .tpl skin template file.

4. Edit skins/xx/styleTemplates/content/viewProd.tpl to use the assignment codes and show your new data in the webpage.

Optional

To make the new data searchable, or to add it to the product list on the viewCat page, you will also need to edit includes/content/viewCat.inc.php, there are SQL queries there and code for the search strings as well as for the product lists. You will need to edit these areas, and if you want to use the data on the viewCat product list shown in your store you would also edit the skins/xx/styleTemplates/content/viewCat.tpl as well.

Have fun :)

hi there, thanks for your instructions.

i've attempted all these before but still having problems.

ok scenerio goes like this. my friend's sellign tattoo inks. he has 100+ different inks to sell. so in the admin side i wanted to put in a text field so that he could key in the colours himself next time he needs to add new products (he'lll be selling sets of colours).

went to create a new field in cubecart_inventory, as what u mentioned in step 1. should be clear cut enough.

secondly, i ran through the whole stupid admin/products/index page, finally figure out where to put in my code (under mode=new section). could you please explain the second step u typed above in details? i've added a text field with a value=<?php if(isset($results[0]['colour'])) echo $results[0]['colour']; ?>

nothing seems to work. i guess this line doesn't save the admin's input in the panel. no matter how many times i've tried adding in new colour names, it reflects an error "Failed to update category." in the view product in the admin pages.

btw i've also edited my viewprod.tpl and viewprod.inc.php too. not sure if they're correct but i guess the main problem lies in my product/index page.

Link to comment
Share on other sites

OK, well, stock CubeCart has a text field for the product name - so look at how that works. First, you need code to record the name into db, so here it is:

$record["name"] = $db->mySQLSafe($_POST['name']);

Second, you need the html code for inputting the text into a text field, so you find it here:

<tr>

<td width="25%" class="tdText"><strong><?php echo $lang['admin']['products']['prod_name2'];?></strong></td>

<td>

<input name="name" type="text" class="textbox" value="<?php if(isset($results[0]['name'])) echo validHTML($results[0]['name']); ?>" maxlength="255" />

</td>

</tr>

That's it

Note, the part in blue is just printing a string of text from the language file as a label, Name:

Now, I'm not sure why you would want a text filed for color, but if that's what you wanted, why wouldn't this work?

Part one:

$record["colour"] = $db->mySQLSafe($_POST['colour']);

Part two:

<tr>

<td width="25%" class="tdText"><strong>Colour:</strong></td>

<td>

<input name="colour" type="text" class="textbox" value="<?php if(isset($results[0]['colour'])) echo validHTML($results[0]['colour']); ?>" maxlength="255" />

</td>

</tr>

. . . assuming you have added a field named colour to the db CubeCart_inventory table.

Link to comment
Share on other sites

Guest rongrong

OK, well, stock CubeCart has a text field for the product name - so look at how that works. First, you need code to record the name into db, so here it is:

$record["name"] = $db->mySQLSafe($_POST['name']);

Second, you need the html code for inputting the text into a text field, so you find it here:

<tr>

<td width="25%" class="tdText"><strong><?php echo $lang['admin']['products']['prod_name2'];?></strong></td>

<td>

<input name="name" type="text" class="textbox" value="<?php if(isset($results[0]['name'])) echo validHTML($results[0]['name']); ?>" maxlength="255" />

</td>

</tr>

That's it

Note, the part in blue is just printing a string of text from the language file as a label, Name:

Now, I'm not sure why you would want a text filed for color, but if that's what you wanted, why wouldn't this work?

Part one:

$record["colour"] = $db->mySQLSafe($_POST['colour']);

Part two:

<tr>

<td width="25%" class="tdText"><strong>Colour:</strong></td>

<td>

<input name="colour" type="text" class="textbox" value="<?php if(isset($results[0]['colour'])) echo validHTML($results[0]['colour']); ?>" maxlength="255" />

</td>

</tr>

. . . assuming you have added a field named colour to the db CubeCart_inventory table.

ok one more question.

i've gave up trying to make it possible for admin to key in colour options in the admin panel...

now what i'm trying to figure out is how to simply just display out my colour list (i've made a new table named CubeCart_inksinglez, with 3 rows, colour_id, colour and price). My nice little list REFUSED to display. I am hoping someone could help me out on this.

in viewProd.inc.php I inserted this lines:

/ Ink Options

$query = 'SELECT * FROM `CubeCart_inksinglez`';

$view_prod->assign("Colour_List");

$view_prod->parse("view_prod.colour_options");

in viewProd.tpl I inserted these:

<!--BEGIN: colour_options-->

{Colour_List}

<!--END: colour_options-->

these are all the changes i've made, never touched any other files except my db. i'll gladly appreciate if some php guru could point out my dumb mistake.

Link to comment
Share on other sites

Well, you are missing a lot of details here. You can't expect it to work like this. For one, you do not indiccate which product you are pulling the data for, you are just pulling all data from the table. For another, you are not assigning anything.

If you appended the query to the product query properly, you would be able to assign it like this:

$view_prod->assign("COLOUR_LIST", $prodArray[0]['Colour_List']);

and use it like this, {COLOUR_LIST}

You really need to read through the existing CubeCart code again, you are missing most of the pertinent details, the assignments are arrays, first the tag "COLOUR_LIST" then the assignment like 'Colour_List' separated by a comma :sourcerer:

Link to comment
Share on other sites

  • 3 months later...

any ideas on why its not updating to our my database. Everything else works fine. If i added manually works beautifully but when i update it erases the information. hmmm

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