classes/helper/AbstractImportModel.php
protected function importImageList()
    {
        if (!$this->bNeedUpdateImageList) {
            return;
        }

        if (empty($this->arImageList)) {
            $this->removeAllImages();

            return;
        }

        //Update old images
        $obImageList = $this->obModel->images;
        if (!$obImageList->isEmpty()) {
            /** @var File $obImage */
            foreach ($obImageList as $obImage) {
                $sFilePath = array_shift($this->arImageList);

                //Check image
                if (!empty($sFilePath) && (!file_exists($obImage->getLocalPath()) || md5_file($sFilePath) != md5_file($obImage->getLocalPath()))) {
                    $obImage->deleteThumbs();
                    $obImage->fromFile($sFilePath);
                    $obImage->save();
                } elseif (empty($sFilePath)) {
                    $obImage->deleteThumbs();
                    $obImage->delete();
                }
            }
        }

        //Create new images
        if (!empty($this->arImageList)) {
            foreach ($this->arImageList as $sFilePath) {
                $obImage = new File();
                $obImage->fromFile($sFilePath);

                $this->obModel->images()->add($obImage);
            }
        }
    }
protected function importImageList()
    {
        if (!$this->bNeedUpdateImageList) {
            return;
        }

        if (empty($this->arImageList)) {
            $this->removeAllImages();

            return;
        }

        //Update old images
        $obImageList = $this->obModel->images;
        if (!$obImageList->isEmpty()) {
            /** @var File $obImage */
            foreach ($obImageList as $obImage) {
                $sFilePath = array_shift($this->arImageList);

                //Check image
                if (!empty($sFilePath) && (!file_exists($obImage->getLocalPath()) || md5_file($sFilePath) != md5_file($obImage->getLocalPath()))) {
                    $obImage->deleteThumbs();
                    $obImage->fromFile($sFilePath);
                    $obImage->save();
                } elseif (empty($sFilePath)) {
                    $obImage->deleteThumbs();
                    $obImage->delete();
                }
            }
        }

        //Create new images
        if (!empty($this->arImageList)) {
            foreach ($this->arImageList as $sFilePath) {
                $obImage = new File();
                $obImage->fromFile($sFilePath);

                $this->obModel->images()->add($obImage);
            }
        }
    }
protected function importImageList ( ) { if ( ! $ this -> bNeedUpdateImageList ) { return ; } if ( empty ( $ this -> arImageList ) ) { $ this -> removeAllImages ( ) ; return ; } //Update old images $ obImageList = $ this -> obModel -> images ; if ( ! $ obImageList -> isEmpty ( ) ) { /** @var File $obImage */ foreach ( $ obImageList as $ obImage ) { $ sFilePath = array_shift ( $ this -> arImageList ) ; //Check image if ( ! empty ( $ sFilePath ) && ( ! file_exists ( $ obImage -> getLocalPath ( ) ) || md5_file ( $ sFilePath ) != md5_file ( $ obImage -> getLocalPath ( ) ) ) ) { $ obImage -> deleteThumbs ( ) ; $ obImage -> fromFile ( $ sFilePath ) ; $ obImage -> save ( ) ; } elseif ( empty ( $ sFilePath ) ) { $ obImage -> deleteThumbs ( ) ; $ obImage -> delete ( ) ; } } } //Create new images if ( ! empty ( $ this -> arImageList ) ) { foreach ( $ this -> arImageList as $ sFilePath ) { $ obImage = new File ( ) ; $ obImage -> fromFile ( $ sFilePath ) ; $ this -> obModel -> images ( ) -> add ( $ obImage ) ; } } }
Import obProductModel images
Import obProductModel images