Sfoglia il codice sorgente

axico id warranty edit, list, insert on save cat/comp, config update

master
Dukai Károly 3 anni fa
parent
commit
4c313d06f9
19 ha cambiato i file con 466 aggiunte e 176 eliminazioni
  1. +14
    -135
      README.txt
  2. +8
    -0
      modules/custom/arlista/arlista.links.menu.yml
  3. +8
    -0
      modules/custom/arlista/arlista.module
  4. +25
    -8
      modules/custom/arlista/arlista.routing.yml
  5. +3
    -0
      modules/custom/arlista/arlista.services.yml
  6. +8
    -0
      modules/custom/arlista/css/arlista.css
  7. +1
    -0
      modules/custom/arlista/src/Controller/ArlistaAbstractController.php
  8. +30
    -0
      modules/custom/arlista/src/Entity/AxicoIdWarranty.php
  9. +9
    -0
      modules/custom/arlista/src/Entity/Product.php
  10. +22
    -30
      modules/custom/arlista/src/Factory/AxicoIdFactory.php
  11. +111
    -0
      modules/custom/arlista/src/Factory/AxicoIdWarrantyFactory.php
  12. +1
    -0
      modules/custom/arlista/src/Factory/ProductFactory.php
  13. +9
    -1
      modules/custom/arlista/src/Form/ArlistaAbstractForm.php
  14. +95
    -0
      modules/custom/arlista/src/Form/AxicoIdWarranty/AxicoIdWarrantyEdit.php
  15. +69
    -0
      modules/custom/arlista/src/Form/AxicoIdWarranty/AxicoIdWarrantyList.php
  16. +5
    -1
      modules/custom/arlista/src/Form/Category/CategoryEdit.php
  17. +8
    -0
      modules/custom/arlista/src/Form/Component/ComponentEdit.php
  18. +21
    -1
      modules/custom/arlista/src/Form/Config/ArlistaSetupForm.php
  19. +19
    -0
      modules/custom/arlista/templates/arlista-axico-id-warranty-list.html.twig

+ 14
- 135
README.txt Vedi File

-- Change log


CONTENTS OF THIS FILE
---------------------
- axico id starts from 1 instead of 0
- axico id can be higher than 999, as 1000 and 1001 etc, starting numbers will still have 3 characters, like ABCCBA001


* About Drupal
* Configuration and features
* Installation profiles
* Appearance
* Developing for Drupal
* More information
- new product now can be added trough a file to the uplodaded products, as if it was inside the excel file
- newly added product can be confirmed as ACTIVATED
- saving a newly added product redirects on its self for further editing that allows inspecting its generated details as well


- user is informed if no product can be found in the excel file


ABOUT DRUPAL
------------
- files now can have up to 25 sheets instead of 20


Drupal is an open source content management platform supporting a variety of
websites ranging from personal weblogs to large community-driven websites. For
more information, see the Drupal website at https://www.drupal.org, and join
the Drupal community at https://www.drupal.org/community.
- default warranty can be set and saved in config form


Legal information about Drupal:
* Know your rights when using Drupal:
See LICENSE.txt in the "core" directory.
* Learn about the Drupal trademark and logo policy:
https://www.drupal.com/trademark
- axico id warranty entities can be listed and edited
- axico id warranty entities can be refreshed from axic id table
- new axico id warranties are stored with default warranty from drupal config


- after saving a new product category or component, a new axico id warranty is stored with default warranty from config


CONFIGURATION AND FEATURES
--------------------------

Drupal core (what you get when you download and extract a drupal-x.y.tar.gz or
drupal-x.y.zip file from https://www.drupal.org/project/drupal) has what you
need to get started with your website. It includes several modules (extensions
that add functionality) for common website features, such as managing content,
user accounts, image uploading, and search. Core comes with many options that
allow site-specific configuration. In addition to the core modules, there are
thousands of contributed modules (for functionality not included with Drupal
core) available for download.

More about configuration:
* Install, update, and maintain Drupal:
See INSTALL.txt and UPDATE.txt in the "core" directory.
* Learn about how to use Drupal to create your site:
https://www.drupal.org/documentation
* Follow best practices:
https://www.drupal.org/best-practices
* Download contributed modules to /modules to extend Drupal's functionality:
https://www.drupal.org/project/project_module
* See also: "Developing for Drupal" for writing your own modules, below.


INSTALLATION PROFILES
---------------------

Installation profiles define additional steps (such as enabling modules,
defining content types, etc.) that run after the base installation provided
by core when Drupal is first installed. There are two basic installation
profiles provided with Drupal core.

Installation profiles from the Drupal community modify the installation process
to provide a website for a specific use case, such as a CMS for media
publishers, a web-based project tracking tool, or a full-fledged CRM for
non-profit organizations raising money and accepting donations. They can be
distributed as bare installation profiles or as "distributions". Distributions
include Drupal core, the installation profile, and all other required
extensions, such as contributed and custom modules, themes, and third-party
libraries. Bare installation profiles require you to download Drupal Core and
the required extensions separately; place the downloaded profile in the
/profiles directory before you start the installation process.

More about installation profiles and distributions:
* Read about the difference between installation profiles and distributions:
https://www.drupal.org/docs/distributions/creating-distributions
* Download contributed installation profiles and distributions:
https://www.drupal.org/project/project_distribution
* Develop your own installation profile or distribution:
https://www.drupal.org/docs/distributions/creating-distributions


APPEARANCE
----------

In Drupal, the appearance of your site is set by the theme (themes are
extensions that set fonts, colors, and layout). Drupal core comes with several
themes. More themes are available for download, and you can also create your own
custom theme.

More about themes:
* Download contributed themes to /themes to modify Drupal's appearance:
https://www.drupal.org/project/project_theme
* Develop your own theme:
https://www.drupal.org/docs/theming-drupal


DEVELOPING FOR DRUPAL
---------------------

Drupal contains an extensive API that allows you to add to and modify the
functionality of your site. The API consists of "hooks", which allow modules to
react to system events and customize Drupal's behavior, and functions that
standardize common operations such as database queries and form generation. The
flexible hook architecture means that you should never need to directly modify
the files that come with Drupal core to achieve the functionality you want;
instead, functionality modifications take the form of modules.

When you need new functionality for your Drupal site, search for existing
contributed modules. If you find a module that matches except for a bug or an
additional needed feature, change the module and contribute your improvements
back to the project in the form of a "patch". Create new custom modules only
when nothing existing comes close to what you need.

More about developing:
* Search for existing contributed modules:
https://www.drupal.org/project/project_module
* Contribute a patch:
https://www.drupal.org/patch/submit
* Develop your own module:
https://www.drupal.org/developing/modules
* Follow programming best practices:
https://www.drupal.org/docs/develop/standards
* Refer to the API documentation:
https://api.drupal.org/api/drupal/9
* Learn from documented Drupal API examples:
https://www.drupal.org/project/examples


MORE INFORMATION
----------------

* See the Drupal.org online documentation:
https://www.drupal.org/documentation

* For a list of security announcements, see the "Security advisories" page at
https://www.drupal.org/security (available as an RSS feed). This page also
describes how to subscribe to these announcements via email.

* For information about the Drupal security process, or to find out how to
report a potential security issue to the Drupal security team, see the
"Security team" page at https://www.drupal.org/drupal-security-team

* For information about the wide range of available support options, visit
https://www.drupal.org and click on Community and Support in the top or
bottom navigation.
- products garancia field is filled trough

+ 8
- 0
modules/custom/arlista/arlista.links.menu.yml Vedi File

weight: 20 weight: 20
menu_name: main menu_name: main
route_parameters: { mid: '0' } route_parameters: { mid: '0' }
arlista.warranty.list:
title: "Garanciák"
description: "Garanciák listája"
parent: main
route_name: arlista.warranty.list
weight: 25
menu_name: main
route_parameters: { mid: '0' }
arlista.file.list: arlista.file.list:
title: "Fájlok" title: "Fájlok"
description: "Fájlok feltöltése" description: "Fájlok feltöltése"

+ 8
- 0
modules/custom/arlista/arlista.module Vedi File

'template' => 'arlista-component-list', 'template' => 'arlista-component-list',
'render element' => 'form', 'render element' => 'form',
], ],
'arlista_axico_id_warranty_list' => [
'variables' => [
'warranties' => null,
'sheetSettingList' => null,
],
'template' => 'arlista-axico-id-warranty-list',
'render element' => 'form',
],
'arlista_component_enable_calculations' => [ 'arlista_component_enable_calculations' => [
'variables' => [ 'variables' => [
'components' => null, 'components' => null,

+ 25
- 8
modules/custom/arlista/arlista.routing.yml Vedi File

# CONFIGURATION
### CONFIGURATION
arlista.config.setup: arlista.config.setup:
path: '/arlista/setup' path: '/arlista/setup'
defaults: defaults:
_title: 'Axico cikkszámok helyreállítása' _title: 'Axico cikkszámok helyreállítása'
requirements: requirements:
_permission: 'arlista manage_pricelists' _permission: 'arlista manage_pricelists'
# MANUFACTURER
### MANUFACTURER
arlista.manufacturer.list: arlista.manufacturer.list:
path: "/manufacturer/list" path: "/manufacturer/list"
defaults: defaults:
_permission: "arlista manage_pricelists" _permission: "arlista manage_pricelists"
_disable_route_normalizer: "TRUE" _disable_route_normalizer: "TRUE"
id: ^\d+$ id: ^\d+$
# SHEET SETTING
### SHEET SETTING
arlista.manufacturer.sheet-setting.edit: arlista.manufacturer.sheet-setting.edit:
path: "/manufacturer/sheet-settings" path: "/manufacturer/sheet-settings"
defaults: defaults:
mid: ^\d+$ mid: ^\d+$
sheetSettingId: ^\d+$ sheetSettingId: ^\d+$
componentBased: ^\d+$ componentBased: ^\d+$
# CALCULATION
### CALCULATION
arlista.manufacturer.calculations.list: arlista.manufacturer.calculations.list:
path: "/manufacturer/{mid}/calculations/list" path: "/manufacturer/{mid}/calculations/list"
defaults: defaults:
mid: ^\d+$ mid: ^\d+$
catId: ^\d+$ catId: ^\d+$
cmpId: ^\d+$ cmpId: ^\d+$
# CATEGORY
### CATEGORY
arlista.category.list: arlista.category.list:
path: "/category/list" path: "/category/list"
defaults: defaults:
_permission: "arlista manage_pricelists" _permission: "arlista manage_pricelists"
_disable_route_normalizer: "TRUE" _disable_route_normalizer: "TRUE"
id: ^\d+$ id: ^\d+$
# COMPONENT
### COMPONENT
arlista.component.list: arlista.component.list:
path: "/component/list" path: "/component/list"
defaults: defaults:
_permission: "arlista manage_pricelists" _permission: "arlista manage_pricelists"
_disable_route_normalizer: "TRUE" _disable_route_normalizer: "TRUE"
id: ^\d+$ id: ^\d+$
# FILE
### AXICO ID WARRANTY
arlista.warranty.list:
path: "/axico-id-warranty/list"
defaults:
_form: '\Drupal\arlista\Form\AxicoIdWarranty\AxicoIdWarrantyList'
_title: "Garanciák"
requirements:
_permission: "arlista manage_pricelists"
_disable_route_normalizer: "TRUE"
arlista.warranty.edit:
path: "/axico-id-warranty/list/edit/{id}"
defaults:
_form: '\Drupal\arlista\Form\AxicoIdWarranty\AxicoIdWarrantyEdit'
_title: "Axico cikkszám garancia szerkesztése"
requirements:
_permission: "arlista manage_pricelists"
_disable_route_normalizer: "TRUE"
### FILE
arlista.file.list: arlista.file.list:
path: "/files/{mid}/list" path: "/files/{mid}/list"
defaults: defaults:
_permission: "arlista manage_pricelists" _permission: "arlista manage_pricelists"
_disable_route_normalizer: "TRUE" _disable_route_normalizer: "TRUE"
mid: ^\d+$ mid: ^\d+$
# PRODUCT
### PRODUCT
arlista.product.list: arlista.product.list:
path: "product/list/file" path: "product/list/file"
defaults: defaults:

+ 3
- 0
modules/custom/arlista/arlista.services.yml Vedi File

arlista.component.factory: arlista.component.factory:
class: Drupal\arlista\Factory\ComponentFactory class: Drupal\arlista\Factory\ComponentFactory
arguments: ['@database', '@current_user', '@datetime.time'] arguments: ['@database', '@current_user', '@datetime.time']
arlista.warranty.factory:
class: Drupal\arlista\Factory\AxicoIdWarrantyFactory
arguments: ['@database', '@current_user', '@datetime.time', '@config.factory']
arlista.install.factory: arlista.install.factory:
class: Drupal\arlista\Factory\InstallFactory class: Drupal\arlista\Factory\InstallFactory
arguments: ['@arlista.axico-id.factory', '@arlista.category.factory', '@arlista.component.factory', '@arlista.manufacturer.factory', '@arlista.product.factory', '@arlista.calculation.factory', '@arlista.file.factory', '@arlista.spread-sheet.factory'] arguments: ['@arlista.axico-id.factory', '@arlista.category.factory', '@arlista.component.factory', '@arlista.manufacturer.factory', '@arlista.product.factory', '@arlista.calculation.factory', '@arlista.file.factory', '@arlista.spread-sheet.factory']

+ 8
- 0
modules/custom/arlista/css/arlista.css Vedi File

} }


button.button { button.button {
margin-top: 1rem;
margin-right: 1rem; margin-right: 1rem;
} }

footer.footer {
display: flex;
flex-direction: row;
justify-content: center;
margin-top: 5rem;
}

+ 1
- 0
modules/custom/arlista/src/Controller/ArlistaAbstractController.php Vedi File

$sameProductInOtherFiles->setAxicoId($product->getAxicoId()); $sameProductInOtherFiles->setAxicoId($product->getAxicoId());
$sameProductInOtherFiles->setWorkFlow(WorkFlow::ACTIVATED); $sameProductInOtherFiles->setWorkFlow(WorkFlow::ACTIVATED);
$sameProductInOtherFiles->setCorrectStatus(Status::CORRECT_IMPORTED); $sameProductInOtherFiles->setCorrectStatus(Status::CORRECT_IMPORTED);
$sameProductInOtherFiles->setWarranty($product->getWarranty());
$this->getProductFactory()->save($sameProductInOtherFiles); $this->getProductFactory()->save($sameProductInOtherFiles);

+ 30
- 0
modules/custom/arlista/src/Entity/AxicoIdWarranty.php Vedi File

<?php

namespace Drupal\arlista\Entity;

class AxicoIdWarranty extends AbstractEntity {

private ?string $axicoIdName = null;
private ?int $defaultWarranty = null;

public function __construct() {
parent::__construct();
}
public function getAxicoIdName(): ?string {
return $this->axicoIdName;
}

public function setAxicoIdName(?string $axicoIdName): void {
$this->axicoIdName = $axicoIdName;
}

public function getDefaultWarranty(): ?int {
return $this->defaultWarranty;
}

public function setDefaultWarranty(?int $defaultWarranty): void {
$this->defaultWarranty = $defaultWarranty;
}
}

+ 9
- 0
modules/custom/arlista/src/Entity/Product.php Vedi File

private ?float $weight = null; private ?float $weight = null;
private ?float $width = null; private ?float $width = null;
private ?string $workFlow = null; private ?string $workFlow = null;
private ?int $defaultWarranty = null;
/* /*
* Transitional * Transitional
*/ */
return $this->getPriceChanged() || $this->isOtherProductDataChanged($this); return $this->getPriceChanged() || $this->isOtherProductDataChanged($this);
} }


public function getDefaultWarranty(): ?int {
return $this->defaultWarranty;
}

public function setDefaultWarranty(?int $defaultWarranty): void {
$this->defaultWarranty = $defaultWarranty;
}

public function copyBaseProperties(Product $product): void { public function copyBaseProperties(Product $product): void {
$this->setSif($product->getSif()); $this->setSif($product->getSif());
$this->setAxicoId($product->getAxicoId()); $this->setAxicoId($product->getAxicoId());

+ 22
- 30
modules/custom/arlista/src/Factory/AxicoIdFactory.php Vedi File

return null; return null;
} }


}

// $groupName = $this->getGroupAxicoId($axicoIdEntity->getName());
// $specificGroups = $this->getSpecificGroups();
//
// /*
// * Remove it from the other group if necessary
// */
//
//
//
//
//// if (!isset($specificGroups[$groupName])) {
//// return $this->reviveAxicoIdEntity($axicoIdEntity);
//// } else {
// /*
// * Total removal of this axico id entity
// * if sorted product belongs to a specific group
// */
//// $this->delete($axicoIdEntity);
//// if ($axicoIdEntity->getParentComponentId()) {
//// $lastSimilar = $this->findHighestCurrentAxicoIdByComponentId($axicoIdEntity->getParentComponentId());
//// } else {
//// $lastSimilar = $this->findHighestCurrentAxicoIdByManufacturerIdAndCategoryIdAndComponentId(
//// $axicoIdEntity->getParentManufacturerId(), $axicoIdEntity->getParentCategoryId(), null);
//// }
////
//// return $this->reviveAxicoIdEntity($lastSimilar);
//// return null;
//// }
public function findAllDistinct(): array {
$axicoIds = $this->getConnection()
->select($this->getActiveTable(), 'w')
->isNull('w.deleted_at')
->distinct()
->fields('w', array('name'))
->orderBy('name')
->execute()
->fetchAll();

return $axicoIds;

/*$distinct = [];
foreach ($axicoIds as $axicoId){
if(!isset($distinct[$axicoId->getName()])){
$distinct[$axicoId->getName()] = $axicoId->getName();
}
}
return $distinct;*/
}

}

+ 111
- 0
modules/custom/arlista/src/Factory/AxicoIdWarrantyFactory.php Vedi File

<?php

namespace Drupal\arlista\Factory;

use Drupal\arlista\Entity\AbstractEntity;
use Drupal\arlista\Entity\AxicoIdWarranty;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Database\Connection;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use stdClass;

class AxicoIdWarrantyFactory extends AbstractFactory
{
public function __construct(Connection $connection, AccountInterface $currentUser,
TimeInterface $time, ConfigFactoryInterface $configFactory) {
parent::__construct($connection, $currentUser, $time, 'axico_id_warranty');
$this->config = $configFactory->get('arlista.settings');
}

public function create(): AxicoIdWarranty
{
$entity = new AxicoIdWarranty();
$entity->setDefaultWarranty($this->config->get('default_warranty'));
}

protected function insert(AbstractEntity $entity): AxicoIdWarranty
{
$id = $this->getConnection()
->insert($this->getActiveTable())
->fields([
'axico_id_name' => $entity->getAxicoIdName(),
'default_warranty' => $entity->getDefaultWarranty(),
'created_at' => date('Y-m-d H:i:s', $this->getTime()->getRequestTime()),
'created_by' => $this->getCurrentUser()->id(),
])
->execute();

$entity->setId($id);

return $entity;
}

protected function update(AbstractEntity $entity): AxicoIdWarranty
{
$this->getConnection()
->update($this->getActiveTable())
->fields([
'default_warranty' => $entity->getDefaultWarranty(),
'modified_at' => date('Y-m-d H:i:s', $this->getTime()->getRequestTime()),
'modified_by' => $this->getCurrentUser()->id(),
])
->condition('id', $entity->getId())
->execute();

return $entity;
}

protected function load(stdClass $data): AxicoIdWarranty
{
$entity = $this->create();
$entity->setId($data->id);
$entity->setAxicoIdName($data->axico_id_name);
$entity->setDefaultWarranty($data->default_warranty);
$entity->setCreatedAt($data->created_at);
$entity->setCreatedBy($data->created_by);
$entity->setModifiedAt($data->modified_at);
$entity->setModifiedBy($data->modified_by);
$entity->setDeletedAt($data->deleted_at);
$entity->setSif($data->sif);

return $entity;
}

public function updateDatabase(array $axicoIds): array
{
$result['axicoIdWarrantyList'] = [];
$result['axicoIdWarrantyList']['inserted'] = [];

/* @var axicoId AxicoId */
foreach ($axicoIds as $axicoId) {
$entity = $this->findByAxicoIdName($axicoId->name);
if (empty($entity)) {
$entity = $this->create();
$entity->setAxicoIdName($axicoId->name);
$entity = $this->save($entity);
$result['axicoIdWarrantyList']['inserted'][$entity->getId()] = $entity;
}
}

return $result;
}

public function findByAxicoIdName($axicoIdName)
{
$data = $this->getConnection()
->select($this->getActiveTable(), 'w')
->fields('w')
->condition('w.axico_id_name', $axicoIdName)
->isNull('w.deleted_at')
->execute()
->fetchObject();

if (empty($data)) {
return null;
}

return $this->load($data);
}

}

+ 1
- 0
modules/custom/arlista/src/Factory/ProductFactory.php Vedi File

private ComponentFactory $componentFactory; private ComponentFactory $componentFactory;
private ManufacturerFactory $manufacturerFactory; private ManufacturerFactory $manufacturerFactory;
private CacheService $cacheService; private CacheService $cacheService;
private CalculationFactory $calculationFactory;
private array $fontAwesomeIcons = []; private array $fontAwesomeIcons = [];


public function __construct(Connection $connection, AccountInterface $currentUser, public function __construct(Connection $connection, AccountInterface $currentUser,

+ 9
- 1
modules/custom/arlista/src/Form/ArlistaAbstractForm.php Vedi File

use Drupal\arlista\Factory\SpreadSheetFactory; use Drupal\arlista\Factory\SpreadSheetFactory;
use Drupal\arlista\Factory\CalculationFactory; use Drupal\arlista\Factory\CalculationFactory;
use Drupal\arlista\Factory\EnabledGroupFactory; use Drupal\arlista\Factory\EnabledGroupFactory;
use Drupal\arlista\Factory\AxicoIdWarrantyFactory;
use Drupal\Core\Config\ImmutableConfig; use Drupal\Core\Config\ImmutableConfig;
use Drupal\arlista\Entity\Component; use Drupal\arlista\Entity\Component;
use Drupal\arlista\Entity\Manufacturer; use Drupal\arlista\Entity\Manufacturer;
private $spreadSheetFactory; private $spreadSheetFactory;
private $calculationFactory; private $calculationFactory;
private $enabledGroupFactory; private $enabledGroupFactory;
private $axicoIdWarrantyFactory;
private $config; private $config;


public function __construct(ComponentFactory $componentFactory, CategoryFactory $categoryFactory, public function __construct(ComponentFactory $componentFactory, CategoryFactory $categoryFactory,
SheetSettingFactory $SheetSettingFactory, CacheService $cacheService, SheetSettingFactory $SheetSettingFactory, CacheService $cacheService,
AxicoIdFactory $axicoIdFactory, ProductFactory $productFactory, AxicoIdFactory $axicoIdFactory, ProductFactory $productFactory,
SpreadSheetFactory $spreadSheetFactory, CalculationFactory $calculationFactory, SpreadSheetFactory $spreadSheetFactory, CalculationFactory $calculationFactory,
EnabledGroupFactory $enabledGroupFactory) {
EnabledGroupFactory $enabledGroupFactory, AxicoIdWarrantyFactory $axicoIdWarrantyFactory) {
$this->componentFactory = $componentFactory; $this->componentFactory = $componentFactory;
$this->categoryFactory = $categoryFactory; $this->categoryFactory = $categoryFactory;
$this->fileFactory = $fileFactory; $this->fileFactory = $fileFactory;
$this->spreadSheetFactory = $spreadSheetFactory; $this->spreadSheetFactory = $spreadSheetFactory;
$this->calculationFactory = $calculationFactory; $this->calculationFactory = $calculationFactory;
$this->enabledGroupFactory = $enabledGroupFactory; $this->enabledGroupFactory = $enabledGroupFactory;
$this->axicoIdWarrantyFactory = $axicoIdWarrantyFactory;
$this->config = \Drupal::config('arlista.settings'); $this->config = \Drupal::config('arlista.settings');
} }


$container->get('arlista.spread-sheet.factory'), $container->get('arlista.spread-sheet.factory'),
$container->get('arlista.calculation.factory'), $container->get('arlista.calculation.factory'),
$container->get('arlista.enabled-group.factory'), $container->get('arlista.enabled-group.factory'),
$container->get('arlista.warranty.factory'),
); );
} }


return $this->axicoIdFactory; return $this->axicoIdFactory;
} }


public function getAxicoIdWarrantyFactory(): AxicoIdWarrantyFactory {
return $this->axicoIdWarrantyFactory;
}

public function getProductFactory(): ProductFactory { public function getProductFactory(): ProductFactory {
return $this->productFactory; return $this->productFactory;
} }

+ 95
- 0
modules/custom/arlista/src/Form/AxicoIdWarranty/AxicoIdWarrantyEdit.php Vedi File

<?php

namespace Drupal\arlista\Form\AxicoIdWarranty;

use Drupal\Core\Form\FormStateInterface;
use Drupal\arlista\Form\ArlistaAbstractForm;
use Drupal\arlista\Entity\AxicoIdWarranty;

use Drupal\Core\Link;
use Drupal\Core\Url;

class AxicoIdWarrantyEdit extends ArlistaAbstractForm {

private $id;

/**
* {@inheritdoc}
*/
public function getFormId() {
return 'arlista_axico_id_warranty_edit_form';
}

/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state,
int $id = null) {
$this->id = $id;
/* @var $axicoIdWarranty AxicoIdWarranty */
$axicoIdWarranty = $this->getAxicoIdWarrantyFactory()->find($id);

$form['items_wrapper']['#prefix'] ='<div class="col-lg-6">';
$form['items_wrapper']['id'] = [
'#type' => 'hidden',
'#value' => $axicoIdWarranty->getId(),
'#prefix' => '<div class="row">'];
$form['items_wrapper']['axico_id_name'] = [
'#title' => 'Axico cikkszám',
'#type' => 'textfield',
'#required' => true,
'#disabled' => true,
'#default_value' => $axicoIdWarranty->getAxicoIdName(),
'#prefix' => '<div class="col-lg-3">',
];

$form['items_wrapper']['default_warranty'] = [
'#title' => 'Garancia',
'#type' => 'number',
'#precision' => 0,
'#scale' => 2,
'#step' => 1,
'#max' => 72,
'#min' => 12,
'#required' => true,
'#default_value' => $axicoIdWarranty->getDefaultWarranty(),
'#suffix' => '</div>'
];

$form['buttons'] = array(
'#type' => 'container',
'#weight' => 1000,
);
$form['buttons']['arlista_axico_id_warranty_edit_form_submit'] = [
'#type' => 'submit',
'#value' => 'Mentés',
'#attributes' => ['class' => ['btn-success']]];
$form['items_wrapper']['#suffix'] ='</div>';

return $form;
}

/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
if ($form_state->getValue('default_warranty') < 12 || $form_state->getValue('default_warranty') > 60) {
$message = 'Az érték minimum 12, maximum 60 lehet!';
$form_state->setErrorByName('default_warranty', $message);
}
}

/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state->getValues();
/* @var $manufacturer Manufacturer */
$axicoIdWarranty = $this->getAxicoIdWarrantyFactory()->find($values['id']);
$axicoIdWarranty->setDefaultWarranty($values['default_warranty']);
$this->getAxicoIdWarrantyFactory()->save($axicoIdWarranty);

\Drupal::messenger()->addStatus($this->t('Sikeres mentés!'));
}

}

+ 69
- 0
modules/custom/arlista/src/Form/AxicoIdWarranty/AxicoIdWarrantyList.php Vedi File

<?php

/**
* @file
* Components list all form.
*/

namespace Drupal\arlista\Form\AxicoIdWarranty;

use Drupal\Core\Form\FormStateInterface;
use Drupal\arlista\Form\ArlistaAbstractForm;
use Drupal\arlista\Entity\ManufAxicoIdWarranty;
use Drupal\Core\Url;

class AxicoIdWarrantyList extends ArlistaAbstractForm {

/**
* {@inheritdoc}
*/
public function getFormId() {
return 'arlista_axico_id_warranty_list_form';
}

/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
if ($data = $this->getCacheService()->getCachedDataByName([$this->getFormId(), 1])) {
return $data;
}

$axicoIdWarranties = $this->getAxicoIdWarrantyFactory()->findAll('axico_id_name', 'ASC');

$form['items_wrapper']['#prefix'] ='<div class="col-lg-6">';
if(count($axicoIdWarranties)){
$renderableItems = [
'#theme' => 'arlista_axico_id_warranty_list',
'#warranties' => $axicoIdWarranties,
'#form' => $form,
];
$renderedList = \Drupal::service('renderer')->render($renderableItems);
$form['items_wrapper']['axicoIdWaranties'] = ['#markup' => $renderedList];
}
$form['items_wrapper']['buttons']['axico_id_warranties_form_submit'] = array(
'#type' => 'submit',
'#value' => 'Axico Cikkszámok frissítése',
);
$form['items_wrapper']['buttons']['axico_id_warranties_form_submit']['#attributes']['class'][] = 'btn-primary';
$form['items_wrapper']['#suffix'] ='</div>';
$this->getCacheService()->setCachedDataByName([$this->getFormId(), 1], $form);

return $form;
}

/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {

$data = $this->getAxicoIdFactory()->findAllDistinct();
$result = $this->getAxicoIdWarrantyFactory()->updateDatabase($data);
\Drupal::messenger()->addStatus('Új Axico Cikkszám Garancia entitások száma ('. count($result['axicoIdWarrantyList']['inserted']) .')');

$this->getCacheService()->resetCache([$this->getFormId(), 1]);
}

}

+ 5
- 1
modules/custom/arlista/src/Form/Category/CategoryEdit.php Vedi File

$manufacturers = $this->getManufacturerFactory()->findAll(); $manufacturers = $this->getManufacturerFactory()->findAll();
foreach ($manufacturers as $manufacturer) { foreach ($manufacturers as $manufacturer) {
/* /*
* Create axico id for each existing category upon saving a new manufacturer
* Create axico id for each existing manugacturer upon saving a new category
*/ */
if (!$this->getAxicoIdFactory()->isAxicoIdPresentInGroup($manufacturer->getId(), $category->getId(), null)) { if (!$this->getAxicoIdFactory()->isAxicoIdPresentInGroup($manufacturer->getId(), $category->getId(), null)) {
/* @var $axicoId AxicoId */ /* @var $axicoId AxicoId */
$axicoId = $this->getAxicoIdFactory()->createForCategory($manufacturer->getId(), $category->getId()); $axicoId = $this->getAxicoIdFactory()->createForCategory($manufacturer->getId(), $category->getId());
$axicoId->setName($manufacturer->getAxicoIdName() . $category->getAxicoIdName()); $axicoId->setName($manufacturer->getAxicoIdName() . $category->getAxicoIdName());
$this->getAxicoIdFactory()->save($axicoId); $this->getAxicoIdFactory()->save($axicoId);

$axicoIdWarranty = $this->getAxicoIdWarrantyFactory()->create();
$axicoIdWarranty->setAxicoIdName($axicoId->getName());
$this->getAxicoIdWarrantyFactory()->save($axicoIdWarranty);
} }
/* /*
* Create calculation for each newly created category * Create calculation for each newly created category

+ 8
- 0
modules/custom/arlista/src/Form/Component/ComponentEdit.php Vedi File

$axicoId = $this->getAxicoIdFactory()->createForComponent($manufacturer->getId(), $component->getId()); $axicoId = $this->getAxicoIdFactory()->createForComponent($manufacturer->getId(), $component->getId());
$axicoId->setName($manufacturer->getAxicoIdName() . $component->getAxicoIdName()); $axicoId->setName($manufacturer->getAxicoIdName() . $component->getAxicoIdName());
$axicoId = $this->getAxicoIdFactory()->save($axicoId); $axicoId = $this->getAxicoIdFactory()->save($axicoId);

$axicoIdWarranty = $this->getAxicoIdWarrantyFactory()->create();
$axicoIdWarranty->setAxicoIdName($axicoId->getName());
$this->getAxicoIdWarrantyFactory()->save($axicoIdWarranty);
} }
/* @var $calculation Calculation */ /* @var $calculation Calculation */
$calculation = $this->getCalculationFactory()->findByComponent($component); $calculation = $this->getCalculationFactory()->findByComponent($component);
if (empty($calculation)) { if (empty($calculation)) {
$this->getCalculationFactory()->createFor($component, null, $manufacturer); $this->getCalculationFactory()->createFor($component, null, $manufacturer);
} }

\Drupal::messenger()->addStatus('Új komponens sikeresen mentve!'); \Drupal::messenger()->addStatus('Új komponens sikeresen mentve!');

} else { } else {
$component = $this->getComponentFactory()->save($component); $component = $this->getComponentFactory()->save($component);
\Drupal::messenger()->addStatus('Sikeres mentés!'); \Drupal::messenger()->addStatus('Sikeres mentés!');

+ 21
- 1
modules/custom/arlista/src/Form/Config/ArlistaSetupForm.php Vedi File

'#min' => 1, '#min' => 1,
'#default_value' => [$config->get('exchange_rate_usd') ? $config->get('exchange_rate_usd') : 350] '#default_value' => [$config->get('exchange_rate_usd') ? $config->get('exchange_rate_usd') : 350]
]; ];

$form['default_warranty'] = [
'#title' => 'Alapértelmezett Axico Cikkszám garancia',
'#type' => 'number',
'#precision' => 0,
'#scale' => 0,
'#step' => 1,
'#max' => 72,
'#min' => 12,
'#required' => true,
'#default_value' => [$config->get('default_warranty') ? $config->get('default_warranty') : 12]
];

$form = parent::buildForm($form, $form_state); $form = parent::buildForm($form, $form_state);
$form['actions']['submit']['#value'] = 'Mentés'; $form['actions']['submit']['#value'] = 'Mentés';
$form['buttons_secondary'] = [ $form['buttons_secondary'] = [
'USD' => ['name' => 'USD', 'change' => false, 'exchangeRate' => 0], 'USD' => ['name' => 'USD', 'change' => false, 'exchangeRate' => 0],
]; ];


$message = '';

if ($config->get('exchange_rate_eur') <> $form_state->getValue('exchange_rate_eur')) { if ($config->get('exchange_rate_eur') <> $form_state->getValue('exchange_rate_eur')) {
$exchangeRateChanges['EUR']['change'] = true; $exchangeRateChanges['EUR']['change'] = true;
$exchangeRateChanges['EUR']['exchangeRate'] = $form_state->getValue('exchange_rate_eur'); $exchangeRateChanges['EUR']['exchangeRate'] = $form_state->getValue('exchange_rate_eur');
$message = $message . 'termékárak újrakalkulálva';
$message = $message . 'termékárak újrakalkulálva.';
} }
if ($config->get('exchange_rate_usd') <> $form_state->getValue('exchange_rate_usd')) { if ($config->get('exchange_rate_usd') <> $form_state->getValue('exchange_rate_usd')) {
$exchangeRateChanges['USD']['change'] = true; $exchangeRateChanges['USD']['change'] = true;
$exchangeRateChanges['USD']['exchangeRate'] = $form_state->getValue('exchange_rate_usd'); $exchangeRateChanges['USD']['exchangeRate'] = $form_state->getValue('exchange_rate_usd');
} }


if ($config->get('default_warranty') <> $form_state->getValue('default_warranty')) {
$message = $message . ' Alapértelmezett garancia mentve (a korábban mentett cikkszám garancia adatok változatlanok).';
}

$this->configFactory->getEditable(static::SETTINGS) $this->configFactory->getEditable(static::SETTINGS)
->set('default_listed', $form_state->getValue('default_listed')) ->set('default_listed', $form_state->getValue('default_listed'))
->set('exchange_rate_eur', $form_state->getValue('exchange_rate_eur')) ->set('exchange_rate_eur', $form_state->getValue('exchange_rate_eur'))
->set('exchange_rate_usd', $form_state->getValue('exchange_rate_usd')) ->set('exchange_rate_usd', $form_state->getValue('exchange_rate_usd'))
->set('default_warranty', $form_state->getValue('default_warranty'))
->save(); ->save();


$this->productService->updateAllProductPrices($exchangeRateChanges); $this->productService->updateAllProductPrices($exchangeRateChanges);

+ 19
- 0
modules/custom/arlista/templates/arlista-axico-id-warranty-list.html.twig Vedi File

{% set enabled = 'col-lg-3 entity-list highlighted' %}
{% set disabled = 'col-lg-3 entity-list disabled' %}
<div class="list-container">
<table class="table component-list">
<tr>
<th>Axico Cikkszám</th>
<th>Garancia</th>
</tr>
{% for warranty in warranties %}
<tr>
<td><a href="{{ url('<front>') }}axico-id-warranty/list/edit/{{ warranty.id }}">{{ warranty.axicoIdName }}</a></td>
<td>{{ warranty.defaultWarranty }}</td>
<td>
</td>
</tr>
{% endfor %}
</table>
</div>


Loading…
Annulla
Salva