/** * @param AbstractProductMedia $media * * @return void */ protected function copyMedia(AbstractProductMedia $media) { if (null === $media->getFilePath() || '' === $media->getFileName()) { return; } $result = $this->mediaManager->copy($media, dirname($this->getPath())); $exportPath = $this->mediaManager->getExportPath($media); if (true === $result) { $this->writtenFiles[sprintf('%s/%s', dirname($this->getPath()), $exportPath)] = $exportPath; } else { $this->stepExecution->addWarning($this->getName(), sprintf('Copy of "%s" failed.', $media->getFilename()), [], $media); } }
function it_returns_flat_data(Channel $channel, $channelManager, AbstractProduct $item, AbstractProductMedia $media1, AbstractProductMedia $media2, $serializer) { $media1->getFilename()->willReturn('media_name'); $media1->getFilePath()->willReturn('media_file_path'); $media1->getOriginalFilename()->willReturn('media_original_name'); $media2->getFilename()->willReturn('media_name'); $media2->getFilePath()->willReturn('media_file_path'); $media2->getOriginalFilename()->willReturn('media_original_name'); $item->getMedia()->willReturn([$media1, $media2]); $serializer->normalize($item, 'flat', ['scopeCode' => 'foobar', 'localeCodes' => ''])->willReturn(['normalized_product']); $channelManager->getChannelByCode('foobar')->willReturn($channel); $this->setChannel('foobar'); $this->process($item)->shouldReturn(['media' => [$media1, $media2], 'product' => ['normalized_product']]); }
/** * Predicate to know if file exists physically * * @param AbstractProductMedia $media * * @return boolean */ protected function fileExists(AbstractProductMedia $media) { return $this->filesystem->has($media->getFilename()); }
/** * Set media * * @param AbstractProductMedia $media * * @return ProductValue */ public function setMedia(AbstractProductMedia $media) { $media->setValue($this); $this->media = $media; return $this; }
function it_normalizes_media(AbstractProductMedia $media) { $media->getFilename()->willReturn('myfile.pdf'); $media->getOriginalFilename()->willReturn('myfile.pdf'); $this->normalize($media, 'mongodb_json', [])->shouldReturn(['filename' => 'myfile.pdf', 'originalFilename' => 'myfile.pdf']); }
function it_normalizes_media_by_keeping_the_media_filename(AbstractProductMedia $media) { $media->getFilename()->willReturn('foo.jpg'); $this->normalize($media, null, ['field_name' => 'front', 'versioning' => true])->shouldReturn(['front' => 'foo.jpg']); }