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

Can not create a product attribute fixture of type 'select' #8264

Closed
Keloo opened this issue Jul 10, 2017 · 8 comments
Closed

Can not create a product attribute fixture of type 'select' #8264

Keloo opened this issue Jul 10, 2017 · 8 comments
Labels
Feature New feature proposals.
Milestone

Comments

@Keloo
Copy link

Keloo commented Jul 10, 2017

In the config.yml I have my fixutres. I want to create an product attribute fixture of type 'select'.
I can not find the right definition of it.
I tried like this:

sylius_fixtures:
    suites:
        app:
            listeners:
                logger: ~
            fixtures:            
                product_attribute:
                    options:
                        custom:
                            canvas_type:
                                name: "type"
                                code: "type"
                                type: "select"
                                configuration:
                                    choices:
                                        - "Type 2"
                                        - "Type 2"

when I try to load the fixutres it says:
[Symfony\Component\Config\Definition\Exception\InvalidConfigurationException] Unrecognized option "configuration" under "product_attribute.custom.canvas_type"

@Keloo Keloo changed the title Can not create an attribute fixture of type 'select' Can not create a product attribute fixture of type 'select' Jul 10, 2017
@pjedrzejewski pjedrzejewski added the Feature New feature proposals. label Jul 11, 2017
@pjedrzejewski pjedrzejewski added this to the v1.0.0 milestone Jul 11, 2017
@pjedrzejewski
Copy link
Member

@pamil Is it possible? :)

@lchrusciel
Copy link
Member

@Keloo which version of Sylius are you using? configuration node has been added after beta.2, so you will need to update to newest master in order to use it.

@Keloo
Copy link
Author

Keloo commented Jul 11, 2017

@lchrusciel I'm using beta 1. Thx for the info regarding beta 2 version. 👍

@lchrusciel
Copy link
Member

Closing then. :)

@broiniac
Copy link

Just for the record: in version 1.1.2 (and probably up) working fixture look like this:

sylius_fixtures:
    suites:
        app:
            listeners:
                logger: ~
            fixtures:
                product_attribute:
                    options:
                        custom:
                            custom_attribute_name: 
                                name: real name here # attribute name (for default locale)
                                code: code_name_here
                                type: select
                                configuration:
                                    choices:
                                        -
                                            # localeCode: translated name
                                            en_US: "name 1"
                                            pl: "nazwa 1"
                                        -
                                            en_US: "name 2"
                                            pl: "nazwa 2"
                                    multiple: false   # optional
                                    min: 1            # optional
                                    max: 1            # optional

@vntw
Copy link
Contributor

vntw commented Apr 9, 2018

Hm not sure this is correct. I tried to define them like it's described here but when trying to add the attribute to a product with one or more values, I get an error This value should be of type string. on the multiselect input.

image

Looking at how the attribute configuration was inserted, it looks different than a select attribute that was created via the shop backend:

The comment above produces:

a:2:{s:7:"choices";a:14:{i:0;a:1:{s:5:"en_US";s:9:"Something";}

Creating one in the backend produces:

a:4:{s:7:"choices";a:2:{s:36:"ced63470-3bf9-11e8-9568-38c9860c388b";a:1:{s:5:"en_US";s:9:"Something";}

So the difference is the array index for each choice (which explains the form error message on the input) which needs to be a string code. Creating them like the following works:

something:
  name: Name 1
  code: name1
  type: select
  configuration:
    choices:
      some-code1:
        en_US: "Something"
      some-code2:
        en_US: "Something 2"

That was at least my experience, maybe I'm missing something here. The fixture doesn't seem to throw any errors, no matter how you enter the configuration. Any thoughts on this @pamil @lchrusciel since you "👍" the comment?

@maximehuran
Copy link
Contributor

maximehuran commented Aug 2, 2018

I also used the trick some-code1 etc... to make my fixture works

FYI I had to add also

multiple: false
min: null
max: null

In order to avoid this error :

Argument 1 passed to Sylius\Component\Attribute\Model\AttributeValue::setJson() must be of the type array or null, string given, called in /var/www/apps/sylius/vendor/sylius/sylius/src/Sylius/Component/Attribute/Model/AttributeValue.php on line 156

@broiniac
Copy link

broiniac commented Aug 21, 2018

@venyii I've just return to the project based on Sylius. After update to 1.2.5 "mine" method was not working any more, but yours is (with addition of suggested by @maximehuran constrains).
Thank you for your response and sorry for long time to reply on this one. I've been unable to confirm your discovery in any way until now.

My first guess was that it has something to do with strict types, but quick glance at code history reveals, that strict type checking and php7.1+ was introduced few months earlier. So honestly, I don't know what have changed since 1.1.2.

Anyway, thank you both. Without your comments I would probably burn few hours looking for solution on my own.

EDIT: Import and usage is fine, but I it seems that I can't edit AttributeValue created via fixture. Hmm. There's no rest for the wicked I guess :)

EDIT2: I guess this one is strongly related to our problem: #9387

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

No branches or pull requests

6 participants