Sample of Creating Extensions with Widget for Editing and Outputting Additional Information about Product

From osCommerce Wiki
Jump to navigation Jump to search

First of all, refer to the article describing the process of creating an extension and its main parts - Creating Extension from Scratch.

In this article we will review on the sample the process of creating the extension with the widget for editing and outputting the additional information about the product.

Keep in mind that for keeping and displaying the additional information about products, you can use the functionality Properties, that allows to keep, edit and display the structural information about the product.

1. Creating the extension template.

Image 870.png
Image 869.png
Image 868.png

Click on Generate button and download the archived extension template. Then unpack this zip file in the catalogue /lib/common/extensions.

Image 867.png

2. Changing the product table.

We need to add the additional column to the product table while installing the extension and delete this column if the extension is uninstalled with the chosen option Drop extension data tables.

Open the file Setup.php in the editor and do the corresponding changes.

Image 871.png

3. Creating the line massive, that will be used for the possible translation of the additional field title and name into other languages.

Image 879.png

4. Displaying and saving the additional field while editing the product in the backend.

While creating the template we indicated only one hook, that will be used for displaying the information. Add the hook 'categories/productedit-beforesave' for its saving:

Image 872.png

Here we can use the simplified hook description where it is expected that the file name matches the hook name:

Image 873.png

Edit the template for displaying the field (categories.productedit.details-right-column.tpl):

Image 874.png

Edit the template for saving the field (categories.productedit-beforesave.php):

Image 875.png

5. Editing the widget for displaying the information on the frontend.

Edit the widget template (add-product-info.tpl):

Image 876.png

Edit the main widget file (AddProductInfo.php):

Image 877.png

Check the widget description function in the file Setup.php

Image 878.png

6. Installation and checking.

Install the new extension in the backend (Modules->Extensions menu).

Image 880.png

Activate the extension on the next page.

Image 881.png

Check the new product field editing.

Image 882.png

Add the widget to the theme for displaying on the frontend.

Open the active theme in Design and CMS->Themes. Choose the product page, click on Widget button and find the widget with the name that was indicated in the function getWidgets:

Image 883.png

And drag it to the product page.

Image 884.png

Save the theme and check the additional field display on the frontend.

Image 885.png

P.S. You can download the extention by clicking on this link