Skip to main content
123 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
119 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
  • 14.1k
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
50 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.3k
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,562
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,179
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.9k
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,041
26 votes

Getting simple products from configurable

The answers to this question are wrong. Although their implementations might work, it's not the proper way to handle this. The correct way to do this is by using Magentos' service contracts and data ...
Giel Berkers's user avatar
  • 12.3k
24 votes
Accepted

How to "add to cart" a product with custom input field and save it to Database?

To accomplish this you could use Magento built-in "additional_options" functionality so that you don't have to edit email template, admin order view, customer order view (etc) to display ...
MagePal Extensions's user avatar
23 votes

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

You shouldn't use setAreaCode in the __construct for CLI commands. When you run any command Magento collect and create instance for each script registered in your application. If there are more than ...
Eugene Kovalyov's user avatar
23 votes
Accepted

How to show success message in session Magento2

In Magento 2, we can do achieve this in two steps: First, we need to assign the message to 'messageManager' from your module as below: $this->messageManager->addSuccess(__('This is a success ...
Jino's user avatar
  • 793
23 votes
Accepted

how to get main product image url in phtml file?

Try this $product = $block->getProduct(); $imageUrl = $this->helper('Magento\Catalog\Helper\Image') ->init($product, 'product_base_image') ->...
Dinesh Yadav's user avatar
  • 6,465
22 votes

Magento 2: Programmatically Updating Inventory

If you are using the @giel-berkers solution, you may need to set isInStock also, because it will not be automatically sets. So, the following code was useful for me: public function __construct( \...
spiilmusic's user avatar
20 votes
Accepted

Magento 2 can not upload product images

Solved This error can be caused by several server configuration issues. Each error will always present itself with the same generic warning from Magento 2: Attention: We don't recognize or support ...
Blizzardengle's user avatar
19 votes
Accepted

Constant name is expected. Error

I think some problem in your etc folder. check all xml files. Constant name should be in CAPITAL letters. any of your constant remain in small letters. check it and correct it. Hope this will solve ...
A chauhan's user avatar
  • 216
19 votes
Accepted

How to override system.xml core file in magento2

Magento may load our custom system config and merge into the exist nodes. In our custom system config, we should try: Tested on Magento 2.0.2 and 2.1.2 Vendor/ModuleName/etc/adminhtml/system.xml <?...
Khoa TruongDinh's user avatar
18 votes

Constant name is expected. Error

Edit, extra information: As explained below, please investigate folder names/case for your files, also make sure the class defined matches your file path. Incorrect folder case/names means the ...
masitko's user avatar
  • 281
17 votes

Magento 2 CSS and JavaScript not loading from correct folder

you just need to update the apache2.conf file. On Ubuntu 16.04 Open and edit the file /etc/apache2/apache2.conf Navigate to the place in the apache2.conf file <Directory /var/www/> Change "...
S.A's user avatar
  • 171
16 votes

Magento 2: setdata() is not saving the values into the database

Hi guys thanks for the support. Finally i found the solution after searching many sites. In default Magento will try to update the database not insertion when we trying to save the data with the ...
Selva Kumar's user avatar
15 votes

Magento 2 - How to retrieve product informations

On top of others answers, I highly suggest using the following service contracts methods: \Magento\Catalog\Api\ProductRepositoryInterface::getById : to load a product by id \Magento\Catalog\Api\...
Raphael at Digital Pianism's user avatar
15 votes

Magento 2 Allowed Memory exhausted error when compile code

use this 'dirty' way php -dmemory_limit=-1 bin/magento setup:di:compile
Ansyori's user avatar
  • 842
15 votes

How to show success message in session Magento2

Magento2 is using MessageInterface to add all message, please use below code to show Messages Magento Message Framework class use \Magento\Framework\Message\ManagerInterface; use below code in your ...
Rahul Anand's user avatar
14 votes

Magento 2 CSS and JavaScript not loading from correct folder

For me it was simply because mod_rewrite wasn't enabled. sudo a2enmod rewrite and service apache2 restart
Haim's user avatar
  • 2,154
14 votes
Accepted

How to disable the minicart popup function completely in Magento2

The feature to disable the popup is actually built into Magento2. To disable, go to Stores > Configuration > Sales > Checkout > Shopping Cart Sidebar and change "Display Shopping Cart ...
themanwhoknowstheman's user avatar
14 votes

How to override or disable core Plugins in Magento2?

If you use sergei.sss 1st solution, you will get the error of duplicate Magento\Sales\Model\ResourceModel\Order\Plugin\Authorization The correct way to do that is: <type name="Magento\Sales\Model\...
fudu's user avatar
  • 1,298
13 votes

Magento 2 CSS and JavaScript not loading from correct folder

Here is the simplest solution if showing version name in css path like : pub/static/version323334/ then run this query in mysql INSERT INTO core_config_data (path, value) VALUES ('dev/static/sign',...
Surendra Kumar Ahir's user avatar
13 votes
Accepted

$_File array empty in Magento 2 while Uploading file at admin form

It was my bad !! I forgot to add enctype'=>'multipart/form-data You have to add following code while creating formFactory $form = $this->_formFactory->create( ['data' => ...
Bhupendra Jadeja's user avatar
12 votes

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

In most cases exception is caused by some actions performed in console command. Solution (instead of setting area code) is to emulate area code and perform action using $this->state->...
Bartosz Kubicki's user avatar

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