From a1997a813d0b45b933f1d1afcdc1a4b2ba18a610 Mon Sep 17 00:00:00 2001 From: Almira Krdzic Date: Tue, 6 Nov 2018 14:03:58 +0100 Subject: [PATCH] Validate that items are from the same country and catalogue --- .../wiaas/includes/class-wiaas-cart.php | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/backend/app/plugins/wiaas/includes/class-wiaas-cart.php b/backend/app/plugins/wiaas/includes/class-wiaas-cart.php index d057b15..c5374eb 100644 --- a/backend/app/plugins/wiaas/includes/class-wiaas-cart.php +++ b/backend/app/plugins/wiaas/includes/class-wiaas-cart.php @@ -164,11 +164,35 @@ class Wiaas_Cart { return false; } - // TODO: Add validation that only packages from the same country can be added to cart at the same time - update_user_meta( get_current_user_id(), '_wiaas_cart_items_country', $country); + // Validate that order contains only stuff for single country + if ( ! WC()->cart->is_empty() ) { - // TODO: Add validation that only packages from the same shop can be added to cart at the same time - update_user_meta( get_current_user_id(), '_wiaas_cart_shop_owner_id', $shop_owner_id); + $current_country = get_user_meta(get_current_user_id(), '_wiaas_cart_items_country', true); + + if ($country !== $current_country) { + + wc_add_notice('Only packages from single country can be purchased at the same time!', 'error'); + return false; + } + } else { + + update_user_meta( get_current_user_id(), '_wiaas_cart_items_country', $country); + } + + // Validate that order contains only stuff from single commercial lead / reseller / shop owner + if ( ! WC()->cart->is_empty() ) { + + $current_shop_owner_id = get_user_meta(get_current_user_id(), '_wiaas_cart_shop_owner_id', true); + + if (absint($shop_owner_id) !== absint($current_shop_owner_id)) { + + wc_add_notice('Only packages from single catalogue can be purchased at the same time!', 'error'); + return false; + } + } else { + + update_user_meta( get_current_user_id(), '_wiaas_cart_shop_owner_id', $shop_owner_id); + } $customer_id = wiaas_get_current_user_organization_id();