You are here:  » New field

Support Forum



New field

Submitted by wdekreij on Thu, 2007-03-22 11:08 in

Hi,

Just like explained here: http://www.pricetapestry.com/node/313

I want to add a new field, but it has to be just like the "category" and "brand", I want to have the option (with registering) to type the input, or to select a field from the feed and use that one.

Can anyone help?

Thanks in advance,

Wilco

Submitted by support on Thu, 2007-03-22 11:17

Hi Wilco,

What I would recommend is first going through the steps to add the field as per the other thread, as this covers most of the work involved. If you find that works ok, let me know what the name of the field you have added is and i'll post the modifications then required to turn it into an optional field with user input....

Cheers,
David.

Submitted by wdekreij on Thu, 2007-03-22 11:21

Sorry, I forget to mention: I already did that.

I added the field "soort".

Submitted by support on Thu, 2007-03-22 11:38

Hi Wilco,

Ok, what you basically need to do is copy all the code that supports the category and brand fields and apply it to your new "soort" field. This amounts to adding the field user_soort.

Firstly, you need to add the field "user_soort" to the feeds table just as you added the field "field_soort".

To make the code modification, firstly in admin/feeds_register_step2.php, where you have currently added:

    field("Soort","fieldSoort",$prefixHTML);

...change this as follows:

    $userSoortDefault = (isset($_POST["userSoort"]) ? widget_safe(widget_posted($_POST["userSoort"])) : "");
    $prefixHTML = "<input type='text' name='userSoort' value='".$userSoortDefault."' />&nbsp;or use field&nbsp;";
    field("Soort","fieldSoort",$prefixHTML);

Then, at the top of admin/feeds_register_step2.php, you should have already modified the call to admin_register() as follows:

admin_register($filename,$format,$_POST["merchant"],$_POST["fieldName"], (isset($_POST["fieldDescription"])?$_POST["fieldDescription"]:"") , (isset($_POST["fieldImageURL"])?$_POST["fieldImageURL"]:"") ,$_POST["fieldBuyURL"],$_POST["fieldPrice"],$_POST["fieldCategory"],$_POST["userCategory"],$_POST["fieldBrand"],$_POST["userBrand"],$_POST["fieldSoort"]);

Now change this line to add the userSoort value as well:

admin_register($filename,$format,$_POST["merchant"],$_POST["fieldName"], (isset($_POST["fieldDescription"])?$_POST["fieldDescription"]:"") , (isset($_POST["fieldImageURL"])?$_POST["fieldImageURL"]:"") ,$_POST["fieldBuyURL"],$_POST["fieldPrice"],$_POST["fieldCategory"],$_POST["userCategory"],$_POST["fieldBrand"],$_POST["userBrand"],$_POST["fieldSoort"],$_POST["userSoort"]);

Now, in includes/admin.php we need to modify the admin_register() function. You should have already modified the declaration as follows:

function admin_register($filename,$format,$merchant,$fieldName,$fieldDescription,$fieldImageURL,$fieldBuyURL,$fieldPrice,$fieldCategory,$userCategory,$fieldBrand,$userBrand,$fieldSoort)

change this to:

function admin_register($filename,$format,$merchant,$fieldName,$fieldDescription,$fieldImageURL,$fieldBuyURL,$fieldPrice,$fieldCategory,$userCategory,$fieldBrand,$userBrand,$fieldSoort,$userSoort)

Next, update the SQL statement as follows:

    $sql = sprintf("INSERT INTO `".$config_databaseTablePrefix."feeds` SET
                    filename='%s',
                    registered='%s',
                    format='%s',
                    merchant='%s',
                    field_name='%s',
                    field_description='%s',
                    field_image_url='%s',
                    field_buy_url='%s',
                    field_price='%s',
                    field_category='%s',
                    user_category='%s',
                    field_brand='%s',
                    user_brand='%s',
                    field_soort='%s',
                    user_soort='%s'
                    ",
                    database_safe($filename),
                    time(),
                    database_safe($format),
                    database_safe(tapestry_normalise(ucwords($merchant),'\.')),
                    database_safe($fieldName),
                    database_safe($fieldDescription),
                    database_safe($fieldImageURL),
                    database_safe($fieldBuyURL),
                    database_safe($fieldPrice),
                    database_safe($fieldCategory),
                    database_safe(tapestry_normalise($userCategory)),
                    database_safe($fieldBrand),
                    database_safe(tapestry_normalise($userBrand)),
                    database_safe($fieldSoort),
                    database_safe(tapestry_normalise($userSoort))
                    );

Finally, lower down in the same file you need to handle the importing of the new field. Find the following code in the

    /* construct brand value if required */
    if ($admin_importFeed["field_brand"])
    {
      $brand = $record[$admin_importFeed["field_brand"]];
    }
    elseif($admin_importFeed["user_brand"])
    {
      $brand = $admin_importFeed["user_brand"];
    }
    else
    {
      $brand = "";
    }

...and add the following new code to create the soort field:

    /* construct soort value if required */
    if ($admin_importFeed["field_soort"])
    {
      $soort = $record[$admin_importFeed["field_soort"]];
    }
    elseif($admin_importFeed["user_soort"])
    {
      $soort = $admin_importFeed["user_soort"];
    }
    else
    {
      $soort = "";
    }

Finally, modify the SQL (line 252 in the distribution) to insert the value of $soort as follows:

    $sql = sprintf("INSERT INTO `".$config_databaseTablePrefix."products` SET
                    merchant='%s',
                    name='%s',
                    description='%s',
                    image_url='%s',
                    buy_url='%s',
                    price='%s',
                    search_name='%s',
                    category='%s',
                    brand='%s',
                    soort='%s',
                    dupe_hash='%s'
                    ",
                    database_safe($admin_importFeed["merchant"]),
                    database_safe($record[$admin_importFeed["field_name"]]),
                    database_safe(isset($record[$admin_importFeed["field_description"]])?$record[$admin_importFeed["field_description"]]:""),
                    database_safe(isset($record[$admin_importFeed["field_image_url"]])?$record[$admin_importFeed["field_image_url"]]:""),
                    database_safe($record[$admin_importFeed["field_buy_url"]]),
                    database_safe($record[$admin_importFeed["field_price"]]),
                    database_safe($searchName),
                    database_safe($category),
                    database_safe($brand),
                    database_safe($soort),
                    $dupe_hash
                    );

That should be it - i'm sorry it's quite a bit of code but take it step by step and compare all changes to the equivalent code for brand or category and you should be ok...

Hope this helps,
Cheers,
David.

Submitted by wdekreij on Fri, 2007-03-23 13:17

Well, I tried it (just like I tried before, before I went to this forum) but I have the same problem.

When I have just a "normal field" (just like in the other topic) it's no problem, but after I have entered the modifications from above (to make it just like the brand or category) it doesn't work anymore.

When I try to register (or import & register) a feed, it does not give an error, but it goes back to the main-admin page, and the feed is still not registered..

It doesn't matter of I select an field from the feed in the "soort"-field, or that I type something myself in the "soort" type..

Submitted by support on Fri, 2007-03-23 15:37

Hello Wilco,

If you could email me your modified admin/feeds_register_step2.php and includes/admin.php I will take a look for you.

If you reply to your reg code or forum reg email is the easiest way to get me...

Cheers,
David.

Submitted by wdekreij on Fri, 2007-03-23 15:57

Thanks a lot david.