How to fix the «No such entity» error on a product save in Magento 2.2.6?

backend
model-save
bug
product
bug-fix
backend-product
magento226

(Dmitry Fedyuk) #1

02


How did I upgrade gymstar.ca from Magento 2.1.9 to 2.2.6?
(Dmitry Fedyuk) #2

How to fix

Step 1

Replace the line:


with the following one:

if (!$this->hasWebsiteIds() || self::is_assoc($this->getData('website_ids'))) {

Step 2

Add the following method to the Magento\Catalog\Model\Product class:

/**
 * 2018-10-02 Dmitry Fedyuk https://www.upwork.com/fl/mage2pro
 * "How to fix the «No such entity» error on a product save in Magento 2.2.6?"
 * https://mage2.pro/t/5691
 * @used-by getWebsiteIds()
 * @param array(int|string => mixed) $a
 * @return bool
 */
private static function is_assoc(array $a) {
	if (!($r = !$a)) { /** @var bool $r */
		foreach (array_keys($a) as $k => $v) {
			if ($k !== $v) {
				$r = true;
				break;
			}
		}
	}
	return $r;
}