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

U03TXRYL7U7
U03TXRYL7U7 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

Comments

  • Alberto Reyer
    Alberto Reyer 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.

  • U03TXRYL7U7
    U03TXRYL7U7 Posts: 64 ๐Ÿง‘๐Ÿปโ€๐Ÿš€ - Cadet

    ok thanks

  • U03TXRYL7U7
    U03TXRYL7U7 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

  • Alberto Reyer
    Alberto Reyer 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

  • U03TXRYL7U7
    U03TXRYL7U7 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.

  • Alberto Reyer
    Alberto Reyer 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.