PHP code example of heptacom / heptaconnect-package-shopware-6

1. Go to this page and download the library: Download heptacom/heptaconnect-package-shopware-6 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/ */

    

heptacom / heptaconnect-package-shopware-6 example snippets




use Heptacom\HeptaConnect\Package\Shopware6\EntitySearch\Contract\Aggregation\TermsAggregation;
use Heptacom\HeptaConnect\Package\Shopware6\EntitySearch\Contract\Filter\EqualsFilter;
use Heptacom\HeptaConnect\Package\Shopware6\Http\AdminApi\Utility\EntityClient;

/** @var $entityClient EntityClient */
$propertyGroupId = $entityClient->create('property_group', [
    'name' => 'Color',
    'sortingType' => 'position',
    'displayType' => 'color',
    'options' => [[
        'position' => 1,
        'name' => 'Red',
        'colorHexCode' => '#aa0000',
    ], [
        'position' => 2,
        'name' => 'Green',
        'colorHexCode' => '#00aa00',
    ], [
        'position' => 3,
        'name' => 'Blue',
        'colorHexCode' => '#0000aa',
    ]],
]);

$colorNamesByName = $entityClient->groupFieldByField(
    'property_group_option',
    'colorHexCode',
    'name',
    new EqualsFilter('group.id', $propertyGroupId)
);
var_export($colorNamesByName);
// array (
//   '#0000aa' => 'Blue',
//   '#00aa00' => 'Green',
//   '#aa0000' => 'Red',
// )

// paginates automatically
foreach ($entityClient->iterate('product') as $product) {
    // …
}

$countryIsos = $entityClient->aggregate('country', new TermsAggregation('countries', 'iso'))->buckets->getKeys();
var_export($countryIsos->asArray());
// array (
//   0 => 'AD',
//   1 => 'AE',
//   2 => 'AF',
//   3 => 'AG',
//   4 => 'AI',
//   …



use Heptacom\HeptaConnect\Package\Shopware6\Http\AdminApi\Utility\ExtensionClient;

/** @var $extensionClient ExtensionClient */
// remote updating security plugin
$extensionClient->upload('/path/to/SwagSecurityPlatform.zip');
$extensionClient->refresh();
$extensionClient->update('SwagSecurityPlatform');

if (!$extensionClient->isInstalled('SwagSecurityPlatform')) {
    $extensionClient->install('SwagSecurityPlatform');
}

if (!$extensionClient->isActive('SwagSecurityPlatform')) {
    $extensionClient->activate('SwagSecurityPlatform');
}



use Heptacom\HeptaConnect\Package\Shopware6\Http\AdminApi\Utility\GenericClient;

/** @var $client GenericClient */
// low amount of parameters
var_export($client->get('_info/version'));
// array (
//   'version' => '6.4.20.0',
// )

// query parameters
var_export($client->get('_action/system-config', [
    'domain' => 'core.update',
]));
// array (
//   'core.update.apiUri' => 'https://update-api.shopware.com',
//   'core.update.channel' => 'stable',
//   'core.update.code' => '',
// )

// JSON body
$client->post('_action/system-config', [
    'key' => 'value',
]);

// header support
$client->post('_action/order/00000000000000000000000000000000/state/complete', [], [], [
    // do not run flows to silently update order state
    'sw-skip-trigger-flow' => 1,
]);



use Heptacom\HeptaConnect\Package\Shopware6\Http\StoreApi\Utility\GenericClient;

/** @var $client GenericClient */
// low amount of parameters
var_export($client->get('context')['token']);
// 12c9a85D538b4795877A95aC908987db

// different methods
var_export(\array_column($client->post('country')['data'], 'iso'));
// array (
//   0 => 'AD',
//   1 => 'AE',
//   2 => 'AF',
//   3 => 'AG',
//   4 => 'AI',
//   …