Introduction
Shopware 6.7 introduces significant enhancements to multi-store architecture and sales channel management, providing developers with more granular control over commerce operations. This guide explores the technical implementation details of configuring multiple stores within a single Shopware instance, covering the underlying database structures, API endpoints, and customization approaches.
Understanding Sales Channels in Shopware 6.7
Sales channels represent distinct commerce frontends within a single Shopware installation, each with its own configuration, themes, products, and customer segments. In version 6.7, the sales channel architecture has been streamlined with improved performance and enhanced flexibility.
The core sales_channel entity now includes additional fields for advanced configuration:
access_tokencustom_fieldsconfigurationpayment_method_idsshipping_method_ids
Each sales channel operates independently while sharing the same product catalog, ensuring consistent inventory management across all storefronts.
Database Structure and Entity Relationships
The multi-store implementation relies on several key database tables:
-- Sales Channel Table
CREATE TABLE `sales_channel` (
`id` BINARY(16) NOT NULL,
`type_id` BINARY(16) NOT NULL,
`language_id` BINARY(16) NOT NULL,
`customer_id` BINARY(16) DEFAULT NULL,
`name` VARCHAR(255) NOT NULL,
`access_token` VARCHAR(255) NOT NULL,
`configuration` JSON DEFAULT NULL,
`custom_fields` JSON DEFAULT NULL,
`created_at` DATETIME(3) NOT NULL,
`updated_at` DATETIME(3) DEFAULT NULL
);
-- Sales Channel Type Table
CREATE TABLE `sales_channel_type` (
`id` BINARY(16) NOT NULL,
`name` VARCHAR(255) NOT NULL,
`created_at` DATETIME(3) NOT NULL,
`updated_at` DATETIME(3) DEFAULT NULL
);
The relationship between entities is managed through foreign keys, ensuring data integrity while allowing flexible configuration. Each sales channel references a specific type (storefront, api, admin, sales_channel) that determines its behavior and capabilities.
API Configuration and Endpoints
Shopware 6.7 exposes comprehensive REST APIs for managing multi-store configurations:
// GET /api/sales-channel
{
"data": [
{
"id": "uuid",
"type": "sales-channel",
"attributes": {
"name": "Main Storefront",
"access_token": "abc123",
"type_id": "storefront",
"language_id": "en-US"
}
}
]
}
// POST /api/sales-channel
{
"data": {
"type": "sales-channel",
"attributes": {
"name": "Mobile Storefront",
"type_id": "storefront",
"language_id": "en-US",
"configuration": {
"seoUrls": true,
"maintenanceMode": false
}
}
}
}
The API supports advanced filtering and sorting capabilities:
- Filter by type:
/api/sales-channel?filter[type.id]=storefront - Sort by creation date:
/api/sales-channel?sort=createdAt - Include related entities:
/api/sales-channel?includes=salesChannelType
Custom Field Implementation
Custom fields provide flexible configuration options for sales channels:
// Custom field registration in services.xml
<service id="Shopware\Core\System\CustomField\CustomFieldDefinition">
<tag name="shopware.custom_field"/>
</service>
// Usage in sales channel configuration
$customFields = [
'storefront_theme' => 'responsive',
'maintenance_message' => 'Scheduled maintenance in progress',
'currency_switcher' => true,
'language_switcher' => false
];
Custom fields are stored in the custom_fields JSON column, allowing developers to extend functionality without modifying core database schemas.
Payment and Shipping Method Configuration
Sales channel-specific payment and shipping methods are configured through dedicated associations:
# config/packages/shopware.yaml
shopware:
sales_channel:
payment_methods:
- id: 'paypal'
sales_channels:
- 'storefront'
- 'mobile'
shipping_methods:
- id: 'standard_shipping'
sales_channels:
- 'storefront'
Each sales channel maintains its own list of enabled payment and shipping methods, ensuring proper configuration for different market segments.
Performance Optimization Strategies
Performance optimization becomes crucial with multiple sales channels. Key strategies include:
- Caching: Implement Redis-based caching for frequently accessed sales channel configurations
- Database Indexing: Ensure proper indexing on
language_id,type_id, andaccess_tokenfields - Query Optimization: Use eager loading to minimize database queries
// Optimized sales channel retrieval
public function getSalesChannels(array $ids): array
{
$qb = $this->connection->createQueryBuilder();
$qb->select('*')
->from('sales_channel')
->where('id IN (:ids)')
->setParameter('ids', $ids, Connection::PARAM_STR_ARRAY);
return $qb->executeQuery()->fetchAllAssociative();
}
Advanced Configuration Patterns
Environment-Based Sales Channel Setup
// config/packages/prod/shopware.yaml
shopware:
sales_channel:
environments:
production:
name: 'Production Storefront'
configuration:
cache_enabled: true
debug_mode: false
staging:
name: 'Staging Storefront'
configuration:
cache_enabled: false
debug_mode: true
Dynamic Sales Channel Routing
// Custom router implementation
class MultiStoreRouter
{
public function resolveSalesChannel(string $host): ?SalesChannelEntity
{
$salesChannels = $this->salesChannelRepository->findAll();
foreach ($salesChannels as $channel) {
if ($channel->getDomains() && in_array($host, $channel->getDomains())) {
return $channel;
}
}
return null;
}
}
Security Considerations
Security implementation requires careful attention to access tokens and permissions:
// Token validation middleware
class SalesChannelTokenMiddleware
{
public function handle(Request $request, Closure $next): Response
{
$token = $request->headers->get('X-Shopware-Token');
if (!$this->validateToken($token)) {
throw new AccessDeniedHttpException('Invalid sales channel token');
}
return $next($request);
}
}
Migration and Upgrade Considerations
When upgrading to Shopware 6.7, existing sales channel configurations must be migrated:
-- Migration script for legacy sales channels
ALTER TABLE `sales_channel`
ADD COLUMN IF NOT EXISTS `configuration` JSON DEFAULT NULL,
ADD COLUMN IF NOT EXISTS `custom_fields` JSON DEFAULT NULL;
UPDATE `sales_channel`
SET `configuration` = '{}'
WHERE `configuration` IS NULL;
Conclusion
Shopware 6.7's multi-store implementation provides developers with powerful tools for creating complex commerce architectures. The enhanced API capabilities, flexible configuration options, and improved performance characteristics make it ideal for enterprise-level implementations requiring multiple storefronts.
Understanding the underlying database structure, leveraging custom fields for extensibility, and implementing proper caching strategies are essential for building scalable multi-store solutions. The framework's modular approach allows for seamless integration with existing systems while maintaining the flexibility needed for diverse business requirements.
As you implement these configurations, remember to test thoroughly across different sales channel types and monitor performance metrics to ensure optimal operation of your multi-store environment.