Exemplo n.º 1
0
 /**
  * Duplicate images for variations
  *
  * @param array $productsData
  *
  * @return array
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function duplicateImagesForVariations($productsData)
 {
     $imagesForCopy = [];
     foreach ($productsData as $variationId => $simpleProductData) {
         if (!isset($simpleProductData['media_gallery']['images'])) {
             continue;
         }
         foreach ($simpleProductData['media_gallery']['images'] as $imageId => $image) {
             $image['variation_id'] = $variationId;
             if (isset($imagesForCopy[$imageId][0])) {
                 // skip duplicate image for first product
                 unset($imagesForCopy[$imageId][0]);
             }
             $imagesForCopy[$imageId][] = $image;
         }
     }
     foreach ($imagesForCopy as $imageId => $variationImages) {
         foreach ($variationImages as $image) {
             $file = $image['file'];
             $variationId = $image['variation_id'];
             $newFile = $this->media->duplicateImageFromTmp($file);
             $productsData[$variationId]['media_gallery']['images'][$imageId]['file'] = $newFile;
             foreach ($this->variationMediaAttributes->getMediaAttributes() as $attribute) {
                 if (isset($productsData[$variationId][$attribute->getAttributeCode()]) && $productsData[$variationId][$attribute->getAttributeCode()] == $file) {
                     $productsData[$variationId][$attribute->getAttributeCode()] = $newFile;
                 }
             }
         }
     }
     return $productsData;
 }
Exemplo n.º 2
0
 /**
  * @return array
  */
 public function getMediaAttributes()
 {
     return $this->variationMediaAttributes->getMediaAttributes();
 }