from oscar.apps.catalogue import views as oscar
from oscar.core.loading import get_class

from ocyan.core.fender import config
from ocyan.core.utils import merge_dicts

AddToBasketForm = get_class("basket.forms", "AddToBasketForm")


class ProductDetailView(oscar.ProductDetailView):
    enforce_parent = config.get("oscar", "enforce_parent", False)

    def get_basket_form(self):
        return AddToBasketForm(basket=self.request.basket, product=self.object)

    def get_media(self):
        return self.get_basket_form().media + self.get_alert_form().media

    def get_context_data(self, **kwargs):
        ctx = super(ProductDetailView, self).get_context_data(**kwargs)
        return merge_dicts(ctx, {"media": self.get_media()})
