OroCommerce Forums

Covering OroCommerce topics, including community updates and company announcements.

Forums OroCommerce How to replace or extend Configuration.php of OroProductBundle?

This topic contains 4 replies, has 2 voices, and was last updated by  Shahriar 4 months, 1 week ago.

  • Creator
    Topic
  • #40025

    Shahriar
    Participant

    I am trying to replace or extend the Configuration.php of OroProductBundle located at:
    vendor/oro/commerce/src/Oro/Bundle/ProductBundle/DependencyInjection/Configuration.php

    in my Custom Bundle.

    I found no Oro or Symfony way of extending/replacing a Configuration.php class. Right now my code only works if I alter the original file.

    I tried ways described in this article https://symfony.com/doc/current/bundles/prepend_extension.html
    to prepend Configuration but looks like it only prepends on existing configs but does not add a new one.

    So this is what I have done so far by adding this class in my Bundle:

    So this does not work. However, if I add this same node inside the original OroProductBundle Configuration.php class, it works.

    Can anyone advise on how to make Oro to use my Bundle’s Configuration.php instead of the OroProductBundle’s one? Thank you

    • This topic was modified 4 months, 1 week ago by  Shahriar.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Author
    Replies
  • #40029
    Andrey Yatsenko
    Andrey Yatsenko
    Moderator

    Hi Shahriar,

    First of all please clarify why do you need to extend the configuration.
    It is not allowed because usually there is no need to do that and you always can define the configuration in your bundle only and reference it in the OroCommerce UI section if needed.

    #40078

    Shahriar
    Participant

    Hello Andrey,
    Thanks for your reply. Let me give you more info on what am I trying to achieve here.

    I created a custom segment called New Brands, which I want to show on my Home page similar to Featured Product or New Arrivals. My New Brand Segment uses a condition to show brands that are created between certain dates. Right now, I have created a NewBrandsProvider, where I used a segmentManager to fetch New Brands segment by id. This works when I pass in segment id with hard code. But I am trying to get the id dynamically as well. This is how my NewBrandsProvider looks:

    I also added a system_configuration_services.yml with below:

    Now if I add the below NEW_BRANDS_SEGMENT_ID node inside OroProductBundle Configuration.php, my NewBrandsProvider can dynamically get the segment id with getSegmentId() function. Which tells me I can manually add a configuration node for my custom Segment ID which I can make query on.

    But obviously, I don’t want to edit core codes and want the same facility by using same logic in my custom bundle.

    Which is why I wanted to make my own Configuration.php but it was returning “null” for getSegmentId().

    Alternate Ways I tried: I thought I need to extend ProductBundle’s Configuration.php as Brand entity is defined inside ProductBundle. So, after my custom bundle’s(BrandBundle) Configuration.php was not working, I also added the below Extension class to extend ProductBundle’s configs from my Custom Bundle.

    But after adding this extension, I was getting error on cache:clear saying NEW_BRANDS_SEGMENT_ID was not found.

    I am sorry for this long post but will appreciate any advice to the right direction. :)

    • This reply was modified 4 months, 1 week ago by  Shahriar.
    • This reply was modified 4 months, 1 week ago by  Shahriar.
    #40091

    Shahriar
    Participant

    Then actual error looks like this:

    new_brands_segment_id is not found in oro_product.settings

    #40097

    Shahriar
    Participant

    Okay, I fixed it. Thanks for the suggestion!
    You are right, I dont need to extend ProductBundle’s Configuration instead I can just have my own bundle’s Configuration.

    It looks like, I was adding Configuration for my own bundle but was not really calling it correct ALIAS.

    I corrected this function in my NewBrandsProvider class

    Also corrected the service name in system_configuration_services.yml

    My getSegmentId() is now returning the id. This is resolved now. :)

    • This reply was modified 4 months, 1 week ago by  Shahriar.
Viewing 4 replies - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

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

Yes No