Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Product variant fieldset does not allow importing other field #1162

Open
admench opened this issue Sep 30, 2024 · 2 comments
Open

Product variant fieldset does not allow importing other field #1162

admench opened this issue Sep 30, 2024 · 2 comments

Comments

@admench
Copy link

admench commented Sep 30, 2024

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 admench added the bug label Sep 30, 2024
@admench
Copy link
Author

admench commented Sep 30, 2024

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

@duncanmcclean
Copy link
Owner

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:

'option_field_defaults' => collect($this->config('option_fields'))
->mapWithKeys(function ($field) {
$field = (
new Field($field['handle'], $field['field'])
);
return [
$field->handle() => $field->fieldtype()->preProcess($field->defaultValue()),
];
})
->toArray(),

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

No branches or pull requests

2 participants