What are the Slack Archives?

It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

Hi team is there any way calling function of another module's class except creating new object using

Posts: 64 πŸ§‘πŸ»β€πŸš€ - Cadet

Hi team
is there any way calling function of another module's class except creating new object using new or dependency injection every time

Welcome!

It looks like you're new here. Sign in or register to get started.

Comments

  • Lead Spryker Solution Architect / Technical Director Posts: 690 πŸͺ - Explorer

    You could make a method static to call it via <class>::<method> but if you neither want to create an object via new nor inject it through DI you might try something very odd and should reconsider if this is the right way to solve your requirement.

  • Posts: 64 πŸ§‘πŸ»β€πŸš€ - Cadet

    ok thanks

  • Posts: 64 πŸ§‘πŸ»β€πŸš€ - Cadet

    please suggest for the following scenario:
    If we need to create category from our custom module then we will call existing function of category module. If in this case we will create object of category class using new to call function of the same class then please let me confirm whether this will not be against spryker coding structure or we can go ahead with using new

  • Lead Spryker Solution Architect / Technical Director Posts: 690 πŸͺ - Explorer

    There is the \Spryker\Zed\Category\Business\CategoryFacadeInterface::createCategory method you can use to add a new category.
    Creating transfer objects with new is completely fine.

    You can then inject the CategoryFacadeInterface into your object that will need to create a new category, by using the respective <YourModule>DependencyProvider as described in the tutorial section: https://docs.spryker.com/docs/scos/dev/tutorials-and-howtos/introduction-tutorials/tutorial-architectural-walkthrough-spryker-commerce-os.html#e[…]e

  • Posts: 64 πŸ§‘πŸ»β€πŸš€ - Cadet

    Thanks @UL6DGRULR. I am able to reach the function create of vendor/spryker/category/src/Spryker/Zed/Category/Business/CategoryFacade.php . Now there is the dependency of CategoryTransfer in that function. Please suggest do I need to follow all the steps given in createCategory function of vendor/spryker/category/tests/SprykerTest/Zed/Category/_support/Helper/CategoryHelper.php All dependencies mentioned in the above function will need to be resolved or there is any better approach for the same to create category.

  • Lead Spryker Solution Architect / Technical Director Posts: 690 πŸͺ - Explorer

    You could use "find usage" in your editor to see where the \Spryker\Zed\Category\Business\CategoryFacade::create is used and how it's done. That would lead you to the \Spryker\Zed\Category\Communication\Controller\CreateController::indexAction and \Spryker\Zed\Category\Communication\Form\CategoryType where you can see what data needs to be passed into the transfer to create a new category. Use this code as a blueprint for what you want to achieve as it is almost the same.

Welcome!

It looks like you're new here. Sign in or register to get started.