Results 1 to 9 of 9
  1. #1
    Join Date
    May 2014
    Location
    UK
    Posts
    299
    Plugin Contributions
    0

    Default Adding a field to Categories

    Evening all. It's been a while since I have been here but I'm stuck on a problem as I want to make some more bespoke changes.

    We run a closed membership book site with multiple server access - the main site itself is working great with all the bespoked changes we have made. Our file downloads contain EPUB and MOBI versions of books in a downloadable ZIP file. Now of course there are many book series that newcomers to certain authors/series may just want to download the entire series in one-click - which is where one of our spare servers will come into its own.

    This server will have two versions of the complete series - one for EPUB and one for MOBI. Now it's not a problem with regards to checking out these series of books because they are all "free" downloads once the member has signed up and paid an annual subscription.

    Our data structure is:

    Genre (top category)

    ==> Author

    ==> Series (or standalone books)

    What I am trying to achieve is to add a field to the Category Descriptions table that can be picked up in the user interface to build two links to the secondary server (SeriesName1_EPUB.zip and SeriesName2_MOBI.zip) as direct downloads.

    So I have made the necessary changes in the languages/english/categories.php file and for new categories have a working page that displays my new field added to the Categories Description Table (cat_series_link)

    On testing I can enter into this field but an array display and exit is showing that the field is blank when it saves it to the database - so I am missing a trick somewhere!

    The file changes to admin/categories.php so far are attached:


    I would be extremely grateful if somebody could advise why on entering a new category this new field remains blank.

    Many thanks

    Alan
    Attached Files Attached Files

  2. #2
    Join Date
    Nov 2005
    Location
    los angeles
    Posts
    962
    Plugin Contributions
    1

    Default Re: Adding a field to Categories

    #1 - have you modified the categories_description table to add your new field? something like:

    Code:
    alter table categories_description
    add cat_series_link longtext;
    #2 i think your code looks fine, but why are you exiting on line 207? the database insert is on line 219 and the update is on line 221. it will never hit either of those statements as once you execute an exit, the script dies.

    that's what i am seeing...

    hope it helps.
    feel free to donate money to carl or to the Zen-Cart Team

  3. #3
    Join Date
    May 2014
    Location
    UK
    Posts
    299
    Plugin Contributions
    0

    Default Re: Adding a field to Categories

    Quote Originally Posted by carlwhat View Post
    #1 - have you modified the categories_description table to add your new field? something like:

    Code:
    alter table categories_description
    add cat_series_link longtext;
    #2 i think your code looks fine, but why are you exiting on line 207? the database insert is on line 219 and the update is on line 221. it will never hit either of those statements as once you execute an exit, the script dies.

    that's what i am seeing...

    hope it helps.
    I added the new field to the categories_description table before I started recoding.

    The exit is there because I wanted to see what the value of the array was on screen as it doesn't update the table with the new field when it continues. For some reason the last element of the array ($cat_series_link) is showing as blank.

  4. #4
    Join Date
    May 2014
    Location
    UK
    Posts
    299
    Plugin Contributions
    0

    Default Re: Adding a field to Categories

    I just realised that line 205 should read:

    'cat_series_link' => zen_db_prepare_input($cat_series_link_array[$language_id]),

    I had this as $cat_seriies_link

    but still get the same blank result in the array when I print it to screen and exit:

    Array ( [categories_name] => Test Name [categories_description] =>
    Test Description

    [cat_series_link] => )

  5. #5
    Join Date
    Dec 2009
    Location
    Amersfoort, The Netherlands
    Posts
    2,285
    Plugin Contributions
    20

    Default Re: Adding a field to Categories

    Quote Originally Posted by DigiBooks View Post
    I just realised that line 205 should read:

    'cat_series_link' => zen_db_prepare_input($cat_series_link_array[$language_id]),

    I had this as $cat_seriies_link

    but still get the same blank result in the array when I print it to screen and exit:

    Array ( [categories_name] => Test Name [categories_description] =>
    Test Description

    [cat_series_link] => )
    Ican not find anything obvious right now,

    but, and I know it is original code
    PHP Code:
    for ($i=0$n=sizeof($languages); $i<$n$i++) {
      
    $categories_name_array $_POST['categories_name'];
      
    $categories_description_array $_POST['categories_description'];
      
    $cat_series_link_array $_POST['cat_series_link'];
      
    $language_id $languages[$i]['id']; 
    Shoul IMHO be
    PHP Code:
    $categories_name_array $_POST['categories_name'];
    $categories_description_array $_POST['categories_description'];
    $cat_series_link_array $_POST['cat_series_link'];
    for (
    $i=0$n=sizeof($languages); $i<$n$i++) {
      
    $language_id $languages[$i]['id']; 
    Now you only define the array once, instead of each time the loop repeats

  6. #6
    Join Date
    Dec 2009
    Location
    Amersfoort, The Netherlands
    Posts
    2,285
    Plugin Contributions
    20

    Default Re: Adding a field to Categories

    This is your problem. You add a '$languages[$i]['id']' without looping through the languages, so either remove this, or loop through. If you do not need multi lingual info move the db field to the categories table.

    your current code
    PHP Code:
        $category_inputs_string .= zen_draw_input_field('cat_series_link[' $languages[$i]['id'] . ']'''zen_set_field_length(TABLE_CATEGORIES_DESCRIPTION'cat_series_link')); 
    should be for multi lingual
    PHP Code:
    for ($i 0$n sizeof($languages); $i $n$i++) {
      
    $category_inputs_string .= '<br />' zen_image(DIR_WS_CATALOG_LANGUAGES $languages[$i]['directory'] . '/images/' $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;';
      
    $category_inputs_string .= zen_draw_input_field('cat_series_link[' $languages[$i]['id'] . ']'''zen_set_field_length(TABLE_CATEGORIES_DESCRIPTION'cat_series_link'));


  7. #7
    Join Date
    Nov 2005
    Location
    los angeles
    Posts
    962
    Plugin Contributions
    1

    Default Re: Adding a field to Categories

    prior to the exit, add a couple of more print_r statements and post the results:

    Code:
            print_r($cat_series_link_array);
            print_r($_POST);
            print_r($sql_data_array);
            exit;
    feel free to donate money to carl or to the Zen-Cart Team

  8. #8
    Join Date
    May 2014
    Location
    UK
    Posts
    299
    Plugin Contributions
    0

    Default Re: Adding a field to Categories

    Thank you so much Carlwhat and Design75 for crawling over this so quickly.

    The code changes posted here have everything working for adding new categories and you have both given me that vitally needed step up to understanding this section of code. Hopefully I will get the update categories bit correct now and then "clone" this back into the products table where all books that are part of a series will use this information also.

    Kindest regards
    Alan

  9. #9
    Join Date
    Dec 2009
    Location
    Amersfoort, The Netherlands
    Posts
    2,285
    Plugin Contributions
    20

    Default Re: Adding a field to Categories

    Quote Originally Posted by DigiBooks View Post
    Thank you so much Carlwhat and Design75 for crawling over this so quickly.

    The code changes posted here have everything working for adding new categories and you have both given me that vitally needed step up to understanding this section of code. Hopefully I will get the update categories bit correct now and then "clone" this back into the products table where all books that are part of a series will use this information also.

    Kindest regards
    Alan
    Your most welcome . The funny thing is i am ploughing through the whole category an product code myself at the moment. Trying to get this whole spaghetti code a bit more uniform, and in more logical files.

 

 

Similar Threads

  1. Adding Field to Checkout
    By paperzombie in forum Templates, Stylesheets, Page Layout
    Replies: 83
    Last Post: 22 Jan 2016, 08:53 AM
  2. Categories box - moving it and adding 2nd layer categories to the list
    By crexis in forum Setting Up Categories, Products, Attributes
    Replies: 2
    Last Post: 19 Jul 2013, 02:58 PM
  3. Adding Field to Checkout
    By earlygrayte in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 17 Feb 2012, 03:00 PM
  4. Adding a flash banner to categories and sub categories
    By shane09 in forum General Questions
    Replies: 0
    Last Post: 1 Jul 2009, 05:32 PM
  5. Adding a field to orders....
    By jkelly in forum General Questions
    Replies: 0
    Last Post: 30 Nov 2007, 08:37 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR