OroPlatform Forums

Covering OroPlatform topics, including community updates and company announcements.

Forums OroPlatform Oro platform: Extending entity ShoppingList not working

This topic contains 15 replies, has 2 voices, and was last updated by Andrey Yatsenko Andrey Yatsenko 3 months, 2 weeks ago.

  • Creator
    Topic
  • #39987

    Frank
    Participant

    Hi there,

    I am trying to extend the ShoppingList-entity with a custom property business unit owner (buOwner). Using the SerialFieldExtensionBundle works fine with migrations (in backend admin panel > manage entities a custom column appers as a serial type property).
    https://github.com/oroinc/OroEntitySerializedFieldsBundle

    However, get working the ShoppingList Entity extension itself fails. I tried to extend the entity using ShoppingList extends ExtendShoppingList- class as described in your guide:
    https://oroinc.com/orocrm/doc/2.0/dev-guide/entities/adding-properties

    1. Created custom MyShoppingListBundle
    2. MyShoppingListBundle/Migrations/Schema/v1-0/AddSerializedFieldMigration.php was loaded succesfully
    3. Created MyBundle/Entity/ShoppingList.php
    4. Created MyBundle/Model/ExtendShoppingList.php
    5. dev-cache cleared

    It happens – nothing!
    If I create my custom controller a new ShoppingList-instance it does not inherit the methods from parent OroShoppingListBundle-class.

    May be ShoppingList-entity cannot be extended this way, as it is already extended in OroShoppingListBundle?
    (EX_OroShoppinglistBundle_ShoppingList – cannot be created twice behind the scene?)

    What I am doing wrong?
    What I should do?

    THanks a lot
    Frank

Viewing 15 replies - 1 through 15 (of 15 total)
  • Author
    Replies
  • #39989

    Frank
    Participant

    A contradiction that I have built in myself is the following:

    The guidline, how to extend an entity
    https://oroinc.com/orocrm/doc/2.0/dev-guide/entities/adding-properties
    says:

    The important part in this migration (which is different from common Doctrine migrations) is the oro_options key. It is passed through the options argument of the addColumn() method:

    Suggested ‘migrations’ code:

    All options nested under this key are handled outside of the usual Doctrine migration workflow.

    When the EntityExtendBundle of the OroPlatform finds the extend key, it generates an intermediate class with getters and setters for the defined properties, thus making them accessible from every part of the code. The intermediate class is generated automatically based on the configured data when the application cache is warmed up.

    However, I generated the serialized field ‘buOwners’ following the guidelines
    https://github.com/oroinc/OroEntitySerializedFieldsBundle
    without using ‘oro_options’ key:

    My ‘migrations’ code:

    Adding ‘oro_options’-key breaks migrations-load (it is not recogized as a migration to load):

    Any idea to resolve this contradiction?

    Thanks a lot
    Frank

    #39990
    Andrey Yatsenko
    Andrey Yatsenko
    Moderator

    To run migrations please use “oro:migration:load” command.

    #39991

    Frank
    Participant

    UPDATE:

    Seems, this will be a thread for mostly talking to myself … smile:

    Trying once again, migration, using ‘oro_options’ was recognized now, during loading-process, but generates an error:

    Failed migrations: Oro\Bundle\EntityExtendBundle\Migration\UpdateExtendConfigMigration.

    Obiously this is aresult of having already 3 serialized fields without ‘oro_options’ generated, may be, I have to delete them before trying the version with ‘oro_options_-key?

    How I can do this?

    Sorry for confusing, and thanks a lot for your help.

    Kind regards
    Frank

    #39992

    Frank
    Participant

    Looking in more detail, I can provide the full error message:

    In ExtendConfigProcessor.php line 386:

    Call to a member function getConfig() on null
    ERROR: The command terminated with an exit code: 255.

    In MigrationExecutor.php line 116:
    Failed migrations: Oro\Bundle\EntityExtendBundle\Migration\UpdateExtendConfigMigration.

    Frank.

    #39996
    Andrey Yatsenko
    Andrey Yatsenko
    Moderator

    I have to delete them before trying the version with ‘oro_options_-key?

    Yes, there is no way to roll back the migration, this why it is required to back up the database before running any migrations, so you will be able to restore from the dump.

    How I can do this?

    With the external tool, like built-in MySQL commands do the backup before running the migration, then restore if something goes wrong.

    Looking in more detail, I can provide the full error message:…

    I haven’t seen this error before. However, with google I found the topic with a similar error, please check it out https://forum.oroinc.com/orocommerce/topic/add-a-custom-string-field-to-customer-entity-programmatically#post-32072

    #39998

    Frank
    Participant

    UPDATE.2
    ——–
    STILL NOT WORKING!

    As I did not know how to delete SerializedFieldExtension-fields, generated without ‘oro_options’-key, I have setup a new, completely fresh oro 319 CE instance.

    Again, migration suggested by EntityExtensionBundle-guidline:

    fails with the same error:
    In ExtendConfigProcessor.php line 386: Call to a member function getConfig() on null.

    Seems to be an incompatibility between SerializedFieldsExtensionBundle, and EntityExtendBundle:
    The ‘oro_options’-key is necessary for entity-extension, but it does not work for SerializedFieldExtension!

    => SerializedFieldExtension-Bug ?

    Your hint

    with google I found the topic with a similar error, please check it out https://forum.oroinc.com/orocommerce/topic/add-a-custom-string-field-to-customer-entity-programmatically#post-32072

    doesn’t give anything new: the forum-manager advices the user to use the same oro-guidlines, as I have described above.

    Any ideas? Very thankful for any helpful solution.

    Frank

    #39999
    Andrey Yatsenko
    Andrey Yatsenko
    Moderator

    Try this one:

    Accroding to the documentation at https://github.com/oroinc/OroEntitySerializedFieldsBundle#oroentityserializedfieldsbundle there should not be oro_options key for serialized field

    #40002

    Frank
    Participant

    Hi Andrey,

    I tried already (see above, I don’t want to be inpolite, but please read my thread carefully :-) ).

    It works, of course. However, this way I am not able to extend the OroBundle entity, for which the ‘oro_options’-key is essential.

    There is another way to built migration for EntityExtendBundle using OroOptions:
    https://github.com/oroinc/platform/tree/master/src/Oro/Bundle/EntityExtendBundle

    I adapted the example from there:

    It generates a serialized field as described, but EntityExtension described in:
    https://oroinc.com/orocrm/doc/2.0/dev-guide/entities/adding-properties

    does not work, too!

    Clearing the cache after the introduction of two new classes
    – MyBundle/Entity/ShoppingList.php
    – MyBundle/Model/ExtendShoppingList.php

    Generates the error:

    No identifier/primary key specified for Entity “MyShoppingListBundle\Entity\ShoppingList” sub class of “MyShoppingListBundle\Model\ExtendShoppingList”. Every Entity must have an identifier/primary key.

    Obviously the OroShoppingListBundle ‘ShoppingList’ is not / cannot be extended. If it would be extended it would have ‘id’, and other properties/methods inherited.

    So, I am not smarter then at the beginning. Unfortunately. :-(

    Thanks for ideas.

    Kind regards
    Frank

    PS: Of course I could implement additional colums instead of using the serialized fields feature. But why to make it more complicate, if a toll exists for doing this automated way (and not changing database schema!).

    #40003
    Andrey Yatsenko
    Andrey Yatsenko
    Moderator

    Thank you for sharing the code, now I hope I have got the clue.

    If you are extending the ShoppingList entity from the core, you must not create a new entity class or the model. Migration is the only thing you should work with, the extended fields you configured at the migrations will be generated automatically.

    And sorry for irrelevant answers, I’m trying to do my best.

    #40004

    Frank
    Participant

    Hi Andrey,

    thanks for your great permanent help!!!

    Your idea … could work, but it does not, due to/for reasons:

    1) Temporarily, I have put a ‘dump($shoppingList);’ into core OroShoppingListBundle-Frontend-Controller (viewAction)-code.
    The output on frontend shows a ShoppingList-Object with
    – empty serializedFields-property, and
    – without any buOwner-property.
    2) To access the buOwner-property without extending the ShoppingList-Entity the buOwner-property should be available through the core-Entity.

    Or I am wrong?
    :-)


    Meanwhile I tried to make experiments with OroOptions like:

    To send a Entity-extend signal for creating the ShoppingListEntitySuperclass – but it want not get working ….

    Thanks a lot

    Kind regards
    Frank

    #40005

    Frank
    Participant

    After adding ‘buOwner’-serialized field to OroShoppingList-Entity:

    dump($shoppingList); added at #50

    and output through the symfony profiler:

    #40006

    Frank
    Participant

    I gave up for today. Could not find a way to access my serializedField-property:

    Routing:

    Controller:

    NO getters/setters for the serialized-field-property available:
    $sl->getBuOwner() – does not exist!

    Getters/setters ARE NOT ADDED automatically to core entity!

    Thanks for new ideas solving this – I think – important problem.

    Kind regards
    Frank

    #40011
    Andrey Yatsenko
    Andrey Yatsenko
    Moderator

    Hi, Frank.

    I’ve tested the migration on a fresh orocommerce-application 3.1.9
    1) added the migration, mentioned at https://forum.oroinc.com/oro-platform/topic/oro-platform-extending-entity-shoppinglist-not-working/#post-39999

    2) launched php bin/console oro:migration:load --force

    Thats it.

    As a result in var/cache/dev/oro_entities/Extend/Entity/EX_OroShoppingListBundle_ShoppingList.php I have 2 new methods generated automatically:

    To check that it works I added 3 simple lines in the existing controller
    \Oro\Bundle\ShoppingListBundle\Controller\Frontend\ShoppingListController::viewAction

    Then I opened “/customer/shoppinglist/2”
    VarDumper showed “test” in a Symfony Profiler, so setter and getter works as expected,

    To check that the value was saved I used the query

    It shows "a:1:{s:7:""buOwner"";s:4:""test"";}"
    So the value also was saved correctly.

    • This reply was modified 3 months, 2 weeks ago by Andrey Yatsenko Andrey Yatsenko. Reason: fixed the query
    #40012

    Frank
    Participant

    Hm.
    :-)

    Works like a clockwork. In principle, I didn’t do anything yesterday other than what you suggested. Today with a fresh installation but it works.

    Andrey, thank you very much for your effort. You really helped me a lot. The way of extending the properties of an entity via the serialized fields will save me a lot of time in the future!

    GREAT SERVICE!

    Kind regrads
    Frank

    PS:
    For people who are using mySQL instead of postgreSQL, the query above would be:
    SELECT convert(FROM_BASE64(serialized_data) using ‘UTF8’) FROM oro_shopping_list WHERE id=2

    #40014
    Andrey Yatsenko
    Andrey Yatsenko
    Moderator

    Thank you, Frank,

    fixed the query as you suggested.

Viewing 15 replies - 1 through 15 (of 15 total)

You must be logged in to reply to this topic.

You will be redirected to [title]. Would you like to continue?

Yes No