Skip to content

Custom attributes values not updated #12186

@danyvega1990

Description

@danyvega1990

When I tried to update a custom attribute from an existing product using the save method in the ProductRepositoryInterface the code don't throw any errors but the attribute remains with the old data.

Preconditions

  1. Magento 2.1.8
  2. PHP 7.0

Steps to reproduce

  • namespace Vendor\Module\Cron;
  • use Magento\Catalog\Api\ProductRepositoryInterface;
  • use Magento\CatalogInventory\Api\StockRegistryInterface;
  • class CronDownloadData
  • {
  • protected $productRepository;
    
  • protected $stockRegistry;
  • public function __construct(
    
  •     SunskyProductRepositoryInterface $repository,
    
  •     DirectoryList $directoryList,
    
  •     ProductRepositoryInterface $productRepository,
    
  •     StockRegistryInterface $stockRegistry
    
  • ) {
  •     $this->productRepository = $productRepository;
    
  •     $this->stockRegistry = $stockRegistry;
    
  • }
    
  • public function updateLocalProduct($modelObj){
  •     try {
    
  •         $local_product = $this->productRepository->get($modelObj->getItem_no());
    
  •         $local_product->setCustomAttribute('description', 'Some description');
    
  •         $this->productRepository->save($local_product);
    
  •     } catch (\Exception $ex){
    
  •         // nothing to do this time;
    
  •     }
    
  • }
    
  • }

Expected result

  1. The existing product shows the new description.

Actual result

  1. Description not update at all

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fixed in 2.2.xThe issue has been fixed in 2.2 release lineIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releaseReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions