<?php
namespace Biloba\ManufacturerPro;
use Biloba\ManufacturerPro\Core\BilobaManufacturerProPluginHelper;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\ActivateContext;
use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
use Shopware\Core\Framework\Plugin\Context\UpdateContext;
use Shopware\Core\Framework\Plugin\Context\InstallContext;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
use Shopware\Core\Framework\Context;
use Shopware\Core\System\CustomField\CustomFieldEntity;
class BilobaManufacturerPro extends Plugin
{
public function install(InstallContext $context): void
{
$this->setupCustomAttributes($context->getContext());
}
public function update(UpdateContext $context): void
{
$this->setupCustomAttributes($context->getContext());
}
public function activate(ActivateContext $context): void
{
$this->setupCustomAttributes($context->getContext());
parent::activate($context);
}
public function deactivate(DeactivateContext $context): void
{
parent::deactivate($context);
}
public function setupCustomAttributes(Context $context): void {
// generate UUID (https://www.guidgenerator.com/online-guid-generator.aspx)
/** @var EntityRepositoryInterface $customFieldSetRepository */
$customFieldSetRepository = $this->container->get('custom_field_set.repository');
$idCustomFieldSetManufacturerInfo = 'c2a8e865733049e6adfe3e0e8d31d43c';
$idCustomFieldSetManufacturerInfo = [
'id' => $idCustomFieldSetManufacturerInfo,
'name' => 'biloba_manufacturer_pro',
'config' => ["label" => ["en-GB" => "Biloba Manufacturer Pro", "de-DE" => "Biloba Manufacturer Pro"], "translated" => "true"],
'active' => boolval(1)
];
$customFieldSetRepository->upsert([$idCustomFieldSetManufacturerInfo], $context);
/** @var EntityRepositoryInterface $customFieldSetRelationRepository */
$customFieldSetRelationRepository = $this->container->get('custom_field_set_relation.repository');
$data = [
'id' => '45aeecb576324ee6945d159d581d884c',
'customFieldSet' => $idCustomFieldSetManufacturerInfo,
'entityName' => 'product_manufacturer'
];
$customFieldSetRelationRepository->upsert([$data] , $context);
/** @var EntityRepositoryInterface $customFieldRepository */
$customFieldRepository = $this->container->get('custom_field.repository');
$data = [
// Inside manufacturer info
[
'id' => '850d48abfaca4cd8989c5dafbfdb45e4',
'name' => 'biloba_manufacturer_pro_hide_manufacturer_in_manufacturerlist',
'type' => 'bool',
'config' => ["label" => ["en-GB" => "Hide Manufacturer in Manufacturerlist", "de-DE" => "Hersteller in Herstellerliste verbergen"], "helpText" => ["en-GB" => null, "de-DE" => null], "componentName" => "sw-field", "customFieldType" => "switch", "customFieldPosition" => 1],
'active' => boolval(1),
'customFieldSet' => $idCustomFieldSetManufacturerInfo
],
[
'id' => '5a176807c86347c08a52ed13d1583ef2',
'name' => 'biloba_manufacturer_pro_highlight_manufacturer',
'type' => 'bool',
'config' => ["label" => ["en-GB" => "Highlight Manufacturer", "de-DE" => "Hersteller hervorheben"], "helpText" => ["en-GB" => null, "de-DE" => null], "componentName" => "sw-field", "customFieldType" => "switch", "customFieldPosition" => 2],
'active' => boolval(1),
'customFieldSet' => $idCustomFieldSetManufacturerInfo
],
[
'id' => 'd734fb9322ed4664b25405251b36d5c7',
'name' => 'biloba_manufacturer_pro_select_color_for_highlighting_manufacturer',
'type' => 'colorpicker',
'config' => ["label" => ["en-GB" => "Select color for highlighting Manufacturer", "de-DE" => "Farbauswahl für das Hervorheben des Herstellers"], "helpText" => ["en-GB" => null, "de-DE" => null], "componentName" => "sw-field", "customFieldType" => "colorpicker", "customFieldPosition" => 3],
'active' => boolval(1),
'customFieldSet' => $idCustomFieldSetManufacturerInfo
],
];
$customFieldRepository->upsert($data, $context);
}
public function removeCustomAttributes(Context $context): void {
//Removing custom_field_set
$customFieldSetRepository = $this->container->get('custom_field_set.repository');
$customFieldSetRepository ->delete(
[
['id' => 'c2a8e865733049e6adfe3e0e8d31d43c'],
],
$context
);
}
public function uninstall(UninstallContext $context): void
{
parent::uninstall($context);
if ($context->keepUserData()) {
return;
}
$this->removeCustomAttributes($context->getContext());
BilobaManufacturerProPluginHelper::removeCmsBlocks($this->container, $context->getContext(), [
'biloba-block-manufacturer-list'
]);
BilobaManufacturerProPluginHelper::removeCmsBlocks($this->container, $context->getContext(), [
'biloba-block-manufacturer-image-grid'
]);
// Delete by type and not by slot
BilobaManufacturerProPluginHelper::removeCmsSlots($this->container, $context->getContext(), [
'biloba-element-manufacturer-list'
]);
BilobaManufacturerProPluginHelper::removeCmsSlots($this->container, $context->getContext(), [
'biloba-block-manufacturer-image-grid'
]);
}
}