Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Drop wishlists (#9313)

Marcin Gębala7c9576925906
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5c6d706c2e..0e591152e4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,8 @@ All notable, unreleased changes to this project will be documented in this file.
### Other changes
+- Drop wishlist models - #9313 by @maarcingebala
+
# 3.1.2
### Breaking changes
diff --git a/saleor/graphql/core/enums.py b/saleor/graphql/core/enums.py
index 5555893f82..fe8f48dd28 100644
--- a/saleor/graphql/core/enums.py
+++ b/saleor/graphql/core/enums.py
@@ -30,7 +30,6 @@ from ...shipping import error_codes as shipping_error_codes
from ...site import error_codes as site_error_codes
from ...warehouse import error_codes as warehouse_error_codes
from ...webhook import error_codes as webhook_error_codes
-from ...wishlist import error_codes as wishlist_error_codes
from ..notifications import error_codes as external_notifications_error_codes
from .utils import str_to_enum
@@ -135,5 +134,4 @@ StockErrorCode = graphene.Enum.from_enum(warehouse_error_codes.StockErrorCode)
UploadErrorCode = graphene.Enum.from_enum(core_error_codes.UploadErrorCode)
WarehouseErrorCode = graphene.Enum.from_enum(warehouse_error_codes.WarehouseErrorCode)
WebhookErrorCode = graphene.Enum.from_enum(webhook_error_codes.WebhookErrorCode)
-WishlistErrorCode = graphene.Enum.from_enum(wishlist_error_codes.WishlistErrorCode)
TranslationErrorCode = graphene.Enum.from_enum(core_error_codes.TranslationErrorCode)
diff --git a/saleor/graphql/core/types/common.py b/saleor/graphql/core/types/common.py
index 2398e1d2a8..65aef75de6 100644
--- a/saleor/graphql/core/types/common.py
+++ b/saleor/graphql/core/types/common.py
@@ -40,7 +40,6 @@ from ..enums import (
WarehouseErrorCode,
WebhookErrorCode,
WeightUnitsEnum,
- WishlistErrorCode,
)
from ..scalars import PositiveDecimal
from .money import VAT
@@ -359,10 +358,6 @@ class WebhookError(Error):
code = WebhookErrorCode(description="The error code.", required=True)
-class WishlistError(ProductWithoutVariantError):
- code = WishlistErrorCode(description="The error code.", required=True)
-
-
class TranslationError(Error):
code = TranslationErrorCode(description="The error code.", required=True)
diff --git a/saleor/settings.py b/saleor/settings.py
index 355ad9ab5d..bd82e0a643 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -226,7 +226,6 @@ INSTALLED_APPS = [
"saleor.payment",
"saleor.warehouse",
"saleor.webhook",
- "saleor.wishlist",
"saleor.app",
# External apps
"versatileimagefield",
diff --git a/saleor/tests/fixtures.py b/saleor/tests/fixtures.py
index 7a5e8535e4..f7bcfd1d52 100644
--- a/saleor/tests/fixtures.py
+++ b/saleor/tests/fixtures.py
@@ -128,7 +128,6 @@ from ..warehouse.models import (
)
from ..webhook.event_types import WebhookEventAsyncType, WebhookEventSyncType
from ..webhook.models import Webhook, WebhookEvent
-from ..wishlist.models import Wishlist
from .utils import dummy_editorjs
@@ -5160,32 +5159,6 @@ def staff_notification_recipient(db, staff_user):
return StaffNotificationRecipient.objects.create(active=True, user=staff_user)
-def customer_wishlist(customer_user):
- return Wishlist.objects.create(user=customer_user)
-
-
-def customer_wishlist_item(customer_wishlist, product_with_single_variant):
- product = product_with_single_variant
- assert product.variants.count() == 1
- variant = product.variants.first()
- item = customer_wishlist.add_variant(variant)
- return item
-
-
-def customer_wishlist_item_with_two_variants(
- customer_wishlist, product_with_two_variants
-):
- product = product_with_two_variants
- assert product.variants.count() == 2
- [variant_1, variant_2] = product.variants.all()
- item = customer_wishlist.add_variant(variant_1)
- item.variants.add(variant_2)
- return item
-
-
@pytest.fixture
def warehouse(address, shipping_zone):
warehouse = Warehouse.objects.create(
diff --git a/saleor/wishlist/__init__.py b/saleor/wishlist/__init__.py
deleted file mode 100644
index e69de29bb2..0000000000
diff --git a/saleor/wishlist/error_codes.py b/saleor/wishlist/error_codes.py
deleted file mode 100644
index 909156ee4c..0000000000
--- a/saleor/wishlist/error_codes.py
+++ /dev/null
@@ -1,10 +0,0 @@
-from enum import Enum
-
-
-class WishlistErrorCode(str, Enum):
- GRAPHQL_ERROR = "graphql_error"
- INVALID = "invalid"
- NOT_FOUND = "not_found"
- REQUIRED = "required"
- UNIQUE = "unique"
- CANNOT_MANAGE_PRODUCT_WITHOUT_VARIANT = "CANNOT_MANAGE_PRODUCT_WITHOUT_VARIANT"
diff --git a/saleor/wishlist/migrations/0001_initial.py b/saleor/wishlist/migrations/0001_initial.py
deleted file mode 100644
index 8b3516c4de..0000000000
--- a/saleor/wishlist/migrations/0001_initial.py
+++ /dev/null
@@ -1,89 +0,0 @@
-# Generated by Django 2.2.6 on 2019-10-11 10:36
-
-import uuid
-
-import django.db.models.deletion
-from django.conf import settings
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
- initial = True
-
- dependencies = [
- ("product", "0109_auto_20191006_1433"),
- migrations.swappable_dependency(settings.AUTH_USER_MODEL),
- ]
-
- operations = [
- migrations.CreateModel(
- name="Wishlist",
- fields=[
- (
- "id",
- models.AutoField(
- auto_created=True,
- primary_key=True,
- serialize=False,
- verbose_name="ID",
- ),
- ),
- ("created_at", models.DateTimeField(auto_now_add=True)),
- (
- "token",
- models.UUIDField(default=uuid.uuid4, editable=False, unique=True),
- ),
- (
- "user",
- models.OneToOneField(
- blank=True,
- null=True,
- on_delete=django.db.models.deletion.CASCADE,
- related_name="wishlist",
- to=settings.AUTH_USER_MODEL,
- ),
- ),
- ],
- ),
- migrations.CreateModel(
- name="WishlistItem",
- fields=[
- (
- "id",
- models.AutoField(
- auto_created=True,
- primary_key=True,
- serialize=False,
- verbose_name="ID",
- ),
- ),
- ("created_at", models.DateTimeField(auto_now_add=True)),
- (
- "product",
- models.ForeignKey(
- on_delete=django.db.models.deletion.CASCADE,
- related_name="wishlist_items",
- to="product.Product",
- ),
- ),
- (
- "variants",
- models.ManyToManyField(
- blank=True,
- related_name="wishlist_items",
- to="product.ProductVariant",
- ),
- ),
- (
- "wishlist",
- models.ForeignKey(
- on_delete=django.db.models.deletion.CASCADE,
- related_name="items",
- to="wishlist.Wishlist",
- ),
- ),
- ],
- options={"unique_together": {("wishlist", "product")}},
- ),
- ]
diff --git a/saleor/wishlist/migrations/__init__.py b/saleor/wishlist/migrations/__init__.py
deleted file mode 100644
index e69de29bb2..0000000000
diff --git a/saleor/wishlist/models.py b/saleor/wishlist/models.py
deleted file mode 100644
index 1e144d6824..0000000000
--- a/saleor/wishlist/models.py
+++ /dev/null
@@ -1,90 +0,0 @@
-import uuid
-
-from django.db import models
-
-from ..account.models import User
-from ..core.tracing import traced_atomic_transaction
-from ..product.models import Product, ProductVariant
-
-
-class Wishlist(models.Model):
- token = models.UUIDField(default=uuid.uuid4, unique=True, editable=False)
- user = models.OneToOneField(
- User, related_name="wishlist", on_delete=models.CASCADE, blank=True, null=True
- )
- created_at = models.DateTimeField(auto_now_add=True)
-
- def set_user(self, user):
- self.user = user
- self.save()
-
- def get_all_variants(self):
- return ProductVariant.objects.filter(
- wishlist_items__wishlist_id=self.pk
- ).distinct()
-
- def add_product(self, product: Product):
- item, _is_created = self.items.get_or_create(product_id=product.pk)
- return item
-
- def remove_product(self, product: Product):
- self.items.filter(product_id=product.pk).delete()
-
- def add_variant(self, variant: ProductVariant):
- item, _is_created = self.items.get_or_create(product_id=variant.product_id)
- item.variants.add(variant)
- return item
-
- def remove_variant(self, variant: ProductVariant):
- try:
- item = self.items.get(product_id=variant.product_id)
- except WishlistItem.DoesNotExist:
- return
- else:
- item.variants.remove(variant)
- # If it was the last variant, delete the whole item
- if item.variants.count() == 0:
- item.delete()
-
-
-class WishlistItemQuerySet(models.QuerySet):
- @traced_atomic_transaction()
- def move_items_between_wishlists(self, src_wishlist, dst_wishlist):
- dst_wishlist_map = {}
- for dst_item in dst_wishlist.items.all():
- dst_wishlist_map[dst_item.product_id] = dst_item
- # Copying the items from the source to the destination wishlist.
- for src_item in src_wishlist.items.all():
- if src_item.product_id in dst_wishlist_map:
- # This wishlist item's product already exist.
- # Adding and the variants, "add" already handles duplicates.
- dst_item = dst_wishlist_map[src_item.product_id]
- dst_item.variants.add(*src_item.variants.all())
- src_item.delete()
- else:
- # This wishlist item contains a new product.
- # It can be reassigned to the destination wishlist.
- src_item.wishlist = dst_wishlist
- src_item.save()
- self.filter(wishlist=src_wishlist).update(wishlist=dst_wishlist)
-
-
-class WishlistItem(models.Model):
- wishlist = models.ForeignKey(
- Wishlist, related_name="items", on_delete=models.CASCADE
- )
- product = models.ForeignKey(
- Product, related_name="wishlist_items", on_delete=models.CASCADE
- )
- variants = models.ManyToManyField(
- ProductVariant, related_name="wishlist_items", blank=True
- )
- created_at = models.DateTimeField(auto_now_add=True)
-
- objects = models.Manager.from_queryset(WishlistItemQuerySet)()
-
- class Meta:
- unique_together = ("wishlist", "product")
-
- def __str__(self):
- return "WishlistItem (%s, %s)" % (self.wishlist.user, self.product)
diff --git a/saleor/wishlist/tests/__init__.py b/saleor/wishlist/tests/__init__.py
deleted file mode 100644
index e69de29bb2..0000000000
diff --git a/saleor/wishlist/tests/test_wishlist.py b/saleor/wishlist/tests/test_wishlist.py
deleted file mode 100644
index 6bcb28a07e..0000000000
--- a/saleor/wishlist/tests/test_wishlist.py
+++ /dev/null
@@ -1,54 +0,0 @@
-import pytest
-
-from ..models import Wishlist, WishlistItem
-
-
-def test_remove_only_variant_also_removes_wishlist_item(customer_wishlist_item):
- assert customer_wishlist_item.variants.count() == 1
- variant = customer_wishlist_item.variants.first()
- wishlist = customer_wishlist_item.wishlist
- assert wishlist.items.count() == 1
- wishlist.remove_variant(variant)
- assert wishlist.items.count() == 0
- with pytest.raises(WishlistItem.DoesNotExist):
- customer_wishlist_item.refresh_from_db()
-
-
-def test_remove_single_variant_from_wishlist_item(
- customer_wishlist_item_with_two_variants,
-):
- assert customer_wishlist_item_with_two_variants.variants.count() == 2
- [variant_1, variant_2] = customer_wishlist_item_with_two_variants.variants.all()
- wishlist = customer_wishlist_item_with_two_variants.wishlist
- wishlist.remove_variant(variant_1)
- customer_wishlist_item_with_two_variants.refresh_from_db()
- assert customer_wishlist_item_with_two_variants.variants.count() == 1
- assert customer_wishlist_item_with_two_variants.variants.first() == variant_2
-
-
-def test_move_items_between_wishlists_with_duplicates(variant, customer_wishlist_item):
- dst_wishlist_item = customer_wishlist_item
- assert dst_wishlist_item.variants.count() == 1
- dst_wishlist = dst_wishlist_item.wishlist
- assert dst_wishlist.items.count() == 1
- dst_variant = dst_wishlist_item.variants.first()
- assert variant.pk != dst_variant.pk
- # Create the source wishlist
- src_wishlist = Wishlist.objects.create()
- # Add the new variant
- src_item_1 = src_wishlist.add_variant(variant)
- # Add the destination variants to the source wishlist (the duplicate case)
- src_item_2 = src_wishlist.add_variant(dst_variant)
- # Move items from the source to the destination wishlist
- WishlistItem.objects.move_items_between_wishlists(src_wishlist, dst_wishlist)
- # Check the source wishlist doesn't have any items
- assert src_wishlist.items.count() == 0
- # Check the destination wishlist has two items
- assert dst_wishlist.items.count() == 2
- # Check that the source wishlist item with the new variant was moved to the
- # destination wishlist
- src_item_1.refresh_from_db()
- assert src_item_1.wishlist == dst_wishlist
- # Check that the source wishlist item with the duplicate variant was removed
- with pytest.raises(WishlistItem.DoesNotExist):
- src_item_2.refresh_from_db()