Can I remove the id/variable between parent and child Glue route URL?
After following the tutorial above, I get the following URL for my child resource:
https://glue-storefront.mysprykershop.com/module/1/bar.
is there a way to remove /1/ from the URL? Ideally, the url should be …/module/bar/…
Answers
-
Bar belongs to an entity of Module, so there has to be an id.
It's like:
products/1/categories
if you remove the productId then there isn't any parent reference to which those categories belong.
0 -
Thanks for your reply.
What I am trying to do to have support for urls like this:
deals/{dealsId}
deals/regional/{regionId}
I have a DealsResource which you can use to get specific deals. And then I have a RegionalResource which is child of DealsResource and I would like to have {regionId} in front of it without having a URL structure like deals/1/regional/{regionId}.
Can you please tell me if this is possible?0 -
fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,075 ⚖️ - Guardians (admin)
Heyhey @muhammad.jadoon ,
have a look at the
getRouteProviderPlugins()
method. (see https://github.com/spryker-shop/b2b-demo-shop/blob/202311.0/src/Pyz/Glue/GlueBackendApiApplication/GlueBackendApiApplicationDependencyProvider.php#L104) This method is available both for Glue Storefront API as well as for Glue Backend API. There you can add custom routes.To have a custom route for otherwise normal resource behaviour like you described it will likely would be a bit more ugly to implement to reuse existing functionality.
Hope this helps.
All the best,
Florian
0 -
fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,075 ⚖️ - Guardians (admin)
Another idea, but not tested by myself:
What happens if you define the resource-type as "deals/regional" and add this ResourcePlugin before the other one?
0 -
This does not work unfortunately.
1 -
IMHO, What you are trying to obtain is a filtering.
you can simply do it this way:
https://glue-storefront.mysprykershop.com/deals?filter[deal.regionId]=2
then in your DealReader
public function getDealCollection(GlueRequestTransfer $glueRequestTransfer): GlueResponseTransfer
{$filters = $glueRequestTransfer→getFilters();
//apply filtering to your entities
}Creating a url like deals/regional/{regionId}. isn't a RESTFUL uri as there is no deal's id mapped to a region.
I hope it helps the above mentioned solution.
0
Categories
- All Categories
- 42 Getting Started & Guidelines
- 7 Getting Started in the Community
- 8 Additional Resources
- 7 Community Ideas and Feedback
- 75 Spryker News
- 919 Developer Corner
- 779 Spryker Development
- 89 Spryker Dev Environment
- 362 Spryker Releases
- 3 Oryx frontend framework
- 34 Propel ORM
- 68 Community Projects
- 3 Community Ideation Board
- 30 Hackathon
- 3 PHP Bridge
- 6 Gacela Project
- 25 Job Opportunities
- 3.2K 📜 Slack Archives
- 116 Academy
- 5 Business Users
- 370 Docker
- 551 Slack General
- 2K Help
- 75 Knowledge Sharing
- 6 Random Stuff
- 4 Code Testing
- 32 Product & Business Questions
- 69 Spryker Safari Questions
- 50 Random