Jump to content
Alexandre Carette

Restriction de commande par code postaux

Recommended Posts

Bonjour, j'avais besoin de restreindre les commandes par codes postaux...
 
1) en bdd on crée une nouvelle table ps_pincode_restriction
-colonne 1 // id --> INT(11)
-colonne 2 // zip_code --> INT(11)
 
2) on crée un override de la classe Address.php pour y ajouter une nouvelle fonction

<?php
/**
* 2007-2016 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author    PrestaShop SA <contact@prestashop.com>
*  @copyright 2007-2016 PrestaShop SA
*  @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*/
class Address extends AddressCore {

  public static function checkzip($zip_code) {

      $sql = new DbQuery();
      $sql->select('zip_code');
      $sql->from('pincode_restriction');
      $sql->where('zip_code = '.(int)$zip_code);
      $result = Db::getInstance()->executeS($sql);
      if( $result ){
      	$result = true;
      }else{
      	$result = false;
      }
      return $result;
    }

}

dans le tpl du theme (order_opc.tpl pour ma part) on crée un assign smarty (qui appelle la fonction) et une condition pour afficher ou non les tpl carrier et paiement:

{assign var=checkzip value=Address::checkzip($addresses[0].postcode)}

		{if $checkzip == true}
		{include file="$tpl_dir./order-carrier.tpl"}
		{include file="$tpl_dir./order-payment.tpl"}
		{else}
		We can't ship your product !
		{/if}
Edited by Alexandre Carette (see edit history)

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

×
×
  • Create New...

Important Information

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