Просмотр исходного кода

axico id revoking fixes

master
Dukai Károly 3 лет назад
Родитель
Сommit
e8ce08ae38
4 измененных файлов: 122 добавлений и 52 удалений
  1. +11
    -3
      README.txt
  2. +2
    -0
      modules/custom/arlista/src/Factory/AbstractFactory.php
  3. +46
    -4
      modules/custom/arlista/src/Factory/AxicoIdFactory.php
  4. +63
    -45
      modules/custom/arlista/src/Factory/ProductFactory.php

+ 11
- 3
README.txt Просмотреть файл

@@ -1,8 +1,15 @@
-- Változás napló 2023-04-27

- cikkszámozás után correct/workflow státusz módosul,
- kézi vagy fájlból feltöltött termék törlés után megfelelő helyre irányítja a felhasználót,
a kezelt fájl nem törölt termékeihez,
- cikkszámozás után a termék állapota Aktiválva státuszt vesz fel, ami azt jelenti hogy a Correctbe importált termékről van szó az árlsta kezelő szerint ,
- ha passzívvá tesszük, a termék kikerült a Correct adatbázisából az árlsta kezelő szerint,
- kézi vagy fájlból feltöltött termék törlés után megfelelő helyre irányítja a felhasználót, a kezelt fájl nem törölt termékeihez,
- cikkszám visszavételezés után, az kiosztható következő cikkszám az a legkissebb értékű visszavont cikkszám (több is visszavehető),

- ha a Correct számára ismert cikkszámot vonunk vissza, és másik terméknek adjuk oda, az különös problémákhoz vezethet, ezért erre figyeljünk oda,

- a SUPVIX, SUPSSG, SUPHAX, SUPHSW, SUPSSG mind olyan csoport, amely lehet SUP standard, és SUP komponens is,
- ezen termékek cikkszámozása és visszavételezése egy sorszámtartományban történik,
- ha több ilyen van, akkor az mielőbb jelezni kell a fejlesztőnek vagy felhasználó által módosíthatóvá tehető,




+ 2
- 0
modules/custom/arlista/src/Factory/AbstractFactory.php Просмотреть файл

@@ -18,6 +18,8 @@ abstract class AbstractFactory
* These groups can be either component or !component based
*/
public const SPECIFIC_GROUPS = ['VIX' => 'VIX', 'HSW' => 'HSW', 'HAX' => 'HAX', 'SSG' => 'SSG'];
public const SPECIFIC_MANUFACTURERS = ['SUP'];
/**
* Database connection.
*

+ 46
- 4
modules/custom/arlista/src/Factory/AxicoIdFactory.php Просмотреть файл

@@ -11,6 +11,7 @@ use Drupal\arlista\Traits\AxicoIdTrait;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Database\Connection;
use Drupal\Core\Session\AccountInterface;
use Drupal\arlista\Entity\Product;
use stdClass;

class AxicoIdFactory extends AbstractFactory {
@@ -51,12 +52,12 @@ class AxicoIdFactory extends AbstractFactory {
$this->reviveAxicoIdEntity($axicoIdEntity);
}

public function reviveAxicoIdEntity(AxicoId $axicoIdEntity): AxicoId {
public function reviveAxicoIdEntity(AxicoId $axicoIdEntity): void {
$axicoIdEntity->setNextCount(1);
$axicoIdEntity->setProductId(null);
$axicoIdEntity->setRevoked(1);

return $this->save($axicoIdEntity);
$this->update($axicoIdEntity);
}

public function deleteNextAxicoIdEntityIfExists($axicoIdEntity): void {
@@ -125,7 +126,7 @@ class AxicoIdFactory extends AbstractFactory {
->range(0, 1)
->execute()
->fetchObject();
if (!empty($data)) {
$newEntity = $this->load($data);
$newEntity->setId(null);
@@ -553,5 +554,46 @@ class AxicoIdFactory extends AbstractFactory {

return $axicoIds;
}

/**
* Delete the other axico id entity
*
* For component, delete category, for category, delete axico id with same
* current count.
*
* @param Product $product
* @param int $currentCount
* @return type void
*/
public function deleteRevokedAxicoIdEntityPairIfExists(Product $product, int $currentCount): void {
$groupAxicoName = $this->getGroupAxicoId($product->getAxicoId());
$manufacturerAxicoIdName = $this->getManufacturerAxicoId($product->getAxicoId());
if (!isset($this::SPECIFIC_GROUPS[$groupAxicoName]) && !isset($this::SPECIFIC_MANUFACTURERS[$manufacturerAxicoIdName])) {
return;
}
$axicoIdName = $manufacturerAxicoIdName . $groupAxicoName;
$deletablePairOfReusedAxicoIdEntity = $this->findDeletablePairOfReusedAxicoIdEntity($axicoIdName, $currentCount, 1);
if (!empty($deletablePairOfReusedAxicoIdEntity)) {
$this->delete($deletablePairOfReusedAxicoIdEntity);
}
}

public function findDeletablePairOfReusedAxicoIdEntity(string $name, int $currentCount, int $revoked): ?AxicoId {
$data = $this->getConnection()
->select($this->getActiveTable(), 'w')
->fields('w')
->isNull('w.deleted_at')
->isNull('w.product_id')
->condition('w.name', $name)
->condition('w.current_count', $currentCount)
->condition('w.revoked', $revoked)
->condition('w.next_count', 1)
->execute()
->fetchObject();
if ($data) {
return $this->load($data);
}
return null;
}

}

+ 63
- 45
modules/custom/arlista/src/Factory/ProductFactory.php Просмотреть файл

@@ -32,8 +32,6 @@ use stdClass;

class ProductFactory extends AbstractFactory {

public const SPECIFIC_MANUFACTURERS = ['SUP'];

private AxicoIdFactory $axicoIdFactory;
private CategoryFactory $categoryFactory;
private ComponentFactory $componentFactory;
@@ -430,25 +428,7 @@ class ProductFactory extends AbstractFactory {
$product = $this->resetProductAxicoId($product);
$product = $this->save($product);
if ($result['revokeAxicoId']) {
$product = $this->resetProductsAxicoIdData($product);

$result['optionValues'][$product->getId()] = $revokeAxicoIdselectOptionValue;
$result['revokedProducts'][$product->getId()] = $product;
$result['status'] = 1;
$result['axicoIdRevoked']++;
$result['axicoId'][$product->getId()] = '';

$productsInOtherFiles = $this->findSameUploadedProductInDifferentFilesByFabricId($product->getFabricId(), $product->getUploadedFileId());
foreach ($productsInOtherFiles as $productInOtherFile) {
$productInOtherFile = $this->resetProductsAxicoIdData($product);
}
$activeProduct = $this->findByFabricIdInTable($product->getFabricId(), 'arlista_manager_active_product');
if ($activeProduct) {
$this->setActiveTable('arlista_manager_active_product');
$this->delete($activeProduct);
}
$this->setActiveTable('arlista_manager_uploaded_product');

$result = $this->executeAxicoIdRevoking($product, $revokeAxicoIdselectOptionValue, $result);
continue;
}
}
@@ -518,12 +498,19 @@ class ProductFactory extends AbstractFactory {
}
$product->setCalculation($calculation);
$product->calculatePrices();
/**
* AXICO ID HANDLING
*
* ? XXX-ZZZ-{1234}
*
* - continue existing OR
* - generate new
*
*/
if ($existingAxicoIdEntity) {
/*
* Continue an existing axico id
* some products were sorted before into this group
* CONTINUE
*/

$product->setAxicoId($existingAxicoIdEntity->getNextAxicoIdName() . $this->getAxicoIdFactory()->addZeros($existingAxicoIdEntity->getCurrentCount()));
$product->setWorkFlow(WorkFlow::NUMBERED);
$axicoIdWarranty = $this->axicoIdWarrantyFactory->findByProductAxicoIdName($product->getAxicoId());
@@ -549,10 +536,15 @@ class ProductFactory extends AbstractFactory {
$newAxicoIdEntity->setCurrentCount($currentCount);
$newAxicoIdEntity = $this->getAxicoIdFactory()->save($newAxicoIdEntity);
$this->createNextForParallelSpecificGroup($newAxicoIdEntity, $product);
} else {
// It was a reused axico id entity
// Check if it is in specifig groups
// Check if the pair axico id entity exists
$this->getAxicoIdFactory()->deleteRevokedAxicoIdEntityPairIfExists($product, $existingAxicoIdEntity->getCurrentCount());
}
} else {
/*
* Generate a new axico id for this component or category
* GENERATE
*/
$axicoIdName = '';
if ($product->isComponentBased()) {
@@ -602,6 +594,44 @@ class ProductFactory extends AbstractFactory {
return $result;
}

private function resetProductAxicoId(Product $product): Product {
/* @var $axicoId AxicoId */
$axicoId = $this->getAxicoIdFactory()->findByFullProductAxicoId($product->getAxicoId());
if (empty($axicoId)) {
// to do
// see if this can happen at all
} else {
$this->getAxicoIdFactory()->resetAxicoIdEntity($axicoId);//ok
$this->createNextForParallelSpecificGroup($axicoId, $product);//not ok
$product->setAxicoId(null);
}

return $product;
}

private function executeAxicoIdRevoking(Product $product, string $revokeAxicoIdselectOptionValue, array $result): array {
$product = $this->resetProductsAxicoIdData($product);

$result['optionValues'][$product->getId()] = $revokeAxicoIdselectOptionValue;
$result['revokedProducts'][$product->getId()] = $product;
$result['status'] = 1;
$result['axicoIdRevoked']++;
$result['axicoId'][$product->getId()] = '';

$productsInOtherFiles = $this->findSameUploadedProductInDifferentFilesByFabricId($product->getFabricId(), $product->getUploadedFileId());
foreach ($productsInOtherFiles as $productInOtherFile) {
$productInOtherFile = $this->resetProductsAxicoIdData($product);
}
$activeProduct = $this->findByFabricIdInTable($product->getFabricId(), 'arlista_manager_active_product');
if ($activeProduct) {
$this->setActiveTable('arlista_manager_active_product');
$this->delete($activeProduct);
}
$this->setActiveTable('arlista_manager_uploaded_product');

return $result;
}

/**
* Reset products axico id data on axico id removal
*
@@ -614,7 +644,7 @@ class ProductFactory extends AbstractFactory {
$product->setWarranty(0);
$product->setAxicoId(null);
$product->setWorkFlow(WorkFlow::COMPARED);
$product = $this->update($product);
$this->update($product);
$this->cacheService->resetCache(['arlista_product_edit_form', 'uploaded', $product->getId()]);

return $product;
@@ -972,22 +1002,6 @@ class ProductFactory extends AbstractFactory {
return $filteredProducts;
}

public function resetProductAxicoId(Product $product): Product {
$axicoId = $this->getAxicoIdFactory()->findByFullProductAxicoId($product->getAxicoId());
if (empty($axicoId)) {
// to do
// see if this can happen at all
} else {
$this->getAxicoIdFactory()->resetAxicoIdEntity($axicoId);
$product->setAxicoId(null);
//$product->setParentCategoryId(null);
//$product->setParentComponentId(null);
//$product->setParentManufacturerId(null);
}

return $product;
}

public function updateExistingProduct(Product $product, Product $existingProduct, string $status): void {
$existingProduct = $this->updateProductsPreviousData($existingProduct, $existingProduct);
$existingProduct->copySpecialProperties($product);
@@ -1033,17 +1047,21 @@ class ProductFactory extends AbstractFactory {
return;
}

$manufacturer = $this->getManufacturerFactory()->findByAxicoIdNameAndComponentBased($manufacturerAxicoIdName, $product->isComponentBased() ? 0 : 1);

if ($product->isComponentBased()) {
$manufacturer = $this->getManufacturerFactory()->findByAxicoIdNameAndComponentBased($manufacturerAxicoIdName, 0);
// Create for category
$category = $this->getCategoryFactory()->findByAxicoIdName($groupAxicoName);
$nextGroupAxicoId = $this->getAxicoIdFactory()->findOrCreateNextAxicoIdByManufacturerIdAndCategoryId($manufacturer->getId(), $category->getId());
} else {
$manufacturer = $this->getManufacturerFactory()->findByAxicoIdNameAndComponentBased($manufacturerAxicoIdName, 1);
// Create for component
$component = $this->getComponentFactory()->findByAxicoIdNameAndParentManufacturerId($groupAxicoName, $manufacturer->getId());
$nextGroupAxicoId = $this->getAxicoIdFactory()->findOrCreateNextAxicoIdByManufacturerIdAndComponentId($component->getParentManufacturerId(), $component->getId());
}
$cuurentCount = $storedAxicoIdEntity->getCurrentCount();
$currentCount = $storedAxicoIdEntity->getCurrentCount();
$nextGroupAxicoId->setId(null);
$nextGroupAxicoId->setCurrentCount($currentCount);
$nextGroupAxicoId->setRevoked($storedAxicoIdEntity->getRevoked());
$this->getAxicoIdFactory()->save($nextGroupAxicoId);
}


Загрузка…
Отмена
Сохранить