Is it good practice to get product collections in helper function and calling in phtml file custom module Magento 2Managing System Configuration data in helper class (DRY Principle)I created a custom module ,but getting error, not able to figure out what the error is about. How to get out of this error?getting error in while running Cutom admin controller URL in magento 2Magento 2.1: Invoke urlBuilder->getUrl() in a controller in a custom moduleCreate Dirty Playground In Magento 2.1.6Magento2 Why I can't get POST data from .MagentoFrameworkAppRequestInterface $request?Zend_Json_Exception Decoding failed: Syntax error some time in Magento (All versions)Magento 2.3 Can't view module's front end page output?Deleted ShipperHQ module causing error in “All Customers” section of Magento 2Captcha Helper method override not working in Magento2

Can a successful book series let the bad guy win?

How to securely dispose of a smartphone?

/etc/hosts not working

Why doesn't SpaceX land boosters in Africa?

Does a lens with a bigger max. aperture focus faster than a lens with a smaller max. aperture?

Can dual citizens open crypto exchange accounts where U.S. citizens are prohibited?

How far can gerrymandering go?

What election rules and voting rights are guaranteed by the US Constitution?

How do I present a future free of gender stereotypes without being jarring or overpowering the narrative?

Can I use Alchemist's fire to turn my sword into a virtual Flame Blade?

How do ohm meters measure high resistances?

When casting a spell with a long casting time, what happens if you don't spend your action on a turn to continue casting?

Avoiding repetition when using the "snprintf idiom" to write text

Why would anyone even use a Portkey?

Sharing referee/AE report online to point out a grievous error in refereeing

If I were to build a J3 cub twice the size of the original using the same CG would it fly?

Why was p[:] designed to work differently in these two situations?

How did they film the Invisible Man being invisible, in 1933?

pgfmath does not work

If a USA citizen marries a foreign citizen who has a kid from a previous marriage

What was the point of separating stdout and stderr?

Calculus, Water Poured into a Cone: Why is Derivative Non-linear?

How can I deal with extreme temperatures in a hotel room?

The Lucas argument vs the theorem-provers--who wins and why?



Is it good practice to get product collections in helper function and calling in phtml file custom module Magento 2


Managing System Configuration data in helper class (DRY Principle)I created a custom module ,but getting error, not able to figure out what the error is about. How to get out of this error?getting error in while running Cutom admin controller URL in magento 2Magento 2.1: Invoke urlBuilder->getUrl() in a controller in a custom moduleCreate Dirty Playground In Magento 2.1.6Magento2 Why I can't get POST data from .MagentoFrameworkAppRequestInterface $request?Zend_Json_Exception Decoding failed: Syntax error some time in Magento (All versions)Magento 2.3 Can't view module's front end page output?Deleted ShipperHQ module causing error in “All Customers” section of Magento 2Captcha Helper method override not working in Magento2






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








4
















Hi all, i wanted to know either is it good practice to get product
collections in helper function and calling that function in phtml file
within custom module Magento 2



Because in my case helper function not working properly.




Please check below Code




appcodeVendorModuleHelperData.php




<?php
namespace VendorModuleHelper;

class Data extends MagentoFrameworkAppHelperAbstractHelper


protected $_objectManager;
const NEWMEMBER = "NEWMEMBER";

public function __construct(
MagentoFrameworkAppHelperContext $context,
MagentoFrameworkObjectManagerInterface $objectmanager
)
$this->_objectManager = $objectmanager;
parent::__construct($context);


public function getProductCollections()
$productSku = self::NEWMEMBER;
$loggedInProducts = $this->_objectManager->get('MagentoCatalogModelProduct')
->getCollection()
->addAttributeToFilter('sku', array('in' => $productSku));
return $loggedInProducts;







appcodeVendorModuleviewfrontendtemplatesMember.phtml




$helper = $this->helper('VendorModuleHelperData');
$getProductCollections = $helper->getProductCollections();









share|improve this question






























    4
















    Hi all, i wanted to know either is it good practice to get product
    collections in helper function and calling that function in phtml file
    within custom module Magento 2



    Because in my case helper function not working properly.




    Please check below Code




    appcodeVendorModuleHelperData.php




    <?php
    namespace VendorModuleHelper;

    class Data extends MagentoFrameworkAppHelperAbstractHelper


    protected $_objectManager;
    const NEWMEMBER = "NEWMEMBER";

    public function __construct(
    MagentoFrameworkAppHelperContext $context,
    MagentoFrameworkObjectManagerInterface $objectmanager
    )
    $this->_objectManager = $objectmanager;
    parent::__construct($context);


    public function getProductCollections()
    $productSku = self::NEWMEMBER;
    $loggedInProducts = $this->_objectManager->get('MagentoCatalogModelProduct')
    ->getCollection()
    ->addAttributeToFilter('sku', array('in' => $productSku));
    return $loggedInProducts;







    appcodeVendorModuleviewfrontendtemplatesMember.phtml




    $helper = $this->helper('VendorModuleHelperData');
    $getProductCollections = $helper->getProductCollections();









    share|improve this question


























      4












      4








      4


      1







      Hi all, i wanted to know either is it good practice to get product
      collections in helper function and calling that function in phtml file
      within custom module Magento 2



      Because in my case helper function not working properly.




      Please check below Code




      appcodeVendorModuleHelperData.php




      <?php
      namespace VendorModuleHelper;

      class Data extends MagentoFrameworkAppHelperAbstractHelper


      protected $_objectManager;
      const NEWMEMBER = "NEWMEMBER";

      public function __construct(
      MagentoFrameworkAppHelperContext $context,
      MagentoFrameworkObjectManagerInterface $objectmanager
      )
      $this->_objectManager = $objectmanager;
      parent::__construct($context);


      public function getProductCollections()
      $productSku = self::NEWMEMBER;
      $loggedInProducts = $this->_objectManager->get('MagentoCatalogModelProduct')
      ->getCollection()
      ->addAttributeToFilter('sku', array('in' => $productSku));
      return $loggedInProducts;







      appcodeVendorModuleviewfrontendtemplatesMember.phtml




      $helper = $this->helper('VendorModuleHelperData');
      $getProductCollections = $helper->getProductCollections();









      share|improve this question

















      Hi all, i wanted to know either is it good practice to get product
      collections in helper function and calling that function in phtml file
      within custom module Magento 2



      Because in my case helper function not working properly.




      Please check below Code




      appcodeVendorModuleHelperData.php




      <?php
      namespace VendorModuleHelper;

      class Data extends MagentoFrameworkAppHelperAbstractHelper


      protected $_objectManager;
      const NEWMEMBER = "NEWMEMBER";

      public function __construct(
      MagentoFrameworkAppHelperContext $context,
      MagentoFrameworkObjectManagerInterface $objectmanager
      )
      $this->_objectManager = $objectmanager;
      parent::__construct($context);


      public function getProductCollections()
      $productSku = self::NEWMEMBER;
      $loggedInProducts = $this->_objectManager->get('MagentoCatalogModelProduct')
      ->getCollection()
      ->addAttributeToFilter('sku', array('in' => $productSku));
      return $loggedInProducts;







      appcodeVendorModuleviewfrontendtemplatesMember.phtml




      $helper = $this->helper('VendorModuleHelperData');
      $getProductCollections = $helper->getProductCollections();






      module phtml magento2.3.1 helper






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jun 21 at 6:43







      Hitesh Balpande

















      asked Jun 21 at 6:30









      Hitesh BalpandeHitesh Balpande

      5442 silver badges14 bronze badges




      5442 silver badges14 bronze badges




















          1 Answer
          1






          active

          oldest

          votes


















          3














          As per the Magento architecture MVC - Model View Controller it is not good practice to use the logic code in helper file.



          Follow Model-View-Control (MVC) pattern



          Make sure your extension adheres to the MVC Pattern, and that it does not violate any of its principles.



          Some important things to check in your extensions:



          1. Make sure your Business Logic, Configuration, and SQL are implemented in the correct places.

          2. Make sure that CSS, JavaScript, HTML, and XML code are all in the appropriate files (i.e. they should not be inline).

          3. Use appropriate logic in a Block, Helper, Template, Controller, or Model.

          4. Ensure correct module design.

          Below are some other things to know while customization and create extension.



          Use dependency injection:



          Direct class instantiation is not recommended because the class can be rewritten. If the class is created directly, any rewrites will not be applied and it breaks Magento’s class rewrite capability. We encourage you to become familiar with how we use dependency injection to get an instance of a class.



          Use the PHP_CodeSniffer tool:



          PHP_CodeSniffer is a set of PHP scripts that checks your code for violations of a particular coding standard. It can be used in conjunction with the Magento Coding Standard to check your code for some of the more common Magento and PHP problems. Using these two tools will ensure that your extension code meets many of Magento’s coding standards. It also has the added benefits of keeping your code clean and maintainable.



          I hope it helps!






          share|improve this answer



























            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "479"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f279114%2fis-it-good-practice-to-get-product-collections-in-helper-function-and-calling-in%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            3














            As per the Magento architecture MVC - Model View Controller it is not good practice to use the logic code in helper file.



            Follow Model-View-Control (MVC) pattern



            Make sure your extension adheres to the MVC Pattern, and that it does not violate any of its principles.



            Some important things to check in your extensions:



            1. Make sure your Business Logic, Configuration, and SQL are implemented in the correct places.

            2. Make sure that CSS, JavaScript, HTML, and XML code are all in the appropriate files (i.e. they should not be inline).

            3. Use appropriate logic in a Block, Helper, Template, Controller, or Model.

            4. Ensure correct module design.

            Below are some other things to know while customization and create extension.



            Use dependency injection:



            Direct class instantiation is not recommended because the class can be rewritten. If the class is created directly, any rewrites will not be applied and it breaks Magento’s class rewrite capability. We encourage you to become familiar with how we use dependency injection to get an instance of a class.



            Use the PHP_CodeSniffer tool:



            PHP_CodeSniffer is a set of PHP scripts that checks your code for violations of a particular coding standard. It can be used in conjunction with the Magento Coding Standard to check your code for some of the more common Magento and PHP problems. Using these two tools will ensure that your extension code meets many of Magento’s coding standards. It also has the added benefits of keeping your code clean and maintainable.



            I hope it helps!






            share|improve this answer





























              3














              As per the Magento architecture MVC - Model View Controller it is not good practice to use the logic code in helper file.



              Follow Model-View-Control (MVC) pattern



              Make sure your extension adheres to the MVC Pattern, and that it does not violate any of its principles.



              Some important things to check in your extensions:



              1. Make sure your Business Logic, Configuration, and SQL are implemented in the correct places.

              2. Make sure that CSS, JavaScript, HTML, and XML code are all in the appropriate files (i.e. they should not be inline).

              3. Use appropriate logic in a Block, Helper, Template, Controller, or Model.

              4. Ensure correct module design.

              Below are some other things to know while customization and create extension.



              Use dependency injection:



              Direct class instantiation is not recommended because the class can be rewritten. If the class is created directly, any rewrites will not be applied and it breaks Magento’s class rewrite capability. We encourage you to become familiar with how we use dependency injection to get an instance of a class.



              Use the PHP_CodeSniffer tool:



              PHP_CodeSniffer is a set of PHP scripts that checks your code for violations of a particular coding standard. It can be used in conjunction with the Magento Coding Standard to check your code for some of the more common Magento and PHP problems. Using these two tools will ensure that your extension code meets many of Magento’s coding standards. It also has the added benefits of keeping your code clean and maintainable.



              I hope it helps!






              share|improve this answer



























                3












                3








                3







                As per the Magento architecture MVC - Model View Controller it is not good practice to use the logic code in helper file.



                Follow Model-View-Control (MVC) pattern



                Make sure your extension adheres to the MVC Pattern, and that it does not violate any of its principles.



                Some important things to check in your extensions:



                1. Make sure your Business Logic, Configuration, and SQL are implemented in the correct places.

                2. Make sure that CSS, JavaScript, HTML, and XML code are all in the appropriate files (i.e. they should not be inline).

                3. Use appropriate logic in a Block, Helper, Template, Controller, or Model.

                4. Ensure correct module design.

                Below are some other things to know while customization and create extension.



                Use dependency injection:



                Direct class instantiation is not recommended because the class can be rewritten. If the class is created directly, any rewrites will not be applied and it breaks Magento’s class rewrite capability. We encourage you to become familiar with how we use dependency injection to get an instance of a class.



                Use the PHP_CodeSniffer tool:



                PHP_CodeSniffer is a set of PHP scripts that checks your code for violations of a particular coding standard. It can be used in conjunction with the Magento Coding Standard to check your code for some of the more common Magento and PHP problems. Using these two tools will ensure that your extension code meets many of Magento’s coding standards. It also has the added benefits of keeping your code clean and maintainable.



                I hope it helps!






                share|improve this answer















                As per the Magento architecture MVC - Model View Controller it is not good practice to use the logic code in helper file.



                Follow Model-View-Control (MVC) pattern



                Make sure your extension adheres to the MVC Pattern, and that it does not violate any of its principles.



                Some important things to check in your extensions:



                1. Make sure your Business Logic, Configuration, and SQL are implemented in the correct places.

                2. Make sure that CSS, JavaScript, HTML, and XML code are all in the appropriate files (i.e. they should not be inline).

                3. Use appropriate logic in a Block, Helper, Template, Controller, or Model.

                4. Ensure correct module design.

                Below are some other things to know while customization and create extension.



                Use dependency injection:



                Direct class instantiation is not recommended because the class can be rewritten. If the class is created directly, any rewrites will not be applied and it breaks Magento’s class rewrite capability. We encourage you to become familiar with how we use dependency injection to get an instance of a class.



                Use the PHP_CodeSniffer tool:



                PHP_CodeSniffer is a set of PHP scripts that checks your code for violations of a particular coding standard. It can be used in conjunction with the Magento Coding Standard to check your code for some of the more common Magento and PHP problems. Using these two tools will ensure that your extension code meets many of Magento’s coding standards. It also has the added benefits of keeping your code clean and maintainable.



                I hope it helps!







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Jun 21 at 6:59

























                answered Jun 21 at 6:53









                Chirag PatelChirag Patel

                3,6186 silver badges28 bronze badges




                3,6186 silver badges28 bronze badges



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Magento Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f279114%2fis-it-good-practice-to-get-product-collections-in-helper-function-and-calling-in%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                    Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

                    Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?