Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Converting Points and Rewards system for osC BS


Tsimi

Recommended Posts

@raiwa

I added that new bug information into the known bug list.
Added new shopping cart with points boxes module to the package
I updated the install manual with minor code cleaning and the changes for that new boxes module.

You can merge them anytime you like. If you made any recent changes to the install manual let me now please.

Next I'll try that navbar module.
You mean that dropdown cart right?

Edited by Tsimi
Link to comment
Share on other sites

1 hour ago, Tsimi said:

@raiwa

Next I'll try that navbar module.

You mean that dropdown cart right?

Yes, drop down cart. I believe it's most used in BS

Send pull request for the other updates, please.

Edited by raiwa
Link to comment
Share on other sites

@LeeFoster and @Tsimi,

First hook to replace the mods in create_account.php found following issue:

If we keep the modifications in the create account confirmation e-mail exact like now, we need to replace the complete e-mail definition in the hook:

      if (ACCOUNT_GENDER == 'true') {
         if ($gender == 'm') {
           $email_text = sprintf(EMAIL_GREET_MR, $lastname);
         } else {
           $email_text = sprintf(EMAIL_GREET_MS, $lastname);
         }
      } else {
        $email_text = sprintf(EMAIL_GREET_NONE, $firstname);
      }

      if ((MODULE_HEADER_TAGS_POINTS_REWARDS_USE_POINTS_SYSTEM == 'True') && (MODULE_HEADER_TAGS_POINTS_REWARDS_POINTS_NEW_SIGNUP_POINT_AMOUNT > 0)) {
	      tep_add_welcome_points($customer_id);
	      
	      $points_account = '<a href="' . tep_href_link('my_points.php', '', 'SSL') . '"><b><u>' . EMAIL_POINTS_ACCOUNT . '</u></b></a>.';
	      $points_faq = '<a href="' . tep_href_link('my_points_help.php', '', 'NONSSL') . '"><b><u>' . EMAIL_POINTS_FAQ . '</u></b></a>.';
	      $text_points = sprintf(EMAIL_WELCOME_POINTS , $points_account, number_format(MODULE_HEADER_TAGS_POINTS_REWARDS_POINTS_NEW_SIGNUP_POINT_AMOUNT,MODULE_HEADER_TAGS_POINTS_REWARDS_POINTS_POINTS_DECIMAL_PLACES), $currencies->format(tep_calc_shopping_pvalue(MODULE_HEADER_TAGS_POINTS_REWARDS_POINTS_NEW_SIGNUP_POINT_AMOUNT)), $points_faq) ."\n\n";
	      
	      $email_text = EMAIL_WELCOME . EMAIL_TEXT . $text_points . EMAIL_CONTACT . EMAIL_WARNING;
      }

If we would alter the order and put "$text_points" at the end, it would be m ore simple and other modifications/add-ons could manipulate the e-mail content on a easier way.

The hook function would look then like this:

      if ((MODULE_HEADER_TAGS_POINTS_REWARDS_USE_POINTS_SYSTEM == 'True') && (MODULE_HEADER_TAGS_POINTS_REWARDS_POINTS_NEW_SIGNUP_POINT_AMOUNT > 0)) {
	      tep_add_welcome_points($customer_id);
	      
	      $points_account = '<a href="' . tep_href_link('my_points.php', '', 'SSL') . '"><b><u>' . EMAIL_POINTS_ACCOUNT . '</u></b></a>.';
	      $points_faq = '<a href="' . tep_href_link('my_points_help.php', '', 'NONSSL') . '"><b><u>' . EMAIL_POINTS_FAQ . '</u></b></a>.';
	      $text_points = sprintf(EMAIL_WELCOME_POINTS , $points_account, number_format(MODULE_HEADER_TAGS_POINTS_REWARDS_POINTS_NEW_SIGNUP_POINT_AMOUNT,MODULE_HEADER_TAGS_POINTS_REWARDS_POINTS_POINTS_DECIMAL_PLACES), $currencies->format(tep_calc_shopping_pvalue(MODULE_HEADER_TAGS_POINTS_REWARDS_POINTS_NEW_SIGNUP_POINT_AMOUNT)), $points_faq) ."\n\n";
	      
	      $email_text .= $text_points;
      }

Your thoughts, other ideas?

Link to comment
Share on other sites

I found a fix for bug 2. In checkout_confirmation.php

Find

if (!tep_session_is_registered('comments')) tep_session_register('comments');
  if (isset($_POST['comments']) && tep_not_null($_POST['comments'])) {
    $comments = tep_db_prepare_input($_POST['comments']);
  }

Add below

if (!tep_session_is_registered('customer_shopping_points_spending')) tep_session_register('customer_shopping_points_spending');
if (isset($_POST['customer_shopping_points_spending']) && tep_not_null($_POST['customer_shopping_points_spending'])) {
    $customer_shopping_points_spending = tep_db_prepare_input($_POST['customer_shopping_points_spending']);
  }

Find

 if ( ($payment_modules->selected_module != $payment) || ( is_array($payment_modules->modules) && (sizeof($payment_modules->modules) > 1) && !is_object($$payment) ) || (is_object($$payment) && ($$payment->enabled == false)) ) {
    tep_redirect(tep_href_link('checkout_payment.php', 'error_message=' . urlencode(ERROR_NO_PAYMENT_MODULE_SELECTED), 'SSL'));
  }

Replace with

 if ( ($payment_modules->selected_module != $payment) || ( is_array($payment_modules->modules) && (sizeof($payment_modules->modules) > 1) && !is_object($$payment) ) && (!$customer_shopping_points_spending) || (is_object($$payment) && ($$payment->enabled == false)) ) {
    tep_redirect(tep_href_link('checkout_payment.php', 'error_message=' . urlencode(ERROR_NO_PAYMENT_MODULE_SELECTED), 'SSL'));
  }

I'm going to look at bug 4 now.

Link to comment
Share on other sites

@LeeFoster

Thanks! Will check it out.

@raiwa

Pull request send.

--------------------------------------------

Also found more bugs

Bug 5

In the Points FAQ page the "Last updated:" won't show any date no matter if you change anything or not.

Bug 6

If the customer has never received points before and you add points to him through the admin area and keep every checkbox unchecked the points don't show up inside the account page and/or shopping cart box/navbar
Unless you click on the adjust button and enter the points then it will show them.

Link to comment
Share on other sites

@LeeFoster

Fix for Bug 2 doesn't work for me.
I get to the payment page and none of the payment methods is selected which is good, then I tick the checkbox to use the points and if I click on the continue button the javascript on the radio buttons tells me to select one.

Additional to your changes if I do the following:

In checkout_payment.php

FIND:

 echo tep_draw_radio_field('payment', $selection[$i]['id'], ($selection[$i]['id'] == $payment), 'aria-required="true"');

REPLACE WITH

 echo tep_draw_radio_field('payment', $selection[$i]['id'], ($selection[$i]['id'] == $payment));

Then it does work.

Edited by Tsimi
Link to comment
Share on other sites

5 minutes ago, LeeFoster said:

This works for me.

Doesn't work for me neither. Lee it seems you need to update all your installation from the actual git hub repository to be up to date.

Link to comment
Share on other sites

3 hours ago, Tsimi said:

Bug 5

In the Points FAQ page the "Last updated:" won't show any date no matter if you change anything or not.

Bug 5 is fixed. My fault, had last modified removed from the configuration entries in the ht module. I put them back and all shows ok now. You'll need to update the ht module and uninstall and reinstall it.

Link to comment
Share on other sites

@LeeFoster, @Tsimi,

I believe the "my_points_help.php" language file needs an overhaul. It's in my opinion not good practice to have all these conditions, database queries and "tep_get_last_date" functions in the language file. Better to use "%s" and move all these coding into the page file.

Your thoughts?

Edited by raiwa
Link to comment
Share on other sites

43 minutes ago, raiwa said:

@LeeFoster, @Tsimi,

I believe the "my_points_help.php" language file needs an overhaul. It's in my opinion not good practice to have all these conditions, database queries and "tep_get_last_date" functions in the language file. Better to use "%s" and move all these coding into the page file.

Your thoughts?

I agree, I'd not even looked at the file.

Link to comment
Share on other sites

Link to comment
Share on other sites

5 hours ago, Tsimi said:

Bug 6

If the customer has never received points before and you add points to him through the admin area and keep every checkbox unchecked the points don't show up inside the account page and/or shopping cart box/navbar
Unless you click on the adjust button and enter the points then it will show them.

In redemptions.php 

Find

if (tep_not_null(MODULE_HEADER_TAGS_POINTS_REWARDS_POINTS_POINTS_AUTO_EXPIRES)) {
		  $points_query = tep_db_query("select customers_shopping_points from customers where customers_id = '" . (int)$id . "' and customers_points_expires > CURDATE() limit 1");
	   } else {
		  $points_query = tep_db_query("select customers_shopping_points from customers where customers_id = '" . (int)$id . "' limit 1");
	  }
	  
	  $points = tep_db_fetch_array($points_query);
	  
	  return $points['customers_shopping_points'];
  }

Replace with

if (tep_not_null(MODULE_HEADER_TAGS_POINTS_REWARDS_POINTS_POINTS_AUTO_EXPIRES)) {
		  $points_query = tep_db_query("select customers_shopping_points from customers where customers_id = '" . (int)$id . "' and customers_points_expires > CURDATE() OR customers_points_expires is null limit 1");
	   } else {
		  $points_query = tep_db_query("select customers_shopping_points from customers where customers_id = '" . (int)$id . "' limit 1");
	  }
	  
	  $points = tep_db_fetch_array($points_query);
	  
	  return $points['customers_shopping_points'];
  }

Fixing this allowed me to replicate Bug 4 so I'll work on that now.

Link to comment
Share on other sites

Bug 4 

In my_points.php

Find


<div class="row">
  <div class="col-md-6 pagenumber"><?php echo $pending_points_split->display_count(TEXT_DISPLAY_NUMBER_OF_RECORDS); ?></div>
  <div class="col-md-6"><span class="pull-right pagenav"><ul class="pagination"><?php echo $pending_points_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info'))); ?></ul></span><span class="pull-right"><?php echo TEXT_RESULT_PAGE; ?></span></div>
  </div>
<?php 
		} else {
?>

Replace with

<?php

  if ($pending_points_split->number_of_rows > 0) {
?>
<div class="row">
  <div class="col-md-6 pagenumber"><?php echo $pending_points_split->display_count(TEXT_DISPLAY_NUMBER_OF_RECORDS); ?></div>
  <div class="col-md-6"><span class="pull-right pagenav"><ul class="pagination"><?php echo $pending_points_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info'))); ?></ul></span><span class="pull-right"><?php echo TEXT_RESULT_PAGE; ?></span></div>
  </div>
<?php 
	}
	} else {
?>

That should fix it.

Link to comment
Share on other sites

@raiwa

To fix bug 2 we needed to add and replace codes inside the checkout_confirmation.php and checkout_payment.php
Can those be implemented into a HT module or Hook? I think you did some work for the checkout_confirmation.php file already right?

@LeeFoster

Thanks! Will check it out asap.

Edited by Tsimi
Link to comment
Share on other sites

40 minutes ago, Tsimi said:

@raiwa

To fix bug 2 we needed to add and replace codes inside the checkout_confirmation.php and checkout_payment.php
Can those be implemented into a HT module or Hook? I think you did some work for the checkout_confirmation.php file already right?

Yes, the checkout_confirmation.php snippet is already moved into ht module:

        case 'checkout_confirmation.php':
          if ((MODULE_HEADER_TAGS_POINTS_REWARDS_USE_POINTS_SYSTEM == 'True') && (MODULE_HEADER_TAGS_POINTS_REWARDS_USE_REDEEM_SYSTEM == 'True')) {
            if (isset($_POST['customer_shopping_points_spending']) && is_numeric($_POST['customer_shopping_points_spending']) && ($_POST['customer_shopping_points_spending'] > 0)) {
              $customer_shopping_points_spending = false;
              // This if sentence should include check for amount of points on account compared to the transferred point from checkout_payment.php
              // Possible Hack Fix included
              if (tep_calc_shopping_pvalue($_POST['customer_shopping_points_spending']) < $order->info['total'] && !is_object($$payment) || (tep_get_shopping_points($customer_id) < $_POST['customer_shopping_points_spending'])) {
                $customer_shopping_points_spending = false;
                $messageStack->add_session('header', MODULE_HEADER_TAGS_POINTS_REWARDS_ERROR_POINTS_NOT);
                tep_redirect(tep_href_link('checkout_payment.php', '', 'SSL'));
              } else {
                $customer_shopping_points_spending = $_POST['customer_shopping_points_spending'];
                if (!tep_session_is_registered('customer_shopping_points_spending')) tep_session_register('customer_shopping_points_spending');
              }
            }
	  
            //To ensure only the first order of a new customer is entitled to grant point to his/her referrer. Otherwise, a hacker might hard-code the email address of  a referrer and cheat for point on every single order the new customer made.
            if (tep_not_null(MODULE_HEADER_TAGS_POINTS_REWARDS_POINTS_USE_REFERRAL_SYSTEM) && (tep_count_customer_orders() == 0)) {
              if (isset($_POST['customer_referred']) && tep_not_null($_POST['customer_referred'])) {
                $customer_referral = false;
                $check_mail = trim($_POST['customer_referred']);
                if (tep_validate_email($check_mail) == false) {
                  $messageStack->add_session('header', MODULE_HEADER_TAGS_POINTS_REWARDS_ERROR_NOT_VALID);
                  tep_redirect(tep_href_link('checkout_payment.php', '', 'SSL'));
                } else {
                  $valid_referral_query = tep_db_query("select customers_id from customers where customers_email_address = '" . $check_mail . "' limit 1");
                  $valid_referral = tep_db_fetch_array($valid_referral_query);
                  if (!tep_db_num_rows($valid_referral_query)) {
                    $messageStack->add_session('header', MODULE_HEADER_TAGS_POINTS_REWARDS_ERROR_NOT_FOUND);
                    tep_redirect(tep_href_link('checkout_payment.php', '', 'SSL'));
                  }
				  
                  if ($check_mail == $order->customer['email_address']) {
                    $messageStack->add_session('header', MODULE_HEADER_TAGS_POINTS_REWARDS_ERROR_SELF);
                    tep_redirect(tep_href_link('checkout_payment.php', '', 'SSL'));
                  } else {
                    $customer_referral = $valid_referral['customers_id'];
                    if (!tep_session_is_registered('customer_referral')) tep_session_register('customer_referral');
                  }
                }
              }
            }
          }
          break;

Please apply the fix there. Anyway it would be great if you 2 could check checkout_confirmation.php for all the redirects and error messages working correct with the ht module.

Edited by raiwa
Link to comment
Share on other sites

3 minutes ago, raiwa said:

Yes, the checkout_confirmation.php snippet is already moved into ht module:


        case 'checkout_confirmation.php':
          if ((MODULE_HEADER_TAGS_POINTS_REWARDS_USE_POINTS_SYSTEM == 'True') && (MODULE_HEADER_TAGS_POINTS_REWARDS_USE_REDEEM_SYSTEM == 'True')) {
            if (isset($_POST['customer_shopping_points_spending']) && is_numeric($_POST['customer_shopping_points_spending']) && ($_POST['customer_shopping_points_spending'] > 0)) {
              $customer_shopping_points_spending = false;
              // This if sentence should include check for amount of points on account compared to the transferred point from checkout_payment.php
              // Possible Hack Fix included
              if (tep_calc_shopping_pvalue($_POST['customer_shopping_points_spending']) < $order->info['total'] && !is_object($$payment) || (tep_get_shopping_points($customer_id) < $_POST['customer_shopping_points_spending'])) {
                $customer_shopping_points_spending = false;
                $messageStack->add_session('header', MODULE_HEADER_TAGS_POINTS_REWARDS_ERROR_POINTS_NOT);
                tep_redirect(tep_href_link('checkout_payment.php', '', 'SSL'));
              } else {
                $customer_shopping_points_spending = $_POST['customer_shopping_points_spending'];
                if (!tep_session_is_registered('customer_shopping_points_spending')) tep_session_register('customer_shopping_points_spending');
              }
            }
	  
            //To ensure only the first order of a new customer is entitled to grant point to his/her referrer. Otherwise, a hacker might hard-code the email address of  a referrer and cheat for point on every single order the new customer made.
            if (tep_not_null(MODULE_HEADER_TAGS_POINTS_REWARDS_POINTS_USE_REFERRAL_SYSTEM) && (tep_count_customer_orders() == 0)) {
              if (isset($_POST['customer_referred']) && tep_not_null($_POST['customer_referred'])) {
                $customer_referral = false;
                $check_mail = trim($_POST['customer_referred']);
                if (tep_validate_email($check_mail) == false) {
                  $messageStack->add_session('header', MODULE_HEADER_TAGS_POINTS_REWARDS_ERROR_NOT_VALID);
                  tep_redirect(tep_href_link('checkout_payment.php', '', 'SSL'));
                } else {
                  $valid_referral_query = tep_db_query("select customers_id from customers where customers_email_address = '" . $check_mail . "' limit 1");
                  $valid_referral = tep_db_fetch_array($valid_referral_query);
                  if (!tep_db_num_rows($valid_referral_query)) {
                    $messageStack->add_session('header', MODULE_HEADER_TAGS_POINTS_REWARDS_ERROR_NOT_FOUND);
                    tep_redirect(tep_href_link('checkout_payment.php', '', 'SSL'));
                  }
				  
                  if ($check_mail == $order->customer['email_address']) {
                    $messageStack->add_session('header', MODULE_HEADER_TAGS_POINTS_REWARDS_ERROR_SELF);
                    tep_redirect(tep_href_link('checkout_payment.php', '', 'SSL'));
                  } else {
                    $customer_referral = $valid_referral['customers_id'];
                    if (!tep_session_is_registered('customer_referral')) tep_session_register('customer_referral');
                  }
                }
              }
            }
          }
          break;

Please apply the fix there. Anyway it would be great if you 2 could check checkout_confirmation.php for all the redirects and error messages working correct with the ht module.

I have the latest ht module installed but the fix for bug 2 has to be in the checkout_confirmation.php it just won't work if it's anywhere else. Unless I'm missing something.

Link to comment
Share on other sites

@Tsimi, @LeeFoster,

I had a look and believe that the first snippet can be moved to the ht, it doesn't matter when "customer_shopping_points_spending" is registered in session, or am I wrong?

I integrated it to the ht, can you please check.

The second modification, can you explain for what is this needed? Maybe no payment module needed to be selected if order total is covered by points? Then it would need to be done in checkout_confirmation indeed.

 

Link to comment
Share on other sites

@raiwa

Quote

The second modification, can you explain for what is this needed? Maybe no payment module needed to be selected if order total is covered by points? Then it would need to be done in checkout_confirmation indeed.

The goal is to allow a customer to continue without selecting any payment method if he has the necessary points to cover everything.
If you keep that required aria... code in there it will always show a popup next to the radio buttons to select a payment method.
If you add the modifications I recommended it will remove that popup. If the customer has not enough points to cover everything it will show a javascript kinda popup which says that he has to select a payment method.
The osC messagstack message becomes obsolete which is not ideal but good for now.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...