Hi Everyone I am trying to add a custom field to c...
# help
a
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
p
Hey, is the column already migrated to the database?
a
Yes
p
Where do you add the data for that field which you want to save?
a
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
p
Do you see you new field in the interface already?
a
I can see the field in my table spy_customer , also in the generated customerTransfer
p
but do you see your adjusted form?
a
Yes I can see that
p
ok, can you show us the code of your form, the DTO-definition and the table-schema definition file?
a
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
p
have you used propel:install as well? or just the migrate?
how did you name the field in the form, in the transfer definition and in the schema file?
form and schema file should be the same; in the DTO you should NOT use lowercase for the same entity
a
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
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
This is in context of b2b_marketplace
Will I need to modify the customerclient or any further mapping is required ?
p
Can you please share the DTO definition?
a
<?xml version="1.0"?> <transfers xmlns="spryker:transfer-01" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="spryker:transfer-01 http://static.spryker.com/transfer-01.xsd"> <transfer name="Customer"> <property name="customerType" type="string"/> </transfer> </transfers>
and this is the column that I added in customer.schema.xml <column name="customer_type" type="VARCHAR" size="500" default="NULL" /> and triggered the same using propel:diff and propel:migrate , I can see this field is added to spy_customer table
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
Issue was resolved by executing propelmodelbuild 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 ?
p
Sorry for the late answer - thats why i use `propel:install`most of the times. it executes several propel commands one after each other
a
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