|
|
|
@@ -9,82 +9,81 @@ use Drupal\arlista\Entity\WorkFlow; |
|
|
|
|
|
|
|
class ProductController extends ArlistaAbstractController { |
|
|
|
|
|
|
|
public function actualiseModifiedProductDataOfFile(Request $request) { |
|
|
|
|
|
|
|
$fid = $request->request->get('fid'); |
|
|
|
$this->getResponseBody()->setFid($fid); |
|
|
|
$this->getResponseBody()->setMessage('Sikertelen aktualizáció'); |
|
|
|
|
|
|
|
if ($this->currentUser->isAnonymous() || !$this->isAdmin()) { |
|
|
|
$this->getResponseBody()->setMessage('Sikertelen azonosítás'); |
|
|
|
$this->getResponse()->setData($this->getResponseBody()->toArray()); |
|
|
|
return $this->getResponse(); |
|
|
|
} |
|
|
|
|
|
|
|
$uploadedFile = $this->getFileFactory()->find($fid); |
|
|
|
if (empty($uploadedFile) || empty($fid)) { |
|
|
|
$this->getResponseBody()->setMessage('Nincs ilyen fájl'); |
|
|
|
$this->getResponse()->setData($this->getResponseBody()->toArray()); |
|
|
|
return $this->getResponse(); |
|
|
|
} |
|
|
|
|
|
|
|
if (empty($uploadedFile->getTotalProducts() < 1)) { |
|
|
|
$this->getResponseBody()->setMessage('A feltöltött fájl nem tartalmaz termékeket'); |
|
|
|
$this->getResponse()->setData($this->getResponseBody()->toArray()); |
|
|
|
return $this->getResponse(); |
|
|
|
} |
|
|
|
|
|
|
|
$products = $this->getProductFactory()->findProductsByUploadedFileId($uploadedFile->getId()); |
|
|
|
if (empty($products)) { |
|
|
|
$this->getResponseBody()->setMessage('A feltöltött fájlhoz kapcsolódó termékek nem találhatóak'); |
|
|
|
$this->getResponse()->setData($this->getResponseBody()->toArray()); |
|
|
|
return $this->getResponse(); |
|
|
|
} |
|
|
|
$modifiedProducts = []; |
|
|
|
|
|
|
|
/* @var $product Product */ |
|
|
|
foreach ($products as $product) { |
|
|
|
if ($product->getModifiedAt() > $uploadedFile->getModifiedAt()) { |
|
|
|
$modifiedProducts[] = $product; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
$result = [ |
|
|
|
'products' => $modifiedProducts, |
|
|
|
'manufacturer' => $this->getManufacturerFactory()->find($uploadedFile->getParentManufacturerId()), |
|
|
|
'totalNumbered' => 0, |
|
|
|
'axicoIdCopied' => 0, |
|
|
|
'axicoIdContinued' => 0, |
|
|
|
'axicoIdGenerated' => 0, |
|
|
|
'axicoId' => [], |
|
|
|
'axicoIdMissing' => 0, |
|
|
|
'status' => false, |
|
|
|
'axicoIdRevoked' => 0, |
|
|
|
'newProduct' => 0, |
|
|
|
'updatedProduct' => 0, |
|
|
|
'revokeAxicoId' => 0, |
|
|
|
'revokedProducts' => [], |
|
|
|
'totalActualised' => 0, |
|
|
|
]; |
|
|
|
|
|
|
|
$result = $this->getProductFactory()->actualiseProducts($result); |
|
|
|
if ($result['totalActualised'] === 0 || !$result['status']) { |
|
|
|
$this->getResponseBody()->setMessage('Nincs aktualizálható termék - ellenőrizze a konfigurációkat'); |
|
|
|
$this->getResponse()->setData($this->getResponseBody()->toArray()); |
|
|
|
return $this->getResponse(); |
|
|
|
} |
|
|
|
|
|
|
|
$uploadedFile->setWorkFlow(WorkFlow::ACTIVATED); |
|
|
|
$this->getFileFactory()->save($uploadedFile); |
|
|
|
|
|
|
|
unset($result['products'], $result['manufacturer']); |
|
|
|
|
|
|
|
$this->getResponseBody()->setMessage('Sikeres aktualizáció'); |
|
|
|
$this->getResponseBody()->setData($result); |
|
|
|
$this->getResponseBody()->setSuccess(1); |
|
|
|
$this->getResponse()->setData($this->getResponseBody()->toArray()); |
|
|
|
|
|
|
|
return $this->getResponse(); |
|
|
|
public function actualiseModifiedProductDataOfFile(Request $request) { |
|
|
|
|
|
|
|
$fid = $request->request->get('fid'); |
|
|
|
$this->getResponseBody()->setFid($fid); |
|
|
|
$this->getResponseBody()->setMessage('Sikertelen aktualizáció'); |
|
|
|
|
|
|
|
if ($this->currentUser->isAnonymous() || !$this->isAdmin()) { |
|
|
|
$this->getResponseBody()->setMessage('Sikertelen azonosítás'); |
|
|
|
$this->getResponse()->setData($this->getResponseBody()->toArray()); |
|
|
|
return $this->getResponse(); |
|
|
|
} |
|
|
|
|
|
|
|
$uploadedFile = $this->getFileFactory()->find($fid); |
|
|
|
if (empty($uploadedFile) || empty($fid)) { |
|
|
|
$this->getResponseBody()->setMessage('Nincs ilyen fájl'); |
|
|
|
$this->getResponse()->setData($this->getResponseBody()->toArray()); |
|
|
|
return $this->getResponse(); |
|
|
|
} |
|
|
|
|
|
|
|
if (empty($uploadedFile->getTotalProducts() < 1)) { |
|
|
|
$this->getResponseBody()->setMessage('A feltöltött fájl nem tartalmaz termékeket'); |
|
|
|
$this->getResponse()->setData($this->getResponseBody()->toArray()); |
|
|
|
return $this->getResponse(); |
|
|
|
} |
|
|
|
|
|
|
|
$products = $this->getProductFactory()->findProductsByUploadedFileId($uploadedFile->getId()); |
|
|
|
if (empty($products)) { |
|
|
|
$this->getResponseBody()->setMessage('A feltöltött fájlhoz kapcsolódó termékek nem találhatóak'); |
|
|
|
$this->getResponse()->setData($this->getResponseBody()->toArray()); |
|
|
|
return $this->getResponse(); |
|
|
|
} |
|
|
|
$modifiedProducts = []; |
|
|
|
|
|
|
|
/* @var $product Product */ |
|
|
|
foreach ($products as $product) { |
|
|
|
if ($product->getModifiedAt() > $uploadedFile->getModifiedAt()) { |
|
|
|
$modifiedProducts[] = $product; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
$result = $this->getProductFactory()->actualiseProducts([ |
|
|
|
'products' => $modifiedProducts, |
|
|
|
'manufacturer' => $this->getManufacturerFactory()->find($uploadedFile->getParentManufacturerId()), |
|
|
|
'totalNumbered' => 0, |
|
|
|
'axicoIdCopied' => 0, |
|
|
|
'axicoIdContinued' => 0, |
|
|
|
'axicoIdGenerated' => 0, |
|
|
|
'axicoId' => [], |
|
|
|
'axicoIdMissing' => 0, |
|
|
|
'status' => false, |
|
|
|
'axicoIdRevoked' => 0, |
|
|
|
'newProduct' => 0, |
|
|
|
'updatedProduct' => 0, |
|
|
|
'revokeAxicoId' => 0, |
|
|
|
'revokedProducts' => [], |
|
|
|
'totalActualised' => 0, |
|
|
|
]); |
|
|
|
|
|
|
|
if ($result['totalActualised'] === 0 || !$result['status']) { |
|
|
|
$this->getResponseBody()->setMessage('Nincs aktualizálható termék - ellenőrizze a konfigurációkat'); |
|
|
|
$this->getResponse()->setData($this->getResponseBody()->toArray()); |
|
|
|
return $this->getResponse(); |
|
|
|
} |
|
|
|
|
|
|
|
$uploadedFile->setWorkFlow(WorkFlow::ACTIVATED); |
|
|
|
$this->getFileFactory()->save($uploadedFile); |
|
|
|
|
|
|
|
unset($result['products'], $result['manufacturer']); |
|
|
|
|
|
|
|
$this->getResponseBody()->setMessage('Sikeres termék ( ' . $result['totalActualised'] . ' db ) aktualizáció! '); |
|
|
|
$this->getResponseBody()->setData($result); |
|
|
|
$this->getResponseBody()->setSuccess(1); |
|
|
|
$this->getResponse()->setData($this->getResponseBody()->toArray()); |
|
|
|
|
|
|
|
return $this->getResponse(); |
|
|
|
} |
|
|
|
|
|
|
|
} |