statamic-rad-pack / shopify

Integrate your Shopify products into Statamic using the Admin API.
https://statamic.com/addons/rad-pack/shopify
Other
8 stars 5 forks source link

Searching for products in Statamic #253

Open dgrigg opened 2 days ago

dgrigg commented 2 days ago

Description

Is it possible to search for a product in Statamic using the product's SKU from Shopify? Right now it appears the search only works against the product title which is a little restrictive.

Steps to reproduce

  1. Go to the product collections in Statamic
  2. Search for a product using the Product ID or SKU from Shopify

Environment

Environment Application Name: Statamic Laravel Version: 10.48.22 PHP Version: 8.2.19 Composer Version: 2.7.6 Environment: local Debug Mode: ENABLED URL: localhost:3000 Maintenance Mode: OFF

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

Drivers Broadcasting: log Cache: file Database: mysql Logs: stack / single Mail: mailgun Queue: database Session: file

Statamic Addons: 4 Sites: 1 Stache Watcher: Disabled Static Caching: Disabled Version: 5.25.0 PRO

Statamic Addons aerni/advanced-seo: 2.9.0 pxlp/headless: dev-main statamic-rad-pack/shopify: 4.0.5 statamic/eloquent-driver: 4.16.0

Statamic Eloquent Driver Asset Containers: eloquent Assets: eloquent Blueprints: file Collection Trees: eloquent Collections: eloquent Entries: eloquent Forms: file Global Sets: file Global Variables: file Navigation Trees: file Navigations: file Revisions: file Sites: file Taxonomies: file Terms: file Tokens: file

ryanmitchell commented 1 day ago

Products is just a standard Statamic collection so you can make a search index on it: https://statamic.dev/collections#search-indexes

Within this index define a transformer which should return all your skus... something like:

'transformers' => [

    // Return a value to store in the index.
    'variants' => function ($value, $searchable) {
        return \Statamic\Facades\Entry::where('collection', 'variants')->whereIn('id', $searchable->get('variants'))->get()->map(fn ($variant) => $variant->sku));
    },

]