Zen Cart Logo
Forums / Upgrading to 2.x.x / Minimum Order Wholesale

Minimum Order Wholesale

Views: 1,229

Results 1 to 20 of 20
5 Nov 2024, 12:50 PM
#1
allmart avatar

allmart

Zen Follower

Join Date:
Feb 2016
Location:
Canada
Posts:
192
Plugin Contributions:
0

Minimum Order Wholesale

Hello,

I am running ZC 2.0.1 with PHP 8.2 and have the Minimum Order Plugin. I am using the wholesale option for some of my customers but wanted a different minimum order for my wholesale customers. I have added a minimum order wholesale field in my customer database which all worked fine with my older version ZC 1.5.7d. The code I used is below which gives me the error "PHP Parse error: syntax error, unexpected variable "$threshold", expecting "," or ";" in ..." in 2.0.1

<?php $threshold = MIN_ORDER_AMOUNT;// set it minimum values if ($_SESSION['cart']->show_total() < $threshold ) { $alertJM="Shipping is only available for orders over " . $currencies->format ($threshold); } if ( $_SESSION['cart']->show_total() > $threshold ) { $alertJM="We do not deliver to your postal code.<br>Please contact us if you have any questions."; } if ($_SESSION['customers_whole'] != '' > 0 ){ $threshold = MIN_WS_ORDER_AMOUNT;// set it minimum values $alertJM="We do not deliver to your postal code.<br>Please contact us if you have any questions."; } ?>

Any help is appreciated.

5 Nov 2024, 2:31 PM
#2
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,682
Plugin Contributions:
56

Re: Minimum Order Wholesale

Change

if ($_SESSION['customers_whole'] != '' > 0 ){

to

if ($_SESSION['customers_whole'] != > 0 ){

(remove extra quotes after = sign)

5 Nov 2024, 2:42 PM
#3
allmart avatar

allmart

Zen Follower

Join Date:
Feb 2016
Location:
Canada
Posts:
192
Plugin Contributions:
0

Re: Minimum Order Wholesale

Thanks, I get the following error:

PHP Parse error: syntax error, unexpected token ">" in /includes/templates/bootstrap/templates/tpl_modules_opc_shipping_choices.php on line 24.

line 24: if ($_SESSION['customers_whole'] != > 0 ){

Ideally which file should I have this code?

5 Nov 2024, 5:10 PM
#4
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,682
Plugin Contributions:
56

Re: Minimum Order Wholesale

sorry copy and paste error

that line should be

line 24: if ($_SESSION['customers_whole'] != 0 ){

5 Nov 2024, 6:16 PM
#5
allmart avatar

allmart

Zen Follower

Join Date:
Feb 2016
Location:
Canada
Posts:
192
Plugin Contributions:
0

Re: Minimum Order Wholesale

Thanks again but now getting error:

PHP Warning: Undefined array key "customers_whole" in /includes/templates/bootstrap/templates/tpl_modules_opc_shipping_choices.php on line 24.

5 Nov 2024, 6:50 PM
#6
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,065
Plugin Contributions:
56

Re: Minimum Order Wholesale

You've apparently got a modified version of that Bootstrap template file. If you'd post (using "CODE" tags) your version thereof, that'd help.

5 Nov 2024, 6:55 PM
#7
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,065
Plugin Contributions:
56

Re: Minimum Order Wholesale

Note that rather than checking for the $_SESSION['customer_whole'] variable directly, there's a function available that lets you know:

if (Customer::isWholesaleCustomer() === true) {
    //- The customer is a wholesale customer
}
5 Nov 2024, 7:52 PM
#8
allmart avatar

allmart

Zen Follower

Join Date:
Feb 2016
Location:
Canada
Posts:
192
Plugin Contributions:
0

Re: Minimum Order Wholesale

lat9:

Note that rather than checking for the $_SESSION['customer_whole'] variable directly, there's a function available that lets you know:

if (Customer::isWholesaleCustomer() === true) {
//- The customer is a wholesale customer
}


This solves my problem, many thanks!!!
5 Nov 2024, 8:19 PM
#9
allmart avatar

allmart

Zen Follower

Join Date:
Feb 2016
Location:
Canada
Posts:
192
Plugin Contributions:
0

Re: Minimum Order Wholesale

allmart:

This solves my problem, many thanks!!!

Do you know similar code to retrieve MIN_ORDER_WS_AMOUNT from the configuration table created by the Minimum Order Plugin?

5 Nov 2024, 9:58 PM
#10
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,065
Plugin Contributions:
56

Re: Minimum Order Wholesale

All configuration 'keys' (like MIN_ORDER_WS_AMOUNT) present in the database are created as PHP defines during each page-load, so you'll just use

if (defined('MIN_ORDER_WS_AMOUNT') && MIN_ORDER_WS_AMOUNT >= $whatever) {
    //- do something
}
11 Nov 2024, 4:19 PM
#11
allmart avatar

allmart

Zen Follower

Join Date:
Feb 2016
Location:
Canada
Posts:
192
Plugin Contributions:
0

Re: Minimum Order Wholesale

I have 2 different fields minimum order fields.
retail customers = 'MIN_ORDER_AMOUNT' which is set at $100
wholesale customers = 'MIN_ORDER_WS_AMOUNT' which is set at $400

If have this code below in zipship.php that works however instead of the $100 and $400 values in the code, I want it to reference MIN_ORDER_AMOUNT and MIN_ORDER_WS_AMOUNT in my "Minimum Values" configuration so that if I ever change the amounts, I don't have to change my code.

if (Customer::isWholesaleCustomer() === true) {
if ( $order->info['subtotal'] < 400 ) {
$this->enabled = (MODULE_SHIPPING_ZIPSHIP_STATUS === 'false');
}
}

if (Customer::isWholesaleCustomer() === false) {
if ( $order->info['subtotal'] < 100 ) {
$this->enabled = (MODULE_SHIPPING_ZIPSHIP_STATUS === 'true');
}
}

I also want to reference them in "class_minimum_order_amount.php'

12 Nov 2024, 8:43 PM
#12
dbltoe avatar

dbltoe

Totally Zenned

Join Date:
Jan 2004
Location:
N of San Antonio TX
Posts:
9,763
Plugin Contributions:
9

Re: Minimum Order Wholesale

Congrats on a well-formed question.

The following is a ChatGPT generated solution, but it might help you get where you want to go.

You can modify your code to reference the configuration values directly using Zen Cart's built-in getConfigValue function. This way, it will dynamically pull the values for MIN_ORDER_AMOUNT and MIN_ORDER_WS_AMOUNT from your configuration, allowing you to change the amounts in the admin panel without modifying the code.

Here’s the updated code:

Updated Code

// Get the minimum order amounts from the configuration
$minOrderRetail = getConfigValue('MIN_ORDER_AMOUNT');
$minOrderWholesale = getConfigValue('MIN_ORDER_WS_AMOUNT');


// Check if the customer is wholesale
if (Customer::isWholesaleCustomer() === true) {
    // Check if the subtotal is less than the wholesale minimum amount
    if ($order->info['subtotal'] < $minOrderWholesale) {
        $this->enabled = (MODULE_SHIPPING_ZIPSHIP_STATUS === 'false');
    }
} else {
    // Check if the subtotal is less than the retail minimum amount
    if ($order->info['subtotal'] < $minOrderRetail) {
        $this->enabled = (MODULE_SHIPPING_ZIPSHIP_STATUS === 'true');
    }
}

Explanation:

  1. Retrieve Configuration Values: The variables $minOrderRetail and $minOrderWholesale are set by fetching the values of MIN_ORDER_AMOUNT and MIN_ORDER_WS_AMOUNT from your Zen Cart configuration.

  2. Dynamic Checking: The code checks if the customer is wholesale or retail and uses the appropriate minimum order amount.

Additional Notes

  • Ensure that the configuration keys MIN_ORDER_AMOUNT and MIN_ORDER_WS_AMOUNT are properly defined in your Zen Cart admin under Minimum Values.
  • If getConfigValue() doesn’t work directly, you may need to use:
    $minOrderRetail = defined('MIN_ORDER_AMOUNT') ? MIN_ORDER_AMOUNT : 100;
    $minOrderWholesale = defined('MIN_ORDER_WS_AMOUNT') ? MIN_ORDER_WS_AMOUNT : 400;
    
  • Test the changes thoroughly to confirm they work with your specific Zen Cart setup.
12 Nov 2024, 9:24 PM
#13
allmart avatar

allmart

Zen Follower

Join Date:
Feb 2016
Location:
Canada
Posts:
192
Plugin Contributions:
0

Re: Minimum Order Wholesale

Thanks dblToe/ChatGPT
it looked promising but $minOrderRetail = getConfigValue('MIN_ORDER_AMOUNT'); and
$minOrderWholesale = getConfigValue('MIN_ORDER_WS_AMOUNT'); gave me the error below:

[12-Nov-2024 16:12:15 US/Eastern] PHP Fatal error: Uncaught Error: Call to undefined function getConfigValue() in /includes/classes/observers/class.minimum_order_amount.php:81
Stack trace:
#0 /includes/classes/traits/NotifierManager.php(87): minimum_order_amount->update(Object(notifier), 'NOTIFY_HEADER_E...', Array, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
#1 /includes/modules/pages/shopping_cart/header_php.php(192): base->notify('NOTIFY_HEADER_E...')
#2 /index.php(35): require('/volume1/web/st...')
#3 {main}
thrown in /includes/classes/observers/class.minimum_order_amount.php on line 81

[12-Nov-2024 16:12:15 US/Eastern] Request URI: /shopping_cart.html, IP address: 192.168.1.123
--> PHP Fatal error: Uncaught Error: Call to undefined function getConfigValue() in /includes/classes/observers/class.minimum_order_amount.php:81
Stack trace:
#0 /includes/classes/traits/NotifierManager.php(87): minimum_order_amount->update(Object(notifier), 'NOTIFY_HEADER_E...', Array, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
#1 /includes/modules/pages/shopping_cart/header_php.php(192): base->notify('NOTIFY_HEADER_E...')
#2 /index.php(35): require('/volume1/web/st...')
#3 {main}
thrown in /includes/classes/observers/class.minimum_order_amount.php on line 81.

[12-Nov-2024 16:12:15 US/Eastern] Request URI: /shopping_cart.html, IP address: 192.168.1.123
--> PHP Fatal error: Uncaught Error: Call to undefined function getConfigValue() in /includes/classes/observers/class.minimum_order_amount.php:81
Stack trace:
#0 /includes/classes/traits/NotifierManager.php(87): minimum_order_amount->update(Object(notifier), 'NOTIFY_HEADER_E...', Array, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
#1 /includes/modules/pages/shopping_cart/header_php.php(192): base->notify('NOTIFY_HEADER_E...')
#2 /index.php(35): require('/volume1/web/st...')
#3 {main}
thrown in /includes/classes/observers/class.minimum_order_amount.php on line 81.

$minOrderWholesale = defined('MIN_ORDER_WS_AMOUNT') ? MIN_ORDER_WS_AMOUNT : 400;
$minOrderRetail = defined('MIN_ORDER_AMOUNT') ? MIN_ORDER_AMOUNT : 100;

did work but it doesn't solve my problem. Is there an alternative to getConfigValue?

15 Nov 2024, 8:19 PM
#14
allmart avatar

allmart

Zen Follower

Join Date:
Feb 2016
Location:
Canada
Posts:
192
Plugin Contributions:
0

Re: Minimum Order Wholesale

I could still use some help with this please.

15 Nov 2024, 11:12 PM
#15
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,954
Plugin Contributions:
8

Re: Minimum Order Wholesale

allmart:

Thanks dblToe/ChatGPT
...

did work but it doesn't solve my problem. Is there an alternative to getConfigValue?

once you start listening to dblToe/ChatGPT, you are in for a world of trouble... especially when taking any coding advice.

you can do something like:

$minOrderWholesale = defined('MIN_ORDER_WS_AMOUNT') ? MIN_ORDER_WS_AMOUNT : 400;
$minOrderRetail = defined('MIN_ORDER_AMOUNT') ? MIN_ORDER_AMOUNT : 100;

$threshold = $minOrderRetail;

if (Customer::isWholesaleCustomer() === true) {
    //- The customer is a wholesale customer
    $threshold = $minOrderWholesale;
}

if ($_SESSION['cart']->show_total() < $threshold ) {
    $alertJM="Shipping is only available for orders over " . $currencies->format ($threshold);
}

why you are testing for something over the threshold, i do not know....

best.

18 Nov 2024, 4:27 PM
#16
allmart avatar

allmart

Zen Follower

Join Date:
Feb 2016
Location:
Canada
Posts:
192
Plugin Contributions:
0

Re: Minimum Order Wholesale

Hi Carl What, thanks but this has already been suggested and is no good for me. I want in to retrieve MIN_ORDER_WS_AMOUNT and MIN_ORDER_AMOUNT from my configuration table, so if I ever have to change the values I can do it from my minimum values setting through the admin panel instead of having to change coding.

18 Nov 2024, 4:44 PM
#17
brittainmark avatar

brittainmark

Totally Zenned

Join Date:
Apr 2009
Posts:
507
Plugin Contributions:
1

Re: Minimum Order Wholesale

Hi allmart. That is exactly what carlwhat has given you.

$minOrderWholesale = defined('MIN_ORDER_WS_AMOUNT') ? MIN_ORDER_WS_AMOUNT : 400; 

This code says. If MIN_ORDER_WS_AMOUNT is defined on the database the use that value if not use 400 as the value.
So as long as MIN_ORDER_WS_AMOUNT is defined then the value you have set will be used.

18 Nov 2024, 5:23 PM
#18
allmart avatar

allmart

Zen Follower

Join Date:
Feb 2016
Location:
Canada
Posts:
192
Plugin Contributions:
0

Re: Minimum Order Wholesale

This is my code in class.minimum.order.amount.php :

$minOrderWholesale = defined('MIN_ORDER_WS_AMOUNT');

			if (Customer::isWholesaleCustomer() === true) {
				
		if ($_SESSION['cart']->count_contents() > 0 && $minOrderWholesale > 0) {
		  if($_SESSION['cart']->show_total() < $minOrderWholesale) {
			$_SESSION['valid_to_checkout'] = false;
			$messageStack->add('shopping_cart', sprintf(TEXT_WS_ORDER_UNDER_MIN_AMOUNT, $currencies->format($minOrderWholesale)) . '<br />', 'alert'); //warning = yellow, alert = blue, alert = red
		  }
		}
	}

which is not giving the messagestack that it is below minimum order which is set at $400.00 in my configuration file and allows checkout. Unless coded as:
$minOrderWholesale = defined('MIN_ORDER_WS_AMOUNT') ? MIN_ORDER_WS_AMOUNT : 400;

18 Nov 2024, 5:44 PM
#19
allmart avatar

allmart

Zen Follower

Join Date:
Feb 2016
Location:
Canada
Posts:
192
Plugin Contributions:
0

Re: Minimum Order Wholesale

allmart:

This is my code in class.minimum.order.amount.php :

$minOrderWholesale = defined('MIN_WS_ORDER_AMOUNT');

  		if (Customer::isWholesaleCustomer() === true) {
  			
  	if ($_SESSION['cart']->count_contents() > 0 && $minOrderWholesale > 0) {
  	  if($_SESSION['cart']->show_total() < $minOrderWholesale) {
  		$_SESSION['valid_to_checkout'] = false;
  		$messageStack->add('shopping_cart', sprintf(TEXT_WS_ORDER_UNDER_MIN_AMOUNT, $currencies->format($minOrderWholesale)) . '<br />', 'alert'); //warning = yellow, alert = blue, alert = red
  	  }
  	}
  }

which is not giving the messagestack that it is below minimum order which is set at $400.00 in my configuration file and allows checkout. Unless coded as:
$minOrderWholesale = defined('MIN_WS_ORDER_AMOUNT') ? MIN_WS_ORDER_AMOUNT : 400;

Typo: MIN_WS_ORDER_AMOUNT not MIN_ORDER_WS_AMOUNT

18 Nov 2024, 6:00 PM
#20
allmart avatar

allmart

Zen Follower

Join Date:
Feb 2016
Location:
Canada
Posts:
192
Plugin Contributions:
0

Re: Minimum Order Wholesale

$minOrderWholesale = zen_get_configuration_key_value('MIN_WS_ORDER_AMOUNT'); works which I got from ChatGTP. Thanks everyone for your help.