Greetings! I'm Aneesh Sreedharan, CEO of 2Hats Logic Solutions. At 2Hats Logic Solutions, we are dedicated to providing technical expertise and resolving your concerns in the world of technology. Our blog page serves as a resource where we share insights and experiences, offering valuable perspectives on your queries.
One of the key challenges encountered during the migration process from Shopware 5 to Shopware 6 is the absence of the product downloads feature in Shopware 6. This gap in migration leaves the process incomplete. In this blog post, we will outline a straightforward step-by-step guide to successfully migrating product downloads from Shopware 5 to Shopware 6.
In Shopware 5, product downloads are stored as part of product media. Therefore, when we utilize the Migration Assistant plugin, all product downloads will be automatically migrated to Shopware 6 media. The remaining steps involve assigning these migrated downloads to the correct products and configuring them for display in the frontend of your Shopware 6 store.
Step 1. Create custom fields for downloads and show them on the product detail page.
We are developing a plugin that includes the creation of custom fields and the extension of product detail page Twig templates. These custom fields will be used to store and display product downloads. Our goal is to showcase these downloads in a new tab near the reviews section. Below, you will find an example of how to add custom field creation code within the class file of the newly created plugin.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | public function install(InstallContext $installContext): void { /** * @var EntityRepositoryInterface $customFieldSetRepository */ $customFieldSetRepository = $this->container->get('custom_field_set.repository'); $customFieldSetRepository->create($this->getCustomFieldSet(), $installContext->getContext()); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | protected function getCustomFieldSet(): array { return [ [ 'name' => 'hatslogic_product_downloads', 'config' => [ 'label' => [ 'de-DE' => 'Downloads', 'en-GB' => 'Downloads', ], ], 'customFields' => [ [ 'name' => 'hatslogic_product_download_1', 'type' => 'media', 'config' => [ 'customFieldPosition' => 1, 'componentName' => 'sw-media-field', 'customFieldType' => 'media', 'label' => [ 'de-DE' => 'Download 1', 'en-GB' => 'Download 1', ], ], ], 'relations' => [ [ 'entityName' => $this->container->get(ProductDefinition::class)->getEntityName() ] ] ] ]; } |
In the services.xml file, please include the following two services:
1 2 3 4 5 6 7 8 9 10 11 | <service id="HatsLogicProductDownloadsSubscriberPageSubscriber"> <argument type="service" id="ShopwareCoreSystemSystemConfigSystemConfigService" /> <argument type="service" id="HatsLogicProductDownloadsServiceProductDownloadsService" /> <tag name="kernel.event_subscriber" /> </service> <service id="HatsLogicProductDownloadsServiceProductDownloadsService"> <argument type="service" id="media.repository"/> <argument type="service" id="custom_field.repository"/> </service> |
In the Product Downloads Service class, add a function to get the download file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | public function getProductDownloads($context, $product) { $mediaFile = []; $customFields = $product->getCustomFields(); if (!empty($customFields)) { $mediaId = $customFields['hatslogic_product_download_1']; if (!empty($mediaId)) { $criteria = new Criteria($mediaId); $searchResult = $this->mediaRepository->search($criteria, $context); if (!empty($searchResult)) { $mediaFile = $searchResult->getElements(); $downloadTitle = $mediaFile->getTitle(); if (empty($downloadTitle)) { $downloadTitle = $mediaFile->getFileName(); } $mediaFile = [ 'id' => $mediaFile->getId(), 'title' => $downloadTitle, 'url' => $mediaFile->getUrl() ]; } } } return $mediaFile; |
FAQ
What is the purpose of creating custom fields for downloads in Shopware 6 during the migration process from Shopware 5?
The purpose of creating custom fields for downloads in Shopware 6 during the migration from Shopware 5 is to ensure a smooth transition of product downloads. Shopware 6 does not inherently support product downloads like Shopware 5 does
How are product downloads stored in Shopware 6 after migration from Shopware 5?
After migrating from Shopware 5 to Shopware 6, product downloads are stored as part of product media. The Migration Assistant plugin automatically transfers these downloads to Shopware 6 media.
What is the role of the custom field set in this migration process?
The custom field set plays a crucial role in this migration process. It defines where and how the product downloads will be stored and displayed in Shopware 6. Custom fields are created within this set to accommodate the downloads, ensuring that they are properly organized and accessible
Why is it important to extend product detail page templates in Shopware 6 during this migration?
Extending the product detail page templates in Shopware 6 is essential because it enables the display of product downloads in a user-friendly manner. By customizing the templates, you can create a dedicated section for downloads, typically near the reviews section.