Skip to content

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

add description json

AlicjaSzu40aa122da8fd
diff --git a/saleor/product/views.py b/saleor/product/views.py
index cb8951adc7..7afe9f9c41 100644
--- a/saleor/product/views.py
+++ b/saleor/product/views.py
@@ -90,6 +90,7 @@ def product_details(request, slug, product_id, form=None):
show_variant_picker = all([v.attributes for v in product.variants.all()])
json_ld_data = product_json_ld(product, product_attributes)
ctx = {
+ "description_json": json.dumps(product.translated.description_json, default=serialize_decimal),
"is_visible": is_visible,
"form": form,
"availability": availability,
diff --git a/saleor/static/js/components/description-json.js b/saleor/static/js/components/description-json.js
new file mode 100644
index 0000000000..fa850b71d7
--- /dev/null
+++ b/saleor/static/js/components/description-json.js
@@ -0,0 +1,13 @@
+
+import draftToHtml from "draftjs-to-html";
+
+export default $(document).ready((e) => {
+ const data = 'data-description-json';
+ const description = document.querySelector(`[${data}]`);
+ if(description) {
+ const parsed = JSON.parse(description.getAttribute(data));
+ const content = draftToHtml(parsed);
+ description.innerHTML = content;
+ }
+});
+
diff --git a/saleor/static/js/storefront.js b/saleor/static/js/storefront.js
index c353a8111d..f10b923e9e 100644
--- a/saleor/static/js/storefront.js
+++ b/saleor/static/js/storefront.js
@@ -15,3 +15,4 @@ import './components/product-filters';
import './components/sorter';
import './components/styleguide';
import './components/variant-picker';
+import './components/description-json';
diff --git a/templates/dashboard/product/form.html b/templates/dashboard/product/form.html
index e1c326dd3c..c200c157d4 100644
--- a/templates/dashboard/product/form.html
+++ b/templates/dashboard/product/form.html
@@ -69,7 +69,8 @@
{{ product_form.name|materializecss }}
</div>
<div class="row">
- {{ product_form.description|materializecss }}
+ <div>{{ product_form.description_json|materializecss }}</div>
+ <div>{{ product_form.description|materializecss }}</div>
</div>
<span class="card-title">Availability</span>
<div class="row">
diff --git a/templates/product/details.html b/templates/product/details.html
index b1613b2f43..e9655d7661 100644
--- a/templates/product/details.html
+++ b/templates/product/details.html
@@ -194,6 +194,7 @@
<h3>{% trans "Description" context "Product details title" %}</h3>
<hr>
{{ product.translated.description|safe }}
+ <div data-description-json='{{ description_json }}'>{{ product }}</div>
</div>
<hr>
<table>