diff --git a/backend/app/plugins/wiaas/includes/class-wiaas-cart.php b/backend/app/plugins/wiaas/includes/class-wiaas-cart.php index d057b15..df8c358 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 from single commercial lead / reseller / shop owner + 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_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 one 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); + } + + // 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();