#Extend Billing Address by Custom Field => Field is not updated

24 messages · Page 1 of 1 (latest)

mellow breach
#
  1. I extended the Address entity:
@Entity()
export class Address extends MedusaAddress {
  @IsString()
  @IsOptional()
  vat_id: string;
}

  1. I extended and registered both Validators:
export class StorePostCustomersCustomerAddressesAddressReq extends MedusaStorePostCustomersCustomerAddressesAddressReq {
  @IsString()
  @IsOptional()
  vat_id: string;
}

export class AddressPayload extends MedusaAddressPayload {
  @IsString()
  @IsOptional()
  vat_id: string;
}

registerOverriddenValidators(StorePostCustomersCustomerAddressesAddressReq);
registerOverriddenValidators(AddressPayload);
  1. I can see that the call to /store/customers/me returns 200 and has the proper payload with the billing_address.vat_id attached to it.
  2. The server stores / updates all address information BUT leaves the extended column vat_id out. Its null basically
  3. The database has the new field (vat_id) that I created during a migration before but I simply fail to populate it on an upte / creation.

I am probably missing some sort validation or other logical break. This one is not so straight forward as Addresses is referenced by shipping and billling addresses.

Thanks for any pointers or examples of someone who has extended the address entity 🙏

mellow breach
#

Guess I am generally confused about all diferrent interfaces / classes around Addresses:

  • Address
  • AddressPayload
  • AddressCreatePayload
  • StorePostCustomersCustomerAddressesReq

Not sure which ones / how to update and extend them properly to reflect my address entity addition

mellow breach
#

i seem to be running into the same issue when extending the Cart object. Does anyone know what I am missing? I seem to be fine extending the entity, extending its type and the validators: The update calls on the Cart / Address go through and return 200 but within the database the new fields never arrive... Its hard to debug since everything seems to be in order...

#

E.g. for the Cart update I did this:

  1. Create the migration and run:
export class CartOrderOptionals1689428677453 implements MigrationInterface {
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.addColumns("cart", [
      new TableColumn({
        name: "internal_order_id",
        type: "varchar",
        isNullable: true,
      }),
      new TableColumn({
        name: "is_partial_delivery",
        type: "boolean",
        isNullable: false,
        default: true,
      }),
    ]);
  }
  1. Update cart model:
@Entity()
export class Cart extends MedusaCart {
  @IsString()
  @IsOptional()
  internal_order_id: string;

  @IsBoolean()
  @IsOptional()
  is_partial_delivery: boolean;
}
  1. Update Validators:
export class StorePostCartsCartReq extends MedusaStorePostCartsCartReq {
  @IsString()
  @IsOptional()
  internal_order_id: string;

  @IsBoolean()
  @IsOptional()
  is_partial_order: boolean;


}
registerOverriddenValidators(StorePostCartsCartReq);
  1. My POST returns 200, I can see I sent the new internal_order_id...
  2. When I check the db (via psql) I see that the field has not been updated, its null respectively....
mellow breach
#

Does anyone have a clue? Very stuck on this as I do not see what I am missing…

mellow breach
#

Can anyone support? Sorry about being pushy here but I really do not understand what I am missing and it is a crazy blocker for me

left nimbus
#

Hi, I have the same problem trying to post a new entity on the store. I try to extend line_item, which works like in your case until I successfully send the payload and receive a 200 but in psql it remains null..

#

could someone explain to us how the cart works to be able to add an entity?

#

I get size: null when I do this post

#

@limpid island there are many of us in this situation

limpid island
#

Again, same as other users, your entity is not using the typeorm decorators but the class-validators decorators

left nimbus
limpid island
#

Can you share me the doc link you have used where it says that the entity properties are defined using IsOptional etc? Cause i think you are mixing entities and validators concept and definition

left nimbus
#

I used the new way with 1.12.2

limpid island
#

If you look at the decorator in the doc, it is @Column in the entity, so how did you come to use IsOptional and IsString?

left nimbus
#

model:

import { Column, Entity } from 'typeorm';
import { LineItem as MedusaProduct } from '@medusajs/medusa';

@Entity()
export class LineItem extends MedusaProduct {
  @Column()
  size: string;
}

validator:

import { StorePostCartsCartLineItemsReq as MedusaStorePostCartsCartLineItemsReq } from '@medusajs/medusa';
import { IsString } from 'class-validator';

export class StorePostCartsCartLineItemsReq extends MedusaStorePostCartsCartLineItemsReq {
  @IsString()
  size: string;
}
#

It's not correct ?

#

ok I understood, you took as an example the present code of another user above

I don't have the same code as him, I used the correct way and size remains null in psql

limpid island
#

I’m just heading out in the car. I’ll take a look tomorrow

left nimbus
#

top merci, bonne route

limpid island
#

Indeed, I was referring to what have been shared by the other member 😂 so for his case it can't work because of what I have explained.

#

In your case, I suppose that you are targetting this end point /store/carts/{id}/line-items if you take a look at it, the line items go through a generation step before being created. Unfortunatelly, this generation does not take into account the custom property you have added. Is it mandatory for you to have it on the line item directly or the metadata could be sufficient for your usecase?

left nimbus
#

I think it might work using metadata but I wanted to do something cleaner with an entity extend

If this is not possible then I will take the metadata solution