Questions? (+84) 247 300 6665 or hr@hri.com.vn

Các lỗi thường gặp trên magento hiện nay

27/10/2020

Lỗi checkout:

[2020-10-27 22:15:21] main.CRITICAL: Notice: Undefined index: product_id in /vendor/magento/module-catalog-inventory/Model/StockManagement.php on line 106 {“exception”:”[object] (Exception(code: 0): Notice: Undefined index: product_id in /vendor/magento/module-catalog-inventory/Model/StockManagement.php on line 106 at vendor/magento/framework/App/ErrorHandler.php:61)”} []

Mô tả: Lỗi này xuất xảy ra khi magento chứa nhiều website.

Cách sửa:

  1. Backup table “cataloginventory_stock_item”
  2. Chạy scriptUPDATE `cataloginventory_stock_item` SET `website_id`=0 WHERE `website_id`!=0

No such entity – Fix for Magento 2

If you receive the error message “No such entity.”, “No such entity with” or “No such entity with customerId” in Magento 2, the issue usually occurred when you try to load not existing object via Magento 2 Repository Class.

To debug this issue, please open the file

vendor/magento/framework/Exception/NoSuchEntityException.php

and at the beginning of the __construct method temporary add debug backtrace code:

foreach (debug_backtrace() as $_stack) {
    echo ($_stack["file"] ? $_stack["file"] : '') . ':' .
        ($_stack["line"] ? $_stack["line"] : '') . ' - ' .
        ($_stack["function"] ? $_stack["function"] : '');
}
exit();

example:

foreach (debug_backtrace() as $_stack) {
    echo ($_stack["file"] ? $_stack["file"] : '') . ':' .
        ($_stack["line"] ? $_stack["line"] : '') . ' - ' .
        ($_stack["function"] ? $_stack["function"] : '');
}
exit();

save the file and refresh the page.

You will see the debug backtrace that will allow you to define the issue source and you will get an idea how to fix it.

Usually third party Magento 2 extensions lead up to this problem, so you can override their code and add “try-catch” exception.

Don’t forget to revert changes in NoSuchEntityException.php file after you’re finished.


Lỗi resize ảnh gif:
Mô tả: Khi magento resize file gif. xuất hiện background đen. Lỗi này trên magento 2.3.2.
Nguyên nhân: ảnh gif ko hổ trợ Alpha.

Cách sửa:

app/code/YourVendor/YourModule/etc/di.xml
app/code/YourVendor/YourModule/Image/Adapter/Gd2.php
namespace YourVendor\YourModule\Image\Adapter;

class Gd2 extends \Magento\Framework\Image\Adapter\Gd2
{
    public function checkAlpha($fileName)
    {
        $fileType = $this->getImageType();
        if (in_array($fileType, [IMAGETYPE_GIF])) {
            return false;
        }
        return (ord(file_get_contents($fileName, false, null, 25, 1)) & 6 & 4) == 4;
    }
}
Share this job
BACK TO BLOG