/** * @param $ids * @param $columns * @return mixed * @throws \Exception */ public function read($ids, $columns) { if (!$ids && empty($ids)) { $message = $this->snippetHelper->getNamespace()->get('adapters/articles_no_ids', 'Can not read articles without ids.'); throw new \Exception($message); } if (!$columns && empty($columns)) { $message = $this->snippetHelper->getNamespace()->get('adapters/articles_no_column_names', 'Can not read articles without column names.'); throw new \Exception($message); } //articles $articleBuilder = $this->getArticleBuilder($columns['article'], $ids); $articles = $articleBuilder->getQuery()->getResult(); $result['article'] = $this->dbAdapterHelper->decodeHtmlEntities($articles); //prices $columns['price'] = array_merge($columns['price'], ['customerGroup.taxInput as taxInput', 'articleTax.tax as tax']); $priceBuilder = $this->getPriceBuilder($columns['price'], $ids); $result['price'] = $priceBuilder->getQuery()->getResult(); if ($result['purchasePrice']) { $result['purchasePrice'] = round($result['purchasePrice'], 2); } foreach ($result['price'] as &$record) { if ($record['taxInput']) { $record['price'] = round($record['price'] * (100 + $record['tax']) / 100, 2); $record['pseudoPrice'] = round($record['pseudoPrice'] * (100 + $record['tax']) / 100, 2); } else { $record['price'] = round($record['price'], 2); $record['pseudoPrice'] = round($record['pseudoPrice'], 2); } if (!$record['inStock']) { $record['inStock'] = '0'; } } //images $imageBuilder = $this->getImageBuilder($columns['image'], $ids); $tempImageResult = $imageBuilder->getQuery()->getResult(); foreach ($tempImageResult as &$tempImage) { $tempImage['imageUrl'] = $this->mediaService->getUrl($tempImage['imageUrl']); } $result['image'] = $tempImageResult; //filter values $propertyValuesBuilder = $this->getPropertyValueBuilder($columns['propertyValues'], $ids); $result['propertyValue'] = $propertyValuesBuilder->getQuery()->getResult(); //configurator $configBuilder = $this->getConfiguratorBuilder($columns['configurator'], $ids); $result['configurator'] = $configBuilder->getQuery()->getResult(); //similar $similarsBuilder = $this->getSimilarBuilder($columns['similar'], $ids); $result['similar'] = $similarsBuilder->getQuery()->getResult(); //accessories $accessoryBuilder = $this->getAccessoryBuilder($columns['accessory'], $ids); $result['accessory'] = $accessoryBuilder->getQuery()->getResult(); //categories $result['category'] = $this->prepareCategoryExport($ids, $columns['category']); $result['translation'] = $this->prepareTranslationExport($ids); return $result; }
/** * Deletes all thumbnails from the given media object * * @param Media $media */ public function removeMediaThumbnails(Media $media) { $thumbnails = array_merge(array_values($media->getThumbnailFilePaths()), array_values($media->getThumbnailFilePaths(true))); foreach ($thumbnails as $thumbnail) { $thumbnailPath = $this->rootDir . '/' . $thumbnail; if ($this->mediaService->has($thumbnailPath)) { $this->mediaService->delete($thumbnailPath); } } }
/** * @param string $destination * @param resource $newImage * @param int $quality - JPEG quality */ private function saveImage($destination, $newImage, $quality) { ob_start(); // saves the image information into a specific file extension switch (strtolower($this->getImageExtension($destination))) { case 'png': imagepng($newImage); break; case 'gif': imagegif($newImage); break; default: imagejpeg($newImage, null, $quality); break; } $content = ob_get_contents(); ob_end_clean(); $this->mediaService->write($destination, $content); }
/** * Saves the passed shop configuration values to the passed * template. * The configuration elements are identified over the * element name. * The values array can contains multiple sub shop values, * which identified over the shopId parameter inside the values array. * * @param Shop\Template $template * @param array $values */ public function saveConfig(Shop\Template $template, array $values) { foreach ($values as $data) { //get the element over the name $element = $this->getElementByName($template->getElements(), $data['elementName']); if (!$element instanceof Shop\TemplateConfig\Element) { continue; } $value = $this->getElementShopValue($element->getValues(), $data['shopId']); /**@var $shop Shop\Shop */ $shop = $this->entityManager->getReference('Shopware\\Models\\Shop\\Shop', $data['shopId']); if ($element->getType() === 'theme-media-selection') { $data['value'] = $this->mediaService->normalize($data['value']); } $value->setShop($shop); $value->setElement($element); $value->setValue($data['value']); } $this->entityManager->flush(); }
/** * Helper function which returns the theme configuration as * key - value array. * * The element name is used as array key, the shop config * as value. If no shop config saved, the value will fallback to * the default value. * * @param \Shopware\Models\Shop\Template $template * @param \Shopware\Models\Shop\Shop $shop * @param bool $lessCompatible * @return array */ private function getShopConfig(Shop\Template $template, Shop\Shop $shop, $lessCompatible = true) { $builder = $this->getShopConfigQuery($template, $lessCompatible); $builder->setParameter('templateId', $template->getId())->setParameter('shopId', $shop->getMain() ? $shop->getMain()->getId() : $shop->getId()); $data = $builder->getQuery()->getArrayResult(); foreach ($data as &$row) { if (!isset($row['value'])) { $row['value'] = $row['defaultValue']; } if ($lessCompatible && $row['type'] === 'theme-media-selection') { $row['value'] = '"' . $row['value'] . '"'; } if ($row['type'] === 'theme-media-selection' && $row['value'] !== $row['defaultValue'] && strpos($row['value'], "media/") !== false) { $row['value'] = $this->mediaService->getUrl($row['value']); } } if (!is_array($data) || empty($data)) { return array(); } //creates a key value array for the configuration. return array_combine(array_column($data, 'name'), array_column($data, 'value')); }
/** * @param MediaServiceInterface $toFileSystem * @param string $path * @param resource $contents * @return boolean */ private function writeStream(MediaServiceInterface $toFileSystem, $path, $contents) { $path = $toFileSystem->encode($path); $dirString = ''; $dirs = explode('/', dirname($path)); foreach ($dirs as $dir) { $dirString .= '/' . $dir; $toFileSystem->createDir($dirString); } $toFileSystem->writeStream($path, $contents); return $toFileSystem->has($path); }
/** * Adds a media by path to used table * * @param $path */ private function addMediaByPath($path) { $path = $this->mediaService->normalize($path); $this->queue['path'][] = $path; }
/** * @param string $file */ private function _testSize($file) { $this->assertEquals($this->testFileSize, $this->mediaService->getSize($file)); }