Jump to content

Restrictions for payment by delivery


ostiepok
 Share

Recommended Posts

Hello, 

i have four delivery methods and three payment methods. Problem is, that one of the delivery options cant be payed with one of the payment method. I couldnt found any existing solution to this or any documentation regarding this problem. I want to ask, if there is already some solution to this and if not, what are your suggestions because iam new to prestashop and the whole structure is still big questionmark for me. 

 

The delivery option is courier added through backoffice. Payment method is C.O.D. (Ive changed it a bit to behave as "payment on the spot")

Share this post


Link to post
Share on other sites

I'm not aware of any configuration or module that would do this.

 

However you could accomplish this by modifying the COD payment module, and updating the hookpayment function so that it would check for the selected carrier ID, and then have the COD module hide itself depending on the carrier ID.

 

Also, depending on your Prestshop version, you could do this via a module override instead of modifying the original module.

  • Like 1

Share this post


Link to post
Share on other sites

You can do in may ways but the easy way is hide the other option in the js file

 

Are you use the 1 step or the 5 steps for the order

 

Iam using 5steps right now. I will look into this ASAP when ill have some time and let u know how its going :)

Share this post


Link to post
Share on other sites

I'm not aware of any configuration or module that would do this.

 

However you could accomplish this by modifying the COD payment module, and updating the hookpayment function so that it would check for the selected carrier ID, and then have the COD module hide itself depending on the carrier ID.

 

Also, depending on your Prestshop version, you could do this via a module override instead of modifying the original module.

 

Ok, so in cashondelivery.php is a function, ive edited it a bit so it looks like this

public function hookPayment($params)
{
if (!$this->active)
return ;


global $smarty;


// Check if cart has product download
if ($this->hasProductDownload($params['cart']))
return false;




$smarty->assign(array(
'this_path' => $this->_path, //keep for retro compat
'this_path_cod' => $this->_path,
'this_path_ssl' => Tools::getShopDomainSsl(true, true).__PS_BASE_URI__.'modules/'.$this->name.'/'
));


{if isset($cart->id_carrier) && $cart->id_carrier == 8}
// STUFF to hide module
{/if}
return $this->display(__FILE__, 'payment.tpl');
}

The question is, how can i hide the module ? ive tried returning false, ive tried displaying new payment.tpl which was called payment_no_cod.tpl which was empty, and i just got blank page after both of my attempts. I would appreciate ur help. Thanks :)

Share this post


Link to post
Share on other sites

 

you simply return false to hide it

{if isset($cart->id_carrier) && $cart->id_carrier == 8}
// STUFF to hide module
     return false;
{/if}

I did, and ive expected the COD payment not to show on payment page, but whole payment page was gone, ive got only blank page :/

  • Like 1

Share this post


Link to post
Share on other sites

then you likely have a code syntax problem in the code you have added.

 

enable debug mode and you will see an error message instead of a blank white page

 

So ive shrinked it a bit to look like this

 

if ($cart->id_carrier == 8)
return false;

Now, everything is fine, i get the whole payment page, but with no change. When ive selected my carrier(with ID 8), the payment method C.O.D. was still there on payment page :/

Edited by ostiepok (see edit history)

Share this post


Link to post
Share on other sites

 

is $cart ever defined in the function?  If not, then you are trying to use an object that does not exist.

 

What if you do this instead

if ($this->context->cart->id_carrier == 8)
     return false;

Yep, that was it, thanks for help (i feel shame :D)

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More