details:   https://code.tryton.org/tryton/commit/df3b0873bbfe
branch:    default
user:      Cédric Krier <[email protected]>
date:      Wed Aug 20 14:01:18 2025 +0200
description:
        Add routes to open Shopify objects

        Closes #14176
diffstat:

 modules/web_shop_shopify/CHANGELOG     |   1 +
 modules/web_shop_shopify/doc/usage.rst |  18 +++++++++
 modules/web_shop_shopify/routes.py     |  67 +++++++++++++++++++++++++++++++++-
 3 files changed, 85 insertions(+), 1 deletions(-)

diffs (114 lines):

diff -r 355e3114e142 -r df3b0873bbfe modules/web_shop_shopify/CHANGELOG
--- a/modules/web_shop_shopify/CHANGELOG        Fri Aug 15 13:08:08 2025 +0200
+++ b/modules/web_shop_shopify/CHANGELOG        Wed Aug 20 14:01:18 2025 +0200
@@ -1,3 +1,4 @@
+* Add routes to open Shopify objects
 * Add support for credit refunds
 
 Version 7.6.0 - 2025-04-28
diff -r 355e3114e142 -r df3b0873bbfe modules/web_shop_shopify/doc/usage.rst
--- a/modules/web_shop_shopify/doc/usage.rst    Fri Aug 15 13:08:08 2025 +0200
+++ b/modules/web_shop_shopify/doc/usage.rst    Wed Aug 20 14:01:18 2025 +0200
@@ -65,3 +65,21 @@
 
    For each variant of a product, the value of the :guilabel:`Shopify Options`
    attributes must be unique.
+
+.. _Admin links:
+
+Admin Links
+===========
+
+The module provides links that offer direct access to the corresponding Tryton
+record based on the Shopify identifier.
+You can use these links to create an `admin link extension
+<https://shopify.dev/docs/apps/build/admin/admin-links>`_.
+
+   - ``GET`` ``/<database_name>/web_shop_shopify/products/<product id>``
+
+   - ``GET`` ``/<database_name>/web_shop_shopify/products/<product 
id>/variants/<variant id>``
+
+   - ``GET`` ``/<database_name>/web_shop_shopify/customers/<customer id>``
+
+   - ``GET`` ``/<database_name>/web_shop_shopify/orders/<order id>``
diff -r 355e3114e142 -r df3b0873bbfe modules/web_shop_shopify/routes.py
--- a/modules/web_shop_shopify/routes.py        Fri Aug 15 13:08:08 2025 +0200
+++ b/modules/web_shop_shopify/routes.py        Wed Aug 20 14:01:18 2025 +0200
@@ -6,7 +6,7 @@
 import logging
 
 from trytond.protocols.wrappers import (
-    HTTPStatus, Response, abort, with_pool, with_transaction)
+    HTTPStatus, Response, abort, redirect, with_pool, with_transaction)
 from trytond.wsgi import app
 
 logger = logging.getLogger(__name__)
@@ -60,3 +60,68 @@
     else:
         logger.info("Unsupported topic '%s'", topic)
     return Response(status=HTTPStatus.NO_CONTENT)
+
+
[email protected]('/<database_name>/web_shop_shopify/products/<id>', methods={'GET'})
[email protected]_required
+@with_pool
+@with_transaction(user='request')
+def shopify_product(request, pool, id):
+    Template = pool.get('product.template')
+    try:
+        template, = Template.search(
+            [('shopify_identifiers.shopify_identifier_char', '=', id)],
+            limit=1)
+    except ValueError:
+        abort(HTTPStatus.NOT_FOUND)
+    return redirect(template.__href__)
+
+
[email protected](
+    '/<database_name>/web_shop_shopify'
+    '/products/<product_id>/variants/<variant_id>',
+    methods={'GET'})
[email protected]_required
+@with_pool
+@with_transaction(user='request')
+def shopify_product_variant(request, pool, product_id, variant_id):
+    Product = pool.get('product.product')
+    try:
+        product, = Product.search([
+                ('template.shopify_identifiers.shopify_identifier_char',
+                    '=', product_id),
+                ('shopify_identifiers.shopify_identifier_char',
+                    '=', variant_id),
+                ],
+            limit=1)
+    except ValueError:
+        abort(HTTPStatus.NOT_FOUND)
+    return redirect(product.__href__)
+
+
[email protected]('/<database_name>/web_shop_shopify/customers/<id>', methods={'GET'})
[email protected]_required
+@with_pool
+@with_transaction(user='request')
+def shopify_customer(request, pool, id):
+    Party = pool.get('party.party')
+    try:
+        party, = Party.search([
+                ('shopify_identifiers.shopify_identifier_char', '=', id),
+                ], limit=1)
+    except ValueError:
+        abort(HTTPStatus.NOT_FOUND)
+    return redirect(party.__href__)
+
+
[email protected]('/<database_name>/web_shop_shopify/orders/<id>', methods={'GET'})
[email protected]_required
+@with_pool
+@with_transaction(user='request')
+def shopify_order(request, pool, id):
+    Sale = pool.get('sale.sale')
+    try:
+        sale, = Sale.search([('shopify_identifier_char', '=', id)], limit=1)
+    except ValueError:
+        abort(HTTPStatus.NOT_FOUND)
+    return redirect(sale.__href__)

Reply via email to