What are the Slack Archives?

It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

New field in customer table not getting saved to database

U057U47RCBD
U057U47RCBD Posts: 28 πŸ§‘πŸ»β€πŸš€ - Cadet
edited May 2023 in Help

Hi Everyone,

I am trying to add a custom field to customer table , have migrated the db changes and also added a DTO and generated the transfer for the same , but my new field is not getting saved in db. Am I missing something here ? Fairly new to spryker

Comments

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,084 βš–οΈ - Guardians (admin)

    Hey, is the column already migrated to the database?

  • U057U47RCBD
    U057U47RCBD Posts: 28 πŸ§‘πŸ»β€πŸš€ - Cadet

    Yes

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,084 βš–οΈ - Guardians (admin)

    Where do you add the data for that field which you want to save?

  • U057U47RCBD
    U057U47RCBD Posts: 28 πŸ§‘πŸ»β€πŸš€ - Cadet

    Actually I have created a new module and extending the core customerpage module to customize the customerpage register , I have added the new field in form of my custom module and passing the same to CustomerTransfer for registration

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,084 βš–οΈ - Guardians (admin)

    Do you see you new field in the interface already?

  • U057U47RCBD
    U057U47RCBD Posts: 28 πŸ§‘πŸ»β€πŸš€ - Cadet

    I can see the field in my table spy_customer , also in the generated customerTransfer

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,084 βš–οΈ - Guardians (admin)

    but do you see your adjusted form?

  • U057U47RCBD
    U057U47RCBD Posts: 28 πŸ§‘πŸ»β€πŸš€ - Cadet

    Yes I can see that

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,084 βš–οΈ - Guardians (admin)

    ok, can you show us the code of your form, the DTO-definition and the table-schema definition file?

  • U057U47RCBD
    U057U47RCBD Posts: 28 πŸ§‘πŸ»β€πŸš€ - Cadet

    for my form
    I have extended the Core CustomerPage/Form/RegisterForm
    , overrided the buildForm method and added a field
    then I have generated a propel diff by adding that field to spy_customer.schema.xml and then executed the propel:migrate command , the new field that i created is then migrated to the spy_customer table
    Post That I create a new module in Pyz\Shared and added the field in transfer xml file and then executed the transfer:generate command which in turn added that field in generated\src\shared\Transfer\CustomerTransfer.php

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,084 βš–οΈ - Guardians (admin)

    have you used propel:install as well? or just the migrate?

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,084 βš–οΈ - Guardians (admin)

    how did you name the field in the form, in the transfer definition and in the schema file?

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,084 βš–οΈ - Guardians (admin)

    form and schema file should be the same; in the DTO you should NOT use lowercase for the same entity

  • U057U47RCBD
    U057U47RCBD Posts: 28 πŸ§‘πŸ»β€πŸš€ - Cadet

    I have just used proper:migrate , i have kept the name of field same across form , schema and DTO , its in lowercase 'type' is the field name which I am just trying out

  • U057U47RCBD
    U057U47RCBD Posts: 28 πŸ§‘πŸ»β€πŸš€ - Cadet

    i have just overrided the indexAction method of RegisterController to add the new form etc , i have not overrided the registerCustomer method of core , was hoping as the DTO and fields are in place it should handle the request , but all other existing fields are getting saved only my custom field is not getting saved, I tried to debug by printing the CustomerTransfer Object , I can see my custom field getting populated there but not getting saved in DB

  • U057U47RCBD
    U057U47RCBD Posts: 28 πŸ§‘πŸ»β€πŸš€ - Cadet

    This is in context of b2b_marketplace

  • U057U47RCBD
    U057U47RCBD Posts: 28 πŸ§‘πŸ»β€πŸš€ - Cadet

    Will I need to modify the customerclient or any further mapping is required ?

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,084 βš–οΈ - Guardians (admin)

    Can you please share the DTO definition?

  • U057U47RCBD
    U057U47RCBD Posts: 28 πŸ§‘πŸ»β€πŸš€ - Cadet

    <?xml version="1.0"?>
    " xsi:schemaLocation="spryker:transfer-01 ">

    <transfer name="Customer">
        <property name="customerType" type="string"/>
    </transfer>
    

  • U057U47RCBD
    U057U47RCBD Posts: 28 πŸ§‘πŸ»β€πŸš€ - Cadet

    and this is the column that I added in customer.schema.xml

    and triggered the same using propel:diff and propel:migrate , I can see this field is added to spy_customer table

  • U057U47RCBD
    U057U47RCBD Posts: 28 πŸ§‘πŸ»β€πŸš€ - Cadet

    I think the issue is because propel:migrate command just created the db field but it didnot rebuild the BaseSpyCustomer class with mapping for my new field

  • U057U47RCBD
    U057U47RCBD Posts: 28 πŸ§‘πŸ»β€πŸš€ - Cadet

    Issue was resolved by executing propel:model:build and again propel:migrate . As a standard convention if it ok to introduce fields in spryker core tables like spy_customer ? or should we be creating our custom tables ?

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,084 βš–οΈ - Guardians (admin)

    Sorry for the late answer - thats why i use propel:installmost of the times. it executes several propel commands one after each other

  • U057U47RCBD
    U057U47RCBD Posts: 28 πŸ§‘πŸ»β€πŸš€ - Cadet

    Thanks , i would be using propel:install going forward . Also I a need one more help regarding overriding a core url say for example 'register' , I added my RouteProvider in RouteProviderDependency but I think it gets overried by YvesRouterPlugin() . Is there a way to efficiently override the route