Jump to content



Photo
- - - - -

[Contribution] Extra Fields


  • Please log in to reply
225 replies to this topic

#1   KiLLaH

KiLLaH
  • Members
  • 55 posts
  • Real Name:Maz

Posted 26 October 2004 - 17:51

Hello everyone,

I have currently made an fresh install of Extra Fields.

URL: http://www.oscommerc...ll/search,extra

Version: 1.3c

Everything went fine until i got this error when i tried to view the product (http://www.url.com/s...eview&read=only)

This problem is obviously why i cannot save the data in the fields on each product.

Case:
---

Error:

Warning: Invalid argument supplied for foreach() in /www/url.com/shop/admin/categories.php on line 1492


Line 1492 in admin/categories.php:

foreach ($extra_fields_array as $key=>$val) {

Entire code:

        <?php 
 // START: Extra Fields Contribution
          $extra_fields_names_query = tep_db_query("SELECT * FROM " . TABLE_PRODUCTS_EXTRA_FIELDS);
          while ($extra_fields_names = tep_db_fetch_array($extra_fields_names_query)) {
            $extra_field_name[$extra_fields_names['products_extra_fields_id']] = $extra_fields_names['products_extra_fields_name'];
          }

          if ($HTTP_GET_VARS['read'] == 'only') {
            $products_extra_fields_query = tep_db_query("SELECT * FROM " . TABLE_PRODUCTS_TO_PRODUCTS_EXTRA_FIELDS . " WHERE products_id=" . (int)$HTTP_GET_VARS['pID']);
            while ($products_extra_fields = tep_db_fetch_array($products_extra_fields_query)) {
//v1.3b       echo "Hi";
              $extra_fields_array[$products_extra_fields['products_extra_fields_id']] = $products_extra_fields['products_extra_fields_value'];
            }
          }
          else {
            $extra_fields_array = $HTTP_POST_VARS['extra_field'];
          }

//v1.3b          if ($HTTP_POST_VARS['extra_field']) { // Check to see if there are any need to update extra fields.
            foreach ($extra_fields_array as $key=>$val) {
            ?>
              <b><? echo $extra_field_name[$key];?>:</b> <? echo $val;?><br />
            <?
            }
//v1.3b          } // Check to see if there are any need to update extra fields.
          // END: Extra Fields Contribution
//   echo "<br />" . $pInfo->products_description;
         ?>

//Maz

#2   Butch

Butch
  • Members
  • 33 posts
  • Real Name:Christophe Buchi
  • Location:Finland

Posted 29 October 2004 - 06:12

Hi,

I suppose the error comes because there is no extra fields defined for the product you want to preview (fields are empty), and the foreach loop does not like empty arrays => you can try to replace the foreach loop by this one:

reset ($extra_fields_array);
while (list ($key, $val) = each ($extra_fields_array)) {

Chris

#3   mat123slade

mat123slade
  • Members
  • 72 posts
  • Real Name:Matthew SLADE
  • Location:France

Posted 29 October 2004 - 09:11

Hi,

Just the Contribution I was looking for but I have many languages to deal with /crying.gif' class='bbc_emoticon' alt=':'(' />

How complexe is it to add language capabilities ? Do I just need to add language files, or is it more complexe than that... Could you possibly direct me for the basic idea of the way to do it ?

Thanx.

#4   Butch

Butch
  • Members
  • 33 posts
  • Real Name:Christophe Buchi
  • Location:Finland

Posted 29 October 2004 - 09:35

There is no language files for this contribution as all informations are in database.

The best way, for me, would be to add a language dropdown box in the admin part, so for each extra field we could choose the corresonding language or "all languages" if the field name and values are same in all the languages of the shop (for example: forum - http://forum.oscommerce.com.....).

It means one more field in the products_extra_fields table, modifying the categories.php for editing and updating the fields, modifying product_info.php to retrieve the correct language fields.

That's it.

This is something I can do but not today...

Chris

#5   mat123slade

mat123slade
  • Members
  • 72 posts
  • Real Name:Matthew SLADE
  • Location:France

Posted 29 October 2004 - 09:59

That's very nice of you, would be very much appreciated. Thanx...

#6   KiLLaH

KiLLaH
  • Members
  • 55 posts
  • Real Name:Maz

Posted 29 October 2004 - 14:55

Hi,

I suppose the error comes because there is no extra fields defined for the product you want to preview (fields are empty), and the foreach loop does not like empty arrays => you can try to replace the foreach loop by this one:

reset ($extra_fields_array);
while (list ($key, $val) = each ($extra_fields_array)) {

Chris

<{POST_SNAPBACK}>


Hello Chris,

I tried replacing the line:

        <?php 
 // START: Extra Fields Contribution
          $extra_fields_names_query = tep_db_query("SELECT * FROM " . TABLE_PRODUCTS_EXTRA_FIELDS);
          while ($extra_fields_names = tep_db_fetch_array($extra_fields_names_query)) {
            $extra_field_name[$extra_fields_names['products_extra_fields_id']] = $extra_fields_names['products_extra_fields_name'];
          }

          if ($HTTP_GET_VARS['read'] == 'only') {
            $products_extra_fields_query = tep_db_query("SELECT * FROM " . TABLE_PRODUCTS_TO_PRODUCTS_EXTRA_FIELDS . " WHERE products_id=" . (int)$HTTP_GET_VARS['pID']);
            while ($products_extra_fields = tep_db_fetch_array($products_extra_fields_query)) {
//v1.3b       echo "Hi";
              $extra_fields_array[$products_extra_fields['products_extra_fields_id']] = $products_extra_fields['products_extra_fields_value'];
            }
          }
          else {
            $extra_fields_array = $HTTP_POST_VARS['extra_field'];
          }

//          if ($HTTP_POST_VARS['extra_field']) { // Check to see if there are any need to update extra fields.
//            foreach ($extra_fields_array as $key=>$val) {
              reset ($extra_fields_array);
              while (list ($key, $val) = each ($extra_fields_array)) {
            ?>
              <b><? echo $extra_field_name[$key];?>:</b> <? echo $val;?><br />
            <?
            }
//         } // Check to see if there are any need to update extra fields.
          // END: Extra Fields Contribution
//   echo "<br />" . $pInfo->products_description;
         ?>

I got this error when i viewed a product again:

Warning: reset(): Passed variable is not an array or object in /www/url.com/shop/admin/categories.php on line 1493

Warning: Variable passed to each() is not an array or object in /www/url.com/shop/admin/categories.php on line 1494


Although i also noticed something else that when i typed in a value when editing a product it shows the value on the viewing page where you can click "update", but it doesnt save the value of the extra field? I think the problem is still because of this?

Thanks for the reply.
//Maz

#7   Butch

Butch
  • Members
  • 33 posts
  • Real Name:Christophe Buchi
  • Location:Finland

Posted 01 November 2004 - 09:00

Sounds like the extra fields parameters are not going from preview page to database. Values are probably not posted correctly: $HTTP_POST_VARS['extra_field'] is empty and therefore values are not saved to database and you get the error message when trying to view it as preview "read only" (preview from product list).

The code to check is in categories.php of course, chapter 1.6 of the installation procedure. The location of the modification is maybe confusing in the doc, try to find the comment /* Re-Post all POST'ed variables */ and some lines more down you find the code that the chapter 1.6 speaks about.

My code looks like that:
<?php
/* Re-Post all POST'ed variables */
      reset($HTTP_POST_VARS);
      while (list($key, $value) = each($HTTP_POST_VARS)) {
        if (!is_array($HTTP_POST_VARS[$key])) {
          echo tep_draw_hidden_field($key, htmlspecialchars(stripslashes($value)));
        }
      }
       $languages = tep_get_languages();
      for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
        echo tep_draw_hidden_field('products_name[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($products_name[$languages[$i]['id']])));
        echo tep_draw_hidden_field('products_description[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($products_description[$languages[$i]['id']])));
        echo tep_draw_hidden_field('products_url[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($products_url[$languages[$i]['id']])));
      }
      echo tep_draw_hidden_field('products_image', stripslashes($products_image_name));
    // START: Extra Fields Contribution (chapter 1.6)
      if ($HTTP_POST_VARS['extra_field']) { // Check to see if there are any need to update extra fields.
        foreach ($HTTP_POST_VARS['extra_field'] as $key=>$val) {
          echo tep_draw_hidden_field('extra_field['.$key.']', stripslashes($val));
        }
      } // Check to see if there are any need to update extra fields.
      // END: Extra Fields Contribution

      echo tep_image_submit('button_back.gif', IMAGE_BACK, 'name="edit"') . '&nbsp;&nbsp;';

Good luck

#8   KiLLaH

KiLLaH
  • Members
  • 55 posts
  • Real Name:Maz

Posted 01 November 2004 - 16:26

The code you mention is added as you say:

<?php
/* Re-Post all POST'ed variables */
      reset($HTTP_POST_VARS);
      while (list($key, $value) = each($HTTP_POST_VARS)) {
        if (!is_array($HTTP_POST_VARS[$key])) {
          echo tep_draw_hidden_field($key, htmlspecialchars(stripslashes($value)));
        }
      }
      $languages = tep_get_languages();
      for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
        echo tep_draw_hidden_field('products_name[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($products_name[$languages[$i]['id']])));
        echo tep_draw_hidden_field('products_info[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($products_info[$languages[$i]['id']])));
        echo tep_draw_hidden_field('products_description[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($products_description[$languages[$i]['id']])));
        echo tep_draw_hidden_field('products_url[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($products_url[$languages[$i]['id']])));
      }
          // START: Extra Fields Contribution
      if ($HTTP_POST_VARS['extra_field']) { // Check to see if there are any need to update extra fields.
      foreach ($HTTP_POST_VARS['extra_field'] as $key=>$val) {
// reset ($extra_fields_array);
// while (list ($key, $val) = each ($extra_fields_array)) {
          echo tep_draw_hidden_field('extra_field['.$key.']', stripslashes($val));
        }
      } // Check to see if there are any need to update extra fields.
      // END: Extra Fields Contribution
................................ and so on..

//Maz

#9   Butch

Butch
  • Members
  • 33 posts
  • Real Name:Christophe Buchi
  • Location:Finland

Posted 02 November 2004 - 08:24

So problem should be with the update of fields in database.
In the switch ($action) near begining of categories.php, find case 'update_product':
and add this right after:

var_dump ($HTTP_POST_VARS);

and comment the last line of this case, just before the break:
// tep_redirect (...

Try to insert or update a product having extra fields. The var_dump instruction will display on the screen the variables that have been posted. Extra fields should be there. If they are, check the extra fields code for the update (chapter 1.2). If they are not, problem is with the re-posted values that we discussed previously.

#10   KiLLaH

KiLLaH
  • Members
  • 55 posts
  • Real Name:Maz

Posted 02 November 2004 - 17:29

So problem should be with the update of fields in database.
In the switch ($action) near begining of categories.php, find case 'update_product':
and add this right after:

var_dump ($HTTP_POST_VARS);

and comment the last line of this case, just before the break:
// tep_redirect (...

Try to insert or update a product having extra fields. The var_dump instruction will display on the screen the variables that have been posted. Extra fields should be there. If they are, check the extra fields code for the update (chapter 1.2). If they are not, problem is with the re-posted values that we discussed previously.

<{POST_SNAPBACK}>



This is what it writes on the top when i click the "update" and go back to the product list in admin.

array(55) { ["products_status"]=> string(1) "1" ["products_date_available"]=> string(0) "" ["manufacturers_id"]=> string(0) "" ["products_tax_class_id"]=> string(1) "1" ["products_price"]=> string(8) "255.2000" ["products_price_gross"]=> string(3) "319" ["products_quantity"]=> string(1) "0" ["products_model"]=> string(5) "12124" ["products_previous_image"]=> string(9) "12124.jpg" ["products_previous_image_sm_1"]=> string(0) "" ["products_previous_image_xl_1"]=> string(0) "" ["products_previous_image_sm_2"]=> string(0) "" ["products_previous_image_xl_2"]=> string(0) "" ["products_previous_image_sm_3"]=> string(0) "" ["products_previous_image_xl_3"]=> string(0) "" ["products_previous_image_sm_4"]=> string(0) "" ["products_previous_image_xl_4"]=> string(0) "" ["products_previous_image_sm_5"]=> string(0) "" ["products_previous_image_xl_5"]=> string(0) "" ["products_previous_image_sm_6"]=> string(0) "" ["products_previous_image_xl_6"]=> string(0) "" ["products_qty_blocks"]=> string(1) "1" ["products_price1"]=> string(8) "232.0000" ["products_price1_qty"]=> string(2) "22" ["products_price2"]=> string(9) "2323.0000" ["products_price2_qty"]=> string(3) "222" ["products_price3"]=> string(9) "2323.0000" ["products_price3_qty"]=> string(2) "22" ["products_price4"]=> string(9) "2323.0000" ["products_price4_qty"]=> string(3) "222" ["products_weight"]=> string(5) "0.130" ["products_sort_order"]=> string(1) "0" ["products_date_added"]=> string(19) "2004-07-27 23:23:20" ["x"]=> string(2) "60" ["y"]=> string(1) "7" ["products_name"]=> array(1) { [4]=> string(45) "Product name here" } ["products_info"]=> array(1) { [4]=> string(0) "" } ["products_description"]=> array(1) { [4]=> string(1221) "Product description: blah blah " } ["products_url"]=> array(1) { [4]=> string(0) "" } ["extra_field"]=> array(1) { [2]=> string(4) "Testing extra" } ["products_image"]=> string(9) "12124.jpg" ["products_image_med"]=> string(0) "" ["products_image_lrg"]=> string(0) "" ["products_image_sm_1"]=> string(0) "" ["products_image_xl_1"]=> string(0) "" ["products_image_sm_2"]=> string(0) "" ["products_image_xl_2"]=> string(0) "" ["products_image_sm_3"]=> string(0) "" ["products_image_xl_3"]=> string(0) "" ["products_image_sm_4"]=> string(0) "" ["products_image_xl_4"]=> string(0) "" ["products_image_sm_5"]=> string(0) "" ["products_image_xl_5"]=> string(0) "" ["products_image_sm_6"]=> string(0) "" ["products_image_xl_6"]=> string(0) "" }


And yet it doesnt add the extrafields..
//Maz

#11   KiLLaH

KiLLaH
  • Members
  • 55 posts
  • Real Name:Maz

Posted 02 November 2004 - 17:43

Heres how i added according to your description:

     case 'update_product':
      var_dump ($HTTP_POST_VARS);
        if (isset($HTTP_POST_VARS['edit_x']) || isset($HTTP_POST_VARS['edit_y'])) {
          $action = 'new_product';

And commented out the tep_redirect line which was in this case.
//Maz

#12   shawn962650

shawn962650
  • Members
  • 24 posts
  • Real Name:Shawn Campbell

Posted 03 November 2004 - 18:36

I am having this problem too. I have tried all this and its still not working. any other thoughts or ideas?

Crystal

#13   KiLLaH

KiLLaH
  • Members
  • 55 posts
  • Real Name:Maz

Posted 03 November 2004 - 18:39

I am having this problem too.  I have tried all this and its still not working.  any other thoughts or ideas?

Crystal

<{POST_SNAPBACK}>


Im trying to figure out myself but rather lost right now.. /smile.gif' class='bbc_emoticon' alt=':)' />
//Maz

#14   shawn962650

shawn962650
  • Members
  • 24 posts
  • Real Name:Shawn Campbell

Posted 03 November 2004 - 18:44

I did everything like the instructions.......This bites! I have a clothing store and am trying to put in the garment measurements, like Bust, Waist, etc.... and it looks fine in preview, but I don't know. If you figure it out, let me know. I have to go run some errands......

Will have hubby look when he comes home and see if he can find it.

Crystal

#15   shawn962650

shawn962650
  • Members
  • 24 posts
  • Real Name:Shawn Campbell

Posted 04 November 2004 - 15:20

General board says its in product_info.php somewhere. I think I found an error, but I am not sure, since I am new to this. It is an error in instructions if it really is an error. Will let you know if I get anywhere with it today.

Crystal

#16   mat123slade

mat123slade
  • Members
  • 72 posts
  • Real Name:Matthew SLADE
  • Location:France

Posted 08 November 2004 - 17:09

and it looks fine in preview, but I don't know.  If you figure it out, let me know.  I have to go run some errands......

<{POST_SNAPBACK}>


Don' think I've figured it out, but the contribution works fine for me, I don't see anything in the preview but on the product page it works... Could that be something to do with it... Are you editing the right files in the right folder ?

PS : Any news about Multi-Lingual version ?
Thanx.

Edited by mat123slade, 08 November 2004 - 17:09.


#17   Butch

Butch
  • Members
  • 33 posts
  • Real Name:Christophe Buchi
  • Location:Finland

Posted 09 November 2004 - 07:43

To KiLLah:

In your $HTTP_POST_VARS listing, you can see that there is one extra field:
["extra_field"]=> array(1) { [2]=> string(4) "Testing extra". If it is not in database, error is in the switch ($action), case 'update_product'.

Here is the code I have in this section:

       // START: Extra Fields Contribution (Chapter 1.2)
          $extra_fields_query = tep_db_query("SELECT * FROM " . TABLE_PRODUCTS_TO_PRODUCTS_EXTRA_FIELDS . " WHERE products_id = " . (int)$products_id);
          while ($products_extra_fields = tep_db_fetch_array($extra_fields_query)) {
            $extra_product_entry[$products_extra_fields['products_extra_fields_id']] = $products_extra_fields['products_extra_fields_value'];
          }

          if ($HTTP_POST_VARS['extra_field']) { // Check to see if there are any need to update extra fields.
            foreach ($HTTP_POST_VARS['extra_field'] as $key=>$val) {
              if (isset($extra_product_entry[$key])) { // an entry exists
                if ($val == '') tep_db_query("DELETE FROM " . TABLE_PRODUCTS_TO_PRODUCTS_EXTRA_FIELDS . " where products_id = " . (int)$products_id . " AND  products_extra_fields_id = " . $key);
                else tep_db_query("UPDATE " . TABLE_PRODUCTS_TO_PRODUCTS_EXTRA_FIELDS . " SET products_extra_fields_value = '" . tep_db_input($val) . "' WHERE products_id = " . (int)$products_id . " AND  products_extra_fields_id = " . $key);
              }
              else { // an entry does not exist
                if ($val != '') tep_db_query("INSERT INTO " . TABLE_PRODUCTS_TO_PRODUCTS_EXTRA_FIELDS . " (products_id, products_extra_fields_id, products_extra_fields_value) VALUES ('" . (int)$products_id . "', '" . $key . "', '" . tep_db_input($val) . "')");
              }
            }
          } // Check to see if there are any need to update extra fields.
          // END: Extra Fields Contribution

Try to 'echo' some values inside this code, to see what is really processed (and keep the tep_redirect commented).

I have started the multi-language version, ready soon...

#18   Butch

Butch
  • Members
  • 33 posts
  • Real Name:Christophe Buchi
  • Location:Finland

Posted 09 November 2004 - 12:36

I've just posted version 2.0 of this contribution, which finally supports multi languages.
You now have the choice to display the fields in all languages, like before, or only in one. (I mean that each field can be separately configured).

Update is quite easy. Post here if any problem.

#19   KiLLaH

KiLLaH
  • Members
  • 55 posts
  • Real Name:Maz

Posted 09 November 2004 - 12:58

To KiLLah:

In your $HTTP_POST_VARS listing, you can see that there is one extra field:
["extra_field"]=> array(1) { [2]=> string(4) "Testing extra". If it is not in database, error is in the switch ($action), case 'update_product'.

Here is the code I have in this section:

       // START: Extra Fields Contribution (Chapter 1.2)
          $extra_fields_query = tep_db_query("SELECT * FROM " . TABLE_PRODUCTS_TO_PRODUCTS_EXTRA_FIELDS . " WHERE products_id = " . (int)$products_id);
          while ($products_extra_fields = tep_db_fetch_array($extra_fields_query)) {
            $extra_product_entry[$products_extra_fields['products_extra_fields_id']] = $products_extra_fields['products_extra_fields_value'];
          }

          if ($HTTP_POST_VARS['extra_field']) { // Check to see if there are any need to update extra fields.
            foreach ($HTTP_POST_VARS['extra_field'] as $key=>$val) {
              if (isset($extra_product_entry[$key])) { // an entry exists
                if ($val == '') tep_db_query("DELETE FROM " . TABLE_PRODUCTS_TO_PRODUCTS_EXTRA_FIELDS . " where products_id = " . (int)$products_id . " AND  products_extra_fields_id = " . $key);
                else tep_db_query("UPDATE " . TABLE_PRODUCTS_TO_PRODUCTS_EXTRA_FIELDS . " SET products_extra_fields_value = '" . tep_db_input($val) . "' WHERE products_id = " . (int)$products_id . " AND  products_extra_fields_id = " . $key);
              }
              else { // an entry does not exist
                if ($val != '') tep_db_query("INSERT INTO " . TABLE_PRODUCTS_TO_PRODUCTS_EXTRA_FIELDS . " (products_id, products_extra_fields_id, products_extra_fields_value) VALUES ('" . (int)$products_id . "', '" . $key . "', '" . tep_db_input($val) . "')");
              }
            }
          } // Check to see if there are any need to update extra fields.
          // END: Extra Fields Contribution

Try to 'echo' some values inside this code, to see what is really processed (and keep the tep_redirect commented).

I have started the multi-language version, ready soon...

<{POST_SNAPBACK}>


I have tried the diffrent stuff but yet still backed with the same errors and problems i cant really see what is what right now. Would you like to check the categories.php source to see if you can see anything wrong setup?

Thanks in advance.
//Maz

#20   mat123slade

mat123slade
  • Members
  • 72 posts
  • Real Name:Matthew SLADE
  • Location:France

Posted 09 November 2004 - 16:52

The new multilmingual version of this contribution works brilliantly... I can now get everything working beautfully, I'm really happy, thanx ever so much... There is a but... a very small one... Is it possible to change the code slightly to allow use of html... I cannot seam to be able to use iframes which I would need to use in nearly all product descriptions to enable Flash animations and othe content from other websites.

Is it simple to change ?

thanx again.