How to Create Custom Helper Class in Magento2 then Call ProductRepository to get Product detailsHow to create magento2 custom theme/designMagento 2 : How can I call helper function on override product list blockMagento 2 - How to call Helper function via BlockMagento2: How to get cart rules applied product details on product view page and cart page?How to use rewrite the cart/item/default.phtml template file my module?How to use overwrite the checkout cart/item/default.phtml template file into my module in Magento2Magento 2 : How to update 'Update cart' Button`s Template?'Class' not found error in Magento 2 frontendDisplay Custom Attribute Multiplace Place on Products Details Page Magento 2RuntimeException When i Load Helper Class magento 2

Taking advantage when HR forgets to communicate the rules

Why do we need a bootloader separate from our application program in microcontrollers?

How did the IEC decide to create kibibytes?

As a supervisor, what feedback would you expect from a PhD who quits?

Do intermediate subdomains need to exist?

Did Stalin kill all Soviet officers involved in the Winter War?

How can I use my cell phone's light as a reading light?

Why does this function pointer assignment work when assigned directly but not with the conditional operator?

Extruder problem

What are some bad ways to subvert tropes?

Why do Martians have to wear space helmets?

Will Jimmy fall off his platform?

Left Side Underexposed on Film Camera

How do resistors generate different heat if we make the current fixed and changed the voltage and resistance? Notice the flow of charge is constant

Array or vector? Two dimensional array or matrix?

Is conquering your neighbors to fight a greater enemy a valid strategy?

Bringing coumarin-containing liquor into the USA

Is there a standard definition of the "stall" phenomena?

Find max number you can create from an array of numbers

Examples of fluid (including air) being used to transmit digital data?

Options for quick email reply to the effect of "I've just done it" or "I've taken care of it"

Is this standard Japanese employment negotiations, or am I missing something?

How to delete multiple process id of a single process?

Do I need transit visa for Dublin?



How to Create Custom Helper Class in Magento2 then Call ProductRepository to get Product details


How to create magento2 custom theme/designMagento 2 : How can I call helper function on override product list blockMagento 2 - How to call Helper function via BlockMagento2: How to get cart rules applied product details on product view page and cart page?How to use rewrite the cart/item/default.phtml template file my module?How to use overwrite the checkout cart/item/default.phtml template file into my module in Magento2Magento 2 : How to update 'Update cart' Button`s Template?'Class' not found error in Magento 2 frontendDisplay Custom Attribute Multiplace Place on Products Details Page Magento 2RuntimeException When i Load Helper Class magento 2






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








4















Actually I need to Create a Helper Class in Magento2 then Call ProductRepository in




app/code/vendor/module/Helper/Data.php




to load Product details by sku and return Product Details in cart page and display




app/code/vendor/{module/view/frontend/templates/cart/item/default.phtml











share|improve this question




























    4















    Actually I need to Create a Helper Class in Magento2 then Call ProductRepository in




    app/code/vendor/module/Helper/Data.php




    to load Product details by sku and return Product Details in cart page and display




    app/code/vendor/{module/view/frontend/templates/cart/item/default.phtml











    share|improve this question
























      4












      4








      4








      Actually I need to Create a Helper Class in Magento2 then Call ProductRepository in




      app/code/vendor/module/Helper/Data.php




      to load Product details by sku and return Product Details in cart page and display




      app/code/vendor/{module/view/frontend/templates/cart/item/default.phtml











      share|improve this question














      Actually I need to Create a Helper Class in Magento2 then Call ProductRepository in




      app/code/vendor/module/Helper/Data.php




      to load Product details by sku and return Product Details in cart page and display




      app/code/vendor/{module/view/frontend/templates/cart/item/default.phtml








      magento2 cart product-page






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jun 27 at 10:02









      Shafeel ShaShafeel Sha

      1098 bronze badges




      1098 bronze badges




















          1 Answer
          1






          active

          oldest

          votes


















          3














          First, you have to create a Helper file




          CustomModuleHelperData.php




          <?php
          namespace CustomModuleHelper;

          /**
          * Custom Helper for Load Products
          */
          class Data extends MagentoFrameworkAppHelperAbstractHelper

          protected $productRepository;

          public function __construct(
          MagentoCatalogApiProductRepositoryInterface $productRepository
          )
          $this->productRepository = $productRepository;


          public function loadMyProduct($sku)

          return $this->productRepository->get($sku);


          ?>


          Then you can call this helper in your phtml file like below:



          $customHelper = $this->helper('CustomModuleHelperData');
          $product = $customHelper->loadMyProduct($sku);





          share|improve this answer

























          • error shows in data.php

            – Shafeel Sha
            Jun 27 at 10:34












          • can you please mention here?

            – Ravi Soni
            Jun 27 at 10:35











          • Thanks for your Support ,its Done

            – Shafeel Sha
            Jun 27 at 10:50











          • Welcome. :) and +1 for accepting as right answer.

            – Ravi Soni
            Jun 27 at 10:53











          • your flag copied by me for profile

            – Jugal Kishor
            Jun 28 at 11:52













          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%2f279887%2fhow-to-create-custom-helper-class-in-magento2-then-call-productrepository-to-get%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














          First, you have to create a Helper file




          CustomModuleHelperData.php




          <?php
          namespace CustomModuleHelper;

          /**
          * Custom Helper for Load Products
          */
          class Data extends MagentoFrameworkAppHelperAbstractHelper

          protected $productRepository;

          public function __construct(
          MagentoCatalogApiProductRepositoryInterface $productRepository
          )
          $this->productRepository = $productRepository;


          public function loadMyProduct($sku)

          return $this->productRepository->get($sku);


          ?>


          Then you can call this helper in your phtml file like below:



          $customHelper = $this->helper('CustomModuleHelperData');
          $product = $customHelper->loadMyProduct($sku);





          share|improve this answer

























          • error shows in data.php

            – Shafeel Sha
            Jun 27 at 10:34












          • can you please mention here?

            – Ravi Soni
            Jun 27 at 10:35











          • Thanks for your Support ,its Done

            – Shafeel Sha
            Jun 27 at 10:50











          • Welcome. :) and +1 for accepting as right answer.

            – Ravi Soni
            Jun 27 at 10:53











          • your flag copied by me for profile

            – Jugal Kishor
            Jun 28 at 11:52















          3














          First, you have to create a Helper file




          CustomModuleHelperData.php




          <?php
          namespace CustomModuleHelper;

          /**
          * Custom Helper for Load Products
          */
          class Data extends MagentoFrameworkAppHelperAbstractHelper

          protected $productRepository;

          public function __construct(
          MagentoCatalogApiProductRepositoryInterface $productRepository
          )
          $this->productRepository = $productRepository;


          public function loadMyProduct($sku)

          return $this->productRepository->get($sku);


          ?>


          Then you can call this helper in your phtml file like below:



          $customHelper = $this->helper('CustomModuleHelperData');
          $product = $customHelper->loadMyProduct($sku);





          share|improve this answer

























          • error shows in data.php

            – Shafeel Sha
            Jun 27 at 10:34












          • can you please mention here?

            – Ravi Soni
            Jun 27 at 10:35











          • Thanks for your Support ,its Done

            – Shafeel Sha
            Jun 27 at 10:50











          • Welcome. :) and +1 for accepting as right answer.

            – Ravi Soni
            Jun 27 at 10:53











          • your flag copied by me for profile

            – Jugal Kishor
            Jun 28 at 11:52













          3












          3








          3







          First, you have to create a Helper file




          CustomModuleHelperData.php




          <?php
          namespace CustomModuleHelper;

          /**
          * Custom Helper for Load Products
          */
          class Data extends MagentoFrameworkAppHelperAbstractHelper

          protected $productRepository;

          public function __construct(
          MagentoCatalogApiProductRepositoryInterface $productRepository
          )
          $this->productRepository = $productRepository;


          public function loadMyProduct($sku)

          return $this->productRepository->get($sku);


          ?>


          Then you can call this helper in your phtml file like below:



          $customHelper = $this->helper('CustomModuleHelperData');
          $product = $customHelper->loadMyProduct($sku);





          share|improve this answer















          First, you have to create a Helper file




          CustomModuleHelperData.php




          <?php
          namespace CustomModuleHelper;

          /**
          * Custom Helper for Load Products
          */
          class Data extends MagentoFrameworkAppHelperAbstractHelper

          protected $productRepository;

          public function __construct(
          MagentoCatalogApiProductRepositoryInterface $productRepository
          )
          $this->productRepository = $productRepository;


          public function loadMyProduct($sku)

          return $this->productRepository->get($sku);


          ?>


          Then you can call this helper in your phtml file like below:



          $customHelper = $this->helper('CustomModuleHelperData');
          $product = $customHelper->loadMyProduct($sku);






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jun 27 at 11:25









          Shafeel Sha

          1098 bronze badges




          1098 bronze badges










          answered Jun 27 at 10:14









          Ravi SoniRavi Soni

          1,0215 silver badges18 bronze badges




          1,0215 silver badges18 bronze badges












          • error shows in data.php

            – Shafeel Sha
            Jun 27 at 10:34












          • can you please mention here?

            – Ravi Soni
            Jun 27 at 10:35











          • Thanks for your Support ,its Done

            – Shafeel Sha
            Jun 27 at 10:50











          • Welcome. :) and +1 for accepting as right answer.

            – Ravi Soni
            Jun 27 at 10:53











          • your flag copied by me for profile

            – Jugal Kishor
            Jun 28 at 11:52

















          • error shows in data.php

            – Shafeel Sha
            Jun 27 at 10:34












          • can you please mention here?

            – Ravi Soni
            Jun 27 at 10:35











          • Thanks for your Support ,its Done

            – Shafeel Sha
            Jun 27 at 10:50











          • Welcome. :) and +1 for accepting as right answer.

            – Ravi Soni
            Jun 27 at 10:53











          • your flag copied by me for profile

            – Jugal Kishor
            Jun 28 at 11:52
















          error shows in data.php

          – Shafeel Sha
          Jun 27 at 10:34






          error shows in data.php

          – Shafeel Sha
          Jun 27 at 10:34














          can you please mention here?

          – Ravi Soni
          Jun 27 at 10:35





          can you please mention here?

          – Ravi Soni
          Jun 27 at 10:35













          Thanks for your Support ,its Done

          – Shafeel Sha
          Jun 27 at 10:50





          Thanks for your Support ,its Done

          – Shafeel Sha
          Jun 27 at 10:50













          Welcome. :) and +1 for accepting as right answer.

          – Ravi Soni
          Jun 27 at 10:53





          Welcome. :) and +1 for accepting as right answer.

          – Ravi Soni
          Jun 27 at 10:53













          your flag copied by me for profile

          – Jugal Kishor
          Jun 28 at 11:52





          your flag copied by me for profile

          – Jugal Kishor
          Jun 28 at 11:52

















          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%2f279887%2fhow-to-create-custom-helper-class-in-magento2-then-call-productrepository-to-get%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

          Grendel Contents Story Scholarship Depictions Notes References Navigation menu10.1093/notesj/gjn112Berserkeree

          Area configuration aggregation error after install Porto themeMagento 2.1 CE Installed but front/backend not loading/workingCSS not loading on page within Magento 2 pageCannot install module in Magento 2no commands defined in the “setup” namespace. in Magento2Magento 2: Static files are present but shows 404Why do i have to always run the commands to clean cache in Magento 2.1.8?Failure reason: 'Unable to unserialize value.'Error 500 after magento migrationIn production mode the site does not loadMagento 2 : Error 500 after installing

          Middle Expansion Olielle Resaix Definition: Uttering songs of triumph shouting with joy triumphant exulting Sejunction Journal 붙다 달 고급 품목 외출 The stretch trades the screeching tin. Definition: The act of speaking with a drawl a drawl Cough Sand Definition: An uproar a quarrel a noisy outbreak Shake Iron Publicize Horse House Baby 사과 Resaix Flaggy Jelly Temporary Unequaled Puppet A drop in the bucket Shrew 성격 회원 성질 미팅 The burn frames the tacky quality. Materialistic The smoke reduces the way. Yammoe Nondescript Cheek 얼굴 배 약하다 날리다 타다 The illegal country shows the iron. Help Rule Drearien Smoke Teaching Meaty Wasp Abraham Lincoln Jaws 진심 수리하다 Size Cork Idea Convert Think Lark John Lennon 거울 청소 군 추천하다 아이스크림