Jump to content
Latest News: (loading..)

Recommended Posts

Another improvement:

 

Saving a new discount code from admin, can throw messages on error.log as these ones:

PHP Notice:  Undefined index: exclude_specials in /opt/lampp/htdocs/fenix/amantis/amantis-fenix.4/admin/discount_codes.php on line 36
PHP Notice:  Undefined index: excluded_products_id in /opt/lampp/htdocs/fenix/amantis/amantis-fenix.4/admin/discount_codes.php on line 69

These fields can be disabled on the form, therefore there are not present on $_POST. This fix it:

 

after:

case 'insert':
        if (!empty($HTTP_POST_VARS['discount_codes']) && !empty($HTTP_POST_VARS['discount_values'])) {

add:

$exclude_specials = isset($HTTP_POST_VARS['exclude_specials']) ? (int) $HTTP_POST_VARS['exclude_specials'] : 0;

and use $exclude_specials to create $sql_data_array:

 'exclude_specials' => $exclude_specials,

Other hand, replace this:

if (is_array($HTTP_POST_VARS['excluded_products_id']) && sizeof($HTTP_POST_VARS['excluded_products_id']) > 0) {

whith this:

if (isset($HTTP_POST_VARS['excluded_products_id']) && is_array($HTTP_POST_VARS['excluded_products_id']) && sizeof($HTTP_POST_VARS['excluded_products_id']) > 0) {

Notes:

a ) Surely the last fix should be applied to other $_POST inspections: $HTTP_POST_VARS['categories_id'], $HTTP_POST_VARS['manufacturers_id'], etc.

b )  Maybe you want to implement the getting of $HTTP_POST_VARS['exclude_specials'] not where I said (before $sql_data_array creation), but on next lines, where tou perform the other checkings and add fields to $sql_data_array, one by one.

Edited by katapofatico

Share this post


Link to post
Share on other sites

@@Tsimi More improvements, this time in order to avoid code changes:

 

A ) Instead of write on admin/template_top.php, you can add these lines on admin/discount_codes.php, before applies_to_onclick() definition:

$(document).ready(function() {
    if (<?php echo ((basename($PHP_SELF) == 'discount_codes.php' && isset($action) && $action == 'new') ? 'true' : 'false')?>) {
        onload();
    }
});

B ) Instead of modify checkout_payment.php, you can use a header_tag module that inject HTML and javascript. I have the module files but... I can't attach to this post! Anybody can show me how?

 

C) Instead of modify 11 lines on checkout_process.php and 7 on application_top, you can use hook callings and write only 1 or 2 lines.

Share this post


Link to post
Share on other sites

[...]

B ) Instead of modify checkout_payment.php, you can use a header_tag module that inject HTML and javascript. I have the module files but... I can't attach to this post! Anybody can show me how?

[...]

 

@@Tsimi I have uploaded my header tag module here: http://addons.oscommerce.com/info/9470

Share this post


Link to post
Share on other sites

Hello Lambros @@Tsimi,

 

I observed something curious with the validation script.

 

If I change in application_top.php the error reporting from:

  error_reporting(E_ALL & ~E_NOTICE);

to:

  error_reporting(E_ALL);

the discount code validation script doesn't validate the coupon. Allthought the code is applied correct and order totals show correct.

 

See the screenshot, it's from shopping cart, but the same happens on checkout_payment.php:

 

 

It's obvious that it's not important for a production store, but it took me a bunch of time to find out why it didn't work on a develop store.

Thought you would like to know.

 

regards

Rainer

Share this post


Link to post
Share on other sites

@@raiwa

 

Thanks Rainer.

Not sure if this issue arised after I changed the original validation code or if it was already that way. Will look into it.

 

The guy above your post suggested a free shipping feature for this addon. I recall greasemonkey mentioning something about you coding that for him a while back. Is that correct! If yes, is it possible to get that code or is it a commercial thing?

Edited by Tsimi

Share this post


Link to post
Share on other sites

Here is a BETA package that contains a couple of code improvements provided by @@katapofatico and the new discount on shipping feature provided by @@raiwa and @@greasemonkey. I need some guys to test this before it can be cleaned and uploaded as new update to the addons area.

 

 

 

 

 

*Please do not use this in a live store yet, this package is not final and contains a lot uncleaned code.

Share this post


Link to post
Share on other sites

Hello Lambros @@Tsimi,

 

I gave it a try and it seems to work all ok in general terms.

Just a few suggestions/observations:

 

1. Shipping discount:

We could add the following mod to show different text in the ot description if shipping discount is used:

In ot_discount.php:

        $this->output[] = array('title' => (($shipping_discount == 'true')? TEXT_SHIPPING_DISCOUNT : TEXT_DISCOUNT) . (!empty($order_info) ? ' (' . $sess_discount_code . ')' : '') . ':',

Then add the language definition to main language file (for now):

  define('TEXT_SHIPPING_DISCOUNT', 'Shipping discount');

2. The language definitions could be moved from the main language file to a module. However I couldn't get the language constants to be defined when placed in the ht module and couldn't figure out why.

 

3. Point 7 in the Installation doc should be removed, this is done now in the ht module.

 

4. I observed that the discount code is not stored any more once it is validated and applied to an order. When going back from checkout confirmation page to any previous page, the discount code gets lost. In the old version it was kept stored in the session or order I suppose.

 

Otherwise great update

regards

Rainer

Share this post


Link to post
Share on other sites

@@raiwa

 

Hi Rainer

 

Thank you very much for the valuable input and time you took to look at the package.

 

Point 1:

 

Done!

 

Point 2:

 

Removed language definitions from english.php and added them inside the ht and ot module lang files.

 

in the  HT module add 

define('TEXT_DISCOUNT_CODE', 'Discount Code');

in the OT module add

 

define('TEXT_DISCOUNT', 'Discount');
define('TEXT_SHIPPING_DISCOUNT', 'Shipping discount');

Point 3:

 

Forgot to remove.  :-  Done now!

 

Point 4:

 

Hmmm... now that you mention it. It does not stay as it was in the previous releases. Just need to find out since when that is happening. 3.6? 3.5? etc...

 

 

I will try to create hooks for the changes in checkout_process and application_top like katapofatico recommended and then we have a no core code change addon. Kinda hard to do all at the moment with the Euro 2016 running, Hobby (bike engine tuning), new dog (4th dog!) and I still need to test your new shopping cart modules too. Just not enough hours in one day.  :wacko:

 

Again thanks for all the help you always provide and also thanks for the code. It is very clever coded (IMO), simple and it does the trick. :thumbsup:  

Share this post


Link to post
Share on other sites

Did you ever manage to sort out the problem with using this and paypal? 

 

I was not aware that there is a problem with PayPal.

I have tested this numerous times with PP and the discount works just fine. It even shows up in the PayPal item listing.

Share this post


Link to post
Share on other sites

Sorry, i should of been a bit more forthcoming with information.. 

 

a set discount amount which if not all spent send the total into minus doesnt work with paypal, you mentioned it quite early on. 

 

(i know set amounts arn't great for this reason, but the discount was already given out to customers before i could advise against it)

Share this post


Link to post
Share on other sites

For your old version (2.6) I showed you the fix. That fix doesn't work in the latest version. It is always recommended to give out coupons with % and not fixed prices. And as you mentioned PayPal will always make trouble if your total goes into minus area.

Share this post


Link to post
Share on other sites

I resolved it by only showing only one form of payment (card) when a discount code which has a total higher then products total is present.

 

its probably messy but it has done the job - thank you for your help Tsimi.  

Share this post


Link to post
Share on other sites

@@raiwa

 

found out the reason why the code wouldn't stay inside the input field.

The $sess_discount_code was missing inside the globals of the HT module.

Share this post


Link to post
Share on other sites

@@raiwa

 

Thanks Rainer.

I went a step further and recoded the whole addon.

I am still testing and cleaning up the code but now when you create a new code you have a radio button that says Shipping. Clicking that will create a code for shipping only and in the admin area where it lists all codes it says "Applies to" there it will say "Shipping".

 

So the whole trick with adding the "s" falls away and works now basically same as the Order Sub-Total feature.

I will upload a package here for testing once I am done. In your case you will need to replace the OT module file and the discount_codes.php in the admin area but later more...stay tuned. :)

 

P.S. php7 fixes will be applied as I go... :thumbsup:

Edited by Tsimi

Share this post


Link to post
Share on other sites

@@raiwa

 

Here the latest package.

Added php7 compatibility and the new shipping discount feature. 

If you still have the previous beta version installed then you only need to replace the OT module file and the discount_codes.php file in the admin area plus the language file for it.

 

Discount_Codes_3.7_BS.zip

 

I might have missed something in the manual or code itself so any input/improvement is very welcome.

Edited by Tsimi

Share this post


Link to post
Share on other sites

@@Tsimi,

 

Checked it and looks all good. Nice, elegant and comprehensive solution. Great job. :thumbsup:

 

Only issue I found is the database update for previous versions.

You should add a subcheck in the ot_discount module if the column "shipping" exists and if not run an update sql.

 

I had to add the "shipping" column by hand.

I uninstalled and installed it again, but as it checks only if the table exists, it doesn't add the shipping column.

 

regards

Rainer

Edited by raiwa

Share this post


Link to post
Share on other sites

@@raiwa

 

Yeah, forgot to mention the new field, sorry about that.

Didn't it install the field after you removed and re-installed the OT module?

Edited by Tsimi

Share this post


Link to post
Share on other sites

But if you remove/uninstall the module once the table gets deleted and then when you reinstall the module it creates the table again but this time with the new field, right?

 

With remove I meant uninstall.

Share this post


Link to post
Share on other sites

@@Tsimi,

 

Sorry, you are right, I removed and installed again the ht module instead of the ot module o:)

 

However there is an issue with the update:

If someone updates from previous versions and uninstall and reinstall the ot module, all existing discount codes will be lost.

You should add a configuration option in the ot module "Remove data = 'true' or 'false'".

I did this in the Wholesale SPPC light add-on.

Here the snippets:

      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())");
    function remove() {
      if ( defined('MODULE_STORE_WHOLESALE_REMOVE_DATA') && MODULE_STORE_WHOLESALE_REMOVE_DATA == 'True' ) {
      	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()) . "')");
    }

Then within the install function in the ot module, a check if the shipping field exists should be added and if it doesn't exist add it.

 

regards

Rainer

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

×