Extra Product Description Fields

Open to all! Ask other shopowners for help.
User avatar
Kofod95
Senior Contributor
Posts: 748
Joined: Sat Feb 06, 2021 7:38 pm
Phoenix Version: 1.0.8.20
Has thanked: 99 times
Been thanked: 179 times

Re: Extra Product Description Fields

Post by Kofod95 »

tessthepup wrote: Sun Jan 02, 2022 11:25 am admin/includes/actions/catalog/views/new_product.php ???
Seems right to me - I still haven't looked too far into versions later than 1.0.8.0, but it looks like something I would copy some parts of to achieve what you need.
Note these as well: admin/includes/actions/catalog/insert_product.php
And
admin/includes/actions/catalog/update_product.php

As you need something from there to save your new input.

//Daniel
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide


Join The Code Co-op to get access to your library in the Code Co-op Forum
User avatar
tessthepup
Certified Developer
Posts: 382
Joined: Mon Mar 01, 2021 5:55 pm
Phoenix Version:
Has thanked: 47 times
Been thanked: 62 times

Re: Extra Product Description Fields

Post by tessthepup »

not going to lie about it, I have no idea what code to put where although I did get the form injected :lol:

Code: Select all

<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2020 osCommerce

  Released under the GNU General Public License
*/

class hook_admin_catalog_extra_product_description_fields {

  public function listen_productActionSave() {

 }

  public function listen_injectDataForm() {
	include DIR_FS_CATALOG . 'includes/languages/' . $_SESSION['language'] . '/hooks/admin/categories/extra_product_description_fields.php';

	?>

            <div>
                  <div class="form-group row" id="zDesc<?= $l['directory'] ?>">
                    <label for="peDesc" class="col-form-label col-sm-3 text-left text-sm-right"><?= TEXT_EXTRA_PRODUCTS_DESCRIPTION ?></label>
                    <div class="col-sm-9">
                      <?= (new Textarea("extra_products_description[{$l['id']}]", ['id' => 'peDesc', 'cols' => '70', 'rows' => '15']))->require()->set_text($translations[$l['id']]['extra_description'] ?? '') ?>
                    </div>
                  </div>
                </div>
             </div>
           </div>

	<?php
  }
}
?>
User avatar
Kofod95
Senior Contributor
Posts: 748
Joined: Sat Feb 06, 2021 7:38 pm
Phoenix Version: 1.0.8.20
Has thanked: 99 times
Been thanked: 179 times

Re: Extra Product Description Fields

Post by Kofod95 »

tessthepup wrote: Sun Jan 02, 2022 12:54 pm not going to lie about it, I have no idea what code to put where although I did get the form injected :lol:
I'm sorry, I don't have the time right now to go as much in depth as I want, but I'll try to at least give something (note, I'm not a coder so I might be wrong about stuff, but it seems to work, when applied the way I think it should be)

Hooks are places in core that are calling for extra code. If the call is answered somewhere, that code will run along the core code. To answer the core hook-calls, our custom code has to listen:

Code: Select all

  public function [b]listen[/b]_productActionSave() {
Everything within that function will run, when core executes the hook-call:

Code: Select all

    $admin_hooks->cat(Admin::camel_case($action) . 'Action');
The above should, on version >=1.0.8.5, probably be:

Code: Select all

  public function listen_insertProductAction() {
for when creating a new product and

Code: Select all

  public function listen_updateProductAction() {
for when editing a existing product. listen_productActionSave will actually not do anything anymore, as there is no call for productActionSave - It has been split into insertProductAction and updateProductAction, but before 1.0.8.5 productActionSave would be correct, and I included it here, as it was what you had in your file
This part ensures that whatever is wanted will be saved into the database.
That is done inside the listening function with something like:

Code: Select all

      $products_extra_description = Text::input($_POST['products_extra_description']);

      $GLOBALS['db']->query("UPDATE products_description SET products_extra_description = '" . $GLOBALS['db']->escape($products_extra_description) . "' WHERE products_id = " . (int)$GLOBALS['products_id']);
The first line makes the Posted value from your form ready for insertion into the database. The next line adds your second description to table.products_description on the product you are editing.

You can insert forms via hooks multiple places:
  • Or in a new tab (This would require a few more things than just adding a form)
So instead of

Code: Select all

public function listen_injectDataForm() {
You should probably use

Code: Select all

public function listen_injectLanguageForm() {
I will gladly expound to the best of my knowledge, if anything is too confusing or just unclear

//Daniel
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide


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