119 votes
Accepted

Magento 2: how do customer sections / sections.xml work?

What are exactly those sections ? A section is a piece of customer data grouped together. Each section is represented by key that is used to access and manage data and data itself. Magento loads ...
Volodymyr Kublytskyi's user avatar
117 votes
Accepted

How to implement service contract for a custom module in Magento 2?

I would like to give a bit more detail in addition to the excellent answer of @ryanF. I would like to sum up the reasons to add a repository for custom entities, give examples how to do so, and also ...
Vinai's user avatar
  • 14k
106 votes
Accepted

'Area code not set' issue in custom CLI commands in Magento 2

The area is not set in Magento CLI (it is not required for any core commands). It can be set at the beginning of your command's execute method: /** @var \Magento\Framework\App\State **/ private $...
Alex Paliarush's user avatar
101 votes
Accepted

Magento 2 Allowed Memory exhausted error when compile code

A quick solution for memory limit in Magento 2 command is directly adding memory limit inside command. For Compilation command, php -dmemory_limit=5G bin/magento setup:di:compile For Deployment ...
Rakesh Jesadiya's user avatar
60 votes
Accepted

Magento 2 CSS and JavaScript not loading from correct folder

SOLUTION # 1 (IF YOU WANT TO EDIT XML FILE) I would like you to download Magento 2 zip from magentocommerce.com/download with sample data, create a new db in phpmyadmin, extract zip in htdocs folder. ...
Fayyaz Khattak's user avatar
59 votes
Accepted

Fatal Error Call to a member function dispatch() while call my Block in magento 2

The problem is that your constructor does not match the parent class constructor. To fix that you need to update your constructor: public function __construct( \Magento\Framework\View\Element\...
Raphael at Digital Pianism's user avatar
51 votes
Accepted

How can I change the default product images sizes on Magento 2?

Magento uses the file called view.xml which is maintained at the theme level of the application. So for example, if you are using the default theme luma you should find the view.xml under vendor/...
Atish Goswami's user avatar
50 votes
Accepted

Theming for Magento 2 - Starting from scratch

TL:DR Do you build using the native luma or blank theme ? Or anything else ? This is up to you, declaring a parent theme is optional. If you don't declare a parent you will still fallback to the ...
Ben Crook's user avatar
  • 15.6k
48 votes
Accepted

magento 2: I want display a image in the module template phtml file

Yes you can store images in your module web directories depending on the area of your templates. The path is: Vendor/Module/view/{frontend|adminhtml}/web/images/ Then in your *.phtml files you can ...
Miroslav Petroff's user avatar
47 votes

'Area code not set' issue in custom CLI commands in Magento 2

I've stumbled into this problem again today and it's important to know that this problem is thrown whenever a dependency down the chain initiates an instance that needs to know the state of the ...
Giel Berkers's user avatar
  • 12.2k
47 votes
Accepted

How to change magento2 admin url?

Change Admin Path It is not recommended to change it directly from app/etc/env.php, always prefer the CLI: php bin/magento setup:config:set --backend-frontname="admin_path" Do not add the first / ...
Raphael at Digital Pianism's user avatar
46 votes
Accepted

Why is Magento 2.1.0 released before 2.0.9?

Magento2 is following semantic versioning. This means that the versions consist of major.minor.patch numbers. Whenever there are bugs or security issues solved, Magento will release a new "patch" ...
7ochem's user avatar
  • 7,502
43 votes

How to implement service contract for a custom module in Magento 2?

@Raphael at Digital Pianism: Please refer to the following sample module structure: app/ ├ code/ | ├ Namespace/ | | ├ Custom/ | | | ├ Api/ | | | | ├ ...
ryanF's user avatar
  • 2,269
40 votes

Magento 2: Programmatically Updating Inventory

This works for me: $item = ['qty' => 11]; // For example $product->setStockData(['qty' => $item['qty'], 'is_in_stock' => $item['qty'] > 0]); $product->save(); Edit: This is no ...
Giel Berkers's user avatar
  • 12.2k
39 votes
Accepted

Magento 2: Plugin before/around/after Interaction

Plugins are sorted by sort order first, and then by method prefix. Example: for method with 3 plugins (PluginA, PluginB, PluginC) with following methods and sortOrder: PluginA (sortOrder = 10) ...
Anton Kril's user avatar
  • 4,476
39 votes
Accepted

Add a note under a form field using ui components

You can achieve this using following tag. <item name="notice" xsi:type="string" translate="true">Some note here</item>
Sohel Rana's user avatar
  • 35.6k
38 votes
Accepted

Deprecated save and load methods in Abstract Model

You should use Module Service Contract. For example for product you should use ProductRepositoryInterface <?php /** * * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for ...
KAndy's user avatar
  • 20.7k
35 votes
Accepted

Magento 2 massaction delete not working

Try the following code: <?php namespace Vendor\ModuleName\Controller\Adminhtml\Module; use Magento\Backend\App\Action\Context; use Magento\Ui\Component\MassAction\Filter; use Vendor\ModuleName\...
Bartłomiej Szubert's user avatar
34 votes
Accepted

Error after magento upgrade

I have solved this problem by just simply doing this steps. follow steps : Delete the "di" folder located in var directory (for 2.0 and 2.1) Run this command and go to your project root folder ...
Murtuza Zabuawala's user avatar
34 votes
Accepted

How to override or disable core Plugins in Magento2?

You can disable plugin by name. In your case it authorization. <type name="Magento\Sales\Model\ResourceModel\Order\Plugin\Authorization"> <plugin name="authorization" ...
sergei.sss's user avatar
  • 1,169
33 votes
Accepted

Create Multi Website/Stores in magento 2

Created multi-website in Magento, Steps to create a multistore in admin panel is same as like in magento1.x. Don't forget to change the base url and secure url for the new website/store. Once made ...
saravanavelu's user avatar
  • 3,941
33 votes
Accepted

magento 2 - Invalid credentials for 'https://repo.magento.com/packages.json', aborting

Use your public key as username and private key as password from your magento connect account you can find the public and private key at: https://developer.magento.com/customer/account/ Developer ...
Prince Patel's user avatar
  • 22.6k
33 votes
Accepted

Why can't one switch back to the default mode on Magento 2?

The default mode is neither here nor there. The Magento team really wants you to use either Production Mode on your live site or Developer Mode during Development. The reason why Default Mode exists ...
Kristof at Fooman's user avatar
33 votes
Accepted

Magento 2 : How to load quote by quote id

you can inject in your class an instance of \Magento\Quote\Model\QuoteFactory. protected $quoteFactory; public function __construct( ... \Magento\Quote\Model\QuoteFactory $quoteFactory, ...
Marius's user avatar
  • 198k
32 votes
Accepted

How does Magento2 generate the specific ExtensionFactory and ExtensionAttributeInterface?

First of all autogeneration is happening based on class name suffix, e.g. Factory, ExtensionInterface (see \Magento\Framework\Api\Code\Generator\ExtensionAttributesInterfaceGenerator::...
Alex Paliarush's user avatar
32 votes
Accepted

How to add Cookie Magento 2?

IMO the best approach would be to create a class to wrap the cookie creation and then just use it where you want. The Cookie Class {Vendor}/{Module}/Cookie/Example.php <?php namespace Vendor\...
MauroNigrele's user avatar
  • 3,005
31 votes
Accepted

Magento2 CLI module:enable gives error "Unkown module(s)"

registration.php missing Apparently my Vendorname_Modulename module was missing the registration.php. I'm running the latest Magento2 version from GitHub. Every module has to register itself in the ...
7ochem's user avatar
  • 7,502
31 votes

Error after magento upgrade

Giving full control (read/write/execute) to var and pub directory solved this issue for me. sudo chmod -R 777 var pub Or, you may also try running the command using sudo. sudo php bin/magento setup:...
Mukesh Chapagain's user avatar
31 votes

Constant name is expected. Error

In order to help you debug what's going on, I would suggest to temporary edit the file vendor/magento/framework/Data/Argument/Interpreter/Constant.php From this... public function evaluate(array $...
rou6e's user avatar
  • 1,021

Only top scored, non community-wiki answers of a minimum length are eligible