Ejemplo n.º 1
0
 def get_context_data(self, context):
     count = self.config.get("count", 4)
     product = context.get("product", None)
     orderable_only = self.config.get("orderable_only", True)
     relation_type = self.config.get("type")
     try:
         type = map_relation_type(relation_type)
     except LookupError:
         type = ProductCrossSellType.RELATED
     return {
         "request":
         context["request"],
         "title":
         self.get_translated_value("title"),
         "use_variation_parents":
         self.config.get("use_variation_parents", False),
         "product":
         product,
         "type":
         type,
         "count":
         count,
         "orderable_only":
         orderable_only,
     }
Ejemplo n.º 2
0
 def __init__(self, config):
     relation_type = config.get("type", None)
     if relation_type:
         # Map initial config string to enum type
         try:
             type = map_relation_type(relation_type)
         except LookupError:
             type = ProductCrossSellType.RELATED
         config["type"] = type
     super(ProductCrossSellsPlugin, self).__init__(config)
Ejemplo n.º 3
0
 def __init__(self, config):
     relation_type = config.get("type", None)
     if relation_type:
         # Map initial config string to enum type
         try:
             type = map_relation_type(relation_type)
         except LookupError:
             type = ProductCrossSellType.RELATED
         config["type"] = type
     super(ProductCrossSellsPlugin, self).__init__(config)
Ejemplo n.º 4
0
    def get_context_data(self, context):
        request = context["request"]
        products = []
        use_variation_parents = self.config.get("use_variation_parents", False)
        count = self.config.get("count", 5)
        cache_timeout = self.config.get("cache_timeout", 0)
        product = context.get("product", self.config.get("product"))
        orderable_only = self.config.get("orderable_only", False)
        relation_type = self.config.get("type")

        try:
            relation_type = map_relation_type(relation_type)
        except LookupError:
            relation_type = ProductCrossSellType.RELATED

        if request.is_ajax() and product:
            if not isinstance(product, Product):
                product = Product.objects.filter(id=product).first()

            if product:
                products = get_product_cross_sells(
                    context,
                    product,
                    relation_type,
                    count=count,
                    orderable_only=orderable_only,
                    use_variation_parents=use_variation_parents,
                )

        return {
            "request":
            context["request"],
            "title":
            self.get_translated_value("title"),
            "products":
            products,
            "orderable_only":
            self.config.get("orderable_only", False),
            "data_url":
            reverse(
                "shuup:xtheme-product-cross-sells-highlight",
                kwargs=dict(
                    product_id=product.id
                    if isinstance(product, Product) else product,
                    relation_type=relation_type.label,
                    use_parents=(1 if use_variation_parents else 0),
                    count=count,
                    cache_timeout=cache_timeout,
                ),
            ) if product else "/",
        }
Ejemplo n.º 5
0
 def get_context_data(self, context):
     count = self.config.get("count", 4)
     product = context.get("product", None)
     orderable_only = self.config.get("orderable_only", True)
     relation_type = self.config.get("type")
     try:
         type = map_relation_type(relation_type)
     except LookupError:
         type = ProductCrossSellType.RELATED
     return {
         "request": context["request"],
         "title": self.get_translated_value("title"),
         "product": product,
         "type": type,
         "count": count,
         "orderable_only": orderable_only,
     }