I have a problem with ProductProcessUrlRewriteSavingObserver when I try to save product attribute data by the Product resource saveAttribute method. Magento 2.4.3 changechanges one validation method in this observer. Now method wantwants to check differences between product originDataorigin data 'website_ids' and actual websites_ids. It works when I save a product, but it causes a warning when I use saveAttribute method.
When I try to save data for only one attribute it returns a warning:
Warning: array_diff(): Expected parameter 1 to be an array, null given in /var/www/html/vendor/magento/module-catalog-url-rewrite/Observer/ProductProcessUrlRewriteSavingObserver.php on line 130
.
Code to save attribute data:
$product->setData('custom_attribute', $customValue);
$this->productResource->saveAttribute($product, 'custom_attribute');
The new validation method looks like this:
/**
* Is website assignment updated
*
* @param Product $product
* @return bool
*/
private function isWebsiteChanged(Product $product)
{
$oldWebsiteIds = $product->getOrigData('website_ids');
$newWebsiteIds = $product->getWebsiteIds();
return array_diff($oldWebsiteIds, $newWebsiteIds) || array_diff($newWebsiteIds, $oldWebsiteIds);
}
When I was debugging this code I found out $product->getOrigData('website_ids')
returns null. I have no idea how I can fix this.
Thank you for any idea.