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;
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
add a comment |
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
add a comment |
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
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
magento2 cart product-page
asked Jun 27 at 10:02
Shafeel ShaShafeel Sha
1098 bronze badges
1098 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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);
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
|
show 1 more comment
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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);
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
|
show 1 more comment
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);
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
|
show 1 more comment
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);
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);
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
|
show 1 more comment
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
|
show 1 more comment
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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