Skip to content

Insert product images on multiple websites problem #14413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
guillermogallego opened this issue Mar 28, 2018 · 4 comments
Closed

Insert product images on multiple websites problem #14413

guillermogallego opened this issue Mar 28, 2018 · 4 comments
Labels
Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P3 May be fixed according to the position in the backlog. Progress: done Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. stale issue

Comments

@guillermogallego
Copy link

I have created a script to insert images into products, the images are inserted correctly but the labels and roles do not do it for all websites, only for the default website

Preconditions

Magento 2.2.3
Php 7.1
Centos 7 with CPANEL
I configure 3 Websites and theirs views

Steps to reproduce

`
use Magento\Framework\App\Bootstrap;

include('../app/bootstrap.php');

// Get all premium products
$pps = $db->query_array("SELECT id_producto, sku FROM productos_has_tienda");

// Magento bootstrap
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');

// Product repository object
$productRepository = $objectManager->get('\Magento\Catalog\Model\ProductRepository');

// mediaGalleryProcessor
$mediaGalleryProcessor = $objectManager->get('Magento\Catalog\Model\Product\Gallery\Processor');

// Image content object
$imageContent = $objectManager->get('\Magento\Framework\Api\Data\ImageContentInterfaceFactory');

// Image processor
$imageProcessor = $objectManager->get('Magento\Framework\Api\ImageProcessorInterface');

// Get all products to import
$pps = $db->query_array("SELECT id_producto, sku FROM productos_has_tienda");

// for each product to import
foreach ($pps as $p){

$product = $productRepository->get($p['sku']);

echo $product->getName()."\n";
echo "Insert images...\n";

$images = $db->query_array("
SELECT s3_name
FROM productos_imagen
WHERE id_producto = ".$p['id_producto']."
ORDER BY id_imagen ASC
");

$ci = 0;
foreach ($images as $i){
$newEntry = array();
$newEntry['disabled'] = false;
$newEntry['label'] = $product->getName();
$newEntry['position'] = $ci;
$newEntry['media_type'] = "image";
($ci == 0) ? $newEntry['types'] = ['image', 'small_image', 'thumbnail'] : $newEntry['types'] = [];

$contentDataObject = $imageContent->create()
  ->setName(getFriedly($product->getName()).".jpg")
  ->setBase64EncodedData(base64_encode(file_get_contents("http://cdns3.amazonaws.com/i/".$i['s3_name']."G")))
  ->setType("image/jpeg");

$newEntry['content'] = $contentDataObject;

/** @var ImageContentInterface $contentDataObject */
$contentDataObject = $newEntry['content'];

/** @var \Magento\Catalog\Model\Product\Media\Config $mediaConfig */
$mediaConfig = $product->getMediaConfig();
$mediaTmpPath = $mediaConfig->getBaseTmpMediaPath();
$relativeFilePath = $imageProcessor->processImageContent($mediaTmpPath, $contentDataObject);
$tmpFilePath = $mediaConfig->getTmpMediaShortUrl($relativeFilePath);

$imageFileUri = $mediaGalleryProcessor->addImage(
  $product,
  $tmpFilePath,
  $newEntry['types'],
  true,
  $newEntry['disabled']
);

// Update additional fields that are still empty after addImage call
$mediaGalleryProcessor->updateImage(
   $product,
   $imageFileUri,
   [
     'label' => $newEntry['label'],
     'position' => $newEntry['position'],
     'disabled' => $newEntry['disabled'],
     'media_type' => $newEntry['media_type'],
   ]
);

$ci++;

}
$product->save();
}
`

Expected result

Insert images with labels and roles in all websites

Actual result

Only in the default website the images have label and roles

@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Mar 28, 2018
@guillermogallego guillermogallego changed the title Image Insert multiple websites problem Insert product images on multiple websites problem Mar 28, 2018
@guillermogallego
Copy link
Author

I think this problem is related to my other entry #14287

@magento-engcom-team magento-engcom-team added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release labels Apr 12, 2018
@magento-engcom-team
Copy link
Contributor

@guillermogallego, thank you for your report.
We've acknowledged the issue and added to our backlog.

@riconeitzel
Copy link
Contributor

riconeitzel commented Sep 2, 2020

so, this is still an issue in 2.3.5?

@ghost ghost removed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development labels Oct 20, 2020
@magento-engcom-team magento-engcom-team added Priority: P3 May be fixed according to the position in the backlog. Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. labels Nov 30, 2020
@stale
Copy link

stale bot commented Feb 15, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 14 days if no further activity occurs. Is this issue still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? Thank you for your contributions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P3 May be fixed according to the position in the backlog. Progress: done Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. stale issue
Projects
None yet
Development

No branches or pull requests

4 participants