Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more

Questions tagged [best-practice]

Denotes questions related to best-practices in Magento.

Filter by
Sorted by
Tagged with
0 votes
1 answer
28 views

Why do some core repositories use a data model in the save function while others use a model?

I have a quick question and this could help me determine what is the good practice using the repositories. To provide an example to the question I ask in the title of this subject, I can take as ...
beluga's user avatar
  • 41
0 votes
1 answer
30 views

Magento 2 Coding Practice

recently I came across one developer's code in magento 2, where he was accessing objects in another class to avoid dependency injections. Like for example we have Vendor\Feature\Helpler\Data class and ...
Knight017's user avatar
  • 632
0 votes
1 answer
575 views

Magento 2 - Best practices - Helper vs Model : Which one to get config values?

I cannot seem to find an official information about what is the recommended way to retrieve configuration values in Magento 2. I am searching for the recommended way to retrieve values from the ...
Cladiuss's user avatar
  • 1,279
0 votes
1 answer
145 views

Using Env.php to Override Module Status in Config.php

What I am trying to achieve is overriding specific modules declared as enabled in the app/etc/config.php to be disabled by the app/etc/env.php file. A use case of that would be the 2FA module which I ...
S.Murtadha's user avatar
0 votes
1 answer
57 views

Getting a Product model from db

I've just started in the world of Magento and throughout the process of many questions I have came across one its proving dificult to find the best description for it. Considering the following ...
rpcm's user avatar
  • 3
0 votes
1 answer
710 views

Adding an Extension Attribute to Sales Order Items - Magento 2

I have created some custom attributes for products and using these attributes in order view in customer account orders section. I have deleted few products. When I view the customer orders, it gives ...
Hafiz Muzamal's user avatar
0 votes
2 answers
200 views

Indentation Style (Code style) Magento 2

Hey, I wanna check if there is some documentation about the code style for magento, specially regarding the best practices Indentation style for magento. I will give 2 examples, and I wanna also know ...
Pedro Lima's user avatar
0 votes
1 answer
628 views

What is the best way to override constructor of a class - Magento 2.4.3

I want to make a single line change in the constructor of a core class. What would be the best recommended practice to achieve it. Here is what my existing constructor /** * Download constructor. ...
Hafiz Muzamal's user avatar
0 votes
1 answer
31 views

how do i make an admin grid based on sales_order table (some columns but not all) using best practice?

Let's say I need an admin grid where not all columns of the sales_order table will be, but only some of them. For example: customer_id customer_name nickname How best to solve such a problem?
esca7a's user avatar
  • 21
0 votes
1 answer
321 views

The best ways to practice Magento 2 when not in work

Any recommendations for how to practice Magento 2 when not working? i.e. it's easier when working as you're presented with real life task, issues, clients etc. but when practicing at home, I'm just ...
SNAFU's user avatar
  • 196
0 votes
1 answer
149 views

Join array values and keys between two php arrays

I need to merge (sort of join) two arrays with both same keys, and in result i want to have the values of the first as keys of the second one : Example : $keyArray = [ "key1" => "...
Marwen Jelloul's user avatar
4 votes
0 answers
476 views

Implementation of Composition Instead of Inheritance in Controllers Magento 2

I am trying to implement Magento 2 Coding Standard so I found an Article Here -> https://community.magento.com/t5/Magento-DevBlog/Decomposition-of-Magento-Controllers/ba-p/430883 I have changed my ...
Waqar Ali's user avatar
  • 2,329
1 vote
0 answers
75 views

Should I be integrating Babel with the frontend javascript in my Magento2 module?

I created a magento 2 module which is using mostly javascript. I want to know what is best practice for implementing backwards compatibility across older browsers in magento2.
Justin Collins's user avatar
1 vote
2 answers
85 views

Current best practices for controllers

Now that we're not supposed to extend Action\Action anymore, is the current best practice to create a separate Controller for each CRUD action? One for create, one for delete etc?
web master's user avatar
4 votes
3 answers
260 views

Magento 2 Extension Best practices

If we list the things that make sure the extension has followed the best Magento practices, what it would be? few of them like Do not use object manager (use constructor dependency instead). Do not ...
Hamendra Sunthwal's user avatar
0 votes
1 answer
374 views

Why should I (not) put my extension into app/code?

a dumb question. From: https://devdocs.magento.com/guides/v2.4/extension-dev-guide/build/module-file-structure.html Magento installs third-party components in the <Magento install directory>/...
sv3n's user avatar
  • 11.7k
0 votes
1 answer
122 views

Magento 2: How to add a class to an observer without construct

I am making this observer class to check if a visitor is logged in. use Magento\Framework\Event\ObserverInterface; use Magento\Customer\Model\Session; class CheckLoginObserver implements ...
Kibret's user avatar
  • 43
1 vote
2 answers
2k views

Need fix for the codesniffer warning "The use of function sleep() is discouraged (Magento2.Functions.DiscouragedFunction.Discouraged)"

When I run PHP Code sniffer on my code, I see the below warning. WARNING | The use of function sleep() is discouraged (Magento2.Functions.DiscouragedFunction.Discouraged) Which class method ...
nikin's user avatar
  • 1,132
2 votes
1 answer
588 views

Which files and directories we should commit to VCS

The fresh Magento installation brings a lot of files and folders to the table. When I measure, it takes like ~150MB. However, I don't think we need them all in VCS (i.e. git), because I can always ...
Bunyamin Inan's user avatar
0 votes
1 answer
2k views

What is the fastest way to check if a configurable product is salable?

A product is salable or not is determined based on below logic: Product should be enabled. Product should be marked in-stock. qty -(minus) sum of reserved quantity in inventory_reservation table ...
amitshree's user avatar
  • 7,036
1 vote
0 answers
31 views

Flat catalog tables considered a bad practice since M2.1.x and above? [duplicate]

Magento no longer recommends the use of a flat catalog as a best practice. Continued use of this feature is known to cause performance degradation and other indexing issues. A detailed description and ...
Akif's user avatar
  • 1,541
1 vote
0 answers
33 views

Code Pattern to Define and Use Javscript Callbacks / Hooks

We are using a third party module, that updates prices via AJAX on product / category pages. No we have to react on this update, to update some custom pricing logic. Of course we do not want to patch ...
Alex's user avatar
  • 13.8k
1 vote
1 answer
2k views

Changing the schedule of magento2 Crons

I have on setup on Magento and i have set cronjobs as per Magento guidelines as below. * * * * * /usr/bin/php /var/www/html/magento2/bin/magento cron:run 2>&1 | grep -v "Ran jobs by schedule" &...
Rizwan Khan's user avatar
  • 1,939
0 votes
1 answer
395 views

CQRS module example magento2

Can anyone point to some decent github repository where module implements CQRS, SOLID, DRY and testing? I was reading about MSI, but it is kind of complex and huge and I am looking for something ...
niziou's user avatar
  • 1
0 votes
3 answers
502 views

How to deploy to production server customizations made in vendor folder?

So, We have 3 environments: development, staging and production. .gitignore file includes "vendor" folder and it has been working fine for us fine. Once We pull changes in Staging We would just run: ...
jtalel's user avatar
  • 13
1 vote
2 answers
2k views

Magento 2 remove version number impact

I noticed if we type /magento_version along with site url then it displays our magento version. So anyone with bad intention can check my version and exploit it. to prevent this I can disable the ...
Jackson Wyss's user avatar
2 votes
1 answer
63 views

Best Practice Magento 2 / Composer / Custom Module

Can you tell me what are the best practice when you create a custom module for a project. I would say to put the custom module related to the project in app/code/MyNamespace/MyModule and all Generic ...
Sony's user avatar
  • 1,154
2 votes
1 answer
806 views

How to load current product in Magento 2 without using deprecated functionality?

The core uses two deprecated classes to load the current product within the block class on the front end: \Magento\Catalog\Block\Product\AbstractProduct \Magento\Framework\Registry See: \Magento\...
bassplayer7's user avatar
  • 2,196
4 votes
2 answers
3k views

Magento 2 - Override a helper using plugin

What is the best practice to override a helper? is it through Preference or Plugin? And how can I override a helper using Plugin?
Shoaib Munir's user avatar
  • 9,482
1 vote
0 answers
91 views

Headless Magento

Please let me know the best practices to be followed while creating an e-commerce solution which uses the headless approach. Whether Magento or frontend-side need to implement custom business logic ...
Binu Mathew's user avatar
0 votes
0 answers
89 views

What is the best way to save a custom field in shipping address?

I have added a custom field on checkout in shipping address section using below code. etc/frontend/di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ...
amitshree's user avatar
  • 7,036
2 votes
1 answer
112 views

Magento 2: best practice building classes

I need some advice how to structure my code in magento 2. I am working on an ERP interface to import and export products, customers and orders. So I need some helper classes to take care of some ...
omsta's user avatar
  • 698
2 votes
1 answer
3k views

Magento Recommended way to add comment to order

I am looking for the Magento recommended best practice for adding a comment to an order. I can easily accomplish this using things such as $order->addCommentToStatusHistory($message)->save() and ...
rain2o's user avatar
  • 465
0 votes
1 answer
998 views

What is the best method to retrieve a SINGLE ITEM order details in Magento2?

I am currently using the \Magento\Sales\Model\OrderFactory $_orderFactory and loadByIncrementId($id) in my custom block and calling it in my .phtml file. I get basic details of the order, but I ...
MSQ's user avatar
  • 211
2 votes
0 answers
288 views

M2: getBaseUrl() - StoreManagerInterface vs StoreConfigInterface

If someone asks for getting base URL, the answer is always to use StoreManagerInterface, like ... protected $storeManager; public function __construct( ... \Magento\Store\Model\...
sv3n's user avatar
  • 11.7k
2 votes
1 answer
72 views

How to replace the production website with the development one?

I've been let down with a developer going AWOL half-way through a project and have had to learn as I go to get our new site sorted. The current site is : ourdomain.co.uk/ (not magento) We have the ...
Ryan's user avatar
  • 21
21 votes
2 answers
3k views

Magento 2 - good practice to use/avoid magic getters?

Magic getters on Varien_Object (M1) and DataObject (M2) are common practice, but with Magento 2 it feels wrong to use it. Good: easy to read/write Bad It causes problems when using digits in keys (...
sv3n's user avatar
  • 11.7k
1 vote
0 answers
161 views

Outdated codesniffer in MEQP2 composer.json for Magento 2.2?

How to correctly test against MEQP2 standard? Normally i use vendor/bin/phpcs --standard=PSR2 To supress errors a i use this: //phpcs:ignore or //phpcs:disable PSR2 When using MEQP2 standards ...
sv3n's user avatar
  • 11.7k
1 vote
1 answer
360 views

custom extensions - are hyphens allowed in the Extension name?

This is a follow up on the Magento 2 Extension naming convention question here. I've learned thus far that you need a Vendor Name an Extension (or Module) name a combination of both like ...
vrms's user avatar
  • 115
0 votes
1 answer
52 views

M1/M2 | Extensions - best practices for naming, versioning, author

was wondering what is the best practice for ... naming an extentsion? where to put the copyright holders /authors name? versioning (major.minor.patch maybe) of extensions I guess there must be ...
vrms's user avatar
  • 115
0 votes
1 answer
99 views

Magento 1.9 Database transfer

We are trying to create our product with a clean version of Magento. But we need to transfer our database. Based on our research we have a couple of choices. Transfer important tables as Mysql dump. ...
mahdi morshedi's user avatar
3 votes
2 answers
359 views

Best practice Magento dev environment, how do teams develop Magento? [closed]

I'm trying to set up a dev environment for my team to work together on 1 Magento project. But I don't know if I should use a shared server with a Magento installation or if we should all install ...
jonasG's user avatar
  • 144
0 votes
1 answer
400 views

DI Compile fails with "Area code not set" error

I'm trying to use the \Magento\Sales\Model\InvoiceOrder class to invoice some orders. If I include the class in my constructor, however, then I get the "Area code not set: Area code must be set before ...
Colin Pickup's user avatar
7 votes
6 answers
9k views

Best practice for local development

I've been trying to find the best way on how to develop a Magento 2 webshop locally. So far, I had no luck: lots of JS, CSS and 404 errors (on which I tried lots of fixes which only partly solved my ...
Condor's user avatar
  • 637
0 votes
3 answers
84 views

CSS good practice : inside theme or module folder?

I just want to know what is the best practice about css in Magento2. We have the possibility to have design in Vendor_Name/MyModule/view/frontend/web/css and we can also put the design in : app/...
Temp's user avatar
  • 63
3 votes
1 answer
777 views

Magento 2 and git, best practice for custom module development

I have trouble wrapping my head around a very particular issue concerning a development setup for magento 2. I have read a lot about using composer and git. It makes a lot of sense to NOT include the ...
omsta's user avatar
  • 698
0 votes
0 answers
33 views

CSS Best Practices - single time use of CSS

I've made a module with a custom page. On this page I have a list of around 20 checkboxes, each followed by a single word for identification. I would like to display this with CSS in multiple columns. ...
Gloweye's user avatar
  • 133
0 votes
3 answers
828 views

How to create a search bar that fixes or prevents spelling mistakes?

So my customers tend to be more so individuals who are not computer literate and often make errors when searching for our products. What is the best way to work out what they're trying to search for ...
John's user avatar
  • 837
0 votes
1 answer
77 views

How to get names, IDs and details of my categories without falling in to bad practice?

It's been commonly accepted you should never use \Magento\Framework\App\ObjectManager::getInstance() I can link sources explaining why if needed. Given this how would I go about getting the names of ...
John's user avatar
  • 837
1 vote
1 answer
157 views

Testing/Development Environment on local server

I need to create a local development environment and struggling a little with the setup. I want to replicate my live server as close as I possibly can. I hope I'm posting this question in a right ...
Greg's user avatar
  • 2,729

1
2 3 4 5