Example #1
0
 /**
  * Import 'images alt' value
  *
  * @param \XLite\Model\Product $model  Product
  * @param array                $value  Value
  * @param array                $column Column info
  *
  * @return void
  */
 protected function importImagesAltColumn(\XLite\Model\Product $model, array $value, array $column)
 {
     if ($value) {
         foreach ($value as $index => $alt) {
             $image = $model->getImages()->get($index);
             if ($image) {
                 $image->setAlt($alt);
             }
         }
     }
 }
 /**
  * {@inheritDoc}
  */
 public function getImages()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getImages', array());
     return parent::getImages();
 }
Example #3
0
 /**
  * Import images
  *
  * @param \XLite\Model\Product $product Product
  * @param string               $data    Data
  *
  * @return void
  */
 protected function importImages(\XLite\Model\Product $product, $data)
 {
     // Save old images ids' list
     $oldImageIds = array();
     foreach ($product->getImages() as $image) {
         $oldImageIds[] = $image->getId();
     }
     if ($data) {
         // Load images
         foreach (explode(';', $data) as $url) {
             $url = trim($url);
             $hash = \Includes\Utils\FileManager::getHash($url);
             $image = null;
             if ($hash) {
                 foreach ($product->getImages() as $i) {
                     if ($i->getHash() == $hash) {
                         $image = $i;
                         $key = array_search($i->getId(), $oldImageIds);
                         unset($oldImageIds[$key]);
                         break;
                     }
                 }
             }
             if (!$image) {
                 $image = new \XLite\Model\Image\Product\Image();
                 $image->setProduct($product);
                 $result = preg_match('/^(https?|ftp):\\/\\//Ss', $url) ? $image->loadFromURL($url) : $image->loadFromLocalFile($url);
                 if ($result) {
                     $product->addImages($image);
                     \XLite\Core\Database::getEM()->persist($image);
                 } else {
                     $this->logImportWarning(static::t('X image unable to load', array('url' => $url)), $this->importCell['position'], 'images', $url, $product);
                 }
             }
         }
     }
     // Remove old images
     foreach ($product->getImages() as $image) {
         if (in_array($image->getId(), $oldImageIds)) {
             $product->getImages()->removeElement($image);
             \XLite\Core\Database::getEM()->remove($image);
         }
     }
 }
Example #4
0
 /**
  * Detect image 
  * 
  * @param \XLite\Model\Product $product Product
  * @param array                $image   Image info
  *  
  * @return \XLite\Model\Image\Product\Image
  */
 protected function detectImage(\XLite\Model\Product $product, array $image)
 {
     $hash = \Includes\Utils\FileManager::getHash($image['url']);
     $model = null;
     if ($hash) {
         foreach ($product->getImages() as $oldImage) {
             if ($oldImage->getHash() == $hash) {
                 $model = $oldImage;
                 break;
             }
         }
     }
     return $model;
 }