Page 1 of 1

Updating Products

Posted: Sun Feb 11, 2024 2:31 pm
by Xpajun
I'm having problems updating products, I have these extra input boxes in admin>catalog: Image
(the tec spec and usage info were imported via phpMyAdmin)
I have included this coding in update_product.php betwwen products_description and products_url:

Code: Select all

      'products_description' => Text::prepare($_POST['products_description'][$l['id']]),
      'products_usage' => Text::prepare($_POST['products_usage'][$l['id']]),
      'products_tec_spec' => Text::prepare($_POST['products_tec_spec'][$l['id']]),
      'products_faq' => Text::prepare($_POST['products_faq'][$l['id']]),
      'products_parts' => Text::prepare($_POST['products_parts'][$l['id']]),
      'products_url' => Text::prepare($_POST['products_url'][$l['id']]),
      
I'm getting the following errors:

Code: Select all

[11-Feb-2024 13:41:27 UTC] PHP Notice:  Undefined index: products_usage in /home/**/public_html/**/admin/includes/actions/catalog/update_product.php on line 45
[11-Feb-2024 13:41:27 UTC] PHP Fatal error:  Uncaught TypeError: Argument 1 passed to Text::prepare() must be of the type string, null given, called in /home/**/public_html/**/admin/includes/actions/catalog/update_product.php on line 45 and defined in /home/**/public_html/**/includes/system/versioned/1.0.8.2/text.php:63
Stack trace:
#0 /home/**/public_html/**/admin/includes/actions/catalog/update_product.php(45): Text::prepare(NULL)
#1 /home/**/public_html/**/admin/includes/segments/process_action.php(19): require('/home/**/...')
#2 /home/**/public_html/**/admin/catalog.php(32): require('/home/**/...')
#3 {main}
  thrown in /home/**/public_html/**/includes/system/versioned/1.0.8.2/text.php on line 63
[11-Feb-2024 13:42:17 UTC] PHP Notice:  Undefined index: products_usage in /home/**/public_html/**/admin/includes/actions/catalog/update_product.php on line 45
[11-Feb-2024 13:42:17 UTC] PHP Fatal error:  Uncaught TypeError: Argument 1 passed to Text::prepare() must be of the type string, null given, called in /home/**/public_html/**/admin/includes/actions/catalog/update_product.php on line 45 and defined in /home/**/public_html/**/includes/system/versioned/1.0.8.2/text.php:63
Stack trace:
#0 /home/**/public_html/**/admin/includes/actions/catalog/update_product.php(45): Text::prepare(NULL)
#1 /home/**/public_html/**/admin/includes/segments/process_action.php(19): require('/home/mudlarki/...')
#2 /home/**/public_html/**/admin/catalog.php(32): require('/home/mudlarki/...')
#3 {main}
  thrown in /home/**/public_html/**/includes/system/versioned/1.0.8.2/text.php on line 63
  
All 4 extra products_ are copies of products_description with the name changed.
I'm trying to work out where I've gone wrong and why I'm getting Undefined index
Can anyone help?

Re: Updating Products

Posted: Sun Feb 11, 2024 2:38 pm
by ecartz
What's the PHP code for displaying the textarea boxes? The problem would seem to lie there, given the messages that you show.

Re: Updating Products

Posted: Sun Feb 11, 2024 4:43 pm
by burt
Text::prepare wont accept a null value, so if you are not "require aria-required=true" these new inputs [which means shopowner must put something in the box (like the product description)], then you need to give text::prepare some other value, eg;

'products_tec_spec' => Text::prepare($_POST['products_tec_spec'][$l['id']] ?? ''),

If those new inputs are a direct copy of products_description, they should also have a "required" setting;

https://github.com/CE-PhoenixCart/Phoen ... t.php#L246

Have you maybe removed "->required" ?

Re: Updating Products

Posted: Sun Feb 11, 2024 5:03 pm
by Xpajun
ecartz wrote: Sun Feb 11, 2024 2:38 pm What's the PHP code for displaying the textarea boxes? The problem would seem to lie there, given the messages that you show.

Code: Select all

                  <div class="form-group row" id="zDesc<?= $l['directory'] ?>">
                    <label for="pDesc" class="col-form-label col-sm-3 text-left text-sm-right"><?= TEXT_PRODUCTS_USEAGE ?></label>
                    <div class="col-sm-9">
                      <?= (new Textarea("products_useage[{$l['id']}]", ['id' => 'pDesc', 'cols' => '70', 'rows' => '15']))->require()->set_text($translations[$l['id']]['usage'] ?? '') ?>
                    </div>
                  </div>
Again copying from products_description

Re: Updating Products

Posted: Sun Feb 11, 2024 5:05 pm
by Xpajun
Xpajun wrote: Sun Feb 11, 2024 5:03 pm
ecartz wrote: Sun Feb 11, 2024 2:38 pm What's the PHP code for displaying the textarea boxes? The problem would seem to lie there, given the messages that you show.

Code: Select all

                  <div class="form-group row" id="zDesc<?= $l['directory'] ?>">
                    <label for="pDesc" class="col-form-label col-sm-3 text-left text-sm-right"><?= TEXT_PRODUCTS_USEAGE ?></label>
                    <div class="col-sm-9">
                      <?= (new Textarea("products_useage[{$l['id']}]", ['id' => 'pDesc', 'cols' => '70', 'rows' => '15']))->require()->set_text($translations[$l['id']]['usage'] ?? '') ?>
                    </div>
                  </div>
Again copying from products_description
And the pDesc would be the problem? would it be the only one?

Re: Updating Products

Posted: Sun Feb 11, 2024 5:25 pm
by burt
You are using:

products_useage

And:

products_usage

Choose one or the other and make sure they match in all places...

In other words you are throwing a ball called "products_useage" and catching a non existing ball called "products_usage",

Re: Updating Products

Posted: Sun Feb 11, 2024 5:29 pm
by Xpajun
Xpajun wrote: Sun Feb 11, 2024 5:05 pm
Xpajun wrote: Sun Feb 11, 2024 5:03 pm
ecartz wrote: Sun Feb 11, 2024 2:38 pm What's the PHP code for displaying the textarea boxes? The problem would seem to lie there, given the messages that you show.

Code: Select all

                  <div class="form-group row" id="zDesc<?= $l['directory'] ?>">
                    <label for="pDesc" class="col-form-label col-sm-3 text-left text-sm-right"><?= TEXT_PRODUCTS_USEAGE ?></label>
                    <div class="col-sm-9">
                      <?= (new Textarea("products_useage[{$l['id']}]", ['id' => 'pDesc', 'cols' => '70', 'rows' => '15']))->require()->set_text($translations[$l['id']]['usage'] ?? '') ?>
                    </div>
                  </div>
Again copying from products_description
And the pDesc would be the problem? would it be the only one?
Have changed the zDesc and pDesc but on entering text in each box and saving I get a blank screen with the following errors:

Code: Select all

[11-Feb-2024 17:17:20 UTC] PHP Notice:  Undefined index: products_usage in /home/**/public_html/**/admin/includes/actions/catalog/update_product.php on line 45
[11-Feb-2024 17:17:20 UTC] PHP Fatal error:  Uncaught TypeError: Argument 1 passed to Text::prepare() must be of the type string, null given, called in /home/**/public_html/**/admin/includes/actions/catalog/update_product.php on line 45 and defined in /home/**/public_html/**/includes/system/versioned/1.0.8.2/text.php:63
Stack trace:
#0 /home/**/public_html/**/admin/includes/actions/catalog/update_product.php(45): Text::prepare(NULL)
#1 /home/**/public_html/**/admin/includes/segments/process_action.php(19): require('/home/**/...')
#2 /home/**/public_html/**/admin/catalog.php(32): require('/home/**/...')
#3 {main}
  thrown in /home/**/public_html/**/includes/system/versioned/1.0.8.2/text.php on line 63


Re: Updating Products

Posted: Sun Feb 11, 2024 5:43 pm
by Xpajun
burt wrote: Sun Feb 11, 2024 5:25 pm You are using:

products_useage

And:

products_usage

Choose one or the other and make sure they match in all places...

In other words you are throwing a ball called "products_useage" and catching a non existing ball called "products_usage",
Thanks Gary - thought I got rid of all the 'useages'
Hasn't made a difference though :(

Re: Updating Products

Posted: Sun Feb 11, 2024 5:48 pm
by Xpajun
Not sure if this helps but the undefined index seems to be stopping everything - if I take products_usage out it flags products_tec_spec as the undefined index

Code: Select all

[11-Feb-2024 17:17:20 UTC] PHP Notice:  Undefined index: products_usage in /home/**/public_html/**/admin/includes/actions/catalog/update_product.php on line 45
[11-Feb-2024 17:17:20 UTC] PHP Fatal error:  Uncaught TypeError: Argument 1 passed to Text::prepare() must be of the type string, null given, called in /home/**/public_html/**/admin/includes/actions/catalog/update_product.php on line 45 and defined in /home/**/public_html/**/includes/system/versioned/1.0.8.2/text.php:63
Stack trace:
#0 /home/**/public_html/**/admin/includes/actions/catalog/update_product.php(45): Text::prepare(NULL)
#1 /home/**/public_html/**/admin/includes/segments/process_action.php(19): require('/home/**/...')
#2 /home/**/public_html/**/admin/catalog.php(32): require('/home/**/...')
#3 {main}
  thrown in /home/**/public_html/**/includes/system/versioned/1.0.8.2/text.php on line 63


Re: Updating Products

Posted: Sun Feb 11, 2024 10:06 pm
by Xpajun
Solved...

After mutiple searches it came down to typos, mixed column names, miss-spellings, not updating all files
Which was all probably due to a fuzzy brain

Many thanks to @ecartz and @burt your help prooved to be invaluable