Cross selling (#4185)

Product categories can now be marked as "cross-selling categories", causing them to 
appear in the add-on checkout step as additional recommendations, depending on 
their cross-selling visibility (always, only if certain products are already in the cart, or 
only if they qualify for a discount according to discount rules).

---------

Co-authored-by: Raphael Michel <michel@rami.io>
Co-authored-by: Richard Schreiber <schreiber@rami.io>
This commit is contained in:
Mira
2024-10-14 14:39:49 +02:00
committed by GitHub
parent 7607cc5d2f
commit 359df1f51e
24 changed files with 1737 additions and 218 deletions

View File

@@ -128,7 +128,10 @@ TEST_CATEGORY_RES = {
"description": {"en": ""},
"internal_name": None,
"position": 0,
"is_addon": False
"is_addon": False,
"cross_selling_mode": None,
"cross_selling_condition": None,
"cross_selling_match_products": [],
}
@@ -211,6 +214,44 @@ def test_category_update(token_client, organizer, event, team, category):
assert ItemCategory.objects.get(pk=category.pk).name == {"en": "Test"}
@pytest.mark.django_db
def test_category_update_cross_selling_options(token_client, organizer, event, team, category):
resp = token_client.patch(
'/api/v1/organizers/{}/events/{}/categories/{}/'.format(organizer.slug, event.slug, category.pk),
{
"cross_selling_mode": "both",
},
format='json'
)
assert resp.status_code == 200
with scopes_disabled():
assert ItemCategory.objects.get(pk=category.pk).cross_selling_mode == 'both'
resp = token_client.patch(
'/api/v1/organizers/{}/events/{}/categories/{}/'.format(organizer.slug, event.slug, category.pk),
{
"cross_selling_mode": "something",
},
format='json'
)
assert resp.status_code == 400
with scopes_disabled():
assert ItemCategory.objects.get(pk=category.pk).cross_selling_mode == 'both'
resp = token_client.patch(
'/api/v1/organizers/{}/events/{}/categories/{}/'.format(organizer.slug, event.slug, category.pk),
{
"is_addon": True,
},
format='json'
)
assert resp.status_code == 400
assert 'mutually exclusive' in str(resp.data)
with scopes_disabled():
assert ItemCategory.objects.get(pk=category.pk).cross_selling_mode == 'both'
assert ItemCategory.objects.get(pk=category.pk).is_addon is False
@pytest.mark.django_db
def test_category_update_wrong_event(token_client, organizer, event2, category):
resp = token_client.patch(