From a1997a813d0b45b933f1d1afcdc1a4b2ba18a610 Mon Sep 17 00:00:00 2001 From: Almira Krdzic Date: Tue, 6 Nov 2018 14:03:58 +0100 Subject: [PATCH 1/2] 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(); From c555571607b741a665066a96d07c59cb6c8ec4a8 Mon Sep 17 00:00:00 2001 From: Almira Krdzic Date: Tue, 6 Nov 2018 15:33:33 +0100 Subject: [PATCH 2/2] Text change --- .../wiaas/includes/class-wiaas-cart.php | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/backend/app/plugins/wiaas/includes/class-wiaas-cart.php b/backend/app/plugins/wiaas/includes/class-wiaas-cart.php index c5374eb..df8c358 100644 --- a/backend/app/plugins/wiaas/includes/class-wiaas-cart.php +++ b/backend/app/plugins/wiaas/includes/class-wiaas-cart.php @@ -164,21 +164,6 @@ class Wiaas_Cart { return false; } - // Validate that order contains only stuff for single country - if ( ! WC()->cart->is_empty() ) { - - $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() ) { @@ -186,7 +171,7 @@ class Wiaas_Cart { 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'); + wc_add_notice('Only packages from one catalogue can be purchased at the same time!', 'error'); return false; } } else { @@ -194,6 +179,21 @@ class Wiaas_Cart { update_user_meta( get_current_user_id(), '_wiaas_cart_shop_owner_id', $shop_owner_id); } + // Validate that order contains only items for single country + if ( ! WC()->cart->is_empty() ) { + + $current_country = get_user_meta(get_current_user_id(), '_wiaas_cart_items_country', true); + + if ($country !== $current_country) { + + wc_add_notice('Only packages from one country can be purchased at the same time!', 'error'); + return false; + } + } else { + + update_user_meta( get_current_user_id(), '_wiaas_cart_items_country', $country); + } + $customer_id = wiaas_get_current_user_organization_id(); // Retrieve package price