custom/plugins/WebkulShowPriceAfterLogin/src/WebkulShowPriceAfterLogin.php line 14

Open in your IDE?
  1. <?php
  2. namespace Webkul\ShowPriceLogin;
  3. use Doctrine\DBAL\Connection;
  4. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  6. use Shopware\Core\Framework\Plugin;
  7. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  8. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  9. use Shopware\Core\Framework\Uuid\Uuid;
  10. use Shopware\Core\System\CustomField\CustomFieldTypes;
  11. class WebkulShowPriceAfterLogin extends Plugin
  12. {
  13.   public function install(InstallContext $installContext): void
  14.   {
  15.     $customFieldRepository $this->container->get('custom_field_set.repository');
  16.         $customFieldData $customFieldRepository->search((new Criteria())->addFilter(new EqualsFilter('name','show_price')), $installContext->getContext())->first();
  17.       if (!$customFieldData) {
  18.         $customFieldRepository->create([
  19.           [
  20.               'name' => 'show_price',
  21.               'config' => [
  22.                   'label' => [
  23.                       'en-GB' => 'Show Price After Login',
  24.                       'de-DE' => 'Preis nach Anmeldung anzeigen'
  25.                   ]
  26.               ],
  27.               'customFields' => [
  28.                   [
  29.                       'name' => 'show_price_enabled',
  30.                       'type' => CustomFieldTypes::BOOL,
  31.                       'config' => [
  32.                           'label' => [
  33.                               'en-GB' => 'Enabled',
  34.                               'de-DE' => 'aktiviert'
  35.                           ],
  36.                           'type' => 'checkbox',
  37.                           'componentName'=> 'sw-field',
  38.                           'customFieldType'=> 'checkbox',
  39.                           'customFieldPosition' => 1,
  40.                           'helpText' => [
  41.                             'en-GB' => 'Allow to show the price for all the guest users',
  42.                             'de-DE' => 'Erlauben Sie, den Preis für alle Gastbenutzer anzuzeigen'
  43.                           ],
  44.                       ]
  45.                   ],
  46.                   
  47.                   [
  48.                     'name' => 'show_price_cart_label_status',
  49.                     'type' => CustomFieldTypes::BOOL,
  50.                     'config' => [
  51.                       'label' => [
  52.                         'en-GB' => 'Add to cart Label',
  53.                         'de-DE' => 'In den Warenkorb legen'
  54.                       ],
  55.                       'type' => 'checkbox',
  56.                         'componentName'=> 'sw-field',
  57.                         'customFieldType'=> 'checkbox',
  58.                         'customFieldPosition' => 3,
  59.                         'helpText' => [
  60.                           'en-GB' => 'Select Yes, if you want to show a customized label button on the product page for users who cannot view the price',
  61.                           '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']
  62.                     ]
  63.                   ],
  64.                   [
  65.                     'name' => 'show_price_cart_title',
  66.                     'type' => CustomFieldTypes::TEXT,
  67.                     'config' => [
  68.                       'label' => [
  69.                         'en-GB' => 'Title',
  70.                         'de-DE' => 'Titel'
  71.                       ],
  72.                       'type' => 'text',
  73.                         'componentName'=> 'sw-field',
  74.                         'customFieldType'=> 'text',
  75.                         'customFieldPosition' => 4,
  76.                         'helpText' => [
  77.                           'en-GB' => 'Enter the name of the button label',
  78.                           'de-DE' => 'Geben Sie den Namen der Schaltflächenbeschriftung ein']
  79.                     ]
  80.                   ]
  81.                  
  82.               ],
  83.               
  84.               'relations' => [
  85.                 [
  86.                   'entityName' => 'product'
  87.                 ]
  88.               ]
  89.           ]
  90.         ]
  91.       , $installContext->getContext());
  92.     }
  93.     
  94.          
  95.         
  96.   
  97.   }
  98.   public function uninstall(UninstallContext $uninstallContext): void
  99.   {
  100.     parent::uninstall($uninstallContext);
  101.     if ($uninstallContext->keepUserData()) {
  102.       return;
  103.     }
  104.     $customFieldRepository $this->container->get('custom_field_set.repository');
  105.     $customFieldEntity $customFieldRepository->search((new Criteria())->addFilter(new EqualsFilter('name','show_price')),$uninstallContext->getContext())->first();
  106.     
  107.     if ($customFieldEntity) {
  108.       $this->container->get('custom_field_set.repository')->delete([['id'=>$customFieldEntity->getId()]],$uninstallContext->getContext());
  109.     }
  110.   }
  111.        
  112. }