X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   hiding a shipping option based on user (https://forum.x-cart.com/showthread.php?t=71447)

keystone 02-21-2015 02:48 PM

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.

elmirage001 02-21-2015 09:08 PM

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

totaltec 02-22-2015 09:18 AM

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}

cherie 03-02-2015 03:50 PM

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


keystone 03-03-2015 05:23 AM

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.

cflsystems 03-03-2015 06:42 AM

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

keystone 03-03-2015 12:37 PM

Re: hiding a shipping option based on user
 
Hi Steve,
Could you give an example of how you would do it with smarty?

cflsystems 03-03-2015 01:24 PM

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

totaltec 03-04-2015 11:32 AM

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

cherie 03-04-2015 11:38 AM

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.


All times are GMT -8. The time now is 10:42 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.