statamic-shopify icon indicating copy to clipboard operation
statamic-shopify copied to clipboard

Inconsistent behavior when importing localized entries in `ImportSingleProductJob` (duplicate `.1` entries)

Open leeuweriq opened this issue 1 year ago • 2 comments

Description

When importing a product using StatamicRadPack\Shopify\Jobs\ImportSingleProductJob, the result is inconsistent in a Statamic multisite setup (handles: en, nl). Specifically, in the translation sync section around line 277, the job attempts to retrieve or create a localized entry for the non-default site (nl).

The relevant logic:

`$localizedEntry = $entry->in($site->handle());

if (! $localizedEntry) { $localizedEntry = $entry->makeLocalization($site); }`

Issue:

Sometimes, even when a Dutch (nl) localized entry already exists, $entry->in('nl') returns null. This causes a new localization to be created with a .1 suffix in the filename, resulting in duplicate entries in the CMS: Image

Expected Behavior:

If a localized entry for the given site already exists, it should always be detected by $entry->in($site->handle()), and never trigger creation of a duplicate entry.

Observed Behavior:

  • Occasionally, localized entries are not detected.
  • This results in duplicate .1 entries being created in the content repository.
  • This seems to happen inconsistently with the same data/product.

I’ve reviewed the contents of the localized entry file and verified that it exists. There doesn’t seem to be any pattern as to when $entry->in('nl') fails.

Let me know if any more debugging info is needed—happy to assist.

Steps to reproduce

  1. Import a product that already exists in both en and nl.
  2. Observe that sometimes a new nl localization is created with a .1 suffix.

Environment

Application Name: JBC
Laravel Version: 11.44.7
PHP Version: 8.4.7
Composer Version: 2.8.8
Environment: local
Debug Mode: ENABLED
URL: jbc-web.test
Maintenance Mode: OFF
Timezone: UTC
Locale: en

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: file
Database: sqlite
Logs: stack / single
Mail: postmark
Queue: sync
Session: file

Statamic
Addons: 3
Sites: 2 (English, Dutch)
Stache Watcher: Enabled (auto)
Static Caching: Disabled
Version: 5.55.0 PRO

Statamic Addons
rias/statamic-redirect: 3.10.9
statamic-rad-pack/shopify: 5.3.1
statamic/seo-pro: 6.7.0

leeuweriq avatar May 21 '25 15:05 leeuweriq

If a localized entry for the given site already exists, it should always be detected by $entry->in($site->handle()), and never trigger creation of a duplicate entry.

That is beyond the scope of this add-on, thats a collection issue in Statamic itself.

I suspect the issue is to do with your origin/propogation settings on the collection - what do you have those set as? At the moment it assumes your default site to be the same as the default site for the products collection, if thats not the case it probably does cause issues.

ryanmitchell avatar May 21 '25 18:05 ryanmitchell

Closing due to inactivity

ryanmitchell avatar Jul 15 '25 05:07 ryanmitchell