2 added 47 characters in body
source | link

Try following way:

public function __construct(
    \Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
    \Magento\Catalog\Model\Product $product,
    \Magento\Framework\Registry $registry
) {
    $this->productRepository = $productRepository;
    $this->product = $product;
    $this->registry = $registry;

}

Now

$this->registry->register('isSecureArea', true);
$product = $this->product->load(12);
$existingMediaGalleryEntries = $product->getMediaGalleryEntries();
foreach ($existingMediaGalleryEntries as $key => $entry) {
    $entry->setLabel('BlahBlah''BlahBlah-1');
}
$product->setStoreId(0);
$product->setMediaGalleryEntries($existingMediaGalleryEntries);
//$this->productRepository->save($product);
$product->save();

Try following way:

public function __construct(
    \Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
    \Magento\Catalog\Model\Product $product,
    \Magento\Framework\Registry $registry
) {
    $this->productRepository = $productRepository;
    $this->product = $product;
    $this->registry = $registry;

}

Now

$this->registry->register('isSecureArea', true);
$product = $this->product->load(1);
$existingMediaGalleryEntries = $product->getMediaGalleryEntries();
foreach ($existingMediaGalleryEntries as $key => $entry) {
    $entry->setLabel('BlahBlah');
}

$product->setMediaGalleryEntries($existingMediaGalleryEntries);
$this->productRepository->save($product);

Try following way:

public function __construct(
    \Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
    \Magento\Catalog\Model\Product $product,
    \Magento\Framework\Registry $registry
) {
    $this->productRepository = $productRepository;
    $this->product = $product;
    $this->registry = $registry;

}

Now

$this->registry->register('isSecureArea', true);
$product = $this->product->load(2);
$existingMediaGalleryEntries = $product->getMediaGalleryEntries();
foreach ($existingMediaGalleryEntries as $key => $entry) {
    $entry->setLabel('BlahBlah-1');
}
$product->setStoreId(0);
$product->setMediaGalleryEntries($existingMediaGalleryEntries);
//$this->productRepository->save($product);
$product->save();
1
source | link

Try following way:

public function __construct(
    \Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
    \Magento\Catalog\Model\Product $product,
    \Magento\Framework\Registry $registry
) {
    $this->productRepository = $productRepository;
    $this->product = $product;
    $this->registry = $registry;

}

Now

$this->registry->register('isSecureArea', true);
$product = $this->product->load(1);
$existingMediaGalleryEntries = $product->getMediaGalleryEntries();
foreach ($existingMediaGalleryEntries as $key => $entry) {
    $entry->setLabel('BlahBlah');
}

$product->setMediaGalleryEntries($existingMediaGalleryEntries);
$this->productRepository->save($product);