Jump to content

[SOLVED]minimum order per customer group


Recommended Posts

It's not possible in PrestaShop without modifying code. You'll need to change line 31 of order.php from:

$minimalPurchase = floatval(Configuration::get('PS_PURCHASE_MINIMUM'));



to:

$minimalPurchase = floatval(Configuration::get('PS_PURCHASE_MINIMUM'));

if (intval($cookie->id_customer) > 0)
{
   $customer = new Customer(intval($cookie->id_customer));

   if ($customer->isMemberOfGroup(1))
       $minimalPurchase = 200;
   elseif ($customer->isMemberOfGroup(2))
       $minimalPurchase = 300;
   else
       $minimalPurchase = 0;
}



This code will force all customers in group 1 to purchase $200 before checking out and all customers in group 2 to purchase $300 before checking out. All other customers have no minimum. Change the group IDs and amounts as appropriate for your site.

  • Like 1
Link to comment
Share on other sites

I propose a module that allows to :
-- specify a minimum purchase per group
-- specifiy per grouop if OutOfStock products is allowed or not.

This allows to manage individual customer that can not order OutOfStock products, and pros customer that can order OutOfStock and that have to purchase a minimum

Link to comment
Share on other sites

  • 7 months later...
  • 2 weeks later...
Hi, as you can set the code, to display an error if you have not reached the minimum amount?
Someone has already created the module?
Thanks.


What do you mean ? There is a bug in the 1.4.0.17 that the message: you don't have reached minim order, is not displaying anymore. This is fixed in 1.4.1.

I cannot update to 1.4.1. due to another bug, but I confirm that the hack posted for 1.3. does not work with 1.4.. It does no more selection of the groups. I think the problem is that customer must be less in Standard and than also in his other group. A selection of only ONE group is not possible for me. Only Standard and second group.
Link to comment
Share on other sites

  • 1 month later...
  • 3 weeks later...
can i modify code in prestashop 1.4.0.17 ?

I cant edit like said rocky because in this version variable $minimalPurchase missing in order.php

thx

No news, unfortunatelly from 1.4. onwards not possible anymore, unless somebody codes a module for that...
Link to comment
Share on other sites

  • 3 weeks later...

Dear All

I am using 1.4.3 final Just installed.

I have 2 groups of user, Retail and Wholesales.

For wholesales, the min order qty per order is 10. Meaning they can buy any product combination up to 10, then they can check out. This is not min 10 per items, but min 10 items per order.

For retail: They can check out even with 1 item.

Secondly..

I would like to have 2 pricing shown on my website, Retail and Wholesales: Is that anyway I can do that?

Regards
ShiokGuy

Link to comment
Share on other sites

  • 4 months later...

Hello to all,

 

As I have the same issue, I decided to look into my presta 1.4.5.1 version and I did this little modification for the customer group ID 4 : 'Resellers' that need a minimum amount order to be set to 400$.

 

So I did activate the minimal order in prestashop, set it up to 400$ and modified this file :>

 

OrderOpcController.php (because I use One Page Checkout !)

 

around line 394 /* Check minimal amount */

 

BEFORE :

/* Check minimal amount */
 $currency = Currency::getCurrency((int)self::$cart->id_currency);
 $minimalPurchase = Tools::convertPrice((float)Configuration::get('PS_PURCHASE_MINIMUM'), $currency);
 if (self::$cart->getOrderTotal(false, Cart::ONLY_PRODUCTS) < $minimalPurchase)
  return '<p class="warning">'.Tools::displayError('A minimum purchase total of').' '.Tools::displayPrice($minimalPurchase, $currency).
  ' '.Tools::displayError('is required in order to validate your order.').'</p>';

 

AFTER :

/* Check minimal amount */
$currency = Currency::getCurrency((int)self::$cart->id_currency);
$minimalPurchase = Tools::convertPrice((float)Configuration::get('PS_PURCHASE_MINIMUM'), $currency);
 if (self::$cookie->id_customer)
 {
  $customer = new Customer((int)(self::$cookie->id_customer));
  $groupes = $customer->getGroups();
 }
 else
  $groupes = array(1);


 if ((self::$cart->getOrderTotal(false, Cart::ONLY_PRODUCTS) < $minimalPurchase) and ($groupes[0]==4))
  return '<p class="warning">'.Tools::displayError('A minimum purchase total of').' '.Tools::displayPrice($minimalPurchase, $currency).
  ' '.Tools::displayError('is required in order to validate your order.').'</p>';

 

And That Works !! Only the Customers from group ID 4 (by default) will have this limitation of Minimal purchase activated !

 

If you need more group ID filters just modifiy the code to make it happen in the way rocky shows above (by the way, it took me some time before I found that "ismemberofgroup" function is deprecated in 1.4.)

 

I Still Do need Help :> How to put this modifications in Overrides directory...so next update it will keep on working.

 

Best Regards to all

Link to comment
Share on other sites

  • 1 month later...
  • 3 weeks later...

Hello to all,

 

As I have the same issue, I decided to look into my presta 1.4.5.1 version and I did this little modification for the customer group ID 4 : 'Resellers' that need a minimum amount order to be set to 400$.

 

So I did activate the minimal order in prestashop, set it up to 400$ and modified this file :>

 

OrderOpcController.php (because I use One Page Checkout !)

 

around line 394 /* Check minimal amount */

 

BEFORE :

/* Check minimal amount */
 $currency = Currency::getCurrency((int)self::$cart->id_currency);
 $minimalPurchase = Tools::convertPrice((float)Configuration::get('PS_PURCHASE_MINIMUM'), $currency);
 if (self::$cart->getOrderTotal(false, Cart::ONLY_PRODUCTS) < $minimalPurchase)
  return '<p class="warning">'.Tools::displayError('A minimum purchase total of').' '.Tools::displayPrice($minimalPurchase, $currency).
  ' '.Tools::displayError('is required in order to validate your order.').'</p>';

 

AFTER :

/* Check minimal amount */
$currency = Currency::getCurrency((int)self::$cart->id_currency);
$minimalPurchase = Tools::convertPrice((float)Configuration::get('PS_PURCHASE_MINIMUM'), $currency);
 if (self::$cookie->id_customer)
 {
  $customer = new Customer((int)(self::$cookie->id_customer));
  $groupes = $customer->getGroups();
 }
 else
  $groupes = array(1);


 if ((self::$cart->getOrderTotal(false, Cart::ONLY_PRODUCTS) < $minimalPurchase) and ($groupes[0]==4))
  return '<p class="warning">'.Tools::displayError('A minimum purchase total of').' '.Tools::displayPrice($minimalPurchase, $currency).
  ' '.Tools::displayError('is required in order to validate your order.').'</p>';

 

And That Works !! Only the Customers from group ID 4 (by default) will have this limitation of Minimal purchase activated !

 

If you need more group ID filters just modifiy the code to make it happen in the way rocky shows above (by the way, it took me some time before I found that "ismemberofgroup" function is deprecated in 1.4.)

 

I Still Do need Help :> How to put this modifications in Overrides directory...so next update it will keep on working.

 

Best Regards to all

 

hi there,

 

it works , but i found a bug , once you have reach a minimum of lets say 400$ , like in the code example, i mean add product to your cart in 400$ value, now you can see the payment options, you can remove items from your cart, lets say you have removed 1 item in the value of 100$ , now you still see the payment options, and your cart is only 300$ and you can continue to payment process. only if you refresh your cart you will see it again the blocking of the 400$ minimum.

i think its because of the ajax cart.

 

any way to fix it?

 

thanks

Matan

Link to comment
Share on other sites

Hello. This bug is solved in SVN version: http://svn.prestasho...cart-summary.js

You only need to change this file.

To try it, make a backup of the file, copy new file to your server and clear the browser cache to test it.

 

I just tryed this new version and I have more problems with this one on a 1.4.5.3 version, with this cart-summary.js file the total amount of the cart is not updated on onepage checkout when you modifiy quantity of an article.

Link to comment
Share on other sites

  • 3 weeks later...

How to set minimumPurchase amount for a group in Presta 1.4.7.0:

 

if (self::$cookie->id_customer)

{

$customer = new Customer((int)(self::$cookie->id_customer));

if ($customer->isMemberOfGroup(???))

$minimalPurchase = ???;

}

 

replace ??? with your variables!

Link to comment
Share on other sites

  • 1 month later...

Les cuento en español, porque no tengo gans de ponerme a escribir en ingles...

La solución, por lo menos para mi, con Prestashop 1.4.4. Es asi:

 

Editan el archivo \controllers\OrderController.php

 

Y reemplazan desde la linea 56:

 

 

/* Check minimal amount */

$currency = Currency::getCurrency((int)self::$cart->id_currency);

 

$orderTotal = self::$cart->getOrderTotal();

$minimalPurchase = Tools::convertPrice((float)Configuration::get('PS_PURCHASE_MINIMUM'), $currency);

if (self::$cart->getOrderTotal(false, Cart::ONLY_PRODUCTS) < $minimalPurchase && $this->step != -1)

{

$this->step = 0;

$this->errors[] = Tools::displayError('A minimum purchase total of').' '.Tools::displayPrice($minimalPurchase, $currency).

' '.Tools::displayError('is required in order to validate your order.');

}

 

if (!self::$cookie->isLogged(true) AND in_array($this->step, array(1, 2, 3)))

Tools::redirect('authentication.php?back='.urlencode('order.php?step='.$this->step));

 

if ($this->nbProducts)

self::$smarty->assign('virtual_cart', $isVirtualCart);

}

 

public function displayHeader()

{

if (!Tools::getValue('ajax'))

parent::displayHeader();

}

 

public function process()

{

parent::process();

 

POR ESTO:

 

 

/* Check minimal amount */

$currency = Currency::getCurrency((int)self::$cart->id_currency);

 

$orderTotal = self::$cart->getOrderTotal();

if (self::$cookie->id_customer)

{

$customer = new Customer((int)(self::$cookie->id_customer));

$groupes = $customer->getGroups();

}

else

$groupes = array(1);

if ($groupes[0]==1)

$minimalPurchase = Tools::convertPrice((float)Configuration::get('PS_PURCHASE_MINIMUM'), $currency);

elseif ($groupes[0]==2)

$minimalPurchase = Tools::convertPrice((float)Configuration::get('PS_PURCHASE_MINIMUM'), $currency)*6;

 

if (self::$cart->getOrderTotal(false, Cart::ONLY_PRODUCTS) < $minimalPurchase && $this->step != -1)

{

$this->step = 0;

$this->errors[] = Tools::displayError('A minimum purchase total of').' '.Tools::displayPrice($minimalPurchase, $currency).

' '.Tools::displayError('is required in order to validate your order.');

}

 

if (!self::$cookie->isLogged(true) AND in_array($this->step, array(1, 2, 3)))

Tools::redirect('authentication.php?back='.urlencode('order.php?step='.$this->step));

 

if ($this->nbProducts)

self::$smarty->assign('virtual_cart', $isVirtualCart);

}

 

public function displayHeader()

{

if (!Tools::getValue('ajax'))

parent::displayHeader();

}

 

public function process()

{

parent::process();

 

En este caso, yo tengo 2 grupos de clientes, 1 con un descuento del 25% y el otro con un descuento del 35%. Para el primero, el monto mínimo es $500 y para el segundo $3000, si se fijan, ('PS_PURCHASE_MINIMUM'), $currency esta multiplicado por 6. Ya que en el BackOffice, configuré a $500 el monto mínimo de compra. Espero lo puedan solucionar. Aparentemente la proxima versión de Prestashop, trae esta configuración incluida en el BackOficce!

 

Les dejo mi sitio Web, para que puedan visitarlo. http://www.oplenceria.com.ar Muchas gracias!

Link to comment
Share on other sites

  • 9 months later...
  • 5 weeks later...

It's not possible in PrestaShop without modifying code. You'll need to change line 31 of order.php from:

 

$minimalPurchase = floatval(Configuration::get('PS_PURCHASE_MINIMUM'));

 

to:

 

$minimalPurchase = floatval(Configuration::get('PS_PURCHASE_MINIMUM'));

if (intval($cookie->id_customer) > 0)
{
$customer = new Customer(intval($cookie->id_customer));

if ($customer->isMemberOfGroup(1))
	$minimalPurchase = 200;
elseif ($customer->isMemberOfGroup(2))
	$minimalPurchase = 300;
else
	$minimalPurchase = 0;
}

 

This code will force all customers in group 1 to purchase $200 before checking out and all customers in group 2 to purchase $300 before checking out. All other customers have no minimum. Change the group IDs and amounts as appropriate for your site.

 

HI rocky

does your solution work for PS 1.3.6 as well?

 

 

I use PS 1.3.6 and i would like to display a specific text message when a customer from the Group X (not conditioned by his/her name of his/her customer id) is logged in.

 

I tried the following combinations:

 

{if $logged}

{if isset($id_group) and $id_group==3}

<p class="warning"> Show this message 1 </p>

{else}

<p class="warning"> Show message 2 </p>

{/if}

{/if}

 

This option does not work ok and it displays the text in the {else} condition only.

 

I tried as well

 

{if $logged}

{if (self::$cookie->id_customer)}

{$customer = new Customer(intval($this->id_customer));

$customer->getGroups()}

{if ($customer_group==3)}

<p class="warning"> Show message 1 </p>

{else}

<p> Show message 2 </p>

{/if}

{/if}

{/if}

 

This code disables the body of the page completely.

 

Any tips on how to code it correctly?

 

Again, this is about showing a specific text message to a customer, depending on the group he's in (as set in the back office), independent of the name of the customer or the customer id.

version PS 1.3.6

Link to comment
Share on other sites

Got it.

Here is the solution in case anyone wants to add whatever message on the customer's account page, addresses page or whatever page, by performing a conditional

check according to the group to which the customer belongs (verified on PS 1.3.6)

 

Add on the my-account.tpl or whichever tpl you want, where you want the message to appear, the following code:

 

<div>

 

{if ($logged)}

{ $customer = new Customer($cookie->id_customer);

if (!$customer->isMemberOfGroup(3));}

<p class="warning"> Show message 1 </p>

{else}

<p> Show message 2 </p>

{/if}

 

</div>

 

 

The above checks the condition id_group id_customer and isMemberofGroup and displays the corresponding warning or message.

 

Tags: if condition $id_group $id_customer ismemeberofgroup

 

Partial credits go to rocky for his post;

http://www.prestashop.com/forums/index.php?/topic/39431-php-help-needed-hide-everythingshop-until-a-user-logs-in/page__view__findpost__p__283507

Link to comment
Share on other sites

  • 8 months later...

It's not possible in PrestaShop without modifying code. You'll need to change line 31 of order.php from:

 

$minimalPurchase = floatval(Configuration::get('PS_PURCHASE_MINIMUM'));

to:

 

$minimalPurchase = floatval(Configuration::get('PS_PURCHASE_MINIMUM'));if (intval($cookie->id_customer) > 0){    $customer = new Customer(intval($cookie->id_customer));        if ($customer->isMemberOfGroup(1))        $minimalPurchase = 200;    elseif ($customer->isMemberOfGroup(2))        $minimalPurchase = 300;    else        $minimalPurchase = 0;}

This code will force all customers in group 1 to purchase $200 before checking out and all customers in group 2 to purchase $300 before checking out. All other customers have no minimum. Change the group IDs and amounts as appropriate for your site.

 

Hi Rocky..

 

I am using 1.5.4.1 ,,, Can you please suggest if I wish to have a minimum quantity restriction and not of price,,

For eaxample I want wholesale group to buy at least 25 items and it can be mix of items totalling to 25...

Link to comment
Share on other sites

  • 1 month later...

Hi Rocky..

 

I am using 1.5.4.1 ,,, Can you please suggest if I wish to have a minimum quantity restriction and not of price,,

For eaxample I want wholesale group to buy at least 25 items and it can be mix of items totalling to 25...

 

Also looking for this in 1.5.4.1. Any help would be fantastic.

Link to comment
Share on other sites

  • 2 months later...

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...