Allow modules to choose which product element a sync updates

Aperta
#264 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
php
Ambito
backend

Direzione di ricerca

Start with Products::createOrUpdateProduct() and the EVENT_BEFORE_SYNCHRONIZE_PRODUCT handler flow described in the issue. Trace where the product element is selected and how event handlers can affect it; the issue proposes two possible extension points but does not settle which one to use. Done means a module can select the existing product to update during sync, preventing duplicates after a database refresh.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

repo:shopify

We'd like to connect our test/acceptance Craft environments to our staging Shopify store, while production Craft stays on the production store. We run into duplicates, though. The non-production databases are frequently refreshed from production, so their products carry production GIDs. Products::createOrUpdateProduct() matches only by GID, so when the staging store syncs, every product is created a second time, next to the one that entries and relations point to.

In our case the handles are the same in both stores, so we match by handle instead. Today the only way to do that is to patch createOrUpdateProduct(). EVENT_BEFORE_SYNCHRONIZE_PRODUCT fires after the element has been picked, and the method keeps using its local variable, so a handler can't swap in a different element.

Handle matching might not belong in the plugin itself, as it's a niche case and handles are only unique within a store. A small extension point would let us move it into a module instead. For example:

  1. Use $event->element after EVENT_BEFORE_SYNCHRONIZE_PRODUCT, so handlers can replace it.
  2. Or add an event before the lookup that lets a handler return the element to update.

We also considered a one-off "relink by handle" command to run after each database copy. Given how often we refresh, we'd rather the sync just handles it.

Does that make sense, or is there a better way to handle this setup?

Lingua principale
PHP
Stelle
56
Fork
31
Merge medio
15h 41m
PR unite (30g)
23

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di craftcms/shopify

Tutte le issue di craftcms/shopify

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.