Updating Products

Open to all! Ask other shopowners for help.
Post Reply
Xpajun
Contributor
Posts: 187
Joined: Thu Mar 04, 2021 1:18 pm
Phoenix Version: v1.0.9.0
Has thanked: 3 times
Been thanked: 6 times

Updating Products

Post 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?
Current Store is now running 1.0.9.0 - php 8.2.18
Now working on taking a short rest :D - php 8.2.18


Join The Code Co-op to get access to your library in the Code Co-op Forum
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: Updating Products

Post 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.
User avatar
burt
Core Team
Posts: 4556
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 412 times

Re: Updating Products

Post 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" ?
Xpajun
Contributor
Posts: 187
Joined: Thu Mar 04, 2021 1:18 pm
Phoenix Version: v1.0.9.0
Has thanked: 3 times
Been thanked: 6 times

Re: Updating Products

Post 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
Current Store is now running 1.0.9.0 - php 8.2.18
Now working on taking a short rest :D - php 8.2.18
Xpajun
Contributor
Posts: 187
Joined: Thu Mar 04, 2021 1:18 pm
Phoenix Version: v1.0.9.0
Has thanked: 3 times
Been thanked: 6 times

Re: Updating Products

Post 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?
Current Store is now running 1.0.9.0 - php 8.2.18
Now working on taking a short rest :D - php 8.2.18
User avatar
burt
Core Team
Posts: 4556
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 412 times

Re: Updating Products

Post 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",
Xpajun
Contributor
Posts: 187
Joined: Thu Mar 04, 2021 1:18 pm
Phoenix Version: v1.0.9.0
Has thanked: 3 times
Been thanked: 6 times

Re: Updating Products

Post 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

Current Store is now running 1.0.9.0 - php 8.2.18
Now working on taking a short rest :D - php 8.2.18
Xpajun
Contributor
Posts: 187
Joined: Thu Mar 04, 2021 1:18 pm
Phoenix Version: v1.0.9.0
Has thanked: 3 times
Been thanked: 6 times

Re: Updating Products

Post 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 :(
Current Store is now running 1.0.9.0 - php 8.2.18
Now working on taking a short rest :D - php 8.2.18
Xpajun
Contributor
Posts: 187
Joined: Thu Mar 04, 2021 1:18 pm
Phoenix Version: v1.0.9.0
Has thanked: 3 times
Been thanked: 6 times

Re: Updating Products

Post 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

Current Store is now running 1.0.9.0 - php 8.2.18
Now working on taking a short rest :D - php 8.2.18
Xpajun
Contributor
Posts: 187
Joined: Thu Mar 04, 2021 1:18 pm
Phoenix Version: v1.0.9.0
Has thanked: 3 times
Been thanked: 6 times

Re: Updating Products

Post 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
Current Store is now running 1.0.9.0 - php 8.2.18
Now working on taking a short rest :D - php 8.2.18


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply