THELIA Forum

Welcome to the THELIA support and discusssion forum

Offline


Hi All,
I trying to make an xml export but I can't find how can i get a ProductImage URL from code?
Please help me.
Regards!

Offline


You have to fire a TheliaEvents::IMAGE_PROCESS event to get the image URL. See the Image loop code to get an example.


CQFDev | Sites, boutiques, modules, développement et intégration pour Thelia 1 et 2

Offline


Thanks Roadster31,
this code working for me (i hope it is Ok).
$images[0] is a ProductImage obj.

            $event = new ImageEvent();
            $sourceFilePath = sprintf(
                "%s%s/%s/%s",
                THELIA_ROOT,
                ConfigQuery::read('images_library_path', 'local'.DS.'media'.DS.'images'),
                "product",
                $images[0]->getFile()
            );
            $event->setSourceFilepath($sourceFilePath);
            $event->setCacheSubdirectory("product");
            $this->container->get("event_dispatcher")->dispatch(TheliaEvents::IMAGE_PROCESS, $event);
            $url = $event->getFileUrl();

Offline


Fine ! To get a resized image, use the setWidth() and setHeight() methods of the ImageEvent.


CQFDev | Sites, boutiques, modules, développement et intégration pour Thelia 1 et 2