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 $...
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 ...
35
votes
Accepted
Exception handling in Magento 2
The easiest way to start logging your exceptions would be to inject the Psr\Log\LoggerInterface into your class's constructor:
private $logger;
public function __construct(\Psr\Log\LoggerInterface $...
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 ...
22
votes
Magento 2: Requested store is not found
I just recently came across this same situation after migrating from Magento 1.6.1.0 to 2.1.4 and hope my answer can be of assistance. The problem came from deleting multiple stores 96 of them to be ...
20
votes
Accepted
Magento 2: Requested store is not found
You need to run the following query in your database, and then try to open the website.
SET FOREIGN_KEY_CHECKS=0;
UPDATE `store` SET store_id = 0 WHERE code='admin';
UPDATE `store_group` SET group_id ...
14
votes
Accepted
Magento2 - ProductRepository how to catch Exception if sku does not exist
I thought I could catch that using generic php Exception class, but it seems we need to use the concrete throwed Exception
Using this code, then the try/catch block works
try {
$product = $...
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->...
12
votes
Magento2.2 - - Failed to read session data
Adding an answer for posterity as this was already correctly resolved in the comments by Anthony.
When using Redis to store the session data, the Warning: session_start(): Failed to read session data ...
11
votes
Magento 2.0: Exception printing is disabled by default for security reasons
Exception errors are stored as number named files in var/report/ except if the directory permissions are so messed up that Magento either cannot write there or tries to store its cache in the system /...
11
votes
Accepted
Magento 2 : Event Observer Exception Not Showing in Screen
I search some more things on this and finaly found my solution,
I need to just change the observer code like this.
app\code\Vendor\Extension\Observer\RemovecartbeforeObserver.php
use Magento\...
10
votes
Accepted
Magento 2: 'Invalid sender data' While sending custom Email
Try with below code,
public function senderEmail($type = null, $storeId = null)
{
$sender ['email'] = $this->scopeConfig->getValue(
self::...
10
votes
Category error : Item (Magento\Catalog\Model\Category\Interceptor) with the same ID "191" already exists
Delete records from 'url_rewrite' table where "entity_type" is "category".
run php bin/magento indexer:reindex
10
votes
Why there are commands missing in bin/magento?
In my case I was setting up a new server and had copied the database over from a development site. Although I had an app/etc/env.php file and it was pointing at the correct db, it was missing the ...
10
votes
Accepted
M 2.3.4 - "Infinite loop detected..." exception on OPC, how to get items in the cart?
Getting items directly from session was causing this error so I only got quote id from session and then used CartRepositoryInterface to retrieve items.
$session = $objectManager->get('\Magento\...
9
votes
Accepted
Custom Exceptions for module for Magento 2
I can't guarantee that it's the best solution but when reading the source code of Magento 2 core files most modules do it this way:
Create a new folder called Exception in your module's directory.
...
9
votes
Magento 2: Requested store is not found
This generally happens whenever config.php and the database get out of sync. For example, whenever I import a database back to my local development environment.
Here were the steps I used to ...
9
votes
Accepted
Magento 2.3: temando.CRITICAL: "accountID" is required. Enter and try again
Please run the below commands and try again:
php bin/magento module:disable Temando_Shipping
rm -rf var/cache/ generated/code pub/static/frontend pub/static/adminhtml
php bin/magento setup:upgrade
php ...
8
votes
Category error : Item (Magento\Catalog\Model\Category\Interceptor) with the same ID "191" already exists
The following SQL query cleans up duplicate category rewrites. Do not use without a backup.
You can use n98-magerun2 db:console or any other mysql client:
delete
from url_rewrite
where ...
8
votes
Why there are commands missing in bin/magento?
Some commands became available only after installation.
The mentioned exception appears once you try to run such commands before installation.
Probably you missed installing Magento.
8
votes
Magento2.2 - - Failed to read session data
This issue can fixed by increase max_concurrency.
It will relate to your traffic and server conditions. In my case i'm able to solved this problem by increase max_concurrency from 6 to 24
This is ...
8
votes
Accepted
Magento 2.3.2 throws DOMXPath exception in backend ("Stores > Configuration") after upgrade from 2.2.7
This issue might be generated due to wrong XML configuration.
Kindly check your customize module and third-party module.
Check di.xml, events.xml,system.xml and router.xml file in your modules.
7
votes
'Area code not set' issue in custom CLI commands in Magento 2
In magento 2 if you set AreaCode but still get this error then please try following code.
Use Magento\Framework\App\Bootstrap;
include app/bootstrap.php;
$bootstrap = Bootstrap::create(BP, $_SERVER);
...
7
votes
Magento2 custom module overrides layout: The element "checkout.cart.item.renderers" already has a child with alias "simple" in exception log
My version override based of method getItemRenderer of Magento\Checkout\Block\Cart\AbstractCart, used variable OverriddenTemplates.
file vendor/module/view/frontend/layout/...
7
votes
Accepted
How should I define and use a custom module Exception?
Are there any rules for how I should do it?
Yes. If you take a look at app/Mage.php in the exception() method, you will see that it looks for an exception that matches the pattern $module . '...
7
votes
Accepted
Magento2 custom collection invalid method exception
Try to get collection the following way:
$productCollection = $this->agencyProductFactory->create()
->getCollection()->addFieldToFilter('zw_agency_product_id', 1);
7
votes
Accepted
Exception usage in magento2
Magento throw, \Magento\Framework\Exception\AlreadyExistsException error type when we have we have tried to a new account on an existing email address.
$result = $connection->fetchOne($select, $...
6
votes
'Area code not set' issue in custom CLI commands in Magento 2
for this areaCode issue, if the 'frontend' parameter is not working, try :
$this->_state->setAreaCode(\Magento\Framework\App\Area::AREA_GLOBAL);
was working for me, hope it helps
6
votes
Exception handling in Magento 2
Magento2 has different types of Exception handlers, for example:
StateException
InputException
InvalidEmailOrPasswordException
MailException
NotFoundException
ValidatorException
Etc.
All handler ...
6
votes
Magento 2: 'Invalid sender data' While sending custom Email
The problem comes from your setFrom method.
I suggest you try to replace:
->setFrom($adminAmail)
With:
->setFrom([
'email' => $this->scopeConfig->getValue(self::EMAIL_TEMPLATE, ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
exception × 292magento2 × 134
error × 53
magento-1.9 × 36
magento2.3 × 14
blocks × 13
product × 12
magento-2.1 × 10
magento2.2 × 10
php × 9
database × 9
magento-1 × 9
category × 8
admin × 7
layout × 7
cart × 7
log × 7
checkout × 6
theme × 6
debugging × 6
email × 5
xml × 5
cache × 5
installation × 5
developer-mode × 5