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

custom_attributes dropped from response when passing expand options #24

Open
molhar opened this issue Mar 6, 2024 · 3 comments
Open

Comments

@molhar
Copy link

molhar commented Mar 6, 2024

Passing any relation to expand for the storefront products/ API endpoint appears to drop custom_attributes from the response data. Should the inclusion of attribute relations in defaultStoreProductsRelations mean they're always returned?

I've worked around this by handling custom_attributes passed in as a relation to expand:

  async listAndCount(
    selector: ProductSelector & {
      attributes: string[];
      int_attributes: IntAttributeParam;
    },
    config: FindProductConfig = {
      relations: [],
      skip: 0,
      take: 20,
      include_discount_prices: false,
    }
  ): Promise<[Product[], number]> {
    const manager = this.activeManager_;
    const productRepo = manager.withRepository(this.productRepository_);

    if (config.relations?.includes("custom_attributes")) {
      config.relations.push(
        "attribute_values",
        "attribute_values.attribute",
        "int_attribute_values",
        "int_attribute_values.attribute",
      )
      config.relations = config.relations.filter(rel => rel !== "custom_attributes");
    }
@vholik
Copy link
Owner

vholik commented Mar 14, 2024

there is no such relation as custom_attributes. It's dynamic value that is concat of int_attribute_values and attribute_values. Adding these values below will help you:

 imports.defaultAdminProductRelations = [
    ...imports.defaultAdminProductRelations,
    "attribute_values",
    "attribute_values.attribute",
    "int_attribute_values",
    "int_attribute_values.attribute",
  ];

@hauseyo
Copy link

hauseyo commented May 16, 2024

there is no such relation as custom_attributes. It's dynamic value that is concat of int_attribute_values and attribute_values. Adding these values below will help you:

 imports.defaultAdminProductRelations = [
    ...imports.defaultAdminProductRelations,
    "attribute_values",
    "attribute_values.attribute",
    "int_attribute_values",
    "int_attribute_values.attribute",
  ];

Hi,
The solution you proposed didn't really help me. I still don't see custom_attributes from response.
Here's my code.
The difference is that I'd like to have the attribute in store/products. Could you please help?

export default async function () {
  const imports = (await import(
    "@medusajs/medusa/dist/api/routes/store/products/index"
  )) as any;
  imports.allowedStoreProductsRelations = [
    ...imports.allowedStoreProductsRelations,
    "attribute_values",
    "attribute_values.attribute",
    "int_attribute_values",
    "int_attribute_values.attribute",
  ];
  imports.defaultStoreProductsRelations = [
    ...imports.defaultStoreProductsRelations,
    "attribute_values",
    "attribute_values.attribute",
    "int_attribute_values",
    "int_attribute_values.attribute",
  ];
}

@hauseyo
Copy link

hauseyo commented May 16, 2024

So instead of having custom_attributes in the response, I receive int_attribute_values, which is okay for me for now.
But anyway it's quite strange.
I'd appreciate to have some sort of configuration to make that field appeared in the response by default or something like that.

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

No branches or pull requests

3 participants