Question

I'm trying to build a module that gets product-data externally and updates existing products to do so. Fetching the products hasn't been a problem,I've been able to do so in a number of ways.

Updating the Description- and Short Description-Texts of the products however seems trickier.

I've found numerous sources citing a setDescription function of the Magento\Catalog\Model\Product Class. That seems to have been removed in recent versions of Magento though. Is the functionality just hidden in one of the other Setters?

Was it helpful?

Solution

As a quick answer, the class Magento\Catalog\Model\Product (by inheritance) is using the magic method __call() from Magento\Framework\DataObject.php to reach to the values of the product attributes, so basically you can use the getDescription() / setDescription() methods directly as it will (behind the scenes) call the getData() / setData() methods for the 'description' key.

I recommend a more thorough reading on this topic so that it becomes clear why this is implemented this way and how to use it in your own custom modules with your own custom models.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top