Skip to content

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

Change Product/Category URI to absolute

Pacu22db6a2a5f1a0
diff --git a/saleor/core/utils/__init__.py b/saleor/core/utils/__init__.py
index e74c22137b..d8a304da17 100644
--- a/saleor/core/utils/__init__.py
+++ b/saleor/core/utils/__init__.py
@@ -35,7 +35,7 @@ class CategoryChoiceField(forms.ModelChoiceField):
return '%s%s' % (indent, smart_text(obj))
-def build_absolute_uri(location, is_secure=False):
+def build_absolute_uri(location, is_secure=settings.ENABLE_SSL):
# type: (str, bool, saleor.site.models.SiteSettings) -> str
host = Site.objects.get_current().domain
current_uri = '%s://%s' % ('https' if is_secure else 'http', host)
diff --git a/saleor/product/models.py b/saleor/product/models.py
index 8aec8a9047..34f7a3106f 100644
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -20,6 +20,7 @@ from versatileimagefield.fields import PPOIField, VersatileImageField
from ..discount.models import calculate_discounted_price
from .utils import get_attributes_display_map
+from ..core.utils import build_absolute_uri
class Category(MPTTModel):
@@ -55,6 +56,11 @@ class Category(MPTTModel):
kwargs={'path': self.get_full_path(ancestors),
'category_id': self.id})
+ def get_full_absolute_url(self, ancestors=None):
+ return build_absolute_uri(
+ self.get_absolute_url(ancestors=ancestors)
+ )
+
def get_full_path(self, ancestors=None):
if not self.parent_id:
return self.slug
@@ -164,6 +170,9 @@ class Product(models.Model, ItemRange):
'product:details',
kwargs={'slug': self.get_slug(), 'product_id': self.id})
+ def get_full_absolute_url(self):
+ return build_absolute_uri(self.get_absolute_url())
+
def get_slug(self):
return slugify(smart_text(unidecode(self.name)))
diff --git a/templates/base.html b/templates/base.html
index b2aeff4363..3d55ac6126 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -24,7 +24,7 @@
{% block meta_tags %}
<meta property="og:title" content="{{ site.name }}">
- <meta property="og:url" content="{{ request.get_full_path }}">
+ <meta property="og:url" content="{{ request.build_absolute_uri }}">
<meta property="og:image" content="{% static "images/block1.png" %}">
{% endblock meta_tags %}
diff --git a/templates/category/index.html b/templates/category/index.html
index 39c3936fa8..73f580d4f4 100644
--- a/templates/category/index.html
+++ b/templates/category/index.html
@@ -13,11 +13,11 @@
{% block title %}{{ category }} — {{ block.super }}{% endblock %}
{% block meta_tags %}
- <meta property="og:title" content="{{ category }} — {{ block.super }}">
+ <meta property="og:title" content="{{ category }}">
<meta property="og:description" content="{{ category.description }}">
<meta property="og:image" content="{% static "images/block1.png" %}">
- {% with category_url=category.get_absolute_url %}
+ {% with category_url=category.get_full_absolute_url %}
<meta property="og:url" content="{{ category_url }}">
<link rel="canonical" href="{{ category_url }}?page={{ products_paginated.number }}">
diff --git a/templates/product/details.html b/templates/product/details.html
index 2aa7fc0297..2eb553b760 100644
--- a/templates/product/details.html
+++ b/templates/product/details.html
@@ -16,7 +16,7 @@
<meta property="og:title" content="{{ product }} — {{ block.super }}">
<meta property="og:description" content="{{ product.description }}">
- {% with product_url=product.get_absolute_url %}
+ {% with product_url=product.get_full_absolute_url %}
<meta property="og:url" content="{{ product_url }}">
<link rel="canonical" href="{{ product_url }}">
{% endwith %}