Pārlūkot izejas kodu

axico id revoking fixes

master
Dukai Károly pirms 3 gadiem
vecāks
revīzija
e8ce08ae38
4 mainītis faili ar 122 papildinājumiem un 52 dzēšanām
  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 Parādīt failu

-- 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 Parādīt failu

* These groups can be either component or !component based * These groups can be either component or !component based
*/ */
public const SPECIFIC_GROUPS = ['VIX' => 'VIX', 'HSW' => 'HSW', 'HAX' => 'HAX', 'SSG' => 'SSG']; public const SPECIFIC_GROUPS = ['VIX' => 'VIX', 'HSW' => 'HSW', 'HAX' => 'HAX', 'SSG' => 'SSG'];
public const SPECIFIC_MANUFACTURERS = ['SUP'];
/** /**
* Database connection. * Database connection.
* *

+ 46
- 4
modules/custom/arlista/src/Factory/AxicoIdFactory.php Parādīt failu

use Drupal\Component\Datetime\TimeInterface; use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Database\Connection; use Drupal\Core\Database\Connection;
use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountInterface;
use Drupal\arlista\Entity\Product;
use stdClass; use stdClass;


class AxicoIdFactory extends AbstractFactory { class AxicoIdFactory extends AbstractFactory {
$this->reviveAxicoIdEntity($axicoIdEntity); $this->reviveAxicoIdEntity($axicoIdEntity);
} }


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


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


public function deleteNextAxicoIdEntityIfExists($axicoIdEntity): void { public function deleteNextAxicoIdEntityIfExists($axicoIdEntity): void {
->range(0, 1) ->range(0, 1)
->execute() ->execute()
->fetchObject(); ->fetchObject();
if (!empty($data)) { if (!empty($data)) {
$newEntity = $this->load($data); $newEntity = $this->load($data);
$newEntity->setId(null); $newEntity->setId(null);


return $axicoIds; 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 Parādīt failu



class ProductFactory extends AbstractFactory { class ProductFactory extends AbstractFactory {


public const SPECIFIC_MANUFACTURERS = ['SUP'];

private AxicoIdFactory $axicoIdFactory; private AxicoIdFactory $axicoIdFactory;
private CategoryFactory $categoryFactory; private CategoryFactory $categoryFactory;
private ComponentFactory $componentFactory; private ComponentFactory $componentFactory;
$product = $this->resetProductAxicoId($product); $product = $this->resetProductAxicoId($product);
$product = $this->save($product); $product = $this->save($product);
if ($result['revokeAxicoId']) { 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; continue;
} }
} }
} }
$product->setCalculation($calculation); $product->setCalculation($calculation);
$product->calculatePrices(); $product->calculatePrices();
/**
* AXICO ID HANDLING
*
* ? XXX-ZZZ-{1234}
*
* - continue existing OR
* - generate new
*
*/
if ($existingAxicoIdEntity) { 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->setAxicoId($existingAxicoIdEntity->getNextAxicoIdName() . $this->getAxicoIdFactory()->addZeros($existingAxicoIdEntity->getCurrentCount()));
$product->setWorkFlow(WorkFlow::NUMBERED); $product->setWorkFlow(WorkFlow::NUMBERED);
$axicoIdWarranty = $this->axicoIdWarrantyFactory->findByProductAxicoIdName($product->getAxicoId()); $axicoIdWarranty = $this->axicoIdWarrantyFactory->findByProductAxicoIdName($product->getAxicoId());
$newAxicoIdEntity->setCurrentCount($currentCount); $newAxicoIdEntity->setCurrentCount($currentCount);
$newAxicoIdEntity = $this->getAxicoIdFactory()->save($newAxicoIdEntity); $newAxicoIdEntity = $this->getAxicoIdFactory()->save($newAxicoIdEntity);
$this->createNextForParallelSpecificGroup($newAxicoIdEntity, $product); $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 { } else {
/* /*
* Generate a new axico id for this component or category
* GENERATE
*/ */
$axicoIdName = ''; $axicoIdName = '';
if ($product->isComponentBased()) { if ($product->isComponentBased()) {
return $result; 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 * Reset products axico id data on axico id removal
* *
$product->setWarranty(0); $product->setWarranty(0);
$product->setAxicoId(null); $product->setAxicoId(null);
$product->setWorkFlow(WorkFlow::COMPARED); $product->setWorkFlow(WorkFlow::COMPARED);
$product = $this->update($product);
$this->update($product);
$this->cacheService->resetCache(['arlista_product_edit_form', 'uploaded', $product->getId()]); $this->cacheService->resetCache(['arlista_product_edit_form', 'uploaded', $product->getId()]);


return $product; return $product;
return $filteredProducts; 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 { public function updateExistingProduct(Product $product, Product $existingProduct, string $status): void {
$existingProduct = $this->updateProductsPreviousData($existingProduct, $existingProduct); $existingProduct = $this->updateProductsPreviousData($existingProduct, $existingProduct);
$existingProduct->copySpecialProperties($product); $existingProduct->copySpecialProperties($product);
return; return;
} }


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

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



Notiek ielāde…
Atcelt
Saglabāt