public function testUrlGeneration() { $file = current($this->testPaths); $baseUrl = Shopware()->Container()->get('router')->assemble(['controller' => 'index', 'module' => 'frontend']); $mediaUrl = $baseUrl . $this->mediaService->encode($file); $this->assertEquals($mediaUrl, $this->mediaService->getUrl($file)); $this->assertNull($this->mediaService->getUrl('')); }
/** * @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; }
/** * 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')); }