Jump to content

Methods of payment according to the state


srondelliweb

Recommended Posts

Hello to all,

I need to assign users of my site different payment methods depending on the state in which it will be shipped. For example banalising Bankwire for those state of x, y, z and state paypal for a, b​​, c.

Is there a configuration from the backoffice, a module or a modest code that allows me to handle this?

thanks to all

 

Link to comment
Share on other sites

not currently supported in Prestashop. 

 

The easiest/fastest way would be to edit each payment module, locate the hookpayment function, and have the module check the address (invoice or delivery?) state before returning the content.

 

ok thanks.

You know how it is possible to get to the function hookpayment of my payment modules the id_state?

Link to comment
Share on other sites

Since you are going to use delivery address, then you might need to consider there could be more than 1 delivery address.  I'm going to assume there will only be 1 delivery address.

 

i would use the context object ...

$address = new Address(intval($this->context->cart->id_address_delivery))

Then check it is a valid address and obtain the state

if (!Validate::isLoadedObject($address))
   return false;

$state = new State(intval($address->id_state))
if (!Validate::isLoadedObject($state))
   return false;

Now that you have the state, do something with it.  For example, if the State is California then return false and the module will not display

if ($state->iso_code!='CA')
    return false;

Or you could do something more complex and use an array to predefine the allowed states.  This defines California, Texas and New York as allowed.

$allowedStates = array('CA', 'NY', 'TX');

if (!in_array($state->iso_code, $allowedStates))
    return false;
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...