PHP code example of it-bens / shopware-sdk-bundle

1. Go to this page and download the library: Download it-bens/shopware-sdk-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

it-bens / shopware-sdk-bundle example snippets


// config/bundles.php

return [
    // ...
    ITB\ShopwareSdkBundle\ITBShopwareSdkBundle::class => ['all' => true],
];



use Symfony\Config\ItbShopwareSdkConfig;

return static function (ItbShopwareSdkConfig $itbShopwareSdk): void {
    $itbShopwareSdk->shopUrl('https://shopware.local');
    $itbShopwareSdk->shopwareVersion('6.5.5.0');
    $itbShopwareSdk->credentials()
        ->grantType('client_credentials')
        ->clientId('CLIENT_ID')
        ->clientSecret('CLIENT_SECRET');
    $itbShopwareSdk->cache('simple_cache.app');
};



use Symfony\Config\ItbShopwareSdkConfig;

return static function (ItbShopwareSdkConfig $itbShopwareSdk): void {
    $itbShopwareSdk->shopUrl('https://shopware.local');
    $itbShopwareSdk->shopwareVersion('6.5.5.0');
    $itbShopwareSdk->credentials()
        ->grantType('password')
        ->clientId('USERNAME')
        ->clientSecret('PASSWORD');
    $itbShopwareSdk->cache('simple_cache.app');
};



namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\Component\Cache\Psr16Cache;

return function (ContainerConfigurator $containerConfigurator) {
    $services = $containerConfigurator->services();
    $services->set('simple_cache.app', Psr16Cache::class)
        ->arg('$pool', service('cache.app'));
};

use Vin\ShopwareSdk\Repository\RepositoryInterface;

final class ProductService {
    public function __construct(
        private RepositoryInterface $productEntityRepository,
        private RepositoryInterface $orderTransactionCaptureRefundPositionEntityRepository,
    ) {
    }
    
    // ...
}

use Vin\ShopwareSdk\Repository\RepositoryProviderInterface;
use Vin\ShopwareSdk\Repository\RepositoryInterface;
use Vin\ShopwareSdk\Data\Entity\v65812\Product\ProductDefinition;
use Vin\ShopwareSdk\Data\Entity\v65812\OrderTransactionCaptureRefundPosition\OrderTransactionCaptureRefundPositionDefinition

final class ProductService {
    private RepositoryInterface $productRepository;
    private RepositoryInterface $orderTransactionCaptureRefundPositionRepository;

    public function __construct(
        RepositoryProviderInterface $repositoryProvider
    ) {
        $this->productRepository = $repositoryProvider->getRepository(ProductDefinition::ENTITY_NAME);
        $this->orderTransactionCaptureRefundPositionRepository = $repositoryProvider->getRepository(OrderTransactionCaptureRefundPositionDefinition::ENTITY_NAME);
    }
    
    // ...
}

use Vin\ShopwareSdk\Service\AdminSearchServiceInterface;
use Vin\ShopwareSdk\Service\DocumentServiceInterface;
use Vin\ShopwareSdk\Service\InfoServiceInterface;
use Vin\ShopwareSdk\Service\MailSendServiceInterface;
use Vin\ShopwareSdk\Service\MediaServiceInterface;
use Vin\ShopwareSdk\Service\NotificationServiceInterface;
use Vin\ShopwareSdk\Service\NumberRangeServiceInterface;
use Vin\ShopwareSdk\Service\StateMachineServiceInterface;
use Vin\ShopwareSdk\Service\SyncServiceInterface;
use Vin\ShopwareSdk\Service\SystemConfigServiceInterface;
use Vin\ShopwareSdk\Service\UserConfigServiceInterface;
use Vin\ShopwareSdk\Service\UserServiceInterface;

final class Services {
    public function __construct(
        private AdminSearchServiceInterface $adminSearchService,
        private DocumentServiceInterface $documentService,
        private InfoServiceInterface $infoService,
        private MailSendServiceInterface $mailSendService,
        private MediaServiceInterface $mediaService,
        private NotificationServiceInterface $notificationService,
        private NumberRangeServiceInterface $numberRangeService,
        private StateMachineServiceInterface $stateMachineService,
        private SyncServiceInterface $syncService,
        private SystemConfigServiceInterface $systemConfigService,
        private UserConfigServiceInterface $userConfigService,
        private UserServiceInterface $userService
    ) {
    }
    
    // ...
}

use ITB\ShopwareSdkBundle\Attribute\AsEntityDefinitionCollectionPopulator;
use Vin\ShopwareSdk\Definition\DefinitionCollectionPopulator;
use Vin\ShopwareSdk\Definition\DefinitionCollection;
use Vin\ShopwareSdk\Data\Entity\EntityDefinition;

#[AsEntityDefinitionCollectionPopulator]
final class CustomDefinitionCollectionPopulator implements DefinitionCollectionPopulator {
    public static function getEntityNames(string $shopwareVersion): array
    {
        return ['custom_entity'];
    }
    
    public static function priority(): int {
        return 0;
    }
    
    public function populateDefinitionCollection(DefinitionCollection $definitionCollection, string $shopwareVersion): void {
        /** @var EntityDefinition $customDefinition */
        $customDefinition = new CustomEntityDefinition();
        $definitionCollection->set($customDefinition); // The entity name is used as a key and allow overwriting of existing definitions
    }
}

use ITB\ShopwareSdkBundle\DependencyInjection\Constant\Tags;

return static function (ContainerConfigurator $containerConfigurator): void {
    $services = $containerConfigurator->services();
    
    $serviceDefinition = $services->get(CustomDefinitionCollectionPopulator::class);
    $serviceDefinition->tag(Tags::ENTITY_DEFINITION_COLLECTION_POPULATOR);
    $services->set(CustomDefinitionCollectionPopulator::class);
};

use Vin\ShopwareSdk\Context\ContextBuilderFactoryInterface;
use Vin\ShopwareSdk\Definition\DefinitionProviderInterface;
use Vin\ShopwareSdk\Definition\SchemaProviderInterface;
use Vin\ShopwareSdk\Service\Api\ApiServiceInterface;

final class AdditionalServices {
    public function __construct(
        private ContextBuilderFactoryInterface $contextBuilderFactory,
        private DefinitionProviderInterface $definitionProvider,
        private SchemaProviderInterface $schemaProvider,
        private ApiServiceInterface $apiService,
    ) {
    }
    
    // ...
}