<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>NemoPS &#187; payments</title>
	<atom:link href="http://nemops.com/tag/payments/feed/" rel="self" type="application/rss+xml" />
	<link>http://nemops.com</link>
	<description>Prestashop Tutorials, Modules and More!</description>
	<lastBuildDate>Wed, 05 Dec 2018 13:25:23 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.35</generator>
	<item>
		<title>Limiting payment methods to specific carriers in PrestaShop</title>
		<link>http://nemops.com/prestashop-payment-methods-specific-carriers/</link>
		<comments>http://nemops.com/prestashop-payment-methods-specific-carriers/#comments</comments>
		<pubDate>Thu, 16 Jun 2016 09:35:22 +0000</pubDate>
		<dc:creator><![CDATA[Nemo]]></dc:creator>
				<category><![CDATA[Tips n Tricks]]></category>
		<category><![CDATA[carriers]]></category>
		<category><![CDATA[payments]]></category>
		<category><![CDATA[prestashop]]></category>

		<guid isPermaLink="false">http://nemops.com/?p=2790</guid>
		<description><![CDATA[<p>If you want to hide or display certain payment methods for specific carriers you have, here is a little trick on how to do it quickly. Upgrade-safe procedure Whenever you want to limit a payment method by carrier, you will necessarily need to edit the module&#8217;s hookPayment method. This means you will need to do [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://nemops.com/prestashop-payment-methods-specific-carriers/">Limiting payment methods to specific carriers in PrestaShop</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>If you want to hide or display certain payment methods for specific carriers you have, here is a little trick on how to do it quickly.<br />
<span id="more-2790"></span></p>
<h2>Upgrade-safe procedure</h2>
<p>Whenever you want to limit a payment method by carrier, you will necessarily need to edit the module&#8217;s <strong>hookPayment</strong> method. This means you will need to do it for every single payment method your shop has. However, if you amend the core file, changes will be lost on the next update of the module itself. If you are running a version newer than PrestaShop 1.6.0.11, you can <a href="http://nemops.com/override-prestashop-modules-core/" title="Override Modules Files">Override Modules Files</a> and make your life easier. This is actually what we are going to do in the tutorial.</p>
<p><strong>Notice: if you use an older PrestaShop version, you can simply modify the core file</strong></p>
<p>Additionally, there is an important thing we need to be aware of, whenever dealing with carriers. <strong>Carrier IDs will change anytime you update a carrier&#8217;s information</strong>, so we cannot use the ID as our static factor to check against to.</p>
<div class="separator"></div>
<h2>Overriding the Bankwire Module</h2>
<p>In this example, we will use the Bankwire module and limit it to a single carrier. The first thing we want to do is override it, so let&#8217;s create a new folder in <em>override/modules</em> and name it <strong>bankwire</strong>. Inside it, create a new file named <strong>bankwire.php</strong>, adding the following code inside php tags:</p>
<pre class="brush: php; title: ; notranslate">
if (!defined('_CAN_LOAD_FILES_'))
    exit;
 
class BankwireOverride extends Bankwire
{
 
 
}
</pre>
<p>Then reach your <em>cache</em> folder, and erase class_index.php. This will make sure our new override is loaded.<br />
Next, we want to extend the <strong>hookPayment</strong> method, which I will simply copy/paste from the original file</p>
<pre class="brush: php; title: ; notranslate">
if (!defined('_CAN_LOAD_FILES_'))
    exit;
 
class BankwireOverride extends Bankwire
{
 
 	public function hookPayment($params)
	{
		if (!$this-&gt;active)
			return;
		if (!$this-&gt;checkCurrency($params['cart']))
			return;

		$this-&gt;smarty-&gt;assign(array(
			'this_path' =&gt; $this-&gt;_path,
			'this_path_bw' =&gt; $this-&gt;_path,
			'this_path_ssl' =&gt; Tools::getShopDomainSsl(true, true).__PS_BASE_URI__.'modules/'.$this-&gt;name.'/'
		));
		return $this-&gt;display(__FILE__, 'payment.tpl');
	}
}
</pre>
<p>At this point, we need our condition. First, I need to know which carrier I want to disable or enable the module for. I have a FedEx carrier that currently has ID 3, so I can temporarily use this information to get the real one I need.<br />
Reach your front office, with a product in the cart, and make sure the 5-steps checkout is enabled. Continue until the payment page, making sure you select the carrier you want to target beforehand.<br />
In our override, at the very beginning of the hookPayment method, let&#8217;s print out some debug code:</p>
<pre class="brush: php; title: ; notranslate">
...
 	public function hookPayment($params)
	{

		d($params['cart']-&gt;id_carrier);
		if (!$this-&gt;active)
			return;
		if (!$this-&gt;checkCurrency($params['cart']))
			return;
...
</pre>
<p>Refresh the payments list, and it will result in a blank page only reading an ID, followed by &#8220;END&#8221;<br />
That&#8217;s the ID of the carrier we selected. As mentioned at the beginning of the article, we cannot use it as static parameter, so <strong>we need to find the static id of this carrier</strong>.<br />
let&#8217;s play with the carrier object a bit:</p>
<pre class="brush: php; title: ; notranslate">
...
 	public function hookPayment($params)
	{

		$id_carrier = $params['cart']-&gt;id_carrier;
		$carrier = new Carrier($id_carrier);
		d($carrier);
		if (!$this-&gt;active)
			return;
		if (!$this-&gt;checkCurrency($params['cart']))
			return;
...
</pre>
<p>You will see a bunch of information as soon as you refresh. What we are interested in is the <strong>id_reference</strong> field of the carrier. This reference will never change, unlike the id_carrier, that will instead increase each time we save carrier information in the back office. Therefore, we can use this reference as our static field to check the payment method&#8217;s availability.</p>
<p>I want to disable bankwire for this carrier, so I will simply add:</p>
<pre class="brush: php; title: ; notranslate">
...
 	public function hookPayment($params)
	{

		$id_carrier = $params['cart']-&gt;id_carrier;
		$carrier = new Carrier($id_carrier);
		if($carrier-&gt;id_reference == 3) // my fedex, make sure your matches the carrier you use
			return false;
		if (!$this-&gt;active)
			return;
		if (!$this-&gt;checkCurrency($params['cart']))
			return;
...
</pre>
<p>As simple as that! On the other hand, if I want to enable bankwire for this carrier only, I can reverse the condition</p>
<pre class="brush: php; title: ; notranslate">
...
 	public function hookPayment($params)
	{

		$id_carrier = $params['cart']-&gt;id_carrier;
		$carrier = new Carrier($id_carrier);
		if($carrier-&gt;id_reference != 3) // my fedex, make sure your matches the carrier you use
			return false;
		if (!$this-&gt;active)
			return;
		if (!$this-&gt;checkCurrency($params['cart']))
			return;
...
</pre>
<p>The post <a rel="nofollow" href="http://nemops.com/prestashop-payment-methods-specific-carriers/">Limiting payment methods to specific carriers in PrestaShop</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://nemops.com/prestashop-payment-methods-specific-carriers/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
