PascalVG Posted January 7, 2013 Share Posted January 7, 2013 Hi there, I just got a Paypal payment through our shop. As it was a tiny order, the Paypay fee was actually more than wished for. We have other payment options (Bank wire) that would be a preferred payment option in this case. Although not a big problem, it made me think... Is it possible to state somewhere what payment option can be chosen with what (minimum) order size? Like if total order size = 1-10$, Option Bank wire available only, if 10+$, also allow Paypal. I look for something a little bit like carriers, where you can choose what carrier can be chosen for what weight (like 1 gr-1 kg = Carrier A, 1-5kg Carrier B etc.) Not sure if it exists in Standard Presta... Anyone?? Thx. Pascal Link to comment Share on other sites More sharing options...
bellini13 Posted January 7, 2013 Share Posted January 7, 2013 I don't think there is a configuration for this yet, however you can accomplish this by altering the Paypal module itself. In the Paypal module there is a function called hookpayment. If can add the following code towards the top of that function and change 20 to your desired amount. $total = floatval(number_format($params['cart']->getOrderTotal(true, 3), 2, '.', '')); if ($total>20) { return false; } 2 Link to comment Share on other sites More sharing options...
PascalVG Posted January 7, 2013 Author Share Posted January 7, 2013 I don't think there is a configuration for this yet, however you can accomplish this by altering the Paypal module itself. In the Paypal module there is a function called hookpayment. If can add the following code towards the top of that function and change 20 to your desired amount. $total = floatval(number_format($params['cart']->getOrderTotal(true, 3), 2, '.', '')); if ($total>20) { return false; } Thanks! I'll have look at this! This sounds like a great solution :-) Link to comment Share on other sites More sharing options...
kenkomuri Posted August 6, 2013 Share Posted August 6, 2013 I don't think there is a configuration for this yet, however you can accomplish this by altering the Paypal module itself. In the Paypal module there is a function called hookpayment. If can add the following code towards the top of that function and change 20 to your desired amount. $total = floatval(number_format($params['cart']->getOrderTotal(true, 3), 2, '.', '')); if ($total>20) { return false; } Hi, But where do you have to set this code? what file? Link to comment Share on other sites More sharing options...
bellini13 Posted August 6, 2013 Share Posted August 6, 2013 Paypal.php Link to comment Share on other sites More sharing options...
kenkomuri Posted August 30, 2013 Share Posted August 30, 2013 (edited) Paypal.php It works. How can I change to specify the amount just for the products excluding the shipping cost? public function hookPayment($params) { $total = floatval(number_format($params['cart']->getOrderTotal(true, 3), 2, '.', '')); if ($total>500) { return false; } Edited August 30, 2013 by kenkomuri (see edit history) Link to comment Share on other sites More sharing options...
bellini13 Posted August 30, 2013 Share Posted August 30, 2013 try this public function hookPayment($params) { $total = floatval(number_format($params['cart']->getOrderTotal(true, Cart::ONLY_PRODUCTS), 2, '.', '')); if ($total>500) { return false; } } 1 Link to comment Share on other sites More sharing options...
Emmanuel M. Posted August 30, 2013 Share Posted August 30, 2013 Hi, I have a module for this! http://addons.prestashop.com/en/administration-tools-prestashop-modules/6136-payments-based-on-the-amount.html Regards, Emmanuel Link to comment Share on other sites More sharing options...
kenkomuri Posted August 31, 2013 Share Posted August 31, 2013 try this public function hookPayment($params) { $total = floatval(number_format($params['cart']->getOrderTotal(true, Cart::ONLY_PRODUCTS), 2, '.', '')); if ($total>500) { return false; } } It works, thank you. I have also to change the < to > in order to deactivate the payment by Paypal if the amount is less than 500 Link to comment Share on other sites More sharing options...
germinc Posted July 5, 2014 Share Posted July 5, 2014 Recently upgraded to PS 1.6.0.8, this code works when in PS 1.5.4 but now when I try to insert the same code, the entire "order" page does not even load, just shows a blank page. Any idea how to implement in this in 1.6? Thanks! Link to comment Share on other sites More sharing options...
bellini13 Posted July 5, 2014 Share Posted July 5, 2014 Recently upgraded to PS 1.6.0.8, this code works when in PS 1.5.4 but now when I try to insert the same code, the entire "order" page does not even load, just shows a blank page. Any idea how to implement in this in 1.6? Thanks! why not purchase the module? http://addons.prestashop.com/en/administration-tools-prestashop-modules/6136-payments-based-on-the-amount.html 1 Link to comment Share on other sites More sharing options...
germinc Posted July 5, 2014 Share Posted July 5, 2014 I would, thanks for the recommendation! Link to comment Share on other sites More sharing options...
armand1984 Posted October 16, 2014 Share Posted October 16, 2014 For Prestashop 1.6In the payment module main file (bankwire.php for example) add a new function: public function checkOrderValue($cart) { $total = $cart->getOrderTotal(); if($total>200) return true; return false; } Also in the main file of the payment module change the "hookPayment" function: public function hookPayment($params) { if (!$this->active) return; if (!$this->checkCurrency($params['cart'])) return; if (!$this->checkOrderValue($params['cart'])) return; $this->smarty->assign(array( 'this_path' => $this->_path, 'this_path_bw' => $this->_path, 'this_path_ssl' => Tools::getShopDomainSsl(true, true).__PS_BASE_URI__.'modules/'.$this->name.'/' )); return $this->display(__FILE__, 'payment.tpl'); } If you have One-Step-Cart activated and want to update payment options when product quantity is changed in the cart, you need to make further changes. In the theme folder > "js" folder > cart-summary.js update 3 functions: deleteProductFromSummary, upQuantity, downQuantity function deleteProductFromSummary(id) { var customizationId = 0; var productId = 0; var productAttributeId = 0; var id_address_delivery = 0; var ids = 0; ids = id.split('_'); productId = parseInt(ids[0]); if (typeof(ids[1]) != 'undefined') productAttributeId = parseInt(ids[1]); if (typeof(ids[2]) != 'undefined') customizationId = parseInt(ids[2]); if (typeof(ids[3]) != 'undefined') id_address_delivery = parseInt(ids[3]); $.ajax({ type: 'GET', url: baseUri, async: true, cache: false, dataType: 'json', data: 'controller=cart' +'&ajax=true&delete&summary' +'&id_product='+productId +'&ipa='+productAttributeId +'&id_address_delivery='+id_address_delivery+ ( (customizationId != 0) ? '&id_customization='+customizationId : '') +'&token=' + static_token +'&allow_refresh=1', success: function(jsonData) { if (jsonData.hasError) { var errors = ''; for(error in jsonData.errors) //IE6 bug fix if (error != 'indexOf') errors += jsonData.errors[error] + "\n"; } else { if (jsonData.refresh) location.reload(); if (parseInt(jsonData.summary.products.length) == 0) { if (typeof(orderProcess) == 'undefined' || orderProcess != 'order-opc') document.location.href = document.location.href; // redirection else { $('#center_column').children().each(function() { if ($(this).attr('id') != 'emptyCartWarning' && $(this).attr('class') != 'breadcrumb' && $(this).attr('id') != 'cart_title') { $(this).fadeOut('slow', function () { $(this).remove(); }); } }); $('#summary_products_label').remove(); $('#emptyCartWarning').fadeIn('slow'); } } else { $('#product_'+ id).fadeOut('slow', function() { $(this).remove(); cleanSelectAddressDelivery(); if (!customizationId) refreshOddRow(); }); var exist = false; for (i=0;i<jsonData.summary.products.length;i++) if (jsonData.summary.products[i].id_product == productId && jsonData.summary.products[i].id_product_attribute == productAttributeId && jsonData.summary.products[i].id_address_delivery == id_address_delivery) exist = true; // if all customization removed => delete product line if (!exist && customizationId) $('#product_' + productId + '_' + productAttributeId + '_0_' + id_address_delivery).fadeOut('slow', function() { $(this).remove(); refreshOddRow(); }); } updateCartSummary(jsonData.summary); updatePaymentMethods(jsonData); updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART); updateHookShoppingCartExtra(jsonData.HOOK_SHOPPING_CART_EXTRA); updateCustomizedDatas(jsonData.customizedDatas); if (typeof(getCarrierListAndUpdate) != 'undefined') getCarrierListAndUpdate(); } }, error: function(XMLHttpRequest, textStatus, errorThrown) { if (textStatus != 'abort') alert("TECHNICAL ERROR: unable to save update quantity \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); } }); } function upQuantity(id, qty) { if (typeof(qty) == 'undefined' || !qty) qty = 1; var customizationId = 0; var productId = 0; var productAttributeId = 0; var id_address_delivery = 0; var ids = 0; ids = id.split('_'); productId = parseInt(ids[0]); if (typeof(ids[1]) != 'undefined') productAttributeId = parseInt(ids[1]); if (typeof(ids[2]) != 'undefined') customizationId = parseInt(ids[2]); if (typeof(ids[3]) != 'undefined') id_address_delivery = parseInt(ids[3]); $.ajax({ type: 'GET', url: baseUri, async: true, cache: false, dataType: 'json', data: 'controller=cart' +'&ajax=true' +'&add' +'&getproductprice' +'&summary' +'&id_product='+productId +'&ipa='+productAttributeId +'&id_address_delivery='+id_address_delivery + ( (customizationId != 0) ? '&id_customization='+customizationId : '') +'&qty='+qty +'&token='+static_token +'&allow_refresh=1', success: function(jsonData) { if (jsonData.hasError) { var errors = ''; for(error in jsonData.errors) //IE6 bug fix if(error != 'indexOf') errors += jsonData.errors[error] + "\n"; alert(errors); $('input[name=quantity_'+ id +']').val($('input[name=quantity_'+ id +'_hidden]').val()); } else { if (jsonData.refresh) location.reload(); updateCustomizedDatas(jsonData.customizedDatas); updateCartSummary(jsonData.summary); updatePaymentMethods(jsonData); updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART); updateHookShoppingCartExtra(jsonData.HOOK_SHOPPING_CART_EXTRA); if (typeof(getCarrierListAndUpdate) != 'undefined') getCarrierListAndUpdate(); } }, error: function(XMLHttpRequest, textStatus, errorThrown) { if (textStatus != 'abort') alert("TECHNICAL ERROR: unable to save update quantity \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); } }); } function downQuantity(id, qty) { var val = $('input[name=quantity_'+id+']').val(); var newVal = val; if(typeof(qty)=='undefined' || !qty) { qty = 1; newVal = val - 1; } else if (qty < 0) qty = -qty; var customizationId = 0; var productId = 0; var productAttributeId = 0; var id_address_delivery = 0; var ids = 0; ids = id.split('_'); productId = parseInt(ids[0]); if (typeof(ids[1]) != 'undefined') productAttributeId = parseInt(ids[1]); if (typeof(ids[2]) != 'undefined') customizationId = parseInt(ids[2]); if (typeof(ids[3]) != 'undefined') id_address_delivery = parseInt(ids[3]); if (newVal > 0 || $('#product_'+id+'_gift').length) { $.ajax({ type: 'GET', url: baseUri, async: true, cache: false, dataType: 'json', data: 'controller=cart' +'&ajax=true' +'&add' +'&getproductprice' +'&summary' +'&id_product='+productId +'&ipa='+productAttributeId +'&id_address_delivery='+id_address_delivery +'&op=down' + ((customizationId != 0) ? '&id_customization='+customizationId : '') +'&qty='+qty +'&token='+static_token +'&allow_refresh=1', success: function(jsonData) { if (jsonData.hasError) { var errors = ''; for(error in jsonData.errors) //IE6 bug fix if(error != 'indexOf') errors += jsonData.errors[error] + "\n"; alert(errors); $('input[name=quantity_'+ id +']').val($('input[name=quantity_'+ id +'_hidden]').val()); } else { if (jsonData.refresh) location.reload(); updateCustomizedDatas(jsonData.customizedDatas); updateCartSummary(jsonData.summary); updatePaymentMethods(jsonData); updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART); updateHookShoppingCartExtra(jsonData.HOOK_SHOPPING_CART_EXTRA); if (newVal == 0) $('#product_'+id).hide(); if (typeof(getCarrierListAndUpdate) != 'undefined') getCarrierListAndUpdate(); } }, error: function(XMLHttpRequest, textStatus, errorThrown) { if (textStatus != 'abort') alert("TECHNICAL ERROR: unable to save update quantity \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); } }); } else { deleteProductFromSummary(id); } } Finally, override the CartController.php file by creating a file in the overrides folder override > controllers > front > CartController.php <?php class CartController extends CartControllerCore { public function displayAjax() { if ($this->errors) die(Tools::jsonEncode(array('hasError' => true, 'errors' => $this->errors))); if ($this->ajax_refresh) die(Tools::jsonEncode(array('refresh' => true))); // write cookie if can't on destruct $this->context->cookie->write(); if (Tools::getIsset('summary')) { $result = array(); if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1) { $groups = (Validate::isLoadedObject($this->context->customer)) ? $this->context->customer->getGroups() : array(1); if ($this->context->cart->id_address_delivery) $deliveryAddress = new Address($this->context->cart->id_address_delivery); $id_country = (isset($deliveryAddress) && $deliveryAddress->id) ? $deliveryAddress->id_country : Configuration::get('PS_COUNTRY_DEFAULT'); Cart::addExtraCarriers($result); } $result['summary'] = $this->context->cart->getSummaryDetails(null, true); $result['customizedDatas'] = Product::getAllCustomizedDatas($this->context->cart->id, null, true); $result['HOOK_SHOPPING_CART'] = Hook::exec('displayShoppingCartFooter', $result['summary']); $result['HOOK_SHOPPING_CART_EXTRA'] = Hook::exec('displayShoppingCart', $result['summary']); $result['HOOK_TOP_PAYMENT'] = Hook::exec('displayPaymentTop'); $result['HOOK_PAYMENT'] = Hook::exec('displayPayment'); foreach ($result['summary']['products'] as $key => &$product) { $product['quantity_without_customization'] = $product['quantity']; if ($result['customizedDatas'] && isset($result['customizedDatas'][(int)$product['id_product']][(int)$product['id_product_attribute']])) { foreach ($result['customizedDatas'][(int)$product['id_product']][(int)$product['id_product_attribute']] as $addresses) foreach ($addresses as $customization) $product['quantity_without_customization'] -= (int)$customization['quantity']; } $product['price_without_quantity_discount'] = Product::getPriceStatic( $product['id_product'], !Product::getTaxCalculationMethod(), $product['id_product_attribute'], 6, null, false, false ); } if ($result['customizedDatas']) Product::addCustomizationPrice($result['summary']['products'], $result['customizedDatas']); Hook::exec('actionCartListOverride', array('summary' => $result, 'json' => &$json)); die(Tools::jsonEncode(array_merge($result, (array)Tools::jsonDecode($json, true)))); } // @todo create a hook elseif (file_exists(_PS_MODULE_DIR_.'/blockcart/blockcart-ajax.php')) require_once(_PS_MODULE_DIR_.'/blockcart/blockcart-ajax.php'); } } 1 Link to comment Share on other sites More sharing options...
mattheoh Posted May 12, 2016 Share Posted May 12, 2016 (edited) For Prestashop 1.6 In the payment module main file (bankwire.php for example) add a new function: public function checkOrderValue($cart) { $total = $cart->getOrderTotal(); if($total>200) return true; return false; } Also in the main file of the payment module change the "hookPayment" function: public function hookPayment($params) { if (!$this->active) return; if (!$this->checkCurrency($params['cart'])) return; if (!$this->checkOrderValue($params['cart'])) return; $this->smarty->assign(array( 'this_path' => $this->_path, 'this_path_bw' => $this->_path, 'this_path_ssl' => Tools::getShopDomainSsl(true, true).__PS_BASE_URI__.'modules/'.$this->name.'/' )); return $this->display(__FILE__, 'payment.tpl'); } That works perfectly ! I used it for check module , thanks a lot. Shame we can't override the module functions. Just have to be careful with updates. Edited May 12, 2016 by mattheoh (see edit history) Link to comment Share on other sites More sharing options...
bellini13 Posted May 13, 2016 Share Posted May 13, 2016 well i believe with PS v1.6 you could do this via an override now Link to comment Share on other sites More sharing options...
dcurbelo Posted September 17, 2016 Share Posted September 17, 2016 Hello, sorry for my bad translation with google translate.I need help with an issue of Paypal and do not know how to follow, I hope you can help me. I'm putting together a store for Uruguay in Prestashop and I can not make the block paypal ALWAYS display at the checkout (although all products are Uruguayan pesos)?I want to sell in Uruguayan pesos and Paypal block appears in the checkout and of course make the conversion to USD.I PS1.6 and I'm testing with Paypal Europe. Currently I have already verified that the conversion does not even appear in the checkout but obviously I need for customers APPEARS.Finally I would like to know what the most appropriate version of paypal to Uruguay.Thank you very much and greetings from Uruguay. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now