simple-commerce icon indicating copy to clipboard operation
simple-commerce copied to clipboard

Product variant fieldset does not allow importing other field

Open admench opened this issue 1 year ago • 2 comments

Description

In my product_with_variants.yaml blueprint, I have configured a field to import another shared field, so the config looks like this:

(here is a git diff, where on the left I'm importing fields from another fieldset, and the fix to manually config the field on the right):

Screenshot 2024-09-30 at 11 12 28

Here is the resulting error:

[2024-09-30 10:01:43] local.ERROR: Statamic\Fields\Field::__construct(): Argument #2 ($config) must be of type array, string given, called in vendor/duncanmcclean/simple-commerce/src/Fieldtypes/ProductVariantsFieldtype.php on line 38

My solution is to not import fields, which is absolutely fine, but there is likely a Statamic helper to ensure the field is imported and the ProductVariantsFieldtype class is not using it. I haven't spent the time trying to fix this yet, but can look. (Duncan if you have an idea what this could be, just mention it's name, and I could PR a fix).

Steps to reproduce

  1. Edit product blueprint in CP and link to other fields.
  2. Click create product (using that blueprint)
  3. Encounter this error.

Environment

Environment
Application Name: App name
Laravel Version: 11.22.0
PHP Version: 8.3.11
Composer Version: 2.7.7
Environment: local
Debug Mode: ENABLED
URL: appname.test
Maintenance Mode: OFF
Timezone: UTC
Locale: en

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

Drivers
Broadcasting: log
Cache: redis
Database: mysql
Logs: stack / single
Mail: smtp
Queue: redis
Session: redis

Simple Commerce
Currencies: GBP
Gateways: Dummy
Repository: Customer: DuncanMcClean\SimpleCommerce\Customers\EntryCustomerRepository
Repository: Order: DuncanMcClean\SimpleCommerce\Orders\EntryOrderRepository
Repository: Product: DuncanMcClean\SimpleCommerce\Products\EntryProductRepository
Shipping Methods: Free Shipping
Tax Engine: DuncanMcClean\SimpleCommerce\Tax\Standard\TaxEngine

Statamic
Addons: 4
Sites: 1
Stache Watcher: Enabled (auto)
Static Caching: Disabled
Version: 5.25.0 PRO

Statamic Addons
duncanmcclean/simple-commerce: 7.5.1
studio1902/statamic-peak-browser-appearance: 3.5.0
studio1902/statamic-peak-seo: 8.16.0
studio1902/statamic-peak-tools: 6.3.2

admench avatar Sep 30 '24 10:09 admench

Interestingly the product.yaml blueprint (the one without variants) does accept importing fields.

admench avatar Sep 30 '24 10:09 admench

I don't have time to dig into this myself at the moment - I'm pretty focused on the next version of Simple Commerce.

However, the issue will likely be here, it's expecting the option_fields to be real fields, it doesn't currently handle fieldsets at all:

https://github.com/duncanmcclean/simple-commerce/blob/f74d2919eaa983aaa6bc70b68acf24be9b063888/src/Fieldtypes/ProductVariantsFieldtype.php#L33-L43

duncanmcclean avatar Sep 30 '24 22:09 duncanmcclean

Released as part of v7.5.5.

github-actions[bot] avatar Nov 23 '24 01:11 github-actions[bot]