瀏覽代碼

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

master
Dukai Károly 3 年之前
父節點
當前提交
4c313d06f9
共有 19 個文件被更改,包括 466 次插入176 次删除
  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 查看文件

@@ -1,143 +1,22 @@
-- 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 查看文件

@@ -20,6 +20,14 @@ arlista.component.list:
weight: 20
menu_name: main
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:
title: "Fájlok"
description: "Fájlok feltöltése"

+ 8
- 0
modules/custom/arlista/arlista.module 查看文件

@@ -29,6 +29,14 @@ function arlista_theme($existing, $type, $theme, $path) {
'template' => 'arlista-component-list',
'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' => [
'variables' => [
'components' => null,

+ 25
- 8
modules/custom/arlista/arlista.routing.yml 查看文件

@@ -1,4 +1,4 @@
# CONFIGURATION
### CONFIGURATION
arlista.config.setup:
path: '/arlista/setup'
defaults:
@@ -20,7 +20,7 @@ arlista.config.fix.axico.id:
_title: 'Axico cikkszámok helyreállítása'
requirements:
_permission: 'arlista manage_pricelists'
# MANUFACTURER
### MANUFACTURER
arlista.manufacturer.list:
path: "/manufacturer/list"
defaults:
@@ -47,7 +47,7 @@ arlista.manufacturer.delete:
_permission: "arlista manage_pricelists"
_disable_route_normalizer: "TRUE"
id: ^\d+$
# SHEET SETTING
### SHEET SETTING
arlista.manufacturer.sheet-setting.edit:
path: "/manufacturer/sheet-settings"
defaults:
@@ -77,7 +77,7 @@ arlista.manufacturer.sheet-setting.enable-groups:
mid: ^\d+$
sheetSettingId: ^\d+$
componentBased: ^\d+$
# CALCULATION
### CALCULATION
arlista.manufacturer.calculations.list:
path: "/manufacturer/{mid}/calculations/list"
defaults:
@@ -98,7 +98,7 @@ arlista.manufacturer.calculation.edit:
mid: ^\d+$
catId: ^\d+$
cmpId: ^\d+$
# CATEGORY
### CATEGORY
arlista.category.list:
path: "/category/list"
defaults:
@@ -124,7 +124,7 @@ arlista.category.delete:
_permission: "arlista manage_pricelists"
_disable_route_normalizer: "TRUE"
id: ^\d+$
# COMPONENT
### COMPONENT
arlista.component.list:
path: "/component/list"
defaults:
@@ -150,7 +150,24 @@ arlista.component.delete:
_permission: "arlista manage_pricelists"
_disable_route_normalizer: "TRUE"
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:
path: "/files/{mid}/list"
defaults:
@@ -188,7 +205,7 @@ arlista.file.actualise-product-data:
_permission: "arlista manage_pricelists"
_disable_route_normalizer: "TRUE"
mid: ^\d+$
# PRODUCT
### PRODUCT
arlista.product.list:
path: "product/list/file"
defaults:

+ 3
- 0
modules/custom/arlista/arlista.services.yml 查看文件

@@ -13,6 +13,9 @@ services:
arlista.component.factory:
class: Drupal\arlista\Factory\ComponentFactory
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:
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']

+ 8
- 0
modules/custom/arlista/css/arlista.css 查看文件

@@ -80,5 +80,13 @@ div.field__item:hover {
}

button.button {
margin-top: 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 查看文件

@@ -124,6 +124,7 @@ abstract class ArlistaAbstractController extends ControllerBase {
$sameProductInOtherFiles->setAxicoId($product->getAxicoId());
$sameProductInOtherFiles->setWorkFlow(WorkFlow::ACTIVATED);
$sameProductInOtherFiles->setCorrectStatus(Status::CORRECT_IMPORTED);
$sameProductInOtherFiles->setWarranty($product->getWarranty());
$this->getProductFactory()->save($sameProductInOtherFiles);

+ 30
- 0
modules/custom/arlista/src/Entity/AxicoIdWarranty.php 查看文件

@@ -0,0 +1,30 @@
<?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 查看文件

@@ -53,6 +53,7 @@ class Product extends AbstractEntity {
private ?float $weight = null;
private ?float $width = null;
private ?string $workFlow = null;
private ?int $defaultWarranty = null;
/*
* Transitional
*/
@@ -551,6 +552,14 @@ class Product extends AbstractEntity {
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 {
$this->setSif($product->getSif());
$this->setAxicoId($product->getAxicoId());

+ 22
- 30
modules/custom/arlista/src/Factory/AxicoIdFactory.php 查看文件

@@ -514,33 +514,25 @@ class AxicoIdFactory extends AbstractFactory {
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 查看文件

@@ -0,0 +1,111 @@
<?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 查看文件

@@ -39,6 +39,7 @@ class ProductFactory extends AbstractFactory {
private ComponentFactory $componentFactory;
private ManufacturerFactory $manufacturerFactory;
private CacheService $cacheService;
private CalculationFactory $calculationFactory;
private array $fontAwesomeIcons = [];

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

+ 9
- 1
modules/custom/arlista/src/Form/ArlistaAbstractForm.php 查看文件

@@ -22,6 +22,7 @@ use Drupal\arlista\Factory\ProductFactory;
use Drupal\arlista\Factory\SpreadSheetFactory;
use Drupal\arlista\Factory\CalculationFactory;
use Drupal\arlista\Factory\EnabledGroupFactory;
use Drupal\arlista\Factory\AxicoIdWarrantyFactory;
use Drupal\Core\Config\ImmutableConfig;
use Drupal\arlista\Entity\Component;
use Drupal\arlista\Entity\Manufacturer;
@@ -42,6 +43,7 @@ abstract class ArlistaAbstractForm extends FormBase {
private $spreadSheetFactory;
private $calculationFactory;
private $enabledGroupFactory;
private $axicoIdWarrantyFactory;
private $config;

public function __construct(ComponentFactory $componentFactory, CategoryFactory $categoryFactory,
@@ -49,7 +51,7 @@ abstract class ArlistaAbstractForm extends FormBase {
SheetSettingFactory $SheetSettingFactory, CacheService $cacheService,
AxicoIdFactory $axicoIdFactory, ProductFactory $productFactory,
SpreadSheetFactory $spreadSheetFactory, CalculationFactory $calculationFactory,
EnabledGroupFactory $enabledGroupFactory) {
EnabledGroupFactory $enabledGroupFactory, AxicoIdWarrantyFactory $axicoIdWarrantyFactory) {
$this->componentFactory = $componentFactory;
$this->categoryFactory = $categoryFactory;
$this->fileFactory = $fileFactory;
@@ -61,6 +63,7 @@ abstract class ArlistaAbstractForm extends FormBase {
$this->spreadSheetFactory = $spreadSheetFactory;
$this->calculationFactory = $calculationFactory;
$this->enabledGroupFactory = $enabledGroupFactory;
$this->axicoIdWarrantyFactory = $axicoIdWarrantyFactory;
$this->config = \Drupal::config('arlista.settings');
}

@@ -81,6 +84,7 @@ abstract class ArlistaAbstractForm extends FormBase {
$container->get('arlista.spread-sheet.factory'),
$container->get('arlista.calculation.factory'),
$container->get('arlista.enabled-group.factory'),
$container->get('arlista.warranty.factory'),
);
}

@@ -127,6 +131,10 @@ abstract class ArlistaAbstractForm extends FormBase {
return $this->axicoIdFactory;
}

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

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

+ 95
- 0
modules/custom/arlista/src/Form/AxicoIdWarranty/AxicoIdWarrantyEdit.php 查看文件

@@ -0,0 +1,95 @@
<?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 查看文件

@@ -0,0 +1,69 @@
<?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 查看文件

@@ -86,13 +86,17 @@ class CategoryEdit extends ArlistaAbstractForm {
$manufacturers = $this->getManufacturerFactory()->findAll();
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)) {
/* @var $axicoId AxicoId */
$axicoId = $this->getAxicoIdFactory()->createForCategory($manufacturer->getId(), $category->getId());
$axicoId->setName($manufacturer->getAxicoIdName() . $category->getAxicoIdName());
$this->getAxicoIdFactory()->save($axicoId);

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

+ 8
- 0
modules/custom/arlista/src/Form/Component/ComponentEdit.php 查看文件

@@ -116,13 +116,21 @@ class ComponentEdit extends ArlistaAbstractForm {
$axicoId = $this->getAxicoIdFactory()->createForComponent($manufacturer->getId(), $component->getId());
$axicoId->setName($manufacturer->getAxicoIdName() . $component->getAxicoIdName());
$axicoId = $this->getAxicoIdFactory()->save($axicoId);

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

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

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

+ 21
- 1
modules/custom/arlista/src/Form/Config/ArlistaSetupForm.php 查看文件

@@ -102,6 +102,19 @@ class ArlistaSetupForm extends ConfigFormBase {
'#min' => 1,
'#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['actions']['submit']['#value'] = 'Mentés';
$form['buttons_secondary'] = [
@@ -148,20 +161,27 @@ class ArlistaSetupForm extends ConfigFormBase {
'USD' => ['name' => 'USD', 'change' => false, 'exchangeRate' => 0],
];

$message = '';

if ($config->get('exchange_rate_eur') <> $form_state->getValue('exchange_rate_eur')) {
$exchangeRateChanges['EUR']['change'] = true;
$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')) {
$exchangeRateChanges['USD']['change'] = true;
$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)
->set('default_listed', $form_state->getValue('default_listed'))
->set('exchange_rate_eur', $form_state->getValue('exchange_rate_eur'))
->set('exchange_rate_usd', $form_state->getValue('exchange_rate_usd'))
->set('default_warranty', $form_state->getValue('default_warranty'))
->save();

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

+ 19
- 0
modules/custom/arlista/templates/arlista-axico-id-warranty-list.html.twig 查看文件

@@ -0,0 +1,19 @@
{% 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…
取消
儲存