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.
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.
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:
YAML
1
2
3
4
5
6
7
8
9
10
11
12
parameters:
oro_product.segment.new_brands.name: 'New Brands'
services:
oro_product.provider.default_value.new_brands:
parent: oro_config.provider.value.entity_id
arguments:
-'@oro_entity.doctrine_helper'
-'%oro_segment.segment.entity.class%'
-
'entity': '%oro_product.entity.brand.class%'
'name': '%oro_product.segment.new_brands.name%'
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.
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
We collect cookie information with a goal to provide you with the best user experience. By using this website, you agree to our use of cookies. Read Oro Inc.’s Cookie policy.
You will be redirected to [title]. Would you like to continue?
We collect cookie information with a goal to provide you with the best user experience. By using this website, you agree to our use of cookies. Read Oro Inc.’s Cookie policy.
You will be redirected to [title]. Would you like to continue?