Add routes to open Shopify objects

Closes #14176
This commit is contained in:
Cédric Krier
2025-08-20 14:01:18 +02:00
parent c642173094
commit 778d064f56
3 changed files with 85 additions and 1 deletions
+1
View File
@@ -1,3 +1,4 @@
* Add routes to open Shopify objects
* Add support for credit refunds
Version 7.6.0 - 2025-04-28
+18
View File
@@ -65,3 +65,21 @@ Options` selected with an `Attribute
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>``
+66 -1
View File
@@ -6,7 +6,7 @@ import hmac
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 @@ def order(request, pool, shop):
else:
logger.info("Unsupported topic '%s'", topic)
return Response(status=HTTPStatus.NO_CONTENT)
@app.route('/<database_name>/web_shop_shopify/products/<id>', methods={'GET'})
@app.auth_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__)
@app.route(
'/<database_name>/web_shop_shopify'
'/products/<product_id>/variants/<variant_id>',
methods={'GET'})
@app.auth_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__)
@app.route('/<database_name>/web_shop_shopify/customers/<id>', methods={'GET'})
@app.auth_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__)
@app.route('/<database_name>/web_shop_shopify/orders/<id>', methods={'GET'})
@app.auth_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__)