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;
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
add a comment |
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
add a comment |
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
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
module phtml magento2.3.1 helper
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
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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:
- Make sure your Business Logic, Configuration, and SQL are implemented in the correct places.
- Make sure that CSS, JavaScript, HTML, and XML code are all in the appropriate files (i.e. they should not be inline).
- Use appropriate logic in a Block, Helper, Template, Controller, or Model.
- 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!
add a 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%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
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:
- Make sure your Business Logic, Configuration, and SQL are implemented in the correct places.
- Make sure that CSS, JavaScript, HTML, and XML code are all in the appropriate files (i.e. they should not be inline).
- Use appropriate logic in a Block, Helper, Template, Controller, or Model.
- 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!
add a comment |
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:
- Make sure your Business Logic, Configuration, and SQL are implemented in the correct places.
- Make sure that CSS, JavaScript, HTML, and XML code are all in the appropriate files (i.e. they should not be inline).
- Use appropriate logic in a Block, Helper, Template, Controller, or Model.
- 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!
add a comment |
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:
- Make sure your Business Logic, Configuration, and SQL are implemented in the correct places.
- Make sure that CSS, JavaScript, HTML, and XML code are all in the appropriate files (i.e. they should not be inline).
- Use appropriate logic in a Block, Helper, Template, Controller, or Model.
- 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!
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:
- Make sure your Business Logic, Configuration, and SQL are implemented in the correct places.
- Make sure that CSS, JavaScript, HTML, and XML code are all in the appropriate files (i.e. they should not be inline).
- Use appropriate logic in a Block, Helper, Template, Controller, or Model.
- 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!
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
add a comment |
add a 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%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
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