Skip to content

feat: add extra fields#144

Open
ahuininga-orisha wants to merge 6 commits into
masterfrom
feat/add-extra-fields
Open

feat: add extra fields#144
ahuininga-orisha wants to merge 6 commits into
masterfrom
feat/add-extra-fields

Conversation

@ahuininga-orisha

Copy link
Copy Markdown
Collaborator

Summary

Fixes #25

The Tweakwise XML feed specification defines <brand>, <image>, and <url> as dedicated first-class fields on every <item> element. Without these fields populated, Tweakwise JS integrations cannot render product images or link to product pages directly from the feed, and brand-based filtering or display relies on the generic <attributes> block rather than the purpose-built field. This change adds all three fields to the export feed and makes the source attributes configurable per store view so merchants with a custom brand attribute (e.g. toppy_brand instead of manufacturer) can wire it up without code changes.

  • <url> is now written as a fully qualified product URL, built from the store's base URL, the product's url_key attribute, and the catalog/seo/product_url_suffix config value (e.g. .html). This ensures the URL is valid and store-scoped.
  • <image> is now written as a fully qualified media URL, resolved by prepending the store's media base URL and the catalog/product path prefix to the relative image path stored in the configured image attribute.
  • <brand> is written from the value of a configurable attribute. If the attribute is a select (e.g. manufacturer), the option label is resolved — not the raw option ID.
  • Two new Brand attribute and Image attribute admin config dropdowns are added under Stores → Configuration → Tweakwise → Export, both scoped to store view. The dropdowns list all catalog product attributes. The default value for both is Disabled, meaning neither field is written until explicitly configured.
  • When a field is set to Disabled, its EAV attribute is not included in the export query at all — no extra data is loaded.
  • The configured attribute codes are resolved per store view. If store A and store B use different image attributes, or one has brand disabled while the other does not, each store's export query only fetches what that store needs.
  • All per-store configuration values (isGroupedExport, brand attribute code, base URL, media URL, URL suffix) are resolved once per store before the product loop via buildStoreContext, avoiding redundant lookups on every product.

How to test

Scenario 1 — <url> and <image> appear in the feed with correct values

  1. Enable the Tweakwise export under Stores → Configuration → Tweakwise → Export.
  2. Set Image attribute to image.
  3. Ensure at least one simple product exists with a url_key and an image assigned.
  4. Run bin/magento tweakwise:export.
  5. Open the generated feed file (var/feeds/tweakwise.xml).
  6. Locate an <item> element for the product from step 3.
  7. Verify a <url> element is present and equals {store_base_url}/{url_key}{url_suffix} (e.g. https://example.com/my-product.html).
  8. Verify an <image> element is present and equals {store_media_url}/catalog/product{image_path} (e.g. https://example.com/media/catalog/product/m/y/my-product.jpg).

Scenario 2 — <brand> is exported as the option label, not the raw option ID

  1. Set Brand attribute to manufacturer.
  2. Assign a manufacturer value to a product (e.g. "Acme").
  3. Run the export.
  4. Locate the product's <item> in the feed.
  5. Verify <brand>Acme</brand> is present with the label, not a numeric option ID.
  6. For a product without a manufacturer value, verify no <brand> element is written.

Scenario 3 — Custom brand attribute is respected

  1. Change Brand attribute to a custom attribute code (e.g. toppy_brand).
  2. Assign a value to that attribute on a product.
  3. Run the export.
  4. Verify <brand> in the feed contains the value from that attribute.

Scenario 4 — Disabling image or brand omits the field and skips loading EAV data

  1. Set both Brand attribute and Image attribute to -- Disabled -- and save.
  2. Run the export.
  3. Verify no <brand> or <image> element appears in any <item>.

Scenario 5 — Products without url_key or image produce no empty elements

  1. Find or create a product with no image assigned (no_selection) and no url_key.
  2. Run the export.
  3. Verify no empty <url> or <image> elements are written for that product.

Scenario 6 — Brand and image attributes vary per store view

  1. Configure Brand attribute to manufacturer on the default store view.
  2. Switch to a second store view and set Brand attribute to -- Disabled --.
  3. Run the export.
  4. Verify <brand> elements appear for the default store view products but not for the second store view products.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Not all fields are exported

1 participant