|
|
|
@@ -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); |
|
|
|
} |
|
|
|
|