Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Converting Points and Rewards system for osC BS


Tsimi

Recommended Posts

YEP, I didn't check the point to redeem (points_selection) display, only the referral display. I thought nothing at all, neither the referral part was shown.

You are 100% right, I must have accidentally deleted this line when I added the PWA support. Will restore and push right now.

Link to comment
Share on other sites

Just looked at your latest commit.

Is this path correct?

require('includes/languages/' . $language . '/hs/shop/checkout_payment/points.php');

shouldn't that be

require('includes/languages/' . $language . '/hooks/shop/checkout_payment/points.php');

Link to comment
Share on other sites

55 minutes ago, raiwa said:

yes sure, will fix it

Done and auto credit mod pushed

Link to comment
Share on other sites

I was thinking about the check boxes in the orders.php page.
Shouldn't they be radio buttons instead of check boxes? I mean wouldn't someone choose one or the other?
Validate the points and delete them at the same time doesn't make sense don't you think?

With radio buttons you can choose one or the other but not both.
Maybe use something like this?

<?php
/*
  $Id: points.php
  $Loc: catalog/includes/hooks/admin/orders/
   
   originally coded by Ben Zukrel 
   Improved and converted for osC Bootstrap by
   @Tsimi
   and
   @raiwa Rainer Schmied / [email protected]  / www.oscaddons.com

   Additional credits to @LeeFoster for bug reports and fixes
   German translation by @Tsimi
   German revision by @raiwa
   Spanish translation by @TITO4
   Spanish revision by @PiLLaO 
  
  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2017 osCommerce

  Released under the GNU General Public License
*/

class hook_admin_orders_points {

  function listen_PointsOrderUpdatePoints() {
    global $comments, $oID, $language;
    
    require(DIR_FS_CATALOG . 'includes/languages/' . $language . '/hooks/admin/orders/points.php');
    
    if ((MODULE_HEADER_TAGS_POINTS_REWARDS_USE_POINTS_SYSTEM == 'True') && !tep_not_null(MODULE_HEADER_TAGS_POINTS_REWARDS_POINTS_POINTS_AUTO_ON)) {
      if ( (isset($_POST['confirm_points']) && ($_POST['confirm_points'] == 'on')) || (isset($_POST['delete_points']) && ($_POST['delete_points'] == 'on')) ) {
        $customer_query = tep_db_query("select customer_id, points_pending from customers_points_pending where points_status = 1 and points_type = 'SP' and orders_id = '" . (int)$oID . "' limit 1");
        $customer_points = tep_db_fetch_array($customer_query);
        if (tep_db_num_rows($customer_query)) {
          if ( isset($_POST['delete_points']) && ($_POST['delete_points'] == 'on') ) {
            tep_db_query("delete from customers_points_pending where orders_id = '" . (int)$oID . "' and points_type = 'SP' limit 1");
            $sql = "optimize table customers_points_pending";
          }
          if ( isset($_POST['confirm_points']) && ($_POST['confirm_points'] == 'on') ) {
            if (tep_not_null(MODULE_HEADER_TAGS_POINTS_REWARDS_POINTS_POINTS_AUTO_EXPIRES)) {
              $expire  = date('Y-m-d', strtotime('+ '. MODULE_HEADER_TAGS_POINTS_REWARDS_POINTS_POINTS_AUTO_EXPIRES .' month'));
              tep_db_query("update customers set customers_shopping_points = customers_shopping_points + '". $customer_points['points_pending'] ."', customers_points_expires = '". $expire ."' where customers_id = '". (int)$customer_points['customer_id'] ."'");
            } else {
              tep_db_query("update customers set customers_shopping_points = customers_shopping_points + '". $customer_points['points_pending'] ."' where customers_id = '". (int)$customer_points['customer_id'] ."'");
            }
            tep_db_query("update customers_points_pending set points_status = 2 where orders_id = '" . (int)$oID . "' and points_type = 'SP' limit 1");
            $sql = "optimize table customers_points_pending";
            $comments = POINTS_HOOK_ORDERS_CONFIRMED_POINTS  . $comments;
          }
        }
      }
    }
  }
  
  function listen_PointsOrderRemovePoints() {
    global $oID;
        
    tep_db_query("delete from customers_points_pending where orders_id = '" . (int)$oID . "'");
    $sql = "optimize table customers_points_pending";
  }

  function listen_PointsOrderPointsFields() {
    global $oID, $language;
        
    require(DIR_FS_CATALOG . 'includes/languages/' . $language . '/hooks/admin/orders/points.php');

    if ((MODULE_HEADER_TAGS_POINTS_REWARDS_USE_POINTS_SYSTEM == 'True') && !tep_not_null(MODULE_HEADER_TAGS_POINTS_REWARDS_POINTS_POINTS_AUTO_ON)) {
      $p_status_query = tep_db_query("select points_status from customers_points_pending where points_status = 1 and points_type = 'SP' and orders_id = '" . (int)$oID . "' limit 1");
      if (tep_db_num_rows($p_status_query)) {
        echo '<tr>
                <td colspan="2"><hr></td>
              </tr>
              <tr>
                <td><strong>' . POINTS_HOOK_ORDERS_ENTRY_NOTIFY_POINTS . '</strong></td><td>' . tep_draw_radio_field('confirm_points', '', false) . POINTS_HOOK_ORDERS_QUE_POINTS . '</td>
              </tr>
              <tr>
                <td></td><td>' . tep_draw_radio_field('delete_points', '', false) . POINTS_HOOK_ORDERS_QUE_DEL_POINTS . '&nbsp;</td>
              <tr>
                <td colspan="2"><hr></td>
              </tr>';
?>
<script>
$('select[name="status"]').change(function(){
  var statusArray = '<?php echo MODULE_HEADER_TAGS_POINTS_REWARDS_POINTS_AUTO_TICK_ORDER_STATUS ?>'.split(',');
  if (statusArray.indexOf($(this).val()) >= 0) {
    $('input:radio[name="confirm_points"]').each(function(){ this.checked = true; });
    $('input:radio[name="delete_points"]').each(function(){ this.checked = false; });
  } else {
    $('input:radio[name="confirm_points"]').each(function(){ this.checked = false; });
  }
});
$('input:radio[name="confirm_points"]').on("click", function (){
  if (this.checked == true) {
    $('input:radio[name="delete_points"]').each(function(){ this.checked = false; });
  }
});
$('input:radio[name="delete_points"]').on("click", function (){
  if (this.checked == true) {
    $('input:radio[name="confirm_points"]').each(function(){ this.checked = false; });
  }
});
</script>
<?php
      }
    }
  }

} // end class

 

Link to comment
Share on other sites

@raiwa

Never mind the radio button idea.
There is a major flaw. You can't deselect/uncheck the radio buttons once selected. So it might cause some issues for people when they want to update the order without touching the points yet but accidentally selected one or the other option.

Check boxes are fine so we go as it is.

Edited by Tsimi
Link to comment
Share on other sites

3 minutes ago, Tsimi said:

There is a major flaw. You can't deselect/uncheck the radio buttons once selected. So it might cause some issues for people when the want to update the order without touch the points yet but accidentally selected one or the other option.

Thats why I kept the checkboxes and added the toggle script

EDIT: I also had the idea to add 3 radios, one with default option "None", but I believe the checkboxes fit better.

Edited by raiwa
Link to comment
Share on other sites

Link to comment
Share on other sites

Hi,

First off wanted to say great work on making this module happen BS Osc has been crying out for this kind of thing.

Did a few tests on my site and came across the following issues, I am using the version uploaded to the apps on 10th October 2017 by Tsimi

Image 1) (delete_points_adjust_admin.jpg) whilst attempting to delete /adjust points in the admin section of a customers points allocation I had the error in the image appear if i tried to delete all of the points the customer had it did however let me delete / adjust points if i only attempted to remove so many points eg. delete 50 out of 100 points

Image 2) (caheckout_paying_cash_all_points) whilst attempting to check out a cash in store checkout option and using all available points as part payment e.g £10 cost of product - (£2 points) £8 to pay the error was shown also has same error when trying to do the same with a paypal payment

with Image 2 by editing the code below i am able to checkout fully and i don't have the 1048 error. However this seemed to have stopped the payment methods from working as a partial checkout. part points / part paypal

i edited the following code on or around Line 203 to line 210 

**FROM THIS

// balance customer points account & record the customers redeemed_points

  function tep_redeemed_points($customer_id, $insert_id, $customer_shopping_points_spending) {

      

      if ((tep_get_shopping_points($customer_id) - $customer_shopping_points_spending) > 0) {

          tep_db_query("update customers set customers_shopping_points = customers_shopping_points - '". $customer_shopping_points_spending ."' where customers_id = '". (int)$customer_id ."' limit 1");

      } else {

          tep_db_query("update customers set customers_shopping_points = null, customers_points_expires = null where customers_id = '". (int)$customer_id ."' limit 1");

      }

 

**TO THIS**

// balance customer points account & record the customers redeemed_points
  function tep_redeemed_points($customer_id, $insert_id, $customer_shopping_points_spending) {
      
      if ((tep_get_shopping_points($customer_id) - $customer_shopping_points_spending) > 0) {
          tep_db_query("update customers set customers_shopping_points = customers_shopping_points - '". $customer_shopping_points_spending ."' where customers_id = '". (int)$customer_id ."' limit 1");
      } else {
          tep_db_query("update customers set customers_shopping_points = '0.00', customers_points_expires = null where customers_id = '". (int)$customer_id ."' limit 1");
      }

found the above almost fix from the old points / rewards module

 

Any questions about the above or  any help with a fix will be greatly appreciated thanks again

 

 

caheckout_paying_cash_all_points.thumb.jpg.fe7ea36fdbca6778c73038cdda48f370.jpg

delete_points_adjust_admin.jpg

Link to comment
Share on other sites

@dnbvinyl

Regarding error #1,

Can't recreate that error.
In my test shop I can adjust/remove points without any issues. Even all the way down to 0.
The only thing that I can think of is maybe set the customers_shopping_points field Null value to "Yes". Access your database via phpMyAdmin and go to the customers table and look for the customers_shopping_points field. Click on the pencil icon to edit that field and tick the checkbox for "Null". 
After you've done that try it again.

Regarding error #2,

do you have a link to that "cash in store" payment module?

Regarding PayPal,

what PayPal method are you using? Did you use the files from the PayPal App package that is contained inside the addon?

Edited by Tsimi
Link to comment
Share on other sites

HI All

Great module. I have been testing this on a clean install of latest BS EDGE and have come up on a bug. Module works great until the total of the order ticks over 1000. then the Total seems to display only the first thousand before the "," separator. IE 2 for 2,000 or 10 for 10,000. I have attached 3 screenshots showing the examples.

Does anyone have any ideas?

 

Thx

Igor

 

1 (3).png

1 (1).png

1 (2).png

Link to comment
Share on other sites

Found a possible fix for bug, let's call it Bug 11.

Inside the order total module we need to add a different number_format.

@igorb

Can you please open the following file

catalog/includes/modules/order_total/ot_redemptions.php

Find this code on line 54
 

$order->info['total'] = number_format($order->info['total'] - tep_calc_shopping_pvalue($customer_shopping_points_spending), 4);

REPLACE WITH
 

$order->info['total'] = $this->format_raw($order->info['total'] - tep_calc_shopping_pvalue($customer_shopping_points_spending));

then FIND this code around line 80-84
 

    function remove() {
        tep_db_query("delete from configuration where configuration_key in ('" . implode("', '", $this->keys()) . "')");
    }
  }

REPLACE WITH
 

    function remove() {
        tep_db_query("delete from configuration where configuration_key in ('" . implode("', '", $this->keys()) . "')");
    }

	function format_raw($number, $currency_code = '', $currency_value = '') {
      global $currencies, $currency;

      if (empty($currency_code) || !$currencies->is_set($currency_code)) {
        $currency_code = $currency;
      }

      if (empty($currency_value) || !is_numeric($currency_value)) {
        $currency_value = $currencies->currencies[$currency_code]['value'];
      }

      return number_format(tep_round($number * $currency_value, $currencies->currencies[$currency_code]['decimal_places']), $currencies->currencies[$currency_code]['decimal_places'], '.', '');
    }
  }

This should fix that bug. Please try it once and report back.

@LeeFoster

You can replicate that bug when you add items into your cart that have total value of more then $1000.
When you then proceed to the checkout and try to redeem points the order total on the confirmation page shows the wrong total.
The fix I recommended above should fix that. I am just not sure yet if that fix impacts anything else in the addon.
I'll just wait for code confirmation from @raiwa before I release the new update of this addon. Lucky the bug was found just in time before the next release.

Edited by Tsimi
Link to comment
Share on other sites

1 minute ago, Tsimi said:

Found a possible fix for bug, let's call it Bug 11.

Inside the order total module we need to add a different number_format.

@igorb

Can you please open the following file

catalog/includes/modules/order_total/ot_redemptions.php

Find this code on line 54
 


$order->info['total'] = number_format($order->info['total'] - tep_calc_shopping_pvalue($customer_shopping_points_spending), 4);

REPLACE WITH
 


$order->info['total'] = $this->format_raw($order->info['total'] - tep_calc_shopping_pvalue($customer_shopping_points_spending));

then FIND this code around line 80-84
 


    function remove() {
        tep_db_query("delete from configuration where configuration_key in ('" . implode("', '", $this->keys()) . "')");
    }
  }

REPLACE WITH
 


    function remove() {
        tep_db_query("delete from configuration where configuration_key in ('" . implode("', '", $this->keys()) . "')");
    }

	function format_raw($number, $currency_code = '', $currency_value = '') {
      global $currencies, $currency;

      if (empty($currency_code) || !$currencies->is_set($currency_code)) {
        $currency_code = $currency;
      }

      if (empty($currency_value) || !is_numeric($currency_value)) {
        $currency_value = $currencies->currencies[$currency_code]['value'];
      }

      return number_format(tep_round($number * $currency_value, $currencies->currencies[$currency_code]['decimal_places']), $currencies->currencies[$currency_code]['decimal_places'], '.', '');
    }
  }

This should fix that bug. Please try it once and report back.

@LeeFoster

You can get that bug when you add items into your cart that have total value of more then $1000.
When you then proceed to the checkout and try to redeem points the order total on the confirmation page shows the wrong total.
The fix I recommended above should fix that. I am just not sure yet if that fix impacts anything else in the addon.
I'll just wait for code confirmation from @raiwa before I release the new update of this addon. Lucky the bug was found just in time before the next release.

Does this only happen if you redeem vouchers or does it happen on the checkout either way? I'm at work right now and don't have my test environment again.

Link to comment
Share on other sites

Only when you try to redeem points because only then it will use the ot_redemptions order total file which contains that wrong code.
If you checkout normal without redeeming points all works just fine as it should.

Link to comment
Share on other sites

@raiwa

  • Fixed typo in path for install steps 2 and 4
  • Added version number to amended files only
  • Updated install manual with a change log
  • Added fix for Bug 11 (needs further testing to 100% sure )

You want me to send a pull request or do you want to have a look before?

Link to comment
Share on other sites

Hello @Tsimi,

Sorry for the late reply, I was out all day.

For the errors reported by @dnbvinyl: I couldn't reproduce them neither.

For the ot bug#11:

I can confirm the bug, but there is an easier solution. We do not need to use our own custom functions. Just use "$currencies->format_raw" instead of "number_format":

	        $order->info['total'] = $currencies->format_raw($order->info['total'] - tep_calc_shopping_pvalue($customer_shopping_points_spending));

I pushed the fix, please check and then ok for update.

Link to comment
Share on other sites

@raiwa

Tomorrow I am at the office the whole day and I'll check your fix. It's 2:23am over here and I'm off to bed.

Did you check my fork regarding the other stuff? Like install manual update, version number thing. Is that OK?

Edited by Tsimi
Link to comment
Share on other sites

5 hours ago, raiwa said:

Hello @Tsimi,

Sorry for the late reply, I was out all day.

For the errors reported by @dnbvinyl: I couldn't reproduce them neither.

For the ot bug#11:

I can confirm the bug, but there is an easier solution. We do not need to use our own custom functions. Just use "$currencies->format_raw" instead of "number_format":


	        $order->info['total'] = $currencies->format_raw($order->info['total'] - tep_calc_shopping_pvalue($customer_shopping_points_spending));

I pushed the fix, please check and then ok for update.

 

This looks like a fix :)

 

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...