Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

hiding a shipping option based on user

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 02-21-2015, 02:48 PM
 
keystone keystone is offline
 

X-Adept
  
Join Date: Jul 2006
Location: USA
Posts: 767
 

Default hiding a shipping option based on user

I have a shipping option "in store pickup" that I only want to show up if a user is a wholesale account.

The id's are as follows

membershipid 2 (wholesale)
shippingid 201 (in store pickup)

I am using altered carts checkout one mod and reboot template. I'm not sure where the shipping methods are pulled from for altered carts checkout page...

I have an IF statement like this...

Code:
{foreach from=$shipping item=s name=sm} {if $s.shippingid eq 201} #if shipping option is in store pickup {if $login ne "" and $userinfo.membershipid eq 2} #if customer is logged in and is wholesale ...shipping method code... {/if} {else} ...shipping method code... {/if} {/foreach}

I have put this if statement in common_files/modules/fast_lane_checkout/shipping_methods.tpl
common_files/modules/one_page_checkout/shipping_methods.tpl
reboot/modules/fast_lane_checkout/shipping_methods.tpl
reboot/modules/one_page_checkout/shipping_methods.tpl

I had this code working in my 4.4.5. site but can't get it to work in my new 4.6.6. site. It looks like it is working when I estimate shipping in the shopping cart but it is hard to tell since you can't see the shipping rates there if you are logged in. I can't get it to work on the checkout page though.

I have also tried switching back and forth between fast lane and one page checkout in the general settings but still no go.
__________________
www.uscandleco.com - X-Cart Version 4.7.11 Gold Plus php7.3
mods:
reCaptcha
running on UNIX

www.keystonecandle.com X-Cart Gold Plus - Version 4.7.11 php7.2
mods:
reCaptcha
cdseo pro
running on UNIX
Reply With Quote
  #2  
Old 02-21-2015, 09:08 PM
 
elmirage001 elmirage001 is offline
 

X-Wizard
  
Join Date: Apr 2007
Posts: 1,908
 

Default Re: hiding a shipping option based on user

Hi Keystone,

I think the following file might be Altered Carts file containing the shipping_methods.tpl code.

Code:
\skin\common_files\modules\Checkout_One\checkout_one_shipping_radio.tpl

Thank you again for your comments on my site when you were evaluating reBOOT. Good Luck!

Paul
__________________
X-Cart GoldPlus v4.7.12 | reBOOT (reDUX) Template | Live
X-Cart GoldPlus v4.7.12 | reBOOT (reDUX) Template | Dev
  • XCARTMODS.CO.UK | reBOOT (reDUX) |
  • Performive Hosting | Linux | PHP v7.4.15 | MySQL v5.7.33 |
Reply With Quote

The following user thanks elmirage001 for this useful post:
totaltec (02-22-2015)
  #3  
Old 02-22-2015, 09:18 AM
  totaltec's Avatar 
totaltec totaltec is offline
 

X-Guru
  
Join Date: Jan 2007
Location: Louisville, KY USA
Posts: 5,823
 

Default Re: hiding a shipping option based on user

Once you have found the loop of shipping methods, you need to determine the ID of the method you want to hide. Then you need the id of the membership level you want it to be associated with. Then you can concoct your if statement, {if $userinfo.membershipid = X} Show radio {/if}
__________________
Mike White - Now Accepting new clients and projects! Work with the best, get a US based development team for just $125 an hour. Call 1-502-773-6454, email mike at babymonkeystudios.com, or skype b8bym0nkey

XcartGuru
X-cart Tutorials | X-cart 5 Tutorials

Check out the responsive template for X-cart.
Reply With Quote
  #4  
Old 03-02-2015, 03:50 PM
  cherie's Avatar 
cherie cherie is online now
 

X-Wizard
  
Join Date: May 2003
Location: USA
Posts: 1,534
 

Default Re: hiding a shipping option based on user

I prefer to do this in php rather than the templates. For 4.6 in include/func/func.shipping.php in func_is_shipping_method_allowable() toward the top add something like this:

PHP Code:
if ($customer_info['membershipid'] != && $shippingid == 201)
    return 
false
__________________
redlimeweb.com
custom mods and design integration
4.7 linux
Reply With Quote

The following user thanks cherie for this useful post:
totaltec (03-04-2015)
  #5  
Old 03-03-2015, 05:23 AM
 
keystone keystone is offline
 

X-Adept
  
Join Date: Jul 2006
Location: USA
Posts: 767
 

Default Re: hiding a shipping option based on user

Hi Cherie, Thanks for that. Seems much more neat and clean, plus then you don't have to hunt down all the different templates.
__________________
www.uscandleco.com - X-Cart Version 4.7.11 Gold Plus php7.3
mods:
reCaptcha
running on UNIX

www.keystonecandle.com X-Cart Gold Plus - Version 4.7.11 php7.2
mods:
reCaptcha
cdseo pro
running on UNIX
Reply With Quote
  #6  
Old 03-03-2015, 06:42 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,079
 

Default Re: hiding a shipping option based on user

Changes directly in php files must be done wisely as they will make future upgrades difficult. And this is very much hardcoding your way there.

You can also do it with smarty function which will require the least changes to stock system
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #7  
Old 03-03-2015, 12:37 PM
 
keystone keystone is offline
 

X-Adept
  
Join Date: Jul 2006
Location: USA
Posts: 767
 

Default Re: hiding a shipping option based on user

Hi Steve,
Could you give an example of how you would do it with smarty?
__________________
www.uscandleco.com - X-Cart Version 4.7.11 Gold Plus php7.3
mods:
reCaptcha
running on UNIX

www.keystonecandle.com X-Cart Gold Plus - Version 4.7.11 php7.2
mods:
reCaptcha
cdseo pro
running on UNIX
Reply With Quote
  #8  
Old 03-03-2015, 01:24 PM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,079
 

Default Re: hiding a shipping option based on user

Look in any function file under include/template/plugins directory - these are smarty function which you can call directly from any template, pass to it the shipping methods array and do the check for whatever you need, adjust the array and return it back to the template. That way you make a small change in the template and all the php code you need for this is in your own file so not messing up with the system.

So if the file is function.change_shipping_methods.php you can call it in the template as
{change_shipping_method shipping=$SHIPPING_ARRAY membershipid=$USER_MEMBERSHIPID assign="SHIPPING_ARRAY"}
And then have the code that uses that shipping array which will already be modified.

Now I just mentioned this as one possibility. That doesn't mean it is always the best way to do it. But in this case it may just be the better option...
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote

The following user thanks cflsystems for this useful post:
totaltec (03-04-2015)
  #9  
Old 03-04-2015, 11:32 AM
  totaltec's Avatar 
totaltec totaltec is offline
 

X-Guru
  
Join Date: Jan 2007
Location: Louisville, KY USA
Posts: 5,823
 

Default Re: hiding a shipping option based on user

Cherie's solution is cleaner and possibly simpler, though I really like Steve's way. The template change I suggested is one of the easiest, and if you are working in a custom skin directory then it will not conflict with any future upgrade, though you might end up rebuilding your skin after the upgrade. I think Steve's solution is the winner. So many ways to skin the cat.
__________________
Mike White - Now Accepting new clients and projects! Work with the best, get a US based development team for just $125 an hour. Call 1-502-773-6454, email mike at babymonkeystudios.com, or skype b8bym0nkey

XcartGuru
X-cart Tutorials | X-cart 5 Tutorials

Check out the responsive template for X-cart.
Reply With Quote
  #10  
Old 03-04-2015, 11:38 AM
  cherie's Avatar 
cherie cherie is online now
 

X-Wizard
  
Join Date: May 2003
Location: USA
Posts: 1,534
 

Default Re: hiding a shipping option based on user

It would be interesting to see an example of just how simple a Smarty plugin could be made to accomplish this. Maybe only a few more lines than our two-liner? The problem might be tracking down all areas where $SHIPPING_ARRAY is used to add the plugin call which kind of defeats the purpose of a simple solution.
__________________
redlimeweb.com
custom mods and design integration
4.7 linux
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 04:14 PM.

   

 
X-Cart forums © 2001-2020