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 ...
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 ...
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
...
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 ...
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 ...
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" ...
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" ...
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 ...
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 $...
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 ...
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 ...
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 ...
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 ...
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')
->...
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(
\...
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 ...
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 ...
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
<?...
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 ...
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 "...
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 ...
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\...
15
votes
Magento 2 Allowed Memory exhausted error when compile code
use this 'dirty' way
php -dmemory_limit=-1 bin/magento setup:di:compile
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 ...
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
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 ...
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\...
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',...
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' => ...
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->...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
magento-2.0 × 555magento2 × 373
magento-2.1 × 67
module × 27
layout × 25
magento2.2 × 23
magento2.3 × 19
rest-api × 19
api × 17
theme × 14
database × 12
error × 12
blocks × 12
product × 11
uicomponent × 11
magento-2.0.7 × 11
php × 10
admin × 10
category × 10
attributes × 10
event-observer × 10
adminhtml × 10
overrides × 10
upgrade × 10
configuration × 10