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 ...
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 ...
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 $...
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
...
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. ...
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\...
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/...
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 ...
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 ...
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 ...
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 / ...
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" ...
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/
| | | | ├ ...
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 ...
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)
...
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>
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 ...
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\...
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 ...
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
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 ...
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 ...
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 ...
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,
...
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::...
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\...
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 ...
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:...
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 $...
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