<?php
namespace Webkul\ShowPriceLogin;
use Doctrine\DBAL\Connection;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\InstallContext;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
use Shopware\Core\Framework\Uuid\Uuid;
use Shopware\Core\System\CustomField\CustomFieldTypes;
class WebkulShowPriceAfterLogin extends Plugin
{
public function install(InstallContext $installContext): void
{
$customFieldRepository = $this->container->get('custom_field_set.repository');
$customFieldData = $customFieldRepository->search((new Criteria())->addFilter(new EqualsFilter('name','show_price')), $installContext->getContext())->first();
if (!$customFieldData) {
$customFieldRepository->create([
[
'name' => 'show_price',
'config' => [
'label' => [
'en-GB' => 'Show Price After Login',
'de-DE' => 'Preis nach Anmeldung anzeigen'
]
],
'customFields' => [
[
'name' => 'show_price_enabled',
'type' => CustomFieldTypes::BOOL,
'config' => [
'label' => [
'en-GB' => 'Enabled',
'de-DE' => 'aktiviert'
],
'type' => 'checkbox',
'componentName'=> 'sw-field',
'customFieldType'=> 'checkbox',
'customFieldPosition' => 1,
'helpText' => [
'en-GB' => 'Allow to show the price for all the guest users',
'de-DE' => 'Erlauben Sie, den Preis für alle Gastbenutzer anzuzeigen'
],
]
],
[
'name' => 'show_price_cart_label_status',
'type' => CustomFieldTypes::BOOL,
'config' => [
'label' => [
'en-GB' => 'Add to cart Label',
'de-DE' => 'In den Warenkorb legen'
],
'type' => 'checkbox',
'componentName'=> 'sw-field',
'customFieldType'=> 'checkbox',
'customFieldPosition' => 3,
'helpText' => [
'en-GB' => 'Select Yes, if you want to show a customized label button on the product page for users who cannot view the price',
'de-DE' => 'Wählen Sie Ja, wenn Sie auf der Produktseite eine benutzerdefinierte Label-Schaltfläche für Benutzer anzeigen möchten, die den Preis nicht sehen können']
]
],
[
'name' => 'show_price_cart_title',
'type' => CustomFieldTypes::TEXT,
'config' => [
'label' => [
'en-GB' => 'Title',
'de-DE' => 'Titel'
],
'type' => 'text',
'componentName'=> 'sw-field',
'customFieldType'=> 'text',
'customFieldPosition' => 4,
'helpText' => [
'en-GB' => 'Enter the name of the button label',
'de-DE' => 'Geben Sie den Namen der Schaltflächenbeschriftung ein']
]
]
],
'relations' => [
[
'entityName' => 'product'
]
]
]
]
, $installContext->getContext());
}
}
public function uninstall(UninstallContext $uninstallContext): void
{
parent::uninstall($uninstallContext);
if ($uninstallContext->keepUserData()) {
return;
}
$customFieldRepository = $this->container->get('custom_field_set.repository');
$customFieldEntity = $customFieldRepository->search((new Criteria())->addFilter(new EqualsFilter('name','show_price')),$uninstallContext->getContext())->first();
if ($customFieldEntity) {
$this->container->get('custom_field_set.repository')->delete([['id'=>$customFieldEntity->getId()]],$uninstallContext->getContext());
}
}
}