uStore Solution Allow Clearing Restriction Per User Group

613 views
Skip to first unread message

Igor

unread,
Apr 15, 2015, 4:03:54 PM4/15/15
to xmpie...@googlegroups.com
there is an old request to allow particular clearing option based on the uStore User group.
Those who still need something like that here something that can be used .
 I do not advise to use it if you do not understand it and can’t maintain it , this is not supported by XMPie . it was tested with uStore 8.x .
1) First backup your skin ThemedPageFullWidth.Master , if you do not have one copy it from ..\XMPie\uStore\App\CustomerApp\PageLayout to your skin folder ..\XMPie\uStore\App\CustomerApp\Images\[Some Skin Name]
2) Add the following code to the master page (in bold)
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="ThemedPageFullWidth.master.cs" Inherits="uStore.PageLayout.ThemedPageFullWidth" %>
<%@ Register TagPrefix="uStore" TagName="MetaTags" Src="~/UControls/MetaTags.ascx" %>
<%@ Register TagPrefix="uStore" TagName="WebEnhancerButton" Src="~/UControls/WebEnhancerButton.ascx" %>
<% 
// check if we are on CheckoutPaymentSubmission page 
 if (Request.Url.AbsolutePath.IndexOf("CheckoutPaymentSubmission.aspx", StringComparison.OrdinalIgnoreCase)!= -1)
      { %>
   <%
         // get current user ID
          var UserGroupsByUser = uStoreAPI.UserGroup.GetUserGroupList(uStore.Common.BLL.CustomerInfo.Current.UserID);
          var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
         // get list of group ID's user belong
          var UserGroupsByUserArray = serializer.Serialize(UserGroupsByUser.Select(g => g.UserGroupID));
         // expose Javascript variable with list of group user ID's
   %>
   <script type="text/javascript">
       var UserGroupsByUserArray = <%= UserGroupsByUserArray %>;
   </script>
   <% } %>

3) you can use same master page or use Add Javascript to Store Front feature to expose Javascript  
<script type="text/javascript">
  
    var UserGroupToClearingMapping = {}; 
     //mapping[group user id] = clearing ids
    // in this example User Group with ID 1 can see clearings with ID 1 , 2 and 10000 , while User Group with ID 2 can only see clearing with ID 1 and 2
   // User group ID's and Clearing ID's can be found in the uStore Admin  in the URL of the page you ,by clicking on particular User group or particular Clearing 
    UserGroupToClearingMapping[1] = [1,2,10000];
    UserGroupToClearingMapping[4]  = [1,2];
 
  
    if(typeof UserGroupsByUserArray !== 'undefined'){
        $(document).ready(function(){  
    
            var cls = $("input[id*='rdlClearingConfig']");
            if(cls.length > 0){
                $(cls).parent().hide();
      
                $.each(UserGroupToClearingMapping, function(groupId, clearings) {
                    if($.inArray(parseInt(groupId), UserGroupsByUserArray) >= 0){
                        $.each(clearings, function(index, value) {
                            var elem = $(cls).filter("[value="+ value +"]");
                            if(elem[0] != null) {
                                $(elem).parent().show();
                            }
                        });
                    }  
                });
         
                var checked = $(cls).filter(":checked");
                if(checked[0] != null){
                    if(checked.parent().is(':visible') == false){
                        var parent = $(cls).parent().filter(':visible')[0];
                        if(parent != null){
                            var input = $(parent).children("input[id*='rdlClearingConfig']");
                            $(input).click();
                        }
                        else{
                            $('td[class=ClearingConfigCell]').hide();
                        }
                    }
                }
     
                $("[id*=btnCheckout]").click(function(){
                    var checked = $(cls).filter(":checked");
                    if(checked[0] != null){
                        if(checked.parent().is(':visible') == false){
                            return false;
                        }
                    }
                });
            }
        });
    }
</script>


couch

unread,
Apr 16, 2015, 2:41:39 AM4/16/15
to xmpie...@googlegroups.com
These are both useful customizations. Thanks Igor!

Simon Knott

unread,
Jun 30, 2016, 4:57:52 AM6/30/16
to XMPie Interest Group
Hi Igor

This works and hides / shows the appropriate clearing method based on the group however it does mess up my page for some reason.

I noticed that if I use the old XMPie skin green it keeps the layout so I was wondering is there anything that needs to be added in because of updates etc as I noticed that this was posted from early 2015?

Kind Regards

Simon Knott

Simon Knott

unread,
Jun 30, 2016, 6:15:48 AM6/30/16
to XMPie Interest Group
I have figured it out, the code needs to be pasted in the ThemedPageFullWidth.Master file under the HTML tag and then it works!

Thanks

On Wednesday, April 15, 2015 at 9:03:54 PM UTC+1, Igor wrote:

Jill

unread,
Mar 3, 2020, 5:01:53 PM3/3/20
to XMPie Interest Group
I've been using this code successfully for a few years, but now I'm having trouble figuring out how to get this to work within the new NG Theme framework. Since we no longer place code directly into the ThemedPageFullWidth.Master page, is there any way to get this to work through the Add Javascript to Storefront feature? 

Thanks!
Jill

tshe...@alphagraphics.com

unread,
Jul 9, 2020, 7:18:45 PM7/9/20
to XMPie Interest Group
I too am wondering if this could be used on the ng storefront. In testing I am not able to get it to work.

Stephen Phillips

unread,
Jul 20, 2020, 12:53:16 PM7/20/20
to XMPie Interest Group
I would like to do this as well with NG Theme

couch

unread,
Jul 20, 2020, 9:38:02 PM7/20/20
to XMPie Interest Group
OK. I have not had the time to test Igor's solution on an NG store, but I have quickly made an example that works with NG:

Stephen Phillips

unread,
Jul 21, 2020, 9:10:45 AM7/21/20
to XMPie Interest Group
Thank you so much Couch!!!

On Mon, Jul 20, 2020 at 8:38 PM couch <sco...@gmail.com> wrote:
OK. I have not had the time to test Igor's solution on an NG store, but I have quickly made an example that works with NG:

--
You received this message because you are subscribed to the Google Groups "XMPie Interest Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xmpie-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/xmpie-users/ce5c3754-6e9e-4d69-a94d-bf6ddac6c540o%40googlegroups.com.


--



 Stephen Phillips
 Senior Web Developer

415 Spence Lane  | Nashville, TN 37210
615-361-7118 Phone  |  615-399-0157 Fax
ste...@nashvilleprinting.com  |   www.nashvilleprinting.com

bouncebacknashville.com

We Value your feedback! Please take a moment to tell us how we are doing. 
Click Here to leave us a review.

Message has been deleted

AnwarG

unread,
Jul 27, 2020, 3:59:11 AM7/27/20
to XMPie Interest Group
Perfect, thanks Couch!


Russell Mitchell

unread,
Aug 25, 2020, 8:53:15 PM8/25/20
to XMPie Interest Group
Hey Couch, thanks for this! I am running into a little bit of an issue though - the clearing portion works fine, however, the script causes issues with the proofing on dynamic items. If I use the script as is, (obviously adjust the 4 parameters), the clearing options work correctly, but I get errors on previewing dynamic items and proofs. If I use the script and adjust "var showclearingType1 = false" and "var showclearingType2 = false" to "=true", the previews and proofs work correctly, but now the clearing options both show up.

We have one Group "Registered" which we want to pay by CC, the other is "Admin" which gets invoiced. We do not want the "Registered" to have the option of choosing invoice.

I just updated to uStore 13.0 to try to fix the issue, and it is an NG store. Static items appear to work fine.

Any input would be much appreciated!

On Monday, July 27, 2020 at 3:59:11 AM UTC-4 AnwarG wrote:
Perfect, thanks Couch!


couch

unread,
Aug 25, 2020, 10:00:48 PM8/25/20
to XMPie Interest Group
Thanks for letting me know. I updated the script so it will only run on the checkout page.

Blake Norwood

unread,
Jan 7, 2021, 3:53:13 PM1/7/21
to XMPie Interest Group
Couch, can this be modified to limit the shipping options base on group? Where would I find the right variables?

couch

unread,
Jan 7, 2021, 4:32:45 PM1/7/21
to XMPie Interest Group
I haven't tried that, but I can't see why it would not be possible. The variables holding the logged in customer's user groups can be seen in the script that you refer to. The only thing to find would be the IDs of the shipping options that are defined on your store. You should be able to use the browser inspect and dev tools to find that information and show/hide as needed.

Blake Norwood

unread,
Jun 2, 2021, 1:30:14 PM6/2/21
to XMPie Interest Group
So I'm finally coming back around to this. I added the JavaScript to the storefront and changed the names but it's not actually doing anything on the shipping service dropdown. How would I modify this to work with the dropdown versus the clearing method radial buttons?

couch

unread,
Jun 3, 2021, 1:16:38 AM6/3/21
to XMPie Interest Group
Simple rewrite changing from clearing methods to shipping types below:

<script>
$(document).ready(function() {

// only run on the checkout final page
if (document.title.indexOf("Checkout - Order Summary") == 0) {

  // set these to be your user group IDs and Shipping names:
  var shippingType1 = "Overnight";
  var shippingType2 = "Standard";
  var userGroupIDforShippingType1 = 10004;
  var userGroupIDforShippingType2 = 10005;
  
  // set to hide first
  var showShippingType1 = false;
  var showShippingType2 = false;
  
  //get current user groups and decide if showing each shipping type
  var currentUser = xmp.sdk.storeFrontParams.currentUser;
  for (var i = 0; i < currentUser.userGroups.length; i++) {
    if (currentUser.userGroups[i].ID == userGroupIDforShippingType1)
      showShippingType1 = true;
    if (currentUser.userGroups[i].ID == userGroupIDforShippingType2)
      showShippingType2 = true;
  }
  
  //hide the unwanted shipping type in the select list
  if (!showShippingType1) 
    $("#ctl00_cphMainContent_cmbServices option[title^='" + shippingType1 + "']").remove();
  if (!showShippingType2) 
    $("#ctl00_cphMainContent_cmbServices option[title^='" + shippingType2 + "']").remove();
}
}); 
</script>

Blake Norwood

unread,
Jun 3, 2021, 8:53:44 AM6/3/21
to XMPie Interest Group
Ohhhhhh, ok! Awesome! Thank you so much for your help, Couch!

Christopher Conlon

unread,
May 29, 2024, 2:33:21 PMMay 29
to XMPie Interest Group

I am on version 17.1 build 13684 and I have a client that is requesting this feature but am unable to get it to work.  Currently it is only showing 1 clearing method (Net 30), regardless of the user group.  Any help would be appreciated.

Christopher Conlon

unread,
May 29, 2024, 7:27:10 PMMay 29
to XMPie Interest Group
I found a solve.  Below is the updated code of how I got it to work.

<script>
$(document).ready(function() {

  // only run on the checkout page

  if (document.title.indexOf("Checkout - Order Summary") == 0) {

    // set these to be your user group IDs and Clearing names:
    var clearingType1 = "Credit Card";
    var clearingType2 = "Net 30";
    var userGroupIDforClearingType1 = 10203;

   
    // set to hide first
    var showClearingType1 = false;
   
    // get current user groups and decide if showing clearing type 1

    var currentUser = xmp.sdk.storeFrontParams.currentUser;
    for (var i = 0; i < currentUser.userGroups.length; i++) {
      if (currentUser.userGroups[i].ID == userGroupIDforClearingType1) {
        showClearingType1 = true;
        break; // No need to continue checking other groups
      }
    }
   
    // If the user is in group 10203, hide the Net 30 clearing type
    if (showClearingType1) {
      var row2 = document.evaluate('//label[text() = "' + clearingType2 + '"]/../..', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
      row2.style.display = "none";
    }
  }
});
</script>


Reply all
Reply to author
Forward
0 new messages