Jump to content
greasemonkey

Oscommerce Affiliate Module - for BS

Recommended Posts

Hey all, I have been work on modernizing the Affiliate Module for 2.3.1 for 2.3.4 BS found here; http://addons.oscommerce.com/info/9171

 

For those that know me.... I'm not a programmer, but have learned enough to be dangerous.... so feel free to make comments and suggestions.

 

Because this addon uses its own (affiliate)_application_top's there are not a huge ton of core changes - however I should be able to get this down to just 2 code adds to call the new affiliate_application_top in admin and catalog.

 

So far I have;

 

1) almost all catalog pages bootstraped.

2) moved the build a link button from product_info into a _pi_ content module

3) I've added all the sql to the new _pi_ content module

4) bootstrapped the box module

5) fixed some basic "math" issues in the affiliate summary

 

Can someone suggest best practices for when when creating new tables on a module install?

 

Currently I have (as an example);

tep_db_query("CREATE TABLE IF NOT EXISTS affiliate_banners (
  affiliate_banners_id int(11) NOT NULL AUTO_INCREMENT,
  affiliate_banners_title varchar(64)  NOT NULL DEFAULT '',
  affiliate_products_id int(11) NOT NULL DEFAULT '0',
  affiliate_category_id int(11) NOT NULL DEFAULT '0',
  affiliate_banners_image varchar(64)  NOT NULL DEFAULT '',
  affiliate_date_added datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  affiliate_date_status_change datetime DEFAULT NULL,
  affiliate_status int(1) NOT NULL DEFAULT '1',
  PRIMARY KEY (affiliate_banners_id)
) 
COLLATE='utf8_unicode_ci'");

I am NOT dropping these new tables on "remove" (un-installtion) to prevent loss of affiliate data. Is this a wise idea?

Share this post


Link to post
Share on other sites

Hello Scott @@greasemonkey,
 
It's a good idea , but better offer an optional remove function for users who just tried the add-on or wants to remove all for whatever reason.
 
You can find an example for optional remove the database entries/tables when uninstalling a module in my SPPC Lite Add-On.
Have a look in the store module (includes/modules/content/store/st_wholesale.php):

      tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Uninstall Removes Database entries', 'MODULE_STORE_WHOLESALE_REMOVE_DATA', 'False', 'Do you want to remove the wholesale database entries when uninstall the module? (wholesale customers,  wholesale product prices and wholesale attribute prices will be lost)', '6', '2', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");

and:

    function remove() {
      if ( defined('MODULE_STORE_WHOLESALE_REMOVE_DATA') && MODULE_STORE_WHOLESALE_REMOVE_DATA == 'True' ) {
      	********'put here your drop table query'***********
        tep_db_query("alter table customers drop `customers_wholesale`");
      	tep_db_query("alter table products drop `products_ws_price`");
      	tep_db_query("alter table products_attributes drop `options_values_ws_price`");
      }
      tep_db_query("delete from configuration where configuration_key in ('" . implode("', '", $this->keys()) . "')");
    }

Like this the user can choose when he uninstalls the module if he wants to keep the database tables/columns or remove them.
 
It is based on the discussion and information in the best practice thread:
http://forums.oscommerce.com/topic/407530-addon-development-best-practices/?hl=%20best%20%20practice
 

 

Here is also a check if a column already exists in a table. Its based on a post Gary @@burt published in the same thread:

      if (tep_db_num_rows(tep_db_query("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA='". DB_DATABASE . "' AND TABLE_NAME='customers' AND COLUMN_NAME LIKE 'customers_wholesale'")) != 1 ) {
      tep_db_query("alter table customers add column `customers_wholesale` CHAR(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL");

rgds
Rainer

Edited by raiwa

Share this post


Link to post
Share on other sites

@@raiwa Hi Rainer, thank you kindly. I was looking for that post....

 

And thank you for that advise.

 

I have added your suggestion in to the box module - to add the required tables on install and remove if only if configuration set to true on remove

 

I have also removed the configuration_group and added all configurations to the content module.

 

Tell me does this make sense?

 

In the content module I have all the configurations

In the box module I have all the tables being added

 

The only reason why I did this is.... if I use this;

	  tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Un-install Removes Database entries', 'MODULE_BOXES_AFFILIATE_REMOVE_DATA', 'False', 'Do you want to remove the Affiliate database entries with un-install? (ALL affiliate date will be lost!!!)', '6', '2', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");

AND all the module configurations

      tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Display Module', 'MODULE_CONTENT_PRODUCT_INFO_BUILDALINK_STATUS', 'True', 'Activate wish list module?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
      tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_CONTENT_PRODUCT_INFO_BUILDALINK_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '6', now())");
      tep_db_query("INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('E-Mail Address', 'AFFILIATE_EMAIL_ADDRESS', 'Enter Email Address', 'The E Mail Address for the Affiliate Program', 0, 1, NULL, now())");
      tep_db_query("INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Affiliate Pay Per Sale Payment % Rate', 'AFFILIATE_PERCENT', '10.0000', 'Percentage Rate for the Affiliate Program', 0, 2, NULL, now())");
      tep_db_query("INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Payment Threshold', 'AFFILIATE_THRESHOLD', '50.00', 'Payment Threshold for paying affiliates', 0, 3, NULL, now())");
      tep_db_query("INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Cookie Lifetime', 'AFFILIATE_COOKIE_LIFETIME', '7200', 'How long does the click count (seconds) if customer comes back', 0, 4, NULL, now())");
      tep_db_query("INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Billing Time', 'AFFILIATE_BILLING_TIME', '30', 'Orders billed must be at least 30 days old.<br>This is needed if a order is refunded', 0, 5, NULL, now())");
      tep_db_query("INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Order Min Status', 'AFFILIATE_PAYMENT_ORDER_MIN_STATUS', '3', 'The status an order must have at least, to be billed', 0, 6, NULL, now())"); 
      tep_db_query("INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Pay Affiliates with check', 'AFFILIATE_USE_CHECK', 'true', 'Pay Affiliates with check', 0, 7, 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
      tep_db_query("INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Pay Affiliates with PayPal', 'AFFILIATE_USE_PAYPAL', 'true', 'Pay Affiliates with PayPal', 0, 8, 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
      tep_db_query("INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Individual Affiliate Percentage', 'AFFILATE_INDIVIDUAL_PERCENTAGE', 'true', 'Allow per Affiliate provision', 0, 9, 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
      tep_db_query("INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Use Affiliate-tier' , 'AFFILATE_USE_TIER', 'false', 'Multilevel Affiliate provisions', 0, 10, 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
      tep_db_query("INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Number of Tierlevels', 'AFFILIATE_TIER_LEVELS', '0', 'Number of Tierlevels', 0, 11, NULL, now())");
      tep_db_query("INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Percentage Rate for the Tierlevels', 'AFFILIATE_TIER_PERCENTAGE', '8.00;5.00;1.00', 'Percent Rates for the tierlevels<br>Example: 8.00;5.00;1.00', 0, 12, NULL, now())");
      tep_db_query("INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Affiliate News', 'MAX_DISPLAY_AFFILIATE_NEWS', '3', 'Maximum number of items to display on the Affiliate News page', 0, 12,  NULL, now())");

I feel the button to remove could easily be looked over - and or mistakenly used.

Share this post


Link to post
Share on other sites

@@dixiegiftshop @@discxpress I have a set of files.... but no instructions so I have not released as an addon.

 

Most/Many of the core changes are no longer required.... However there still are a few which you could compare to my files (which have other mods... so be careful!!!). Feel free to PM me your email address....

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

×