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

Ability to import multiple (related) products at once #1432

Closed
ax2000 opened this issue Apr 19, 2024 · 4 comments
Closed

Ability to import multiple (related) products at once #1432

ax2000 opened this issue Apr 19, 2024 · 4 comments
Assignees
Labels

Comments

@ax2000
Copy link

ax2000 commented Apr 19, 2024

Description

I am trying to import Commerce Product element types that have a "Commerce Products" field that provides a "Related Products" functionality for each product.
Screenshot 2024-04-19 at 12 26 30

It seems that the Related Commerce Product field only accepts a string at the moment and, when providing an array of product Ids, I'm getting the error trim(): Argument #1 ($string) must be of type string, array given - CommerceProducts.php: 110.
Screenshot 2024-04-19 at 12 27 10

Would it be possible that the Commerce Product entry types accept an array similar to what Entries, Assets and Categories field do so it can import multiple related products for each product?

I might be missing something though, so feel free to point me in the right direction if that's the case.

Thanks heaps!

Additional info

  • Craft version: 4.8.9
  • PHP version: 8.2.10
  • Database driver & version: MySQL 8.0.33
  • Plugins & versions: 5.4.0
@ax2000 ax2000 added the bug label Apr 19, 2024
@i-just
Copy link
Contributor

i-just commented May 2, 2024

Hi, thanks for reaching out! Could you please share a snippet of your feed that causes this error to be thrown?

@ax2000
Copy link
Author

ax2000 commented May 3, 2024

Thanks for looking into this.

The feed looks like:

      ....
      "related_products": [],
      "crossell_products": [
        5272,
        5306
      ],
      ....
Screenshot 2024-05-03 at 10 25 42

The values in the crossell_products array above are product entry ids. And the feed is set to match by entry id as per:
Screenshot 2024-05-03 at 10 28 50

Please let me know if you'd need me to provide anything else.

@i-just
Copy link
Contributor

i-just commented May 3, 2024

Thanks, that helped!

You can already import multiple related products at once. That’s true for any field that extends BaseRelationField, such as Commerce Products, Assets, Entries, etc.

So related_products in your feed is an empty array, your feed maps relatedProducts to related_products, and you have “Default Product” selected too - is that correct?

I have raised a PR to improve this, but for now, if you change your feed to use null instead of an empty array for the related_products (and any other relational fields that are not supposed to have a value), it should work as expected.

@i-just i-just self-assigned this May 3, 2024
@ax2000
Copy link
Author

ax2000 commented May 8, 2024

Thanks for your response @i-just.

You are right, I was overlooking the way it was suppose to accept the feed data.

It is all working correctly now!

@ax2000 ax2000 closed this as completed May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants