Jump to content
ArtcoInc

Addon Development - Best Practices

Recommended Posts

Did anyone mention start a repository on github for the addon? It would be real nice for version control.

 

Has there been a way defined on how to completely eliminating core code change yet? WP do it in a way that the module would call a do_action('hook_name', func_name) type function and bring in the custom codes...I think that's how its' done with them...

Share this post


Link to post
Share on other sites

Guys...without wanting to start an argument or even much of a discussion on it (as it's been done to death)...you are shop-owners.  You should be concentrating on your bottom line.  It is developers who should be coding.

 

If shop-owners do not want to support developers and instead do the coding themselves, you all will end up with no developers available to you as they will all move on to where they can sell their products and services.


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest current code (community-supported responsive 2.3.4.1BS Edge) here

 

Share this post


Link to post
Share on other sites

Guys...without wanting to start an argument or even much of a discussion on it (as it's been done to death)...you are shop-owners.  You should be concentrating on your bottom line.  It is developers who should be coding.

 

If shop-owners do not want to support developers and instead do the coding themselves, you all will end up with no developers available to you as they will all move on to where they can sell their products and services.

 

That's a sure way to encourage people not to use osCommerce. osCommerce is meant for people who want to DIY, otherwise they may as well use other feature based carts.

 

Ideas and concepts don't grow obsolete (the addon section), they just require updating from time to time, just like osCommerce itself. I don't think team members should be prescribing to shop owners how to modify their stores. Why must something be done X way only? Personally i like modifying my store they way i see fit.

Share this post


Link to post
Share on other sites

Core code change cause development upgrade shocks and prevent oscommerce r/evolutions..

Its a bad habit so code separation would be a better way.


:blink:
osCommerce based shop owner with minimal design and focused on background works. When the less is more.
Email managment with tracking pixel, package managment for shipping, stock management, warehouse managment with bar code reader, parcel shops management on 3000 pickup points without local store.

Share this post


Link to post
Share on other sites

 

Do you think anyone is dumb enough to un-install and then wonder where all the SPPC data went? Should the un-install of the content module maybe "not" blow out all SPPC data? What is the best practice in this regard?

 

 

That's a valid concern with adding SQL to a module. There are times when you want to uninstall and reinstall a module for testing purposes, can be a pain to reinstall all your data sometimes. Also it may sound foolish, but accidents do happen. With some modules I strip out some of the SQL, especially the creation of tables, and run it separately to make it permanent.

Share this post


Link to post
Share on other sites

@@greasemonkey

 

Remember my first post inside this thread regarding database changes inside a module? (Page 2) There was an additional function where the user could select if he wants to delete or keep the data inside the database when the module gets uninstalled.

You could use that.

Edited by Tsimi

Share this post


Link to post
Share on other sites

this is a (very) part time project with no timeline whatsoever... 

 

Sounds much like osCommerce.


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest current code (community-supported responsive 2.3.4.1BS Edge) here

 

Share this post


Link to post
Share on other sites
@Dan Cole, I welcome your help if you are interested... Keeping in mind this is a (very) part time project with no timeline whatsoever... and I will need a fair amount of help with the catalog side in particular.

 

Scott I assume you're talking about SPPC and if so I would welcome the opportunity....it is a contribution that I make use of so it would be a good one to work on from my point of view.  Maybe we should start a separate thread and lead off with Garys post about how the add-on might be recoded to have as little impact on the core as possible. In any case count me in.

 

Dan

Share this post


Link to post
Share on other sites

@@greasemonkey

 

Remember my first post inside this thread regarding database changes inside a module? (Page 2) There was an additional function where the user could select if he wants to delete or keep the data inside the database when the module gets uninstalled.

You could use that.

 

This approach makes sense to me and would address the concerns pointed out by Ashley as well.

 

Dan

Share this post


Link to post
Share on other sites

@@Tsimi that works like a champ...

 

There are radio buttons false/true where you can choose if you want to drop the tables when removing the module or not.
This option can be changed at anytime while the module is installed.

HOWEVER maybe not if you don't delete (false) the data. It complains of duplicate columns , as you might expect. Below is my first go around...

 

I presume, as a best practice, the drop table should be removed from the install function?

 

So, there must be a way to do "alter table if NOT exist" to prevent it from complaining about the columns still there from previous install...

 

Maybe something like this example;

IF NOT EXISTS( SELECT NULL
            FROM INFORMATION_SCHEMA.COLUMNS
           WHERE table_name = 'tablename'
             AND table_schema = 'db_name'
             AND column_name = 'columnname')  THEN

  ALTER TABLE `TableName` ADD `ColumnName` int(1) NOT NULL default '0';
// BOF TSIMI
      tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Delete auto created tables on module Remove', 'MODULE_CONTENT_PRODUCT_INFO_REVIEWS_DELETE_TABLES', 'False', 'Do you want to remove the tables that where created during installing this module?<br><i>Note: all the created data will be deleted</i>.', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
// EOF TISMI      
      tep_db_query ("alter table customers add customers_group_id smallint UNSIGNED NOT NULL default '0', add customers_group_ra enum('0','1') NOT NULL, add customers_payment_allowed varchar(255) NOT NULL default '', add customers_shipment_allowed varchar(255) NOT NULL default '', add customers_order_total_allowed varchar(255) NOT NULL default '', add customers_specific_taxes_exempt varchar(255) NOT NULL default '', add entry_company_tax_id VARCHAR(32) DEFAULT NULL");
      tep_db_query ("drop table if exists products_groups");
      tep_db_query ("create table products_groups (customers_group_id smallint UNSIGNED NOT NULL default '0', customers_group_price decimal(15,4) NOT NULL default '0.0000', products_id int(11) NOT NULL default '0', PRIMARY KEY (customers_group_id, products_id)) CHARACTER SET utf8 COLLATE utf8_unicode_ci");
      tep_db_query ("alter table specials add customers_group_id smallint UNSIGNED NOT NULL default '0'");
      tep_db_query ("drop table if exists customers_groups");
      tep_db_query ("create table customers_groups ( customers_group_id smallint UNSIGNED NOT NULL, customers_group_name varchar(32) NOT NULL default '', customers_group_show_tax enum('1','0') NOT NULL, customers_group_tax_exempt enum('0','1') NOT NULL, group_payment_allowed varchar(255) NOT NULL default '', group_shipment_allowed varchar(255) NOT NULL default '', group_order_total_allowed varchar(255) NOT NULL default '', group_specific_taxes_exempt varchar(255) NOT NULL default '', PRIMARY KEY (customers_group_id) )CHARACTER SET utf8 COLLATE utf8_unicode_ci");
      tep_db_query ("insert into customers_groups VALUES('0','Retail','1','0','','','','')");
      tep_db_query ("alter table newsletters add send_to_customer_groups VARCHAR(32) DEFAULT NULL");
      tep_db_query ("alter table products_attributes add attributes_hide_from_groups varchar(255) NOT NULL default '@'");
      tep_db_query ("drop table if exists products_attributes_groups");
      tep_db_query ("create table products_attributes_groups ( products_attributes_id int(11) NOT NULL default '0', customers_group_id smallint(5) NOT NULL default '0', options_values_price decimal(15,4) NOT NULL default '0.0000', price_prefix char(1) NOT NULL default '', products_id int(11) NOT NULL default '0', PRIMARY KEY  (customers_group_id,products_attributes_id))CHARACTER SET utf8 COLLATE utf8_unicode_ci");
      tep_db_query ("drop table if exists specials_retail_prices");
      tep_db_query ("create table specials_retail_prices ( products_id int NOT NULL default '0',  specials_new_products_price decimal(15,4) NOT NULL default '0.0000',  status tinyint,  customers_group_id smallint,  PRIMARY KEY (products_id) )CHARACTER SET utf8 COLLATE utf8_unicode_ci");
      tep_db_query ("insert into specials_retail_prices SELECT s.products_id, s.specials_new_products_price, s.status, s.customers_group_id from specials s where s.customers_group_id = '0'");
      }

   function remove() {
      tep_db_query("delete from configuration where configuration_key in ('" . implode("', '", $this->keys()) . "')");
           if($this->delete_tables){ //drop tables if delete_tables option is true      
      tep_db_query ("alter table customers drop customers_group_id, drop customers_group_ra, drop customers_payment_allowed,drop customers_shipment_allowed, drop customers_order_total_allowed, drop customers_specific_taxes_exempt,drop entry_company_tax_id");
      tep_db_query ("drop table if exists products_groups");
      tep_db_query ("drop table if exists customers_groups");
      tep_db_query ("alter table specials drop customers_group_id");
      tep_db_query ("drop table if exists specials_retail_prices");
      tep_db_query ("drop table if exists products_groups_prices_cg_1");
      tep_db_query ("drop table if exists products_groups_prices_cg_2");
      tep_db_query ("drop table if exists products_groups_prices_cg_3");
      tep_db_query ("drop table if exists products_groups_prices_cg_4");
      tep_db_query ("drop table if exists products_groups_prices_cg_5");
      tep_db_query ("alter table newsletters drop send_to_customer_groups");
      tep_db_query ("alter table products_attributes drop attributes_hide_from_groups");
      tep_db_query ("drop table if exists products_attributes_groups");
           }

Share this post


Link to post
Share on other sites

Use DESCRIBE <table> to get the existing table columns, then check and don't add if they already exist.

      $check_structure_query_raw = "describe " . TABLE_CATEGORIES_DESCRIPTION;
      $check_structure_query = tep_db_query( $check_structure_query_raw );

      $head_title = false;
      $head_description = false;
      while( $check_structure_data = tep_db_fetch_array( $check_structure_query ) ) {
        if( $check_structure_data['Field'] == 'head_title' ) {
          $head_title = true;
        }

        if( $check_structure_data['Field'] == 'head_description' ) {
          $head_description = true;
        }
      }

https://dev.mysql.com/doc/refman/5.0/en/explain.html

 

Regards

Jim

Edited by kymation

See my profile for a list of my addons and ways to get support.

Share this post


Link to post
Share on other sites

Use DESCRIBE <table> to get the existing table columns, then check and don't add if they already exist.

      $check_structure_query_raw = "describe " . TABLE_CATEGORIES_DESCRIPTION;
      $check_structure_query = tep_db_query( $check_structure_query_raw );

      $head_title = false;
      $head_description = false;
      while( $check_structure_data = tep_db_fetch_array( $check_structure_query ) ) {
        if( $check_structure_data['Field'] == 'head_title' ) {
          $head_title = true;
        }

        if( $check_structure_data['Field'] == 'head_description' ) {
          $head_description = true;
        }
      }

https://dev.mysql.com/doc/refman/5.0/en/explain.html

 

Regards

Jim

 

This also works and you may find it easier to follow:

	// does the table need creating?
        $query = tep_db_query('SHOW TABLES LIKE \'shipping_exclusions\'');
	if (tep_db_num_rows($query) == 0){

and

   // does the column need creating?		
   if (!tep_db_num_rows(tep_db_query("SHOW COLUMNS FROM toll_zones LIKE 't_country'"))) {


For a new install or if your store isn't mobile-friendly, get the community-supported responsive osCommerce (2.3.4.1 CE) here: https://github.com/gburton/Responsive-osCommerce/archive/2341-Frozen.zip

Working on generalising bespoke solutions for Quickbooks integration, Easify integration and pay4later (DEKO) integration at 2.3.x

Share this post


Link to post
Share on other sites

Some add-on has only HTTP, it could be a problem if the site is in SSL

 

insert this function in general.php and change 

HTTP_SERVER

 in the files by  

tep_type_url_domain()
/**
* Function to select HTTP or HTTPS
* public function
* @[member='Return'] $domain, type of HTTP of domain
*/
 function tep_type_url_domain() {
   global $request_type;
   $domain = substr((($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER), 0);
  return $domain;
}
Edited by Gyakutsuki


Regards
-----------------------------------------
Loïc

Contact me by skype for business
Contact me @gyakutsuki for an answer on the forum

Tuto for 2.4 :
- How to Display a new page with app
- How to make Header Tags under app APP
- How to make a
boostrap modal with external element
 

 

Share this post


Link to post
Share on other sites

In addition to the shopping cart, I have customers that will phone, FAX, or email us orders. I will enter these orders into our online store to ensure that the online inventory remains accurate. However, some of these orders may use a shipper or payment method that we do not offer through the shopping cart.

 

In another thread, I asked how to include these other shipper or payment methods in the Admin side, but not in the Store side. It was suggested (thanks, @@auzStar !) that I could install these shipping and/or payment modules, and within them, test if the session was from the Admin side, or the Store side. I can see extending this idea to being able to enable and disable the module(s) in the Store and in Admin independently.

 

While this may just be a unique situation for me, and while most add-on's would not benefit from such fine control, as a 'best practice', could/should we at least ask the question, "Are there situations where the shop owner would benefit if this module has this additional fine control?"

 

Malcolm


If you are running the "official" osC 2.3.4 or 2.3.4.1 download, your installation is obsolete! Get the latest community-supported responsive "Frozen" release here

Share this post


Link to post
Share on other sites

Whilst I am still playing with the bootstrap version before releasing it to my unsuspecting customers, I do like the way the code is going. Making things more modular is a great idea. Making addons that need no or very little code changes is probably the best idea someone somewhere had. I just wish all addon makers did the same and removed the need for major core code changes. Having something like this will make future upgrades easier, which will be a benefit to all.

 

My only real concern is that although work is progressing on the BS EDGE version there is no thread on this forum explaining about the recent changes and updates that have been added. If there was something maybe others would keep their code up to the latest version. It will be so much easier to make simple alterations when they happen, rather than have to update the whole package if an updated version is ever released. We poor shop keepers are not the best at leaning new software like github, but we can read and in most cases can cut and paste.

 

Just my two cents. Keep up the good work.


REMEMBER BACKUP, BACKUP AND BACKUP

Before installing the official version of oscommerce first look at a responsive version here

It's very easy to over complicate what are simple things in life

Share this post


Link to post
Share on other sites

Whilst I am still playing with the bootstrap version before releasing it to my unsuspecting customers, I do like the way the code is going. Making things more modular is a great idea. Making addons that need no or very little code changes is probably the best idea someone somewhere had. I just wish all addon makers did the same and removed the need for major core code changes. Having something like this will make future upgrades easier, which will be a benefit to all.

 

My only real concern is that although work is progressing on the BS EDGE version there is no thread on this forum explaining about the recent changes and updates that have been added. If there was something maybe others would keep their code up to the latest version. It will be so much easier to make simple alterations when they happen, rather than have to update the whole package if an updated version is ever released. We poor shop keepers are not the best at leaning new software like github, but we can read and in most cases can cut and paste.

 

Just my two cents. Keep up the good work.

 

I think that would be a good idea to have a thread here where changes are announced.

Share this post


Link to post
Share on other sites

Is there any rule when to use tep_get_products_special_price and tep_get_products_name functions instead to retrieve it in the product query??

 

In the core files both is used:

 

product_info.php, also_purchased_products.php module and bm_whats_new.php use functions.

 

new_products.php module and bm_specials.php retrieves special_price and product_name in the main query.

 

I'm asking to know what would be better to do in the recently_viewed add-on modules see discussion here:

http://forums.oscommerce.com/topic/282340-contribution-recently-viewed-productssales-optimized/?p=1733195

post #242, #254, #257

 

Thank you

Share this post


Link to post
Share on other sites

Splitting out threads.  Let's keep threads "on track" ...


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest current code (community-supported responsive 2.3.4.1BS Edge) here

 

Share this post


Link to post
Share on other sites

Hello :)

 

What about extending core classes, for example order.php? What's the best practice about it? I posted a new topic about this question. Thanks for your comments!

Edited by katapofatico

Share this post


Link to post
Share on other sites

@@katapofatico,

 

You can check this example for a chopping_cart extension:

http://forums.oscommerce.com/topic/408481-sppc-lite/?p=1734997

 

 

and if you download the following add-on you can find a more simple example for a currency extension:

http://addons.oscommerce.com/info/9365

 

the class extension is included and called in the store module: includes/modules/store/st_tax_below_price.php

          $currencies = new currencies_mod();

and the extension class at the end:

  if (class_exists('currencies')) {
    class currencies_mod extends currencies {
    	// add tax below price mod
    	public function format($number, $calculate_currency_value = true, $currency_type = '', $currency_value = '', $products_tax = '', $show_tax_info = true) {
......................

hope this helps

 

regards

Rainer

Edited by raiwa

Share this post


Link to post
Share on other sites

Found that there is a mechanism already existing on admin that allows modules to show its version number (a public property called version) or API version but only seen this in action in the new paypal app and in some modules newly made by @kyrmation.

With the growing quantity of modules I think it would be nice if that feature gets into all the new modules as a best practice to allow an easier version control and a future way to check for updates from the web (like the mechanism in the header tags SEO contribution made by @@Jack_mcs).

Share this post


Link to post
Share on other sites

Still practising with modules. I wanted to improve content modules admin and found some rules to consider for future use when the admin site is improved, for common properties:

 

Content modules width (Bootstrap): There is not a common way to store the content width. Some modules uses strings like "half width" and some others use numerical values. For making some sort of graphical setup to see where each module is placed there should be class methods to set the content width and position, otherwise each module will have it's own way to set these and can't be done.

 

Enable/disable: There is no standard way to enable or disable a module. Some of them has the isEnabed () method but I found none with methods enable() or disable() like install() and uninstall(). If a module needs to disable another one there's not an straight way to do it.

 

thoughts?

Edited by piernas

Share this post


Link to post
Share on other sites

I agree that a standard way to set module width is needed. Perhaps a stock osCommerce function that can be called in the install() method of each module?

 

I don't believe I have ever come across any need to enable or disable a module, other than the installer setting of course. Can you give an example?

 

Regards

Jim


See my profile for a list of my addons and ways to get support.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×