| @@ -11,4 +11,5 @@ themes | |||
| !README.txt | |||
| !.gitignore | |||
| !/modules | |||
| !update.sql | |||
| !update.sql | |||
| !structure.sql | |||
| @@ -1,3 +1,11 @@ | |||
| -- Változás napló 2023-04-18 | |||
| - 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, | |||
| -- Változás napló 2023-02-23 | |||
| - ha több munkalap van mint konfigurált munkalap, az importálás hibaüzenettel tér vissza és nem fut le, | |||
| @@ -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: | |||
| @@ -85,7 +85,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: | |||
| @@ -106,7 +106,7 @@ arlista.manufacturer.calculation.edit: | |||
| mid: ^\d+$ | |||
| catId: ^\d+$ | |||
| cmpId: ^\d+$ | |||
| ### CATEGORY | |||
| ### ------------------- CATEGORY | |||
| arlista.category.list: | |||
| path: "/category/list" | |||
| defaults: | |||
| @@ -132,7 +132,7 @@ arlista.category.delete: | |||
| _permission: "arlista manage_pricelists" | |||
| _disable_route_normalizer: "TRUE" | |||
| id: ^\d+$ | |||
| ### COMPONENT | |||
| ### -------------------- COMPONENT | |||
| arlista.component.list: | |||
| path: "/component/list" | |||
| defaults: | |||
| @@ -158,7 +158,7 @@ arlista.component.delete: | |||
| _permission: "arlista manage_pricelists" | |||
| _disable_route_normalizer: "TRUE" | |||
| id: ^\d+$ | |||
| ### AXICO ID WARRANTY | |||
| ### ---------------------- AXICO ID WARRANTY | |||
| arlista.warranty.list: | |||
| path: "/axico-id-warranty/list/{filterx}" | |||
| defaults: | |||
| @@ -176,7 +176,7 @@ arlista.warranty.edit: | |||
| requirements: | |||
| _permission: "arlista manage_pricelists" | |||
| _disable_route_normalizer: "TRUE" | |||
| ### FILE | |||
| ### ----------------- FILE | |||
| arlista.file.list: | |||
| path: "/files/{mid}/list" | |||
| defaults: | |||
| @@ -214,7 +214,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: | |||
| @@ -1,44 +1,107 @@ | |||
| services: | |||
| arlista.axico-id.factory: | |||
| class: Drupal\arlista\Factory\AxicoIdFactory | |||
| arguments: ['@database', '@current_user', '@datetime.time'] | |||
| arguments: [ | |||
| '@database', | |||
| '@current_user', | |||
| '@datetime.time' | |||
| ] | |||
| arlista.cache-service: | |||
| class: Drupal\arlista\Service\CacheService | |||
| arlista.category.factory: | |||
| class: Drupal\arlista\Factory\CategoryFactory | |||
| arguments: ['@database', '@current_user', '@datetime.time'] | |||
| arguments: [ | |||
| '@database', | |||
| '@current_user', | |||
| '@datetime.time' | |||
| ] | |||
| arlista.calculation.factory: | |||
| class: Drupal\arlista\Factory\CalculationFactory | |||
| arguments: ['@database', '@current_user', '@datetime.time','@config.factory'] | |||
| arguments: [ | |||
| '@database', | |||
| '@current_user', | |||
| '@datetime.time', | |||
| '@config.factory' | |||
| ] | |||
| arlista.component.factory: | |||
| class: Drupal\arlista\Factory\ComponentFactory | |||
| arguments: ['@database', '@current_user', '@datetime.time'] | |||
| arguments: [ | |||
| '@database', | |||
| '@current_user', | |||
| '@datetime.time' | |||
| ] | |||
| arlista.warranty.factory: | |||
| class: Drupal\arlista\Factory\AxicoIdWarrantyFactory | |||
| arguments: ['@database', '@current_user', '@datetime.time', '@config.factory'] | |||
| 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'] | |||
| 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'] | |||
| arlista.enabled-group.factory: | |||
| class: Drupal\arlista\Factory\EnabledGroupFactory | |||
| arguments: ['@database', '@current_user', '@datetime.time'] | |||
| arguments: [ | |||
| '@database', | |||
| '@current_user', | |||
| '@datetime.time' | |||
| ] | |||
| arlista.file.factory: | |||
| class: Drupal\arlista\Factory\FileFactory | |||
| arguments: ['@database', '@current_user', '@datetime.time'] | |||
| arguments: [ | |||
| '@database', | |||
| '@current_user', | |||
| '@datetime.time' | |||
| ] | |||
| arlista.manufacturer.factory: | |||
| class: Drupal\arlista\Factory\ManufacturerFactory | |||
| arguments: ['@database', '@current_user', '@datetime.time'] | |||
| arguments: [ | |||
| '@database', | |||
| '@current_user', | |||
| '@datetime.time' | |||
| ] | |||
| arlista.product.factory: | |||
| class: Drupal\arlista\Factory\ProductFactory | |||
| arguments: ['@database', '@current_user', '@datetime.time', '@arlista.axico-id.factory', '@arlista.category.factory', '@arlista.component.factory', '@arlista.manufacturer.factory', '@arlista.calculation.factory','@arlista.cache-service', | |||
| '@arlista.warranty.factory'] | |||
| arguments: [ | |||
| '@database', | |||
| '@current_user', | |||
| '@datetime.time', | |||
| '@arlista.axico-id.factory', | |||
| '@arlista.category.factory', | |||
| '@arlista.component.factory', | |||
| '@arlista.manufacturer.factory', | |||
| '@arlista.calculation.factory', | |||
| '@arlista.cache-service', | |||
| '@arlista.warranty.factory' | |||
| ] | |||
| arlista.product.service: | |||
| class: Drupal\arlista\Service\ProductService | |||
| arguments: ['@arlista.product.factory','@arlista.file.factory'] | |||
| arguments: [ | |||
| '@arlista.product.factory', | |||
| '@arlista.file.factory' | |||
| ] | |||
| arlista.sheet-setting.factory: | |||
| class: Drupal\arlista\Factory\SheetSettingFactory | |||
| arguments: ['@database', '@current_user', '@datetime.time'] | |||
| arguments: [ | |||
| '@database', | |||
| '@current_user', | |||
| '@datetime.time' | |||
| ] | |||
| arlista.spread-sheet.factory: | |||
| class: Drupal\arlista\Factory\SpreadSheetFactory | |||
| arguments: ['@arlista.component.factory','@arlista.manufacturer.factory', | |||
| '@arlista.category.factory', '@config.factory'] | |||
| arguments: [ | |||
| '@arlista.component.factory', | |||
| '@arlista.manufacturer.factory', | |||
| '@arlista.category.factory', | |||
| '@config.factory' | |||
| ] | |||
| @@ -2,200 +2,224 @@ | |||
| namespace Drupal\arlista\Factory; | |||
| use Drupal\arlista\BaseEntityNotFoundException; | |||
| use Drupal\arlista\Entity\AbstractEntity; | |||
| use Drupal\arlista\Entity\Status; | |||
| use Drupal\Component\Datetime\TimeInterface; | |||
| use Drupal\Core\Database\Connection; | |||
| use Drupal\Core\Session\AccountInterface; | |||
| use Drupal\Component\Datetime\TimeInterface; | |||
| use Drupal\arlista\BaseEntityNotFoundException; | |||
| use stdClass; | |||
| abstract class AbstractFactory { | |||
| const TABLE_PREFIX = 'arlista_manager_'; | |||
| const SPECIFIC_GROUPS = [ | |||
| 'HSW' => 'HSW', 'HAX' => 'HAX', 'SSG' => 'SSG' | |||
| ]; | |||
| /** | |||
| * Database connection. | |||
| * | |||
| * @var $connection \Drupal\Core\Database\Connection | |||
| */ | |||
| private $connection = null; | |||
| private $currentUser; | |||
| private ?string $table = null; | |||
| private $time; | |||
| /** | |||
| * Construct. | |||
| * | |||
| * @param Connection $connection | |||
| * Database connection. | |||
| */ | |||
| public function __construct(Connection $connection, AccountInterface $currentUser, TimeInterface $time, string $class) { | |||
| $this->connection = $connection; | |||
| $this->currentUser = $currentUser; | |||
| $this->time = $time; | |||
| $this->table = $this->createTableName($this::TABLE_PREFIX . $class); | |||
| } | |||
| private function createTableName($class) { | |||
| return $class; | |||
| } | |||
| abstract public function create(); | |||
| public function getCurrentUser() { | |||
| return $this->currentUser; | |||
| } | |||
| public function getTime() { | |||
| return $this->time; | |||
| } | |||
| public function setCurrentUser($currentUser): void { | |||
| $this->currentUser = $currentUser; | |||
| } | |||
| public function setTime($time): void { | |||
| $this->time = $time; | |||
| } | |||
| public function getConnection(): Connection { | |||
| return $this->connection; | |||
| } | |||
| public function getSpecificGroups(): array { | |||
| return $this::SPECIFIC_GROUPS; | |||
| } | |||
| public function find(int $id) { | |||
| $data = $this->connection | |||
| ->select($this->table, 'w') | |||
| ->fields('w') | |||
| ->condition('w.id', $id) | |||
| ->isNull('w.deleted_at') | |||
| ->execute() | |||
| ->fetchObject(); | |||
| if (empty($data)) { | |||
| throw new BaseEntityNotFoundException("FIND - Entity with id : {$id} in table : {$this->table} table not found!"); | |||
| } | |||
| return $this->load($data); | |||
| } | |||
| public function findIn(int $id, string $tableName) { | |||
| $data = $this->connection | |||
| ->select($tableName, 'w') | |||
| ->fields('w') | |||
| ->condition('w.id', $id) | |||
| ->isNull('w.deleted_at') | |||
| ->execute() | |||
| ->fetchObject(); | |||
| if (empty($data)) { | |||
| throw new BaseEntityNotFoundException("FIND IN - Entity with id : {$id} in table {$tableName} table not found!"); | |||
| } | |||
| return $this->load($data); | |||
| } | |||
| abstract protected function load(stdClass $data); | |||
| public function findAll(string $orderBy = 'id', string $orderDirection = 'ASC') { | |||
| $list = $this->connection | |||
| ->select($this->table, 'w') | |||
| ->fields('w') | |||
| ->isNull('w.deleted_at') | |||
| ->orderBy($orderBy, $orderDirection) | |||
| ->execute(); | |||
| $entities = []; | |||
| foreach ($list as $item) { | |||
| $entities[] = $this->load($item); | |||
| } | |||
| return $entities; | |||
| } | |||
| public function findAllActive(string $orderBy = 'id', string $orderDirection = 'ASC') { | |||
| $list = $this->connection | |||
| ->select($this->table, 'w') | |||
| ->fields('w') | |||
| ->condition('status', Status::ACTIVE) | |||
| ->isNull('w.deleted_at') | |||
| ->orderBy($orderBy, $orderDirection) | |||
| ->execute(); | |||
| $entities = []; | |||
| foreach ($list as $item) { | |||
| $entities[] = $this->load($item); | |||
| } | |||
| return $entities; | |||
| } | |||
| public function save(AbstractEntity $entity) { | |||
| if ($entity->isNew()) { | |||
| return $this->insert($entity); | |||
| } | |||
| return $this->update($entity); | |||
| } | |||
| public function saveAll(array $entities): void { | |||
| foreach ($entities as $entity) { | |||
| /* @var $entity AbstractEntity */ | |||
| $this->save($entity); | |||
| } | |||
| } | |||
| public function saveTo(AbstractEntity $entity, string $targetTable) { | |||
| $defaultTable = $this->getActiveTable(); | |||
| $this->setActiveTable($targetTable); | |||
| $stored = $this->save($entity); | |||
| $this->setActiveTable($defaultTable); | |||
| return $stored; | |||
| } | |||
| abstract protected function insert(AbstractEntity $entity); | |||
| abstract protected function update(AbstractEntity $entity); | |||
| public function delete(AbstractEntity $entity) { | |||
| $this->connection | |||
| ->update($this->table) | |||
| ->fields([ | |||
| 'modified_at' => date('Y-m-d H:i:s', $this->time->getRequestTime()), | |||
| 'modified_by' => $this->currentUser->id(), | |||
| 'deleted_at' => date('Y-m-d H:i:s', $this->time->getRequestTime()) | |||
| ]) | |||
| ->condition('id', $entity->getId()) | |||
| ->execute(); | |||
| } | |||
| abstract class AbstractFactory | |||
| { | |||
| protected const TABLE_PREFIX = 'arlista_manager_'; | |||
| /** | |||
| * These groups can be either component or !component based | |||
| */ | |||
| public const SPECIFIC_GROUPS = ['VIX' => 'VIX', 'HSW' => 'HSW', 'HAX' => 'HAX', 'SSG' => 'SSG']; | |||
| /** | |||
| * Database connection. | |||
| * | |||
| * @var $connection \Drupal\Core\Database\Connection | |||
| */ | |||
| private ?Connection $connection = null; | |||
| private ?AccountInterface $currentUser = null; | |||
| private ?string $table = null; | |||
| private ?TimeInterface $time = null; | |||
| /** | |||
| * Construct. | |||
| * | |||
| * @param Connection $connection | |||
| * Database connection. | |||
| */ | |||
| public function __construct(Connection $connection, AccountInterface $currentUser, TimeInterface $time, string $class) | |||
| { | |||
| $this->connection = $connection; | |||
| $this->currentUser = $currentUser; | |||
| $this->time = $time; | |||
| $this->table = $this->createTableName($this::TABLE_PREFIX . $class); | |||
| } | |||
| abstract public function create(); | |||
| abstract protected function insert(AbstractEntity $entity); | |||
| abstract protected function update(AbstractEntity $entity); | |||
| abstract protected function load(stdClass $data); | |||
| /** | |||
| * @param string $class | |||
| */ | |||
| private function createTableName($class) : string | |||
| { | |||
| return $class; | |||
| } | |||
| public function getSpecificGroups() : array | |||
| { | |||
| return $this::SPECIFIC_GROUPS; | |||
| } | |||
| public function getCurrentUser() : AccountInterface | |||
| { | |||
| return $this->currentUser; | |||
| } | |||
| public function setCurrentUser($currentUser) : void | |||
| { | |||
| $this->currentUser = $currentUser; | |||
| } | |||
| public function getTime() | |||
| { | |||
| return $this->time; | |||
| } | |||
| public function setTime($time): void | |||
| { | |||
| $this->time = $time; | |||
| } | |||
| public function remove(AbstractEntity $entity) { | |||
| $this->connection | |||
| ->delete($this->table) | |||
| ->condition('id', $entity->getId()) | |||
| ->execute(); | |||
| } | |||
| public function getConnection(): Connection | |||
| { | |||
| return $this->connection; | |||
| } | |||
| public function getActiveTable(): string { | |||
| return $this->table; | |||
| } | |||
| public function setActiveTable(string $table): void { | |||
| $this->table = $table; | |||
| } | |||
| public function getActiveTable(): string | |||
| { | |||
| return $this->table; | |||
| } | |||
| public function import(string $tableName): array { | |||
| return $this->connection->select($tableName, 'w') | |||
| public function setActiveTable(string $table): void | |||
| { | |||
| $this->table = $table; | |||
| } | |||
| public function find(int $id) | |||
| { | |||
| $data = $this->connection | |||
| ->select($this->table, 'w') | |||
| ->fields('w') | |||
| ->condition('w.id', $id) | |||
| ->isNull('w.deleted_at') | |||
| ->execute() | |||
| ->fetchObject(); | |||
| if (empty($data)) { | |||
| throw new BaseEntityNotFoundException("FIND - Entity with id : {$id} in table : {$this->table} table not found!"); | |||
| } | |||
| return $this->load($data); | |||
| } | |||
| public function findIn(int $id, string $tableName) | |||
| { | |||
| $data = $this->connection | |||
| ->select($tableName, 'w') | |||
| ->fields('w') | |||
| ->condition('w.id', $id) | |||
| ->isNull('w.deleted_at') | |||
| ->execute() | |||
| ->fetchObject(); | |||
| if (empty($data)) { | |||
| throw new BaseEntityNotFoundException("FIND IN - Entity with id : {$id} in table {$tableName} table not found!"); | |||
| } | |||
| return $this->load($data); | |||
| } | |||
| public function findAll(string $orderBy = 'id', string $orderDirection = 'ASC') | |||
| { | |||
| $list = $this->connection | |||
| ->select($this->table, 'w') | |||
| ->fields('w') | |||
| ->isNull('w.deleted_at') | |||
| ->orderBy($orderBy, $orderDirection) | |||
| ->execute(); | |||
| $entities = []; | |||
| foreach ($list as $item) { | |||
| $entities[] = $this->load($item); | |||
| } | |||
| return $entities; | |||
| } | |||
| public function findAllActive(string $orderBy = 'id', string $orderDirection = 'ASC') | |||
| { | |||
| $list = $this->connection | |||
| ->select($this->table, 'w') | |||
| ->fields('w') | |||
| ->condition('status', Status::ACTIVE) | |||
| ->isNull('w.deleted_at') | |||
| ->orderBy($orderBy, $orderDirection) | |||
| ->execute(); | |||
| $entities = []; | |||
| foreach ($list as $item) { | |||
| $entities[] = $this->load($item); | |||
| } | |||
| return $entities; | |||
| } | |||
| public function save(AbstractEntity $entity) | |||
| { | |||
| if ($entity->isNew()) { | |||
| return $this->insert($entity); | |||
| } | |||
| return $this->update($entity); | |||
| } | |||
| public function saveAll(array $entities): void | |||
| { | |||
| foreach ($entities as $entity) { | |||
| /* @var $entity AbstractEntity */ | |||
| $this->save($entity); | |||
| } | |||
| } | |||
| public function saveToDatabaseTable(AbstractEntity $entity, string $targetTable) | |||
| { | |||
| $defaultTable = $this->getActiveTable(); | |||
| $this->setActiveTable($targetTable); | |||
| $stored = $this->save($entity); | |||
| $this->setActiveTable($defaultTable); | |||
| return $stored; | |||
| } | |||
| public function delete(AbstractEntity $entity) | |||
| { | |||
| $this->connection | |||
| ->update($this->table) | |||
| ->fields([ | |||
| 'modified_at' => date('Y-m-d H:i:s', $this->time->getRequestTime()), | |||
| 'modified_by' => $this->currentUser->id(), | |||
| 'deleted_at' => date('Y-m-d H:i:s', $this->time->getRequestTime()), | |||
| ]) | |||
| ->condition('id', $entity->getId()) | |||
| ->execute(); | |||
| } | |||
| public function removeFromTable(AbstractEntity $entity) | |||
| { | |||
| $this->connection | |||
| ->delete($this->table) | |||
| ->condition('id', $entity->getId()) | |||
| ->execute(); | |||
| } | |||
| public function importFromTable(string $tableName): array | |||
| { | |||
| return $this->connection->select($tableName, 'w') | |||
| ->fields('w') | |||
| ->execute() | |||
| ->fetchAll(); | |||
| } | |||
| } | |||
| } | |||
| @@ -2,55 +2,62 @@ | |||
| namespace Drupal\arlista\Factory; | |||
| use Drupal\arlista\Entity\UploadedFile; | |||
| use PhpOffice\PhpSpreadsheet\Spreadsheet; | |||
| use PhpOffice\PhpSpreadsheet\Writer\Xlsx; | |||
| use Drupal\arlista\Entity\UploadedFile; | |||
| abstract class AbstractSpreadSheetFactory { | |||
| private $uploadedFileid; | |||
| abstract class AbstractSpreadSheetFactory | |||
| { | |||
| public function initSpreadSheet(): Spreadsheet { | |||
| return new \PhpOffice\PhpSpreadsheet\Spreadsheet(); | |||
| } | |||
| private $uploadedFileid; | |||
| public function getSpreadSheetWriter(SpreadSheet $spreadSheetData) { | |||
| $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadSheetData); | |||
| $writer->setOffice2003Compatibility(true); | |||
| return $writer; | |||
| } | |||
| public function getUploadedFileid() { | |||
| return $this->uploadedFileid; | |||
| } | |||
| public function initSpreadSheet(): Spreadsheet | |||
| { | |||
| return new \PhpOffice\PhpSpreadsheet\Spreadsheet(); | |||
| } | |||
| public function setUploadedFileid($uploadedFileid): void { | |||
| $this->uploadedFileid = $uploadedFileid; | |||
| } | |||
| public function getSpreadSheetWriter(SpreadSheet $spreadSheetData) | |||
| { | |||
| $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadSheetData); | |||
| $writer->setOffice2003Compatibility(true); | |||
| return $writer; | |||
| } | |||
| public function createNewSpreadSheet(): Spreadsheet { | |||
| return new Spreadsheet(); | |||
| } | |||
| public function getUploadedFileid() | |||
| { | |||
| return $this->uploadedFileid; | |||
| } | |||
| public function createXlsxWriterFromSpreadSheet(Spreadsheet $spreadsheet): Xlsx { | |||
| return new Xlsx($spreadsheet); | |||
| } | |||
| public function setUploadedFileid($uploadedFileid): void | |||
| { | |||
| $this->uploadedFileid = $uploadedFileid; | |||
| } | |||
| public function loadUploadedFile(UploadedFile $uploadedFile): Spreadsheet { | |||
| try { | |||
| $this->setUploadedFileid($uploadedFile->getId()); | |||
| $fileManaged = \Drupal::entityTypeManager() | |||
| ->getStorage('file') | |||
| ->load($uploadedFile->getFid()); | |||
| public function createNewSpreadSheet(): Spreadsheet | |||
| { | |||
| return new Spreadsheet(); | |||
| } | |||
| public function createXlsxWriterFromSpreadSheet(Spreadsheet $spreadsheet): Xlsx | |||
| { | |||
| return new Xlsx($spreadsheet); | |||
| } | |||
| $path = $fileManaged->get('uri')->value; | |||
| $path = str_replace("public://", "sites/default/files/", $path); | |||
| $spreadSheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($path); | |||
| return $spreadSheet; | |||
| } catch (exception $e) { | |||
| return null; | |||
| public function loadUploadedFile(UploadedFile $uploadedFile): Spreadsheet | |||
| { | |||
| try { | |||
| $this->setUploadedFileid($uploadedFile->getId()); | |||
| $fileManaged = \Drupal::entityTypeManager() | |||
| ->getStorage('file') | |||
| ->load($uploadedFile->getFid()); | |||
| $path = $fileManaged->get('uri')->value; | |||
| $path = str_replace("public://", "sites/default/files/", $path); | |||
| $spreadSheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($path); | |||
| return $spreadSheet; | |||
| } catch (exception $e) { | |||
| return null; | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -5,9 +5,9 @@ namespace Drupal\arlista\Factory; | |||
| use Drupal\arlista\Entity\AbstractEntity; | |||
| use Drupal\arlista\Entity\AxicoIdWarranty; | |||
| use Drupal\Component\Datetime\TimeInterface; | |||
| use Drupal\Core\Config\ConfigFactoryInterface; | |||
| use Drupal\Core\Database\Connection; | |||
| use Drupal\Core\Session\AccountInterface; | |||
| use Drupal\Core\Config\ConfigFactoryInterface; | |||
| use stdClass; | |||
| class AxicoIdWarrantyFactory extends AbstractFactory | |||
| @@ -110,7 +110,8 @@ class AxicoIdWarrantyFactory extends AbstractFactory | |||
| return $this->load($data); | |||
| } | |||
| public function findByProductAxicoIdName(string $productAxicoId): AxicoIdWarranty { | |||
| public function findByProductAxicoIdName(string $productAxicoId): AxicoIdWarranty | |||
| { | |||
| $productAxicoId = preg_replace('/[0-9]+/', '', $productAxicoId); | |||
| return $this->findByAxicoIdName($productAxicoId); | |||
| } | |||
| @@ -131,19 +132,20 @@ class AxicoIdWarrantyFactory extends AbstractFactory | |||
| $result = []; | |||
| foreach($data as $item){ | |||
| foreach ($data as $item) { | |||
| array_push($result, $this->load($item)); | |||
| } | |||
| return $result; | |||
| } | |||
| public function findHighestSimilarCategoryWarranty($axicoIdName){ | |||
| public function findHighestSimilarCategoryWarranty($axicoIdName) | |||
| { | |||
| $result = $this->findAllLike($axicoIdName); | |||
| $highest = 0; | |||
| foreach($result as $axicoIdWarranty){ | |||
| $string = substr($axicoIdWarranty->getAxicoIdName(),3,3); | |||
| if($string == $axicoIdName){ | |||
| foreach ($result as $axicoIdWarranty) { | |||
| $string = substr($axicoIdWarranty->getAxicoIdName(), 3, 3); | |||
| if ($string == $axicoIdName) { | |||
| $highest = $axicoIdWarranty->getDefaultWarranty() > $highest ? $axicoIdWarranty->getDefaultWarranty() : $highest; | |||
| } | |||
| } | |||
| @@ -151,19 +153,21 @@ class AxicoIdWarrantyFactory extends AbstractFactory | |||
| return $highest; | |||
| } | |||
| public function updateForManufacturer($manufacturerAxicoIdName, $categoryAxicoIdName, $warranty){ | |||
| public function updateForManufacturer($manufacturerAxicoIdName, $categoryAxicoIdName, $warranty) | |||
| { | |||
| $axicoIdName = $manufacturerAxicoIdName . $categoryAxicoIdName; | |||
| $axicoIdWarranty = $this->findByAxicoIdName($axicoIdName); | |||
| $axicoIdWarranty->setDefaultWarranty($warranty); | |||
| $this->save($axicoIdWarranty); | |||
| } | |||
| public function updateForAllManufacturers($categoryAxicoIdName, $warranty){ | |||
| public function updateForAllManufacturers($categoryAxicoIdName, $warranty) | |||
| { | |||
| $result = $this->findAllLike($categoryAxicoIdName); | |||
| $highest = 0; | |||
| foreach($result as $axicoIdWarranty){ | |||
| $string = substr($axicoIdWarranty->getAxicoIdName(),3,3); | |||
| if($string == $categoryAxicoIdName){ | |||
| foreach ($result as $axicoIdWarranty) { | |||
| $string = substr($axicoIdWarranty->getAxicoIdName(), 3, 3); | |||
| if ($string == $categoryAxicoIdName) { | |||
| $axicoIdWarranty->setDefaultWarranty($warranty); | |||
| $this->update($axicoIdWarranty); | |||
| $highest++; | |||
| @@ -173,6 +177,4 @@ class AxicoIdWarrantyFactory extends AbstractFactory | |||
| return $highest; | |||
| } | |||
| } | |||
| @@ -2,222 +2,234 @@ | |||
| namespace Drupal\arlista\Factory; | |||
| use Drupal\Core\Database\Connection; | |||
| use Drupal\arlista\Entity\Calculation; | |||
| use Drupal\arlista\Entity\AbstractEntity; | |||
| use Drupal\Core\Session\AccountInterface; | |||
| use Drupal\Component\Datetime\TimeInterface; | |||
| use Drupal\arlista\Entity\Manufacturer; | |||
| use Drupal\arlista\Entity\Component; | |||
| use Drupal\arlista\Entity\Calculation; | |||
| use Drupal\arlista\Entity\Category; | |||
| use Drupal\arlista\Entity\Component; | |||
| use Drupal\arlista\Entity\Currency; | |||
| use Drupal\arlista\Entity\Manufacturer; | |||
| use Drupal\Component\Datetime\TimeInterface; | |||
| use Drupal\Core\Config\ConfigFactoryInterface; | |||
| use Drupal\Core\Database\Connection; | |||
| use Drupal\Core\Session\AccountInterface; | |||
| use stdClass; | |||
| class CalculationFactory extends AbstractFactory { | |||
| public function __construct(Connection $connection, AccountInterface $currentUser, | |||
| TimeInterface $time, ConfigFactoryInterface $configFactory) { | |||
| parent::__construct($connection, $currentUser, $time, 'calculation'); | |||
| $this->config = $configFactory->get('arlista.settings'); | |||
| } | |||
| public function getConfig() { | |||
| return $this->config; | |||
| } | |||
| class CalculationFactory extends AbstractFactory | |||
| { | |||
| public function getExchangeRate(string $currency): float { | |||
| if (Currency::isSameCurrency($currency, 'USD')) { | |||
| return $this->getConfig()->get('exchange_rate_usd'); | |||
| public function __construct(Connection $connection, AccountInterface $currentUser, | |||
| TimeInterface $time, ConfigFactoryInterface $configFactory) { | |||
| parent::__construct($connection, $currentUser, $time, 'calculation'); | |||
| $this->config = $configFactory->get('arlista.settings'); | |||
| } | |||
| if (Currency::isSameCurrency($currency, 'EUR')) { | |||
| return $this->getConfig()->get('exchange_rate_eur'); | |||
| public function getConfig() | |||
| { | |||
| return $this->config; | |||
| } | |||
| return 1.00; | |||
| } | |||
| public function create(): Calculation { | |||
| return new Calculation(); | |||
| } | |||
| public function findByManufacturerAndCategory(Manufacturer $manufacturer, Category $category): ?Calculation { | |||
| $data = $this->getConnection() | |||
| ->select($this->getActiveTable(), 'w') | |||
| ->fields('w') | |||
| ->condition('w.parent_manufacturer_id', $manufacturer->getId()) | |||
| ->condition('w.parent_category_id', $category->getId()) | |||
| ->isNull('w.deleted_at') | |||
| ->execute() | |||
| ->fetchObject(); | |||
| if (empty($data)) { | |||
| return null; | |||
| public function getExchangeRate(string $currency): float | |||
| { | |||
| if (Currency::isSameCurrency($currency, 'USD')) { | |||
| return $this->getConfig()->get('exchange_rate_usd'); | |||
| } | |||
| if (Currency::isSameCurrency($currency, 'EUR')) { | |||
| return $this->getConfig()->get('exchange_rate_eur'); | |||
| } | |||
| return 1.00; | |||
| } | |||
| return $this->load($data); | |||
| } | |||
| public function findByComponent(Component $component): ?Calculation { | |||
| $data = $this->getConnection() | |||
| ->select($this->getActiveTable(), 'w') | |||
| ->fields('w') | |||
| ->condition('w.parent_component_id', $component->getId()) | |||
| ->condition('w.parent_manufacturer_id', $component->getParentManufacturerId()) | |||
| ->isNull('w.deleted_at') | |||
| ->execute() | |||
| ->fetchObject(); | |||
| if (empty($data)) { | |||
| return null; | |||
| public function create(): Calculation | |||
| { | |||
| return new Calculation(); | |||
| } | |||
| return $this->load($data); | |||
| } | |||
| public function findByManufacturerAndCategory(Manufacturer $manufacturer, Category $category): ?Calculation | |||
| { | |||
| $data = $this->getConnection() | |||
| ->select($this->getActiveTable(), 'w') | |||
| ->fields('w') | |||
| ->condition('w.parent_manufacturer_id', $manufacturer->getId()) | |||
| ->condition('w.parent_category_id', $category->getId()) | |||
| ->isNull('w.deleted_at') | |||
| ->execute() | |||
| ->fetchObject(); | |||
| if (empty($data)) { | |||
| return null; | |||
| } | |||
| return $this->load($data); | |||
| } | |||
| public function createFor(Component $component = null, Category $category = null, Manufacturer $manufacturer = null): Calculation { | |||
| if (empty($component)) { | |||
| $entity = $this->create(); | |||
| $entity->setParentManufacturerId($manufacturer->getId()); | |||
| $entity->setParentCategoryId($category->getId()); | |||
| $entity->setParentComponentId(null); | |||
| $entity->setName($manufacturer->getName() . ' - ' . $category->getName() . ' ' . 'kalkuláció'); | |||
| public function findByComponent(Component $component): ?Calculation | |||
| { | |||
| $data = $this->getConnection() | |||
| ->select($this->getActiveTable(), 'w') | |||
| ->fields('w') | |||
| ->condition('w.parent_component_id', $component->getId()) | |||
| ->condition('w.parent_manufacturer_id', $component->getParentManufacturerId()) | |||
| ->isNull('w.deleted_at') | |||
| ->execute() | |||
| ->fetchObject(); | |||
| if (empty($data)) { | |||
| return null; | |||
| } | |||
| return $this->load($data); | |||
| } | |||
| return $this->save($entity); | |||
| } else { | |||
| public function createFor(Component $component = null, Category $category = null, Manufacturer $manufacturer = null): Calculation | |||
| { | |||
| if (empty($component)) { | |||
| $entity = $this->create(); | |||
| $entity->setParentManufacturerId($manufacturer->getId()); | |||
| $entity->setParentCategoryId($category->getId()); | |||
| $entity->setParentComponentId(null); | |||
| $entity->setName($manufacturer->getName() . ' - ' . $category->getName() . ' ' . 'kalkuláció'); | |||
| return $this->save($entity); | |||
| } else { | |||
| $entity = $this->create(); | |||
| $entity->setParentManufacturerId($component->getParentManufacturerId()); | |||
| $entity->setParentComponentId($component->getId()); | |||
| $entity->setParentCategoryId(null); | |||
| $entity->setName($manufacturer->getName() . ' - ' . $component->getName() . ' ' . 'kalkuláció'); | |||
| return $this->save($entity); | |||
| } | |||
| } | |||
| $entity = $this->create(); | |||
| $entity->setParentManufacturerId($component->getParentManufacturerId()); | |||
| $entity->setParentComponentId($component->getId()); | |||
| $entity->setParentCategoryId(null); | |||
| $entity->setName($manufacturer->getName() . ' - ' . $component->getName() . ' ' . 'kalkuláció'); | |||
| protected function insert(AbstractEntity $entity): Calculation | |||
| { | |||
| $id = $this->getConnection() | |||
| ->insert($this->getActiveTable()) | |||
| ->fields([ | |||
| 'name' => $entity->getName(), | |||
| 'status' => $entity->getStatus(), | |||
| 'parent_manufacturer_id' => $entity->getParentManufacturerId(), | |||
| 'parent_category_id' => $entity->getParentCategoryId(), | |||
| 'parent_component_id' => $entity->getParentComponentId(), | |||
| 'list_price_factor' => $entity->getListPriceFactor(), | |||
| 'price_factor_d_one' => $entity->getPriceFactorDOne(), | |||
| 'price_factor_d_two' => $entity->getPriceFactorDTwo(), | |||
| 'price_factor_spec' => $entity->getPriceFactorSpec(), | |||
| 'price_factor_v_spec' => $entity->getPriceFactorVSpec(), | |||
| 'price_factor_dev_d_one' => $entity->getPriceFactorDevDOne(), | |||
| 'price_factor_dev_d_two' => $entity->getPriceFactorDevDTwo(), | |||
| 'price_factor_dev_spec' => $entity->getPriceFactorDevSpec(), | |||
| 'price_factor_dev_v_spec' => $entity->getPriceFactorDevVSpec(), | |||
| 'transport_expense' => $entity->getTransportExpense(), | |||
| 'default_setting' => $entity->getDefaultCalculation(), | |||
| 'created_at' => date('Y-m-d H:i:s', $this->getTime()->getRequestTime()), | |||
| 'created_by' => $this->getCurrentUser()->id(), | |||
| ]) | |||
| ->execute(); | |||
| $entity->setId($id); | |||
| return $entity; | |||
| } | |||
| return $this->save($entity); | |||
| protected function update(AbstractEntity $entity): Calculation | |||
| { | |||
| $this->getConnection() | |||
| ->update($this->getActiveTable()) | |||
| ->fields([ | |||
| 'name' => $entity->getName(), | |||
| 'status' => $entity->getStatus(), | |||
| 'parent_manufacturer_id' => $entity->getParentManufacturerId(), | |||
| 'parent_category_id' => $entity->getParentCategoryId(), | |||
| 'parent_component_id' => $entity->getParentComponentId(), | |||
| 'list_price_factor' => $entity->getListPriceFactor(), | |||
| 'price_factor_d_one' => $entity->getPriceFactorDOne(), | |||
| 'price_factor_d_two' => $entity->getPriceFactorDTwo(), | |||
| 'price_factor_spec' => $entity->getPriceFactorSpec(), | |||
| 'price_factor_v_spec' => $entity->getPriceFactorVSpec(), | |||
| 'price_factor_dev_d_one' => $entity->getPriceFactorDevDOne(), | |||
| 'price_factor_dev_d_two' => $entity->getPriceFactorDevDTwo(), | |||
| 'price_factor_dev_spec' => $entity->getPriceFactorDevSpec(), | |||
| 'price_factor_dev_v_spec' => $entity->getPriceFactorDevVSpec(), | |||
| 'transport_expense' => $entity->getTransportExpense(), | |||
| 'default_setting' => $entity->getDefaultCalculation(), | |||
| '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 insert(AbstractEntity $entity): Calculation { | |||
| $id = $this->getConnection() | |||
| ->insert($this->getActiveTable()) | |||
| ->fields([ | |||
| 'name' => $entity->getName(), | |||
| 'status' => $entity->getStatus(), | |||
| 'parent_manufacturer_id' => $entity->getParentManufacturerId(), | |||
| 'parent_category_id' => $entity->getParentCategoryId(), | |||
| 'parent_component_id' => $entity->getParentComponentId(), | |||
| 'list_price_factor' => $entity->getListPriceFactor(), | |||
| 'price_factor_d_one' => $entity->getPriceFactorDOne(), | |||
| 'price_factor_d_two' => $entity->getPriceFactorDTwo(), | |||
| 'price_factor_spec' => $entity->getPriceFactorSpec(), | |||
| 'price_factor_v_spec' => $entity->getPriceFactorVSpec(), | |||
| 'price_factor_dev_d_one' => $entity->getPriceFactorDevDOne(), | |||
| 'price_factor_dev_d_two' => $entity->getPriceFactorDevDTwo(), | |||
| 'price_factor_dev_spec' => $entity->getPriceFactorDevSpec(), | |||
| 'price_factor_dev_v_spec' => $entity->getPriceFactorDevVSpec(), | |||
| 'transport_expense' => $entity->getTransportExpense(), | |||
| 'default_setting' => $entity->getDefaultCalculation(), | |||
| '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): Calculation { | |||
| $this->getConnection() | |||
| ->update($this->getActiveTable()) | |||
| ->fields([ | |||
| 'name' => $entity->getName(), | |||
| 'status' => $entity->getStatus(), | |||
| 'parent_manufacturer_id' => $entity->getParentManufacturerId(), | |||
| 'parent_category_id' => $entity->getParentCategoryId(), | |||
| 'parent_component_id' => $entity->getParentComponentId(), | |||
| 'list_price_factor' => $entity->getListPriceFactor(), | |||
| 'price_factor_d_one' => $entity->getPriceFactorDOne(), | |||
| 'price_factor_d_two' => $entity->getPriceFactorDTwo(), | |||
| 'price_factor_spec' => $entity->getPriceFactorSpec(), | |||
| 'price_factor_v_spec' => $entity->getPriceFactorVSpec(), | |||
| 'price_factor_dev_d_one' => $entity->getPriceFactorDevDOne(), | |||
| 'price_factor_dev_d_two' => $entity->getPriceFactorDevDTwo(), | |||
| 'price_factor_dev_spec' => $entity->getPriceFactorDevSpec(), | |||
| 'price_factor_dev_v_spec' => $entity->getPriceFactorDevVSpec(), | |||
| 'transport_expense' => $entity->getTransportExpense(), | |||
| 'default_setting' => $entity->getDefaultCalculation(), | |||
| '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): Calculation { | |||
| $entity = $this->create(); | |||
| $entity->setId($data->id); | |||
| $entity->setName($data->name); | |||
| $entity->setStatus($data->status); | |||
| $entity->setParentManufacturerId($data->parent_manufacturer_id); | |||
| $entity->setParentCategoryId($data->parent_category_id); | |||
| $entity->setParentComponentId($data->parent_component_id); | |||
| $entity->setListPriceFactor($data->list_price_factor); | |||
| $entity->setPriceFactorDOne($data->price_factor_d_one); | |||
| $entity->setPriceFactorDTwo($data->price_factor_d_two); | |||
| $entity->setPriceFactorSpec($data->price_factor_spec); | |||
| $entity->setPriceFactorVSpec($data->price_factor_v_spec); | |||
| $entity->setPriceFactorDevDOne($data->price_factor_dev_d_one); | |||
| $entity->setPriceFactorDevDTwo($data->price_factor_dev_d_two); | |||
| $entity->setPriceFactorDevSpec($data->price_factor_dev_spec); | |||
| $entity->setPriceFactorDevVSpec($data->price_factor_dev_v_spec); | |||
| $entity->setTransportExpense($data->transport_expense); | |||
| $entity->setDefaultCalculation($data->default_setting); | |||
| $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); | |||
| return $entity; | |||
| } | |||
| public function findAllByManufacturerAndItsCategories(Manufacturer $manufacturer): array { | |||
| $entities = []; | |||
| $data = $this->getConnection() | |||
| ->select($this->getActiveTable(), 'w') | |||
| ->fields('w') | |||
| ->condition('w.parent_manufacturer_id', $manufacturer->getId()) | |||
| ->isNull('w.parent_component_id') | |||
| ->isNull('w.deleted_at') | |||
| ->execute() | |||
| ->fetchAll(); | |||
| if (empty($data)) { | |||
| return $entities; | |||
| protected function load(stdClass $data): Calculation | |||
| { | |||
| $entity = $this->create(); | |||
| $entity->setId($data->id); | |||
| $entity->setName($data->name); | |||
| $entity->setStatus($data->status); | |||
| $entity->setParentManufacturerId($data->parent_manufacturer_id); | |||
| $entity->setParentCategoryId($data->parent_category_id); | |||
| $entity->setParentComponentId($data->parent_component_id); | |||
| $entity->setListPriceFactor($data->list_price_factor); | |||
| $entity->setPriceFactorDOne($data->price_factor_d_one); | |||
| $entity->setPriceFactorDTwo($data->price_factor_d_two); | |||
| $entity->setPriceFactorSpec($data->price_factor_spec); | |||
| $entity->setPriceFactorVSpec($data->price_factor_v_spec); | |||
| $entity->setPriceFactorDevDOne($data->price_factor_dev_d_one); | |||
| $entity->setPriceFactorDevDTwo($data->price_factor_dev_d_two); | |||
| $entity->setPriceFactorDevSpec($data->price_factor_dev_spec); | |||
| $entity->setPriceFactorDevVSpec($data->price_factor_dev_v_spec); | |||
| $entity->setTransportExpense($data->transport_expense); | |||
| $entity->setDefaultCalculation($data->default_setting); | |||
| $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); | |||
| return $entity; | |||
| } | |||
| foreach ($data as $item) { | |||
| $entities[] = $this->load($item); | |||
| public function findAllByManufacturerAndItsCategories(Manufacturer $manufacturer): array | |||
| { | |||
| $entities = []; | |||
| $data = $this->getConnection() | |||
| ->select($this->getActiveTable(), 'w') | |||
| ->fields('w') | |||
| ->condition('w.parent_manufacturer_id', $manufacturer->getId()) | |||
| ->isNull('w.parent_component_id') | |||
| ->isNull('w.deleted_at') | |||
| ->execute() | |||
| ->fetchAll(); | |||
| if (empty($data)) { | |||
| return $entities; | |||
| } | |||
| foreach ($data as $item) { | |||
| $entities[] = $this->load($item); | |||
| } | |||
| return $entities; | |||
| } | |||
| return $entities; | |||
| } | |||
| public function copyCalculationFactorFields(Calculation $source, Calculation $target) : Calculation{ | |||
| $target->setListPriceFactor($source->getListPriceFactor()); | |||
| $target->setPriceFactorDOne($source->getPriceFactorDOne()); | |||
| $target->setPriceFactorDTwo($source->getPriceFactorDTwo()); | |||
| $target->setPriceFactorSpec($source->getPriceFactorSpec()); | |||
| $target->setPriceFactorVSpec($source->getPriceFactorVSpec()); | |||
| $target->setPriceFactorDevDOne($source->getPriceFactorDevDOne()); | |||
| $target->setPriceFactorDevDTwo($source->getPriceFactorDevDTwo()); | |||
| $target->setPriceFactorDevSpec($source->getPriceFactorDevSpec()); | |||
| $target->setPriceFactorDevVSpec($source->getPriceFactorDevVSpec()); | |||
| $target->setTransportExpense($source->getTransportExpense()); | |||
| return $target; | |||
| } | |||
| public function copyCalculationFactorFields(Calculation $source, Calculation $target): Calculation | |||
| { | |||
| $target->setListPriceFactor($source->getListPriceFactor()); | |||
| $target->setPriceFactorDOne($source->getPriceFactorDOne()); | |||
| $target->setPriceFactorDTwo($source->getPriceFactorDTwo()); | |||
| $target->setPriceFactorSpec($source->getPriceFactorSpec()); | |||
| $target->setPriceFactorVSpec($source->getPriceFactorVSpec()); | |||
| $target->setPriceFactorDevDOne($source->getPriceFactorDevDOne()); | |||
| $target->setPriceFactorDevDTwo($source->getPriceFactorDevDTwo()); | |||
| $target->setPriceFactorDevSpec($source->getPriceFactorDevSpec()); | |||
| $target->setPriceFactorDevVSpec($source->getPriceFactorDevVSpec()); | |||
| $target->setTransportExpense($source->getTransportExpense()); | |||
| return $target; | |||
| } | |||
| } | |||
| @@ -2,144 +2,153 @@ | |||
| namespace Drupal\arlista\Factory; | |||
| use Drupal\Core\Database\Connection; | |||
| use Drupal\arlista\Entity\AbstractEntity; | |||
| use Drupal\arlista\Entity\Category; | |||
| use Drupal\arlista\Entity\Product; | |||
| use Drupal\arlista\Entity\Status; | |||
| use Drupal\arlista\Entity\AbstractEntity; | |||
| use Drupal\Core\Session\AccountInterface; | |||
| use Drupal\Component\Datetime\TimeInterface; | |||
| use Drupal\Core\Database\Connection; | |||
| use stdClass; | |||
| class CategoryFactory extends AbstractFactory { | |||
| public function __construct(Connection $connection, AccountInterface $currentUser, | |||
| TimeInterface $time) { | |||
| parent::__construct($connection, $currentUser, $time, 'category'); | |||
| } | |||
| public function create() { | |||
| return new Category(); | |||
| } | |||
| public function createByCategoryAxicoId(string $categoryAxicoId): Category { | |||
| $entity = $this->create(); | |||
| $entity->setName($categoryAxicoId); | |||
| $entity->setAxicoIdName($categoryAxicoId); | |||
| $entity->setStatus(Status::PASSIVE); | |||
| $entity->setCreatedAt(date('Y-m-d H:i:s', $this->getTime()->getRequestTime())); | |||
| $entity->setCreatedBy(1); | |||
| $entity->setSif(0); | |||
| return $this->save($entity); | |||
| } | |||
| public function findByAxicoIdName(string $axicoIdName): ?Category { | |||
| $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; | |||
| class CategoryFactory extends AbstractFactory | |||
| { | |||
| public function __construct(Connection $connection, AccountInterface $currentUser, | |||
| TimeInterface $time) { | |||
| parent::__construct($connection, $currentUser, $time, 'category'); | |||
| } | |||
| return $this->load($data); | |||
| } | |||
| protected function insert(AbstractEntity $entity) { | |||
| $id = $this->getConnection() | |||
| ->insert($this->getActiveTable()) | |||
| ->fields([ | |||
| 'name' => $entity->getName(), | |||
| 'axico_id_name' => $entity->getAxicoIdName(), | |||
| 'status' => $entity->getStatus(), | |||
| 'sif' => $entity->getSif(), | |||
| '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) { | |||
| $this->getConnection() | |||
| ->update($this->getActiveTable()) | |||
| ->fields([ | |||
| 'name' => $entity->getName(), | |||
| 'axico_id_name' => $entity->getAxicoIdName(), | |||
| 'status' => $entity->getStatus(), | |||
| 'sif' => $entity->getSif(), | |||
| '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) { | |||
| $entity = $this->create(); | |||
| $entity->setId($data->id); | |||
| $entity->setName($data->name); | |||
| $entity->setAxicoIdName($data->axico_id_name); | |||
| $entity->setStatus($data->status); | |||
| $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 importAll(array $data): array { | |||
| foreach ($data as $i => $category) { | |||
| if (empty($category['table_name'])) { | |||
| continue; | |||
| } | |||
| $items = parent::import($category['table_name']); | |||
| foreach ($items as $item) { | |||
| /* @var $entity Category */ | |||
| $entity = $this->findByAxicoIdName($item->csopkod); | |||
| if (empty($entity)) { | |||
| $entity = $this->create(); | |||
| $entity->setName($item->csopnev); | |||
| $entity->setAxicoIdName($item->csopkod); | |||
| $entity->setStatus(0); | |||
| $entity->setCreatedAt(date('Y-m-d H:i:s', $this->getTime()->getRequestTime())); | |||
| $entity->setCreatedBy(1); | |||
| $entity->setSif(0); | |||
| $entity = $this->save($entity); | |||
| public function create() | |||
| { | |||
| return new Category(); | |||
| } | |||
| public function createByCategoryAxicoId(string $categoryAxicoId): Category | |||
| { | |||
| $entity = $this->create(); | |||
| $entity->setName($categoryAxicoId); | |||
| $entity->setAxicoIdName($categoryAxicoId); | |||
| $entity->setStatus(Status::PASSIVE); | |||
| $entity->setCreatedAt(date('Y-m-d H:i:s', $this->getTime()->getRequestTime())); | |||
| $entity->setCreatedBy(1); | |||
| $entity->setSif(0); | |||
| return $this->save($entity); | |||
| } | |||
| public function findByAxicoIdName(string $axicoIdName): ?Category | |||
| { | |||
| $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; | |||
| } | |||
| $data[$i]['categories'][$entity->getId()] = $entity; | |||
| } | |||
| return $this->load($data); | |||
| } | |||
| return $data; | |||
| } | |||
| public function importAllFromProductData(array $data): array { | |||
| /* @var $product Product */ | |||
| foreach ($data['products'] as $product) { | |||
| $axicoId = $product->getAxicoId(); | |||
| /* AXICO ID contains 'SUP' */ | |||
| //if (strpos($axicoId, 'SUP') !== false) { | |||
| $categoryAxicoId = substr($axicoId, 3, 3); | |||
| $entity = $this->findByAxicoIdName($categoryAxicoId); | |||
| if (empty($entity)) { | |||
| $data['category_not_found'][$categoryAxicoId] = $axicoId; | |||
| } else { | |||
| $data['category_found'][$categoryAxicoId] = $entity; | |||
| } | |||
| //} | |||
| protected function insert(AbstractEntity $entity) | |||
| { | |||
| $id = $this->getConnection() | |||
| ->insert($this->getActiveTable()) | |||
| ->fields([ | |||
| 'name' => $entity->getName(), | |||
| 'axico_id_name' => $entity->getAxicoIdName(), | |||
| 'status' => $entity->getStatus(), | |||
| 'sif' => $entity->getSif(), | |||
| '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) | |||
| { | |||
| $this->getConnection() | |||
| ->update($this->getActiveTable()) | |||
| ->fields([ | |||
| 'name' => $entity->getName(), | |||
| 'axico_id_name' => $entity->getAxicoIdName(), | |||
| 'status' => $entity->getStatus(), | |||
| 'sif' => $entity->getSif(), | |||
| '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) | |||
| { | |||
| $entity = $this->create(); | |||
| $entity->setId($data->id); | |||
| $entity->setName($data->name); | |||
| $entity->setAxicoIdName($data->axico_id_name); | |||
| $entity->setStatus($data->status); | |||
| $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 importAll(array $data): array | |||
| { | |||
| foreach ($data as $i => $category) { | |||
| if (empty($category['table_name'])) { | |||
| continue; | |||
| } | |||
| $items = $this->importFromTable($category['table_name']); | |||
| foreach ($items as $item) { | |||
| /* @var $entity Category */ | |||
| $entity = $this->findByAxicoIdName($item->csopkod); | |||
| if (empty($entity)) { | |||
| $entity = $this->create(); | |||
| $entity->setName($item->csopnev); | |||
| $entity->setAxicoIdName($item->csopkod); | |||
| $entity->setStatus(0); | |||
| $entity->setCreatedAt(date('Y-m-d H:i:s', $this->getTime()->getRequestTime())); | |||
| $entity->setCreatedBy(1); | |||
| $entity->setSif(0); | |||
| $entity = $this->save($entity); | |||
| } | |||
| $data[$i]['categories'][$entity->getId()] = $entity; | |||
| } | |||
| } | |||
| return $data; | |||
| } | |||
| public function importAllFromProductData(array $data): array | |||
| { | |||
| /* @var $product Product */ | |||
| foreach ($data['products'] as $product) { | |||
| $axicoId = $product->getAxicoId(); | |||
| /* AXICO ID contains 'SUP' */ | |||
| //if (strpos($axicoId, 'SUP') !== false) { | |||
| $categoryAxicoId = substr($axicoId, 3, 3); | |||
| $entity = $this->findByAxicoIdName($categoryAxicoId); | |||
| if (empty($entity)) { | |||
| $data['category_not_found'][$categoryAxicoId] = $axicoId; | |||
| } else { | |||
| $data['category_found'][$categoryAxicoId] = $entity; | |||
| } | |||
| //} | |||
| } | |||
| return $data; | |||
| } | |||
| return $data; | |||
| } | |||
| } | |||
| @@ -2,229 +2,243 @@ | |||
| namespace Drupal\arlista\Factory; | |||
| use Drupal\Core\Database\Connection; | |||
| use Drupal\arlista\Entity\AbstractEntity; | |||
| use Drupal\arlista\Entity\Component; | |||
| use Drupal\arlista\Entity\Status; | |||
| use Drupal\arlista\Entity\AbstractEntity; | |||
| use Drupal\Core\Session\AccountInterface; | |||
| use Drupal\Component\Datetime\TimeInterface; | |||
| use Drupal\Core\Database\Connection; | |||
| use Drupal\Core\Session\AccountInterface; | |||
| use stdClass; | |||
| class ComponentFactory extends AbstractFactory { | |||
| class ComponentFactory extends AbstractFactory | |||
| { | |||
| public function __construct(Connection $connection, AccountInterface $currentUser, | |||
| TimeInterface $time) { | |||
| parent::__construct($connection, $currentUser, $time, 'component'); | |||
| } | |||
| public function __construct(Connection $connection, AccountInterface $currentUser, | |||
| TimeInterface $time) { | |||
| parent::__construct($connection, $currentUser, $time, 'component'); | |||
| } | |||
| public function create(): Component { | |||
| return new Component(); | |||
| } | |||
| public function create(): Component | |||
| { | |||
| return new Component(); | |||
| } | |||
| public function enable(array $components, array $enabled) { | |||
| /* @var $component Component */ | |||
| foreach ($components as $component) { | |||
| public function enable(array $components, array $enabled) | |||
| { | |||
| /* @var $component Component */ | |||
| foreach ($components as $component) { | |||
| $this->getConnection()->query('UPDATE arlista_manager_component SET status = :enabled WHERE id = :id', [ | |||
| ':id' => $component->getId(), | |||
| ':enabled' => isset($enabled[$component->getId()]) ? 1 : 0, | |||
| ]); | |||
| } | |||
| } | |||
| protected function insert(AbstractEntity $entity): Component { | |||
| $id = $this->getConnection() | |||
| ->insert($this->getActiveTable()) | |||
| ->fields([ | |||
| 'name' => $entity->getName(), | |||
| 'status' => $entity->getStatus(), | |||
| 'sif' => $entity->getSif(), | |||
| 'axico_id_name' => $entity->getAxicoIdName(), | |||
| 'parent_manufacturer_id' => $entity->getParentManufacturerId(), | |||
| '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): Component { | |||
| $this->getConnection() | |||
| ->update($this->getActiveTable()) | |||
| ->fields([ | |||
| 'name' => $entity->getName(), | |||
| 'status' => $entity->getStatus(), | |||
| 'sif' => $entity->getSif(), | |||
| 'axico_id_name' => $entity->getAxicoIdName(), | |||
| 'parent_manufacturer_id' => $entity->getParentManufacturerId(), | |||
| '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): Component { | |||
| $entity = $this->create(); | |||
| $entity->setId($data->id); | |||
| $entity->setName($data->name); | |||
| $entity->setStatus($data->status); | |||
| $entity->setAxicoIdName($data->axico_id_name); | |||
| $entity->setParentManufacturerId($data->parent_manufacturer_id); | |||
| $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 importAll(array $data): array { | |||
| foreach ($data as $i => $componentData) { | |||
| foreach ($componentData['components'] as $manufacturerId => $componentAxicoIdNames) { | |||
| foreach ($componentAxicoIdNames as $key => $value) { | |||
| if (empty($this->findByManufacturerIdAndComponentAxicoIdName((int) $manufacturerId, $value))) { | |||
| $entity = $this->create(); | |||
| $entity->setName($value); | |||
| $entity->setAxicoIdName($value); | |||
| $entity->setParentManufacturerId($manufacturerId); | |||
| $entity->setStatus(1); | |||
| $entity->setCreatedBy(1); | |||
| $entity->setCreatedAt(date('Y-m-d H:i:s', $this->getTime()->getRequestTime())); | |||
| $entity = $this->save($entity); | |||
| $data[$i]['components'][$manufacturerId][$value] = $entity; | |||
| } | |||
| $this->getConnection()->query('UPDATE arlista_manager_component SET status = :enabled WHERE id = :id', [ | |||
| ':id' => $component->getId(), | |||
| ':enabled' => isset($enabled[$component->getId()]) ? 1 : 0, | |||
| ]); | |||
| } | |||
| } | |||
| } | |||
| return $data; | |||
| } | |||
| protected function insert(AbstractEntity $entity): Component | |||
| { | |||
| $id = $this->getConnection() | |||
| ->insert($this->getActiveTable()) | |||
| ->fields([ | |||
| 'name' => $entity->getName(), | |||
| 'status' => $entity->getStatus(), | |||
| 'sif' => $entity->getSif(), | |||
| 'axico_id_name' => $entity->getAxicoIdName(), | |||
| 'parent_manufacturer_id' => $entity->getParentManufacturerId(), | |||
| 'created_at' => date('Y-m-d H:i:s', $this->getTime()->getRequestTime()), | |||
| 'created_by' => $this->getCurrentUser()->id(), | |||
| ]) | |||
| ->execute(); | |||
| $entity->setId($id); | |||
| return $entity; | |||
| } | |||
| public function createAllFromTable(string $tableName, int $parentManufacturerId): array { | |||
| $componentsCreated = []; | |||
| $items = $this->import($tableName); | |||
| foreach ($items as $item) { | |||
| /* @var $entity Component */ | |||
| $entity = $this->findByAxicoIdNameAndParentManufacturerId($item->csopkod, $parentManufacturerId); | |||
| if (empty($entity)) { | |||
| protected function update(AbstractEntity $entity): Component | |||
| { | |||
| $this->getConnection() | |||
| ->update($this->getActiveTable()) | |||
| ->fields([ | |||
| 'name' => $entity->getName(), | |||
| 'status' => $entity->getStatus(), | |||
| 'sif' => $entity->getSif(), | |||
| 'axico_id_name' => $entity->getAxicoIdName(), | |||
| 'parent_manufacturer_id' => $entity->getParentManufacturerId(), | |||
| '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): Component | |||
| { | |||
| $entity = $this->create(); | |||
| $entity->setAxicoIdName($item->csopkod); | |||
| $entity->setName($item->csopnev); | |||
| $entity->setParentManufacturerId($parentManufacturerId); | |||
| $entity->setStatus(1); | |||
| $entity->setCreatedBy(1); | |||
| $entity->setCreatedAt(date('Y-m-d H:i:s', $this->getTime()->getRequestTime())); | |||
| $entity = $this->save($entity); | |||
| $componentsCreated[$item->csopkod] = $entity; | |||
| } | |||
| $entity->setId($data->id); | |||
| $entity->setName($data->name); | |||
| $entity->setStatus($data->status); | |||
| $entity->setAxicoIdName($data->axico_id_name); | |||
| $entity->setParentManufacturerId($data->parent_manufacturer_id); | |||
| $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 importAll(array $data): array | |||
| { | |||
| foreach ($data as $i => $componentData) { | |||
| foreach ($componentData['components'] as $manufacturerId => $componentAxicoIdNames) { | |||
| foreach ($componentAxicoIdNames as $key => $value) { | |||
| if (empty($this->findByManufacturerIdAndComponentAxicoIdName((int) $manufacturerId, $value))) { | |||
| $entity = $this->create(); | |||
| $entity->setName($value); | |||
| $entity->setAxicoIdName($value); | |||
| $entity->setParentManufacturerId($manufacturerId); | |||
| $entity->setStatus(1); | |||
| $entity->setCreatedBy(1); | |||
| $entity->setCreatedAt(date('Y-m-d H:i:s', $this->getTime()->getRequestTime())); | |||
| $entity = $this->save($entity); | |||
| $data[$i]['components'][$manufacturerId][$value] = $entity; | |||
| } | |||
| } | |||
| } | |||
| } | |||
| return $data; | |||
| } | |||
| return $componentsCreated; | |||
| } | |||
| public function findByManufacturerIdAndComponentAxicoIdName(int $mid, string $axicoIdName): ?Component { | |||
| $data = $this->getConnection() | |||
| ->select($this->getActiveTable(), 'w') | |||
| ->fields('w') | |||
| ->condition('w.parent_manufacturer_id', $mid) | |||
| ->condition('w.axico_id_name', $axicoIdName) | |||
| ->isNull('w.deleted_at') | |||
| ->execute() | |||
| ->fetchObject(); | |||
| if (empty($data)) { | |||
| return null; | |||
| public function createAllFromTable(string $tableName, int $parentManufacturerId): array | |||
| { | |||
| $componentsCreated = []; | |||
| $items = $this->importFromTable($tableName); | |||
| foreach ($items as $item) { | |||
| /* @var $entity Component */ | |||
| $entity = $this->findByAxicoIdNameAndParentManufacturerId($item->csopkod, $parentManufacturerId); | |||
| if (empty($entity)) { | |||
| $entity = $this->create(); | |||
| $entity->setAxicoIdName($item->csopkod); | |||
| $entity->setName($item->csopnev); | |||
| $entity->setParentManufacturerId($parentManufacturerId); | |||
| $entity->setStatus(1); | |||
| $entity->setCreatedBy(1); | |||
| $entity->setCreatedAt(date('Y-m-d H:i:s', $this->getTime()->getRequestTime())); | |||
| $entity = $this->save($entity); | |||
| $componentsCreated[$item->csopkod] = $entity; | |||
| } | |||
| } | |||
| return $componentsCreated; | |||
| } | |||
| return $this->load($data); | |||
| } | |||
| public function createByAxicoIdDataOfProduct(int $parentManufacturerId, $axicoIdName): Component { | |||
| $entity = $this->create(); | |||
| $entity->setName($axicoIdName); | |||
| $entity->setAxicoIdName($axicoIdName); | |||
| $entity->setParentManufacturerId($parentManufacturerId); | |||
| $entity->setStatus(Status::PASSIVE); | |||
| $entity->setCreatedAt(date('Y-m-d H:i:s', $this->getTime()->getRequestTime())); | |||
| $entity->setCreatedBy(1); | |||
| $entity->setSif(0); | |||
| return $this->save($entity); | |||
| } | |||
| public function importAllFromProductData(array $data): array { | |||
| /* @var $product Product */ | |||
| foreach ($data['products'] as $product) { | |||
| $axicoId = $product->getAxicoId(); | |||
| $componentAxicoId = substr($axicoId, 3, 3); | |||
| $manufacturer = $this->getConnection()->query('SELECT * FROM arlista_manager_manufacturer a WHERE a.component_based = :component_based AND a.axico_id = :axico_id', | |||
| [':component_based' => 1,':axico_id' => substr($axicoId, 4, 3),])->fetchObject(); | |||
| if (empty($manufacturer)) { | |||
| continue; | |||
| } | |||
| $entity = $this->findByAxicoIdNameAndParentManufacturerId($componentAxicoId, $manufacturer->getId()); | |||
| if (empty($entity)) { | |||
| $data['component_not_found'][$componentAxicoId] = $componentAxicoId; | |||
| } else { | |||
| $data['component_found'][$componentAxicoId] = $componentAxicoId; | |||
| } | |||
| public function findByManufacturerIdAndComponentAxicoIdName(int $mid, string $axicoIdName): ?Component | |||
| { | |||
| $data = $this->getConnection() | |||
| ->select($this->getActiveTable(), 'w') | |||
| ->fields('w') | |||
| ->condition('w.parent_manufacturer_id', $mid) | |||
| ->condition('w.axico_id_name', $axicoIdName) | |||
| ->isNull('w.deleted_at') | |||
| ->execute() | |||
| ->fetchObject(); | |||
| if (empty($data)) { | |||
| return null; | |||
| } | |||
| return $this->load($data); | |||
| } | |||
| return $data; | |||
| } | |||
| public function findByAxicoIdNameAndParentManufacturerId(string $axicoIdName, int $parentManufacturerId): ?Component { | |||
| $data = $this->getConnection() | |||
| ->select($this->getActiveTable(), 'w') | |||
| ->fields('w') | |||
| ->condition('w.axico_id_name', $axicoIdName) | |||
| ->condition('w.parent_manufacturer_id', $parentManufacturerId) | |||
| ->isNull('w.deleted_at') | |||
| ->execute() | |||
| ->fetchObject(); | |||
| if (empty($data)) { | |||
| return null; | |||
| public function createByAxicoIdDataOfProduct(int $parentManufacturerId, $axicoIdName): Component | |||
| { | |||
| $entity = $this->create(); | |||
| $entity->setName($axicoIdName); | |||
| $entity->setAxicoIdName($axicoIdName); | |||
| $entity->setParentManufacturerId($parentManufacturerId); | |||
| $entity->setStatus(Status::PASSIVE); | |||
| $entity->setCreatedAt(date('Y-m-d H:i:s', $this->getTime()->getRequestTime())); | |||
| $entity->setCreatedBy(1); | |||
| $entity->setSif(0); | |||
| return $this->save($entity); | |||
| } | |||
| return $this->load($data); | |||
| } | |||
| public function findAllActiveWhereManufacturerIdIn(string $orderBy = 'id', string $orderDirection = 'ASC', array $ids): array { | |||
| $entities = []; | |||
| $items = $this->getConnection() | |||
| ->select($this->getActiveTable(), 'w') | |||
| ->fields('w') | |||
| ->condition('w.status', Status::ACTIVE) | |||
| ->condition('w.parent_manufacturer_id', $ids, 'IN') | |||
| ->isNull('w.deleted_at') | |||
| ->orderBy($orderBy, $orderDirection) | |||
| ->execute() | |||
| ->fetchAll(); | |||
| if (empty($items)) { | |||
| return $entities; | |||
| public function importAllFromProductData(array $data): array | |||
| { | |||
| /* @var $product Product */ | |||
| foreach ($data['products'] as $product) { | |||
| $axicoId = $product->getAxicoId(); | |||
| $componentAxicoId = substr($axicoId, 3, 3); | |||
| $manufacturer = $this->getConnection()->query('SELECT * FROM arlista_manager_manufacturer a WHERE a.component_based = :component_based AND a.axico_id = :axico_id', | |||
| [':component_based' => 1, ':axico_id' => substr($axicoId, 4, 3)])->fetchObject(); | |||
| if (empty($manufacturer)) { | |||
| continue; | |||
| } | |||
| $entity = $this->findByAxicoIdNameAndParentManufacturerId($componentAxicoId, $manufacturer->getId()); | |||
| if (empty($entity)) { | |||
| $data['component_not_found'][$componentAxicoId] = $componentAxicoId; | |||
| } else { | |||
| $data['component_found'][$componentAxicoId] = $componentAxicoId; | |||
| } | |||
| } | |||
| return $data; | |||
| } | |||
| foreach ($items as $item) { | |||
| $entities[] = $this->load($item); | |||
| public function findByAxicoIdNameAndParentManufacturerId(string $axicoIdName, int $parentManufacturerId): ?Component | |||
| { | |||
| $data = $this->getConnection() | |||
| ->select($this->getActiveTable(), 'w') | |||
| ->fields('w') | |||
| ->condition('w.axico_id_name', $axicoIdName) | |||
| ->condition('w.parent_manufacturer_id', $parentManufacturerId) | |||
| ->isNull('w.deleted_at') | |||
| ->execute() | |||
| ->fetchObject(); | |||
| if (empty($data)) { | |||
| return null; | |||
| } | |||
| return $this->load($data); | |||
| } | |||
| return $entities; | |||
| } | |||
| public function findAllWhereManufacturerId(int $parentManufacturerId, string $orderBy = 'id', string $orderDirection = 'ASC') { | |||
| $list = $this->getConnection() | |||
| ->select($this->getActiveTable(), 'w') | |||
| ->fields('w') | |||
| ->isNull('w.deleted_at') | |||
| ->condition('w.parent_manufacturer_id', $parentManufacturerId) | |||
| ->orderBy($orderBy, $orderDirection) | |||
| ->execute(); | |||
| $entities = []; | |||
| foreach ($list as $item) { | |||
| $entities[] = $this->load($item); | |||
| public function findAllActiveWhereManufacturerIdIn(string $orderBy = 'id', string $orderDirection = 'ASC', array $ids): array | |||
| { | |||
| $entities = []; | |||
| $items = $this->getConnection() | |||
| ->select($this->getActiveTable(), 'w') | |||
| ->fields('w') | |||
| ->condition('w.status', Status::ACTIVE) | |||
| ->condition('w.parent_manufacturer_id', $ids, 'IN') | |||
| ->isNull('w.deleted_at') | |||
| ->orderBy($orderBy, $orderDirection) | |||
| ->execute() | |||
| ->fetchAll(); | |||
| if (empty($items)) { | |||
| return $entities; | |||
| } | |||
| foreach ($items as $item) { | |||
| $entities[] = $this->load($item); | |||
| } | |||
| return $entities; | |||
| } | |||
| return $entities; | |||
| } | |||
| public function findAllWhereManufacturerId(int $parentManufacturerId, string $orderBy = 'id', string $orderDirection = 'ASC') | |||
| { | |||
| $list = $this->getConnection() | |||
| ->select($this->getActiveTable(), 'w') | |||
| ->fields('w') | |||
| ->isNull('w.deleted_at') | |||
| ->condition('w.parent_manufacturer_id', $parentManufacturerId) | |||
| ->orderBy($orderBy, $orderDirection) | |||
| ->execute(); | |||
| $entities = []; | |||
| foreach ($list as $item) { | |||
| $entities[] = $this->load($item); | |||
| } | |||
| return $entities; | |||
| } | |||
| } | |||
| @@ -2,154 +2,159 @@ | |||
| namespace Drupal\arlista\Factory; | |||
| use Drupal\Core\Database\Connection; | |||
| use Drupal\arlista\Entity\AbstractEntity; | |||
| use Drupal\arlista\Entity\EnabledGroup; | |||
| use Drupal\arlista\Entity\Status; | |||
| use Drupal\arlista\Entity\AbstractEntity; | |||
| use Drupal\Core\Session\AccountInterface; | |||
| use Drupal\Component\Datetime\TimeInterface; | |||
| use Drupal\Core\Database\Connection; | |||
| use Drupal\Core\Session\AccountInterface; | |||
| use stdClass; | |||
| class EnabledGroupFactory extends AbstractFactory { | |||
| public function __construct(Connection $connection, AccountInterface $currentUser, | |||
| TimeInterface $time) { | |||
| parent::__construct($connection, $currentUser, $time, 'enabled_group'); | |||
| } | |||
| public function create(): EnabledGroup { | |||
| return new EnabledGroup(); | |||
| } | |||
| class EnabledGroupFactory extends AbstractFactory | |||
| { | |||
| public function updateSheetSettingsEnabledGroups(int $sheetSettingId, array $newGroups, bool $componentBased): void { | |||
| $activeGroups = $this->findAllEnabledGroups($sheetSettingId, $componentBased); | |||
| foreach ($activeGroups as $activeGroup) { | |||
| if ($activeGroup->isComponentBased() && $componentBased) { | |||
| $this->delete($activeGroup); | |||
| } | |||
| if (!$activeGroup->isComponentBased() && empty($componentBased)) { | |||
| $this->delete($activeGroup); | |||
| } | |||
| public function __construct(Connection $connection, AccountInterface $currentUser, | |||
| TimeInterface $time) { | |||
| parent::__construct($connection, $currentUser, $time, 'enabled_group'); | |||
| } | |||
| /* @var $item AbstractEntity */ | |||
| foreach ($newGroups as $item) { | |||
| $newGroup = $this->create(); | |||
| $newGroup->setName($item->getName()); | |||
| $newGroup->setSheetSettingId($sheetSettingId); | |||
| if ($componentBased) { | |||
| $newGroup->setComponentId($item->getId()); | |||
| } else { | |||
| $newGroup->setCategoryId($item->getId()); | |||
| } | |||
| $this->save($newGroup); | |||
| } | |||
| } | |||
| public function findAllEnabledGroups(int $sheetSettingId = null, bool $componentBased): array { | |||
| $list = []; | |||
| if ($componentBased) { | |||
| if ($sheetSettingId !== null) { | |||
| \Drupal::messenger()->addStatus('not null'.$sheetSettingId.' '.$componentBased); | |||
| $list = $this->getConnection() | |||
| ->select($this->getActiveTable(), 'w') | |||
| ->fields('w') | |||
| ->condition('w.status', Status::ACTIVE) | |||
| ->condition('sheet_setting_id', $sheetSettingId) | |||
| ->isNull('w.deleted_at') | |||
| ->isNull('w.category_id') | |||
| ->orderBy('id', 'ASC') | |||
| ->execute() | |||
| ->fetchAll(); | |||
| } else { | |||
| \Drupal::messenger()->addStatus('not null'.$sheetSettingId.' '.$componentBased); | |||
| $list = $this->getConnection() | |||
| ->select($this->getActiveTable(), 'w') | |||
| ->fields('w') | |||
| ->condition('w.status', Status::ACTIVE) | |||
| ->isNull('w.deleted_at') | |||
| ->isNull('w.category_id') | |||
| ->orderBy('id', 'ASC') | |||
| ->execute() | |||
| ->fetchAll(); | |||
| } | |||
| } else { | |||
| if ($sheetSettingId) { | |||
| $list = $this->getConnection() | |||
| ->select($this->getActiveTable(), 'w') | |||
| ->fields('w') | |||
| ->condition('sheet_setting_id', $sheetSettingId) | |||
| ->isNull('w.deleted_at') | |||
| ->isNull('w.component_id') | |||
| ->orderBy('id', 'ASC') | |||
| ->execute() | |||
| ->fetchAll(); | |||
| } else { | |||
| $list = $this->getConnection() | |||
| ->select($this->getActiveTable(), 'w') | |||
| ->fields('w') | |||
| ->condition('w.status', Status::ACTIVE) | |||
| ->isNull('w.deleted_at') | |||
| ->isNull('w.component_id') | |||
| ->orderBy('id', 'ASC') | |||
| ->execute() | |||
| ->fetchAll(); | |||
| } | |||
| public function create(): EnabledGroup | |||
| { | |||
| return new EnabledGroup(); | |||
| } | |||
| $entities = []; | |||
| foreach ($list as $item) { | |||
| $entities[$componentBased ? $item->component_id : $item->category_id] = $this->load($item); | |||
| public function updateSheetSettingsEnabledGroups(int $sheetSettingId, array $newGroups, bool $componentBased): void | |||
| { | |||
| $activeGroups = $this->findAllEnabledGroups($sheetSettingId, $componentBased); | |||
| foreach ($activeGroups as $activeGroup) { | |||
| if ($activeGroup->isComponentBased() && $componentBased) { | |||
| $this->delete($activeGroup); | |||
| } | |||
| if (!$activeGroup->isComponentBased() && empty($componentBased)) { | |||
| $this->delete($activeGroup); | |||
| } | |||
| } | |||
| /* @var $item AbstractEntity */ | |||
| foreach ($newGroups as $item) { | |||
| $newGroup = $this->create(); | |||
| $newGroup->setName($item->getName()); | |||
| $newGroup->setSheetSettingId($sheetSettingId); | |||
| if ($componentBased) { | |||
| $newGroup->setComponentId($item->getId()); | |||
| } else { | |||
| $newGroup->setCategoryId($item->getId()); | |||
| } | |||
| $this->save($newGroup); | |||
| } | |||
| } | |||
| return $entities; | |||
| } | |||
| public function findAllEnabledGroups(int $sheetSettingId = null, bool $componentBased): array | |||
| { | |||
| $list = []; | |||
| if ($componentBased) { | |||
| if ($sheetSettingId !== null) { | |||
| $list = $this->getConnection() | |||
| ->select($this->getActiveTable(), 'w') | |||
| ->fields('w') | |||
| ->condition('w.status', Status::ACTIVE) | |||
| ->condition('sheet_setting_id', $sheetSettingId) | |||
| ->isNull('w.deleted_at') | |||
| ->isNull('w.category_id') | |||
| ->orderBy('id', 'ASC') | |||
| ->execute() | |||
| ->fetchAll(); | |||
| } else { | |||
| $list = $this->getConnection() | |||
| ->select($this->getActiveTable(), 'w') | |||
| ->fields('w') | |||
| ->condition('w.status', Status::ACTIVE) | |||
| ->isNull('w.deleted_at') | |||
| ->isNull('w.category_id') | |||
| ->orderBy('id', 'ASC') | |||
| ->execute() | |||
| ->fetchAll(); | |||
| } | |||
| } else { | |||
| if ($sheetSettingId) { | |||
| $list = $this->getConnection() | |||
| ->select($this->getActiveTable(), 'w') | |||
| ->fields('w') | |||
| ->condition('sheet_setting_id', $sheetSettingId) | |||
| ->isNull('w.deleted_at') | |||
| ->isNull('w.component_id') | |||
| ->orderBy('id', 'ASC') | |||
| ->execute() | |||
| ->fetchAll(); | |||
| } else { | |||
| $list = $this->getConnection() | |||
| ->select($this->getActiveTable(), 'w') | |||
| ->fields('w') | |||
| ->condition('w.status', Status::ACTIVE) | |||
| ->isNull('w.deleted_at') | |||
| ->isNull('w.component_id') | |||
| ->orderBy('id', 'ASC') | |||
| ->execute() | |||
| ->fetchAll(); | |||
| } | |||
| } | |||
| $entities = []; | |||
| foreach ($list as $item) { | |||
| $entities[$componentBased ? $item->component_id : $item->category_id] = $this->load($item); | |||
| } | |||
| protected function insert(AbstractEntity $entity): EnabledGroup { | |||
| $id = $this->getConnection() | |||
| ->insert($this->getActiveTable()) | |||
| ->fields([ | |||
| 'name' => $entity->getName(), | |||
| 'sheet_setting_id' => $entity->getSheetSettingId(), | |||
| 'component_id' => $entity->getComponentId(), | |||
| 'category_id' => $entity->getCategoryId(), | |||
| 'created_at' => date('Y-m-d H:i:s', $this->getTime()->getRequestTime()), | |||
| 'created_by' => $this->getCurrentUser()->id() | |||
| ]) | |||
| ->execute(); | |||
| return $entities; | |||
| } | |||
| $entity->setId($id); | |||
| protected function insert(AbstractEntity $entity): EnabledGroup | |||
| { | |||
| $id = $this->getConnection() | |||
| ->insert($this->getActiveTable()) | |||
| ->fields([ | |||
| 'name' => $entity->getName(), | |||
| 'sheet_setting_id' => $entity->getSheetSettingId(), | |||
| 'component_id' => $entity->getComponentId(), | |||
| 'category_id' => $entity->getCategoryId(), | |||
| 'created_at' => date('Y-m-d H:i:s', $this->getTime()->getRequestTime()), | |||
| 'created_by' => $this->getCurrentUser()->id(), | |||
| ]) | |||
| ->execute(); | |||
| return $entity; | |||
| } | |||
| $entity->setId($id); | |||
| protected function update(AbstractEntity $entity): EnabledGroup { | |||
| $this->getConnection() | |||
| ->update($this->getActiveTable()) | |||
| ->fields([ | |||
| 'name' => $entity->getName(), | |||
| 'sheet_setting_id' => $entity->getSheetSettingId(), | |||
| 'component_id' => $entity->getComponentId(), | |||
| 'category_id' => $entity->getCategoryId(), | |||
| 'modified_at' => date('Y-m-d H:i:s', $this->getTime()->getRequestTime()), | |||
| 'modified_by' => $this->getCurrentUser()->id() | |||
| ]) | |||
| ->condition('id', $entity->getId()) | |||
| ->execute(); | |||
| return $entity; | |||
| } | |||
| return $entity; | |||
| } | |||
| protected function load(stdClass $data): EnabledGroup { | |||
| $entity = $this->create(); | |||
| $entity->setId($data->id); | |||
| $entity->setName($data->name); | |||
| $entity->setCategoryId($data->category_id); | |||
| $entity->setComponentId($data->component_id); | |||
| $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); | |||
| protected function update(AbstractEntity $entity): EnabledGroup | |||
| { | |||
| $this->getConnection() | |||
| ->update($this->getActiveTable()) | |||
| ->fields([ | |||
| 'name' => $entity->getName(), | |||
| 'sheet_setting_id' => $entity->getSheetSettingId(), | |||
| 'component_id' => $entity->getComponentId(), | |||
| 'category_id' => $entity->getCategoryId(), | |||
| '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): EnabledGroup | |||
| { | |||
| $entity = $this->create(); | |||
| $entity->setId($data->id); | |||
| $entity->setName($data->name); | |||
| $entity->setCategoryId($data->category_id); | |||
| $entity->setComponentId($data->component_id); | |||
| $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); | |||
| return $entity; | |||
| } | |||
| return $entity; | |||
| } | |||
| } | |||
| @@ -12,117 +12,125 @@ use Drupal\Component\Datetime\TimeInterface; | |||
| use stdClass; | |||
| use Drupal\arlista\Entity\WorkFlow; | |||
| class FileFactory extends AbstractFactory { | |||
| public function __construct(Connection $connection, AccountInterface $currentUser, | |||
| TimeInterface $time) { | |||
| parent::__construct($connection, $currentUser, $time, 'uploaded_file'); | |||
| } | |||
| public function create(): UploadedFile { | |||
| return new UploadedFile(); | |||
| } | |||
| public function find(int $id): UploadedFile { | |||
| return parent::find($id); | |||
| } | |||
| public function findAllByParentManufacturerId(int $parentManufacturerId): array { | |||
| $entities = []; | |||
| $data = $this->getConnection() | |||
| ->select($this->getActiveTable(), 'w') | |||
| ->fields('w') | |||
| ->condition('w.parent_manufacturer_id', $parentManufacturerId) | |||
| ->isNull('w.deleted_at') | |||
| ->execute() | |||
| ->fetchAll(); | |||
| if (empty($data)) { | |||
| return $entities; | |||
| class FileFactory extends AbstractFactory | |||
| { | |||
| public function __construct(Connection $connection, AccountInterface $currentUser, | |||
| TimeInterface $time) { | |||
| parent::__construct($connection, $currentUser, $time, 'uploaded_file'); | |||
| } | |||
| public function create(): UploadedFile | |||
| { | |||
| return new UploadedFile(); | |||
| } | |||
| foreach ($data as $item) { | |||
| $entities[] = $this->load($item); | |||
| public function find(int $id): UploadedFile | |||
| { | |||
| return parent::find($id); | |||
| } | |||
| return $entities; | |||
| } | |||
| protected function insert(AbstractEntity $entity): UploadedFile { | |||
| $id = $this->getConnection() | |||
| ->insert($this->getActiveTable()) | |||
| ->fields([ | |||
| 'name' => $entity->getName(), | |||
| 'status' => $entity->getStatus(), | |||
| 'parent_manufacturer_id' => $entity->getParentManufacturerId(), | |||
| 'component_based' => $entity->getComponentBased(), | |||
| 'fid' => $entity->getFid(), | |||
| 'work_flow' => $entity->getWorkFlow(), | |||
| 'total_products' => $entity->getTotalProducts(), | |||
| '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): UploadedFile { | |||
| $this->getConnection() | |||
| ->update($this->getActiveTable()) | |||
| ->fields([ | |||
| 'name' => $entity->getName(), | |||
| 'status' => $entity->getStatus(), | |||
| 'parent_manufacturer_id' => $entity->getParentManufacturerId(), | |||
| 'component_based' => $entity->getComponentBased(), | |||
| 'fid' => $entity->getFid(), | |||
| 'work_flow' => $entity->getWorkFlow(), | |||
| 'total_products' => $entity->getTotalProducts(), | |||
| '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): UploadedFile { | |||
| $entity = $this->create(); | |||
| $entity->setId($data->id); | |||
| $entity->setName($data->name); | |||
| $entity->setStatus($data->status); | |||
| $entity->setParentManufacturerId($data->parent_manufacturer_id); | |||
| $entity->setComponentBased($data->component_based); | |||
| $entity->setFid($data->fid); | |||
| $entity->setWorkFlow($data->work_flow); | |||
| $entity->setTotalProducts($data->total_products); | |||
| $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); | |||
| return $entity; | |||
| } | |||
| public function delete(AbstractEntity $entity): void { | |||
| $fileManaged = \Drupal::entityTypeManager() | |||
| ->getStorage('file') | |||
| ->load($entity->getFid()); | |||
| if ($fileManaged !== null) { | |||
| \Drupal::entityTypeManager() | |||
| ->getStorage('file')->delete([$fileManaged]); | |||
| public function findAllByParentManufacturerId(int $parentManufacturerId): array | |||
| { | |||
| $entities = []; | |||
| $data = $this->getConnection() | |||
| ->select($this->getActiveTable(), 'w') | |||
| ->fields('w') | |||
| ->condition('w.parent_manufacturer_id', $parentManufacturerId) | |||
| ->isNull('w.deleted_at') | |||
| ->execute() | |||
| ->fetchAll(); | |||
| if (empty($data)) { | |||
| return $entities; | |||
| } | |||
| foreach ($data as $item) { | |||
| $entities[] = $this->load($item); | |||
| } | |||
| return $entities; | |||
| } | |||
| protected function insert(AbstractEntity $entity): UploadedFile | |||
| { | |||
| $id = $this->getConnection() | |||
| ->insert($this->getActiveTable()) | |||
| ->fields([ | |||
| 'name' => $entity->getName(), | |||
| 'status' => $entity->getStatus(), | |||
| 'parent_manufacturer_id' => $entity->getParentManufacturerId(), | |||
| 'component_based' => $entity->getComponentBased(), | |||
| 'fid' => $entity->getFid(), | |||
| 'work_flow' => $entity->getWorkFlow(), | |||
| 'total_products' => $entity->getTotalProducts(), | |||
| '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): UploadedFile | |||
| { | |||
| $this->getConnection() | |||
| ->update($this->getActiveTable()) | |||
| ->fields([ | |||
| 'name' => $entity->getName(), | |||
| 'status' => $entity->getStatus(), | |||
| 'parent_manufacturer_id' => $entity->getParentManufacturerId(), | |||
| 'component_based' => $entity->getComponentBased(), | |||
| 'fid' => $entity->getFid(), | |||
| 'work_flow' => $entity->getWorkFlow(), | |||
| 'total_products' => $entity->getTotalProducts(), | |||
| '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): UploadedFile | |||
| { | |||
| $entity = $this->create(); | |||
| $entity->setId($data->id); | |||
| $entity->setName($data->name); | |||
| $entity->setStatus($data->status); | |||
| $entity->setParentManufacturerId($data->parent_manufacturer_id); | |||
| $entity->setComponentBased($data->component_based); | |||
| $entity->setFid($data->fid); | |||
| $entity->setWorkFlow($data->work_flow); | |||
| $entity->setTotalProducts($data->total_products); | |||
| $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); | |||
| return $entity; | |||
| } | |||
| public function delete(AbstractEntity $entity): void | |||
| { | |||
| $fileManaged = \Drupal::entityTypeManager() | |||
| ->getStorage('file') | |||
| ->load($entity->getFid()); | |||
| if ($fileManaged !== null) { | |||
| \Drupal::entityTypeManager() | |||
| ->getStorage('file')->delete([$fileManaged]); | |||
| } | |||
| $this->getConnection() | |||
| ->update($this->getActiveTable()) | |||
| ->fields([ | |||
| 'modified_at' => date('Y-m-d H:i:s', $this->getTime()->getRequestTime()), | |||
| 'modified_by' => $this->getCurrentUser()->id(), | |||
| 'deleted_at' => date('Y-m-d H:i:s', $this->getTime()->getRequestTime()), | |||
| 'work_flow' => WorkFlow::DELETED, | |||
| ]) | |||
| ->condition('id', $entity->getId()) | |||
| ->execute(); | |||
| } | |||
| $this->getConnection() | |||
| ->update($this->getActiveTable()) | |||
| ->fields([ | |||
| 'modified_at' => date('Y-m-d H:i:s', $this->getTime()->getRequestTime()), | |||
| 'modified_by' => $this->getCurrentUser()->id(), | |||
| 'deleted_at' => date('Y-m-d H:i:s', $this->getTime()->getRequestTime()), | |||
| 'work_flow' => WorkFlow::DELETED, | |||
| ]) | |||
| ->condition('id', $entity->getId()) | |||
| ->execute(); | |||
| } | |||
| } | |||
| @@ -12,205 +12,217 @@ use Drupal\arlista\Entity\SheetSetting; | |||
| use Drupal\Component\Datetime\TimeInterface; | |||
| use stdClass; | |||
| class ManufacturerFactory extends AbstractFactory { | |||
| public function __construct(Connection $connection, AccountInterface $currentUser, | |||
| TimeInterface $time) { | |||
| parent::__construct($connection, $currentUser, $time, 'manufacturer'); | |||
| } | |||
| public function create(): Manufacturer { | |||
| return new Manufacturer(); | |||
| } | |||
| protected function insert(AbstractEntity $entity): Manufacturer { | |||
| $id = $this->getConnection() | |||
| ->insert($this->getActiveTable()) | |||
| ->fields([ | |||
| 'name' => $entity->getName(), | |||
| 'status' => $entity->getStatus(), | |||
| 'sif' => $entity->getSif(), | |||
| 'axico_id_name' => $entity->getAxicoIdName(), | |||
| 'component_based' => $entity->getComponentBased(), | |||
| 'created_at' => date('Y-m-d H:i:s', $this->getTime()->getRequestTime()), | |||
| 'created_by' => $this->getCurrentUser()->id() | |||
| ]) | |||
| ->execute(); | |||
| $entity->setId($id); | |||
| if (empty($entity->getSheetSettings())) { | |||
| return $entity; | |||
| } | |||
| $sheetSettings = $entity->getSheetSettings(); | |||
| foreach ($sheetSettings as $sheetSetting) { | |||
| /* @var $sheetSetting SheetSetting */ | |||
| $sheetSetting->setManufacturerId($entity->getId()); | |||
| class ManufacturerFactory extends AbstractFactory | |||
| { | |||
| public function __construct(Connection $connection, AccountInterface $currentUser, | |||
| TimeInterface $time) { | |||
| parent::__construct($connection, $currentUser, $time, 'manufacturer'); | |||
| } | |||
| $entity->setSheetSettings($sheetSettings); | |||
| return $entity; | |||
| } | |||
| protected function update(AbstractEntity $entity): Manufacturer { | |||
| $this->getConnection() | |||
| ->update($this->getActiveTable()) | |||
| ->fields([ | |||
| 'name' => $entity->getName(), | |||
| 'status' => $entity->getStatus(), | |||
| 'sif' => $entity->getSif(), | |||
| 'axico_id_name' => $entity->getAxicoIdName(), | |||
| 'component_based' => $entity->getComponentBased(), | |||
| 'modified_at' => date('Y-m-d H:i:s', $this->getTime()->getRequestTime()), | |||
| 'modified_by' => $this->getCurrentUser()->id() | |||
| ]) | |||
| ->condition('id', $entity->getId()) | |||
| ->execute(); | |||
| return $entity; | |||
| } | |||
| public function delete(AbstractEntity $entity) { | |||
| parent::delete($entity); | |||
| $this->getConnection() | |||
| ->update($this::TABLE_PREFIX . 'sheet_setting') | |||
| ->fields(['manufacturer_id' => 0]) | |||
| ->condition('manufacturer_id', $entity->getId()) | |||
| ->execute(); | |||
| } | |||
| protected function load(stdClass $data): Manufacturer { | |||
| $entity = $this->create(); | |||
| $entity->setId($data->id); | |||
| $entity->setName($data->name); | |||
| $entity->setAxicoIdName($data->axico_id_name); | |||
| $entity->setComponentBased($data->component_based); | |||
| $entity->setStatus($data->status); | |||
| $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 importAll(array $data): array { | |||
| foreach ($data as $key => $manufacturerData) { | |||
| $entity = $this->create(); | |||
| $manufacturerName = $this->getManufacturerNameByAxicoId($manufacturerData['axico_id']); | |||
| $entity->setName($manufacturerName ? $manufacturerName : $manufacturerData['axico_id']); | |||
| $entity->setAxicoIdName($manufacturerData['axico_id']); | |||
| $entity->setComponentBased($manufacturerData['component_based']); | |||
| $entity->setStatus(0); | |||
| $entity->setSif(0); | |||
| $data[$key]['manufacturer'] = $this->save($entity); | |||
| public function create(): Manufacturer | |||
| { | |||
| return new Manufacturer(); | |||
| } | |||
| return $data; | |||
| } | |||
| public function importAllFromComponentData(array $data): array { | |||
| foreach ($data as $key => $value) { | |||
| $items = $this->import($value['table_name']); | |||
| foreach ($items as $item) { | |||
| $axicoId = $item->cikkszam; | |||
| $manufacturerAxicoId = substr($axicoId, 0, 3); | |||
| /* @var $entity Manufacturer */ | |||
| $entity = $this->findByAxicoIdName($manufacturerAxicoId); | |||
| if (empty($entity)) { | |||
| $entity = $this->create(); | |||
| $manufacturerName = $this->getManufacturerNameByAxicoId($manufacturerAxicoId); | |||
| $entity->setName($manufacturerName ? $manufacturerName : $manufacturerAxicoId); | |||
| $entity->setAxicoIdName($manufacturerAxicoId); | |||
| $entity->setComponentBased(1); | |||
| $entity->setStatus(Status::PASSIVE); | |||
| $entity->setSif(0); | |||
| $entity = $this->save($entity); | |||
| protected function insert(AbstractEntity $entity): Manufacturer | |||
| { | |||
| $id = $this->getConnection() | |||
| ->insert($this->getActiveTable()) | |||
| ->fields([ | |||
| 'name' => $entity->getName(), | |||
| 'status' => $entity->getStatus(), | |||
| 'sif' => $entity->getSif(), | |||
| 'axico_id_name' => $entity->getAxicoIdName(), | |||
| 'component_based' => $entity->getComponentBased(), | |||
| 'created_at' => date('Y-m-d H:i:s', $this->getTime()->getRequestTime()), | |||
| 'created_by' => $this->getCurrentUser()->id(), | |||
| ]) | |||
| ->execute(); | |||
| $entity->setId($id); | |||
| if (empty($entity->getSheetSettings())) { | |||
| return $entity; | |||
| } | |||
| $data[$key]['manufacturers'][$entity->getId()] = $entity; | |||
| $componentAxicoId = substr($axicoId, 3, 3); | |||
| if (strpos($manufacturerAxicoId, 'SUP') !== false) { | |||
| $data[$key]['categories'][$entity->getId()][$componentAxicoId] = $componentAxicoId; | |||
| } else { | |||
| $data[$key]['components'][$entity->getId()][$componentAxicoId] = $componentAxicoId; | |||
| $sheetSettings = $entity->getSheetSettings(); | |||
| foreach ($sheetSettings as $sheetSetting) { | |||
| /* @var $sheetSetting SheetSetting */ | |||
| $sheetSetting->setManufacturerId($entity->getId()); | |||
| } | |||
| } | |||
| $entity->setSheetSettings($sheetSettings); | |||
| return $entity; | |||
| } | |||
| return $data; | |||
| } | |||
| public function importAllFromProductData(array $data): array { | |||
| /* @var $product Product */ | |||
| foreach ($data['products'] as $product) { | |||
| $axicoId = $product->getAxicoId(); | |||
| $manufacturerAxicoId = substr($axicoId, 0, 3); | |||
| $entity = $this->findByAxicoIdName($manufacturerAxicoId); | |||
| if (empty($entity)) { | |||
| $data['manufacturer_created'][$manufacturerAxicoId] = $manufacturerAxicoId; | |||
| } else { | |||
| $data['manufacturer_found'][$manufacturerAxicoId] = $manufacturerAxicoId; | |||
| } | |||
| protected function update(AbstractEntity $entity): Manufacturer | |||
| { | |||
| $this->getConnection() | |||
| ->update($this->getActiveTable()) | |||
| ->fields([ | |||
| 'name' => $entity->getName(), | |||
| 'status' => $entity->getStatus(), | |||
| 'sif' => $entity->getSif(), | |||
| 'axico_id_name' => $entity->getAxicoIdName(), | |||
| 'component_based' => $entity->getComponentBased(), | |||
| 'modified_at' => date('Y-m-d H:i:s', $this->getTime()->getRequestTime()), | |||
| 'modified_by' => $this->getCurrentUser()->id(), | |||
| ]) | |||
| ->condition('id', $entity->getId()) | |||
| ->execute(); | |||
| return $entity; | |||
| } | |||
| if (!empty($data['manufacturer_created'])) { | |||
| foreach ($data['manufacturer_created'] as $key => $manufacturerAxicoId) { | |||
| public function delete(AbstractEntity $entity) | |||
| { | |||
| parent::delete($entity); | |||
| $this->getConnection() | |||
| ->update($this::TABLE_PREFIX . 'sheet_setting') | |||
| ->fields(['manufacturer_id' => 0]) | |||
| ->condition('manufacturer_id', $entity->getId()) | |||
| ->execute(); | |||
| } | |||
| protected function load(stdClass $data): Manufacturer | |||
| { | |||
| $entity = $this->create(); | |||
| $entity->setName($manufacturerAxicoId); | |||
| $entity->setAxicoIdName($manufacturerAxicoId); | |||
| $entity->setComponentBased(0); | |||
| $entity->setStatus(Status::PASSIVE); | |||
| $entity->setSif(0); | |||
| $entity = $this->save($entity); | |||
| } | |||
| $entity->setId($data->id); | |||
| $entity->setName($data->name); | |||
| $entity->setAxicoIdName($data->axico_id_name); | |||
| $entity->setComponentBased($data->component_based); | |||
| $entity->setStatus($data->status); | |||
| $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 importAll(array $data): array | |||
| { | |||
| foreach ($data as $key => $manufacturerData) { | |||
| $entity = $this->create(); | |||
| $manufacturerName = $this->getManufacturerNameByAxicoId($manufacturerData['axico_id']); | |||
| $entity->setName($manufacturerName ? $manufacturerName : $manufacturerData['axico_id']); | |||
| $entity->setAxicoIdName($manufacturerData['axico_id']); | |||
| $entity->setComponentBased($manufacturerData['component_based']); | |||
| $entity->setStatus(0); | |||
| $entity->setSif(0); | |||
| $data[$key]['manufacturer'] = $this->save($entity); | |||
| } | |||
| return $data; | |||
| } | |||
| return $data; | |||
| } | |||
| public function findByAxicoIdName(string $axicoIdName): ?Manufacturer { | |||
| $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; | |||
| public function importAllFromComponentData(array $data): array | |||
| { | |||
| foreach ($data as $key => $value) { | |||
| $items = $this->importFromTable($value['table_name']); | |||
| foreach ($items as $item) { | |||
| $axicoId = $item->cikkszam; | |||
| $manufacturerAxicoId = substr($axicoId, 0, 3); | |||
| /* @var $entity Manufacturer */ | |||
| $entity = $this->findByAxicoIdName($manufacturerAxicoId); | |||
| if (empty($entity)) { | |||
| $entity = $this->create(); | |||
| $manufacturerName = $this->getManufacturerNameByAxicoId($manufacturerAxicoId); | |||
| $entity->setName($manufacturerName ? $manufacturerName : $manufacturerAxicoId); | |||
| $entity->setAxicoIdName($manufacturerAxicoId); | |||
| $entity->setComponentBased(1); | |||
| $entity->setStatus(Status::PASSIVE); | |||
| $entity->setSif(0); | |||
| $entity = $this->save($entity); | |||
| } | |||
| $data[$key]['manufacturers'][$entity->getId()] = $entity; | |||
| $componentAxicoId = substr($axicoId, 3, 3); | |||
| if (strpos($manufacturerAxicoId, 'SUP') !== false) { | |||
| $data[$key]['categories'][$entity->getId()][$componentAxicoId] = $componentAxicoId; | |||
| } else { | |||
| $data[$key]['components'][$entity->getId()][$componentAxicoId] = $componentAxicoId; | |||
| } | |||
| } | |||
| } | |||
| return $data; | |||
| } | |||
| return $this->load($data); | |||
| } | |||
| public function findByAxicoIdNameAndComponentBased(string $axicoIdName, int $componentBased): ?Manufacturer { | |||
| $data = $this->getConnection() | |||
| ->select($this->getActiveTable(), 'w') | |||
| ->fields('w') | |||
| ->condition('w.axico_id_name', $axicoIdName) | |||
| ->condition('w.component_based', $componentBased) | |||
| ->isNull('w.deleted_at') | |||
| ->execute() | |||
| ->fetchObject(); | |||
| if (empty($data)) { | |||
| return null; | |||
| public function importAllFromProductData(array $data): array | |||
| { | |||
| /* @var $product Product */ | |||
| foreach ($data['products'] as $product) { | |||
| $axicoId = $product->getAxicoId(); | |||
| $manufacturerAxicoId = substr($axicoId, 0, 3); | |||
| $entity = $this->findByAxicoIdName($manufacturerAxicoId); | |||
| if (empty($entity)) { | |||
| $data['manufacturer_created'][$manufacturerAxicoId] = $manufacturerAxicoId; | |||
| } else { | |||
| $data['manufacturer_found'][$manufacturerAxicoId] = $manufacturerAxicoId; | |||
| } | |||
| } | |||
| if (!empty($data['manufacturer_created'])) { | |||
| foreach ($data['manufacturer_created'] as $key => $manufacturerAxicoId) { | |||
| $entity = $this->create(); | |||
| $entity->setName($manufacturerAxicoId); | |||
| $entity->setAxicoIdName($manufacturerAxicoId); | |||
| $entity->setComponentBased(0); | |||
| $entity->setStatus(Status::PASSIVE); | |||
| $entity->setSif(0); | |||
| $entity = $this->save($entity); | |||
| } | |||
| } | |||
| return $data; | |||
| } | |||
| return $this->load($data); | |||
| } | |||
| public function getComponentManufacturerIds() { | |||
| $data = $this->getConnection() | |||
| ->select($this->getActiveTable(), 'w') | |||
| ->fields('w') | |||
| ->condition('w.component_based', 1) | |||
| ->isNull('w.deleted_at') | |||
| ->execute() | |||
| ->fetchAll(); | |||
| $ids = []; | |||
| if (empty($data)) { | |||
| return $ids; | |||
| public function findByAxicoIdName(string $axicoIdName): ?Manufacturer | |||
| { | |||
| $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); | |||
| } | |||
| foreach ($data as $item) { | |||
| $ids[] = $item->id; | |||
| public function findByAxicoIdNameAndComponentBased(string $axicoIdName, int $componentBased): ?Manufacturer | |||
| { | |||
| $data = $this->getConnection() | |||
| ->select($this->getActiveTable(), 'w') | |||
| ->fields('w') | |||
| ->condition('w.axico_id_name', $axicoIdName) | |||
| ->condition('w.component_based', $componentBased) | |||
| ->isNull('w.deleted_at') | |||
| ->execute() | |||
| ->fetchObject(); | |||
| if (empty($data)) { | |||
| return null; | |||
| } | |||
| return $this->load($data); | |||
| } | |||
| public function getComponentManufacturerIds() | |||
| { | |||
| $data = $this->getConnection() | |||
| ->select($this->getActiveTable(), 'w') | |||
| ->fields('w') | |||
| ->condition('w.component_based', 1) | |||
| ->isNull('w.deleted_at') | |||
| ->execute() | |||
| ->fetchAll(); | |||
| $ids = []; | |||
| if (empty($data)) { | |||
| return $ids; | |||
| } | |||
| foreach ($data as $item) { | |||
| $ids[] = $item->id; | |||
| } | |||
| return $ids; | |||
| } | |||
| return $ids; | |||
| } | |||
| } | |||
| @@ -32,8 +32,7 @@ use stdClass; | |||
| class ProductFactory extends AbstractFactory { | |||
| const SPECIFIC_GROUPS = ['VIX' => 'VIX', 'HSW' => 'HSW', 'HAX' => 'HAX', 'SSG' => 'SSG']; | |||
| const SPECIFIC_MANUFACTURERS = ['SUP']; | |||
| public const SPECIFIC_MANUFACTURERS = ['SUP']; | |||
| private AxicoIdFactory $axicoIdFactory; | |||
| private CategoryFactory $categoryFactory; | |||
| @@ -202,7 +201,7 @@ class ProductFactory extends AbstractFactory { | |||
| $status = $product->getCorrectStatus(); | |||
| $product->setCorrectStatus(Status::CORRECT_IMPORTED); | |||
| $this->saveTo($product, 'arlista_manager_active_product'); | |||
| $this->saveToDatabaseTable($product, 'arlista_manager_active_product'); | |||
| $product->setId($id); | |||
| $product->setCorrectStatus($status); | |||
| @@ -214,11 +213,11 @@ class ProductFactory extends AbstractFactory { | |||
| $existingProduct->setUploadedFileId($product->getUploadedFileId()); | |||
| $existingProduct->setCorrectStatus(Status::CORRECT_IMPORTED); | |||
| $this->saveTo($existingProduct, 'arlista_manager_active_product'); | |||
| $this->saveToDatabaseTable($existingProduct, 'arlista_manager_active_product'); | |||
| $result['updatedProduct']++; | |||
| } | |||
| $product->setWorkFlow(WorkFlow::ACTIVATED); | |||
| $this->saveTo($product, 'arlista_manager_uploaded_product'); | |||
| $this->saveToDatabaseTable($product, 'arlista_manager_uploaded_product'); | |||
| } | |||
| if ($result['newProduct'] > 0 || $result['updatedProduct'] > 0) { | |||
| $result['totalActualised'] = $result['newProduct'] + $result['updatedProduct']; | |||
| @@ -941,7 +940,7 @@ class ProductFactory extends AbstractFactory { | |||
| $existingProduct->calculatePrices(); | |||
| $existingProduct->setCorrectStatus($status); | |||
| $this->saveTo($existingProduct, 'arlista_manager_active_product'); | |||
| $this->saveToDatabaseTable($existingProduct, 'arlista_manager_active_product'); | |||
| } | |||
| public function testIfSpecificProductIsComponentBased(Product $product): int { | |||
| @@ -1331,7 +1330,7 @@ class ProductFactory extends AbstractFactory { | |||
| $this->cacheService->resetCache(['arlista_product_edit_form', 'uploaded', $product->getId()]); | |||
| $liveProduct = $this->findByAxicoIdInTable($product->getAxicoId(), 'arlista_manager_active_product'); | |||
| $liveProduct->copyPrices($liveProduct); | |||
| $this->saveTo($liveProduct, 'arlista_manager_active_product'); | |||
| $this->saveToDatabaseTable($liveProduct, 'arlista_manager_active_product'); | |||
| $this->cacheService->resetCache(['arlista_product_edit_form', 'live', $liveProduct->getId()]); | |||
| } | |||
| } | |||
| @@ -1370,7 +1369,7 @@ class ProductFactory extends AbstractFactory { | |||
| $liveProduct = $this->findByAxicoIdInTable($product->getAxicoId(), 'arlista_manager_active_product'); | |||
| $liveProduct->copyPrices($product); | |||
| $this->saveTo($liveProduct, 'arlista_manager_active_product'); | |||
| $this->saveToDatabaseTable($liveProduct, 'arlista_manager_active_product'); | |||
| $this->cacheService->resetCache(['arlista_product_edit_form', 'live', $liveProduct->getId()]); | |||
| } | |||
| } | |||
| @@ -2,195 +2,204 @@ | |||
| namespace Drupal\arlista\Factory; | |||
| use Drupal\Core\Database\Connection; | |||
| use Drupal\arlista\Entity\AbstractEntity; | |||
| use Drupal\Core\Session\AccountInterface; | |||
| use Drupal\Component\Datetime\TimeInterface; | |||
| use Drupal\arlista\Entity\SheetSetting; | |||
| use Drupal\Component\Datetime\TimeInterface; | |||
| use Drupal\Core\Database\Connection; | |||
| use Drupal\Core\Session\AccountInterface; | |||
| use stdClass; | |||
| class SheetSettingFactory extends AbstractFactory { | |||
| public function __construct(Connection $connection, AccountInterface $currentUser, | |||
| TimeInterface $time) { | |||
| parent::__construct($connection, $currentUser, $time, 'sheet_setting'); | |||
| } | |||
| public function findSettingBySheetIndex(int $mid, int $index): SheetSetting { | |||
| $data = $this->getConnection() | |||
| ->select($this->getActiveTable(), 'w') | |||
| ->fields('w') | |||
| ->condition('w.manufacturer_id', $mid) | |||
| ->condition('w.index', $index) | |||
| ->isNull('w.deleted_at') | |||
| ->execute() | |||
| ->fetchObject(); | |||
| if (empty($data)) { | |||
| return $this->findDefaultSheetSetting($mid); | |||
| class SheetSettingFactory extends AbstractFactory | |||
| { | |||
| public function __construct(Connection $connection, AccountInterface $currentUser, | |||
| TimeInterface $time) { | |||
| parent::__construct($connection, $currentUser, $time, 'sheet_setting'); | |||
| } | |||
| return $this->load($data); | |||
| } | |||
| public function findSheetSettingsByManufacturerId(int $manufacturer_id, string $orderBy = 'index', string $orderDirection = 'ASC'): array { | |||
| $list = $this->getConnection() | |||
| ->select($this->getActiveTable(), 'w') | |||
| ->fields('w') | |||
| ->isNull('w.deleted_at') | |||
| ->condition('w.manufacturer_id', $manufacturer_id) | |||
| ->orderBy($orderBy, $orderDirection) | |||
| ->execute(); | |||
| $entities = []; | |||
| foreach ($list as $item) { | |||
| $entities[$item->index] = $this->load($item); | |||
| public function findSettingBySheetIndex(int $mid, int $index): SheetSetting | |||
| { | |||
| $data = $this->getConnection() | |||
| ->select($this->getActiveTable(), 'w') | |||
| ->fields('w') | |||
| ->condition('w.manufacturer_id', $mid) | |||
| ->condition('w.index', $index) | |||
| ->isNull('w.deleted_at') | |||
| ->execute() | |||
| ->fetchObject(); | |||
| if (empty($data)) { | |||
| return $this->findDefaultSheetSetting($mid); | |||
| } | |||
| return $this->load($data); | |||
| } | |||
| return $entities; | |||
| } | |||
| public function findDefaultSheetSetting(int $mid): SheetSetting { | |||
| $data = $this->getConnection() | |||
| ->select($this->getActiveTable(), 'w') | |||
| ->fields('w') | |||
| ->condition('w.manufacturer_id', $mid) | |||
| ->condition('w.default_setting', 1) | |||
| ->isNull('w.deleted_at') | |||
| ->execute() | |||
| ->fetchObject(); | |||
| if (empty($data)) { | |||
| return $this->create(); | |||
| public function findSheetSettingsByManufacturerId(int $manufacturer_id, string $orderBy = 'index', string $orderDirection = 'ASC'): array | |||
| { | |||
| $list = $this->getConnection() | |||
| ->select($this->getActiveTable(), 'w') | |||
| ->fields('w') | |||
| ->isNull('w.deleted_at') | |||
| ->condition('w.manufacturer_id', $manufacturer_id) | |||
| ->orderBy($orderBy, $orderDirection) | |||
| ->execute(); | |||
| $entities = []; | |||
| foreach ($list as $item) { | |||
| $entities[$item->index] = $this->load($item); | |||
| } | |||
| return $entities; | |||
| } | |||
| $data->id = null; | |||
| $data->name = null; | |||
| $data->default_setting = 0; | |||
| return $this->load($data); | |||
| } | |||
| public function create(): SheetSetting { | |||
| return new SheetSetting(); | |||
| } | |||
| private function clearDefaultSettingOnOtherEntities(int $mid, int $id): void { | |||
| $sheetSettings = $this->findSheetSettingsByManufacturerId($mid); | |||
| if (count($sheetSettings) > 1) { | |||
| foreach ($sheetSettings as $sheetSetting) { | |||
| if ($sheetSetting->getId() !== $id) { | |||
| $sheetSetting->setDefaultSetting(0); | |||
| $this->update($sheetSetting); | |||
| public function findDefaultSheetSetting(int $mid): SheetSetting | |||
| { | |||
| $data = $this->getConnection() | |||
| ->select($this->getActiveTable(), 'w') | |||
| ->fields('w') | |||
| ->condition('w.manufacturer_id', $mid) | |||
| ->condition('w.default_setting', 1) | |||
| ->isNull('w.deleted_at') | |||
| ->execute() | |||
| ->fetchObject(); | |||
| if (empty($data)) { | |||
| return $this->create(); | |||
| } | |||
| } | |||
| $data->id = null; | |||
| $data->name = null; | |||
| $data->default_setting = 0; | |||
| return $this->load($data); | |||
| } | |||
| } | |||
| protected function insert(AbstractEntity $entity): SheetSetting { | |||
| $id = $this->getConnection() | |||
| ->insert($this->getActiveTable()) | |||
| ->fields([ | |||
| 'manufacturer_id' => $entity->getManufacturerId(), | |||
| 'index' => $entity->getIndex(), | |||
| 'name' => $entity->getName(), | |||
| 'product_name' => $entity->getProductName(), | |||
| 'product_axico_name' => $entity->getProductAxicoName(), | |||
| 'product_fabric_name' => $entity->getProductFabricName(), | |||
| 'product_fabric_id' => $entity->getProductFabricId(), | |||
| 'product_ean' => $entity->getProductEan(), | |||
| 'product_warranty' => $entity->getProductWarranty(), | |||
| 'product_eol' => $entity->getProductEol(), | |||
| 'product_notes' => $entity->getProductNotes(), | |||
| 'product_description' => $entity->getProductDescription(), | |||
| 'product_category' => $entity->getProductCategory(), | |||
| 'product_price' => $entity->getProductPrice(), | |||
| 'currency' => $entity->getCurrency(), | |||
| 'product_vtsz' => $entity->getProductVtsz(), | |||
| 'filterable' => $entity->getFilterable(), | |||
| 'filterable_remarks' => $entity->getFilterableRemarks(), | |||
| 'default_setting' => $entity->getDefaultSetting(), | |||
| 'status' => $entity->getStatus(), | |||
| 'created_at' => date('Y-m-d H:i:s', $this->getTime()->getRequestTime()), | |||
| 'created_by' => $this->getCurrentUser()->id() | |||
| ]) | |||
| ->execute(); | |||
| $entity->setId($id); | |||
| if ($entity->isDefaultSetting()) { | |||
| $this->clearDefaultSettingOnOtherEntities($entity->getManufacturerId(), $entity->getId()); | |||
| public function create(): SheetSetting | |||
| { | |||
| return new SheetSetting(); | |||
| } | |||
| private function clearDefaultSettingOnOtherEntities(int $mid, int $id): void | |||
| { | |||
| $sheetSettings = $this->findSheetSettingsByManufacturerId($mid); | |||
| if (count($sheetSettings) > 1) { | |||
| foreach ($sheetSettings as $sheetSetting) { | |||
| if ($sheetSetting->getId() !== $id) { | |||
| $sheetSetting->setDefaultSetting(0); | |||
| $this->update($sheetSetting); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| return $entity; | |||
| } | |||
| protected function update(AbstractEntity $entity): SheetSetting { | |||
| $this->getConnection() | |||
| ->update($this->getActiveTable()) | |||
| ->fields([ | |||
| 'manufacturer_id' => $entity->getManufacturerId(), | |||
| 'index' => $entity->getIndex(), | |||
| 'name' => $entity->getName(), | |||
| 'product_name' => $entity->getProductName(), | |||
| 'product_axico_name' => $entity->getProductAxicoName(), | |||
| 'product_fabric_name' => $entity->getProductFabricName(), | |||
| 'product_fabric_id' => $entity->getProductFabricId(), | |||
| 'product_ean' => $entity->getProductEan(), | |||
| 'product_eol' => $entity->getProductEol(), | |||
| 'product_warranty' => $entity->getProductWarranty(), | |||
| 'product_notes' => $entity->getProductNotes(), | |||
| 'product_description' => $entity->getProductDescription(), | |||
| 'product_category' => $entity->getProductCategory(), | |||
| 'product_price' => $entity->getProductPrice(), | |||
| 'currency' => $entity->getCurrency(), | |||
| 'product_vtsz' => $entity->getProductVtsz(), | |||
| 'filterable' => $entity->getFilterable(), | |||
| 'filterable_remarks' => $entity->getFilterableRemarks(), | |||
| 'default_setting' => $entity->getDefaultSetting(), | |||
| 'status' => $entity->getStatus(), | |||
| 'modified_at' => date('Y-m-d H:i:s', $this->getTime()->getRequestTime()), | |||
| 'modified_by' => $this->getCurrentUser()->id() | |||
| ]) | |||
| ->condition('id', $entity->getId()) | |||
| ->execute(); | |||
| if ($entity->isDefaultSetting()) { | |||
| $this->clearDefaultSettingOnOtherEntities($entity->getManufacturerId(), $entity->getId()); | |||
| protected function insert(AbstractEntity $entity): SheetSetting | |||
| { | |||
| $id = $this->getConnection() | |||
| ->insert($this->getActiveTable()) | |||
| ->fields([ | |||
| 'manufacturer_id' => $entity->getManufacturerId(), | |||
| 'index' => $entity->getIndex(), | |||
| 'name' => $entity->getName(), | |||
| 'product_name' => $entity->getProductName(), | |||
| 'product_axico_name' => $entity->getProductAxicoName(), | |||
| 'product_fabric_name' => $entity->getProductFabricName(), | |||
| 'product_fabric_id' => $entity->getProductFabricId(), | |||
| 'product_ean' => $entity->getProductEan(), | |||
| 'product_warranty' => $entity->getProductWarranty(), | |||
| 'product_eol' => $entity->getProductEol(), | |||
| 'product_notes' => $entity->getProductNotes(), | |||
| 'product_description' => $entity->getProductDescription(), | |||
| 'product_category' => $entity->getProductCategory(), | |||
| 'product_price' => $entity->getProductPrice(), | |||
| 'currency' => $entity->getCurrency(), | |||
| 'product_vtsz' => $entity->getProductVtsz(), | |||
| 'filterable' => $entity->getFilterable(), | |||
| 'filterable_remarks' => $entity->getFilterableRemarks(), | |||
| 'default_setting' => $entity->getDefaultSetting(), | |||
| 'status' => $entity->getStatus(), | |||
| 'created_at' => date('Y-m-d H:i:s', $this->getTime()->getRequestTime()), | |||
| 'created_by' => $this->getCurrentUser()->id(), | |||
| ]) | |||
| ->execute(); | |||
| $entity->setId($id); | |||
| if ($entity->isDefaultSetting()) { | |||
| $this->clearDefaultSettingOnOtherEntities($entity->getManufacturerId(), $entity->getId()); | |||
| } | |||
| return $entity; | |||
| } | |||
| return $entity; | |||
| } | |||
| protected function load(stdClass $data): SheetSetting { | |||
| $entity = $this->create(); | |||
| $entity->setId($data->id); | |||
| $entity->setManufacturerId($data->manufacturer_id); | |||
| $entity->setIndex($data->index); | |||
| $entity->setName($data->name); | |||
| $entity->setStatus($data->status); | |||
| $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->setProductName($data->product_name); | |||
| $entity->setProductAxicoName($data->product_axico_name); | |||
| $entity->setProductFabricName($data->product_fabric_name); | |||
| $entity->setProductFabricId($data->product_fabric_id); | |||
| $entity->setProductEan($data->product_ean); | |||
| $entity->setProductWarranty($data->product_warranty); | |||
| $entity->setProductEol($data->product_eol); | |||
| $entity->setProductNotes($data->product_notes); | |||
| $entity->setProductDescription($data->product_description); | |||
| $entity->setProductCategory($data->product_category); | |||
| $entity->setProductPrice($data->product_price); | |||
| $entity->setCurrency($data->currency); | |||
| $entity->setProductVtsz($data->product_vtsz); | |||
| $entity->setFilterable($data->filterable); | |||
| $entity->setFilterableRemarks($data->filterable_remarks); | |||
| $entity->setDefaultSetting($data->default_setting); | |||
| return $entity; | |||
| } | |||
| protected function update(AbstractEntity $entity): SheetSetting | |||
| { | |||
| $this->getConnection() | |||
| ->update($this->getActiveTable()) | |||
| ->fields([ | |||
| 'manufacturer_id' => $entity->getManufacturerId(), | |||
| 'index' => $entity->getIndex(), | |||
| 'name' => $entity->getName(), | |||
| 'product_name' => $entity->getProductName(), | |||
| 'product_axico_name' => $entity->getProductAxicoName(), | |||
| 'product_fabric_name' => $entity->getProductFabricName(), | |||
| 'product_fabric_id' => $entity->getProductFabricId(), | |||
| 'product_ean' => $entity->getProductEan(), | |||
| 'product_eol' => $entity->getProductEol(), | |||
| 'product_warranty' => $entity->getProductWarranty(), | |||
| 'product_notes' => $entity->getProductNotes(), | |||
| 'product_description' => $entity->getProductDescription(), | |||
| 'product_category' => $entity->getProductCategory(), | |||
| 'product_price' => $entity->getProductPrice(), | |||
| 'currency' => $entity->getCurrency(), | |||
| 'product_vtsz' => $entity->getProductVtsz(), | |||
| 'filterable' => $entity->getFilterable(), | |||
| 'filterable_remarks' => $entity->getFilterableRemarks(), | |||
| 'default_setting' => $entity->getDefaultSetting(), | |||
| 'status' => $entity->getStatus(), | |||
| 'modified_at' => date('Y-m-d H:i:s', $this->getTime()->getRequestTime()), | |||
| 'modified_by' => $this->getCurrentUser()->id(), | |||
| ]) | |||
| ->condition('id', $entity->getId()) | |||
| ->execute(); | |||
| if ($entity->isDefaultSetting()) { | |||
| $this->clearDefaultSettingOnOtherEntities($entity->getManufacturerId(), $entity->getId()); | |||
| } | |||
| return $entity; | |||
| } | |||
| protected function load(stdClass $data): SheetSetting | |||
| { | |||
| $entity = $this->create(); | |||
| $entity->setId($data->id); | |||
| $entity->setManufacturerId($data->manufacturer_id); | |||
| $entity->setIndex($data->index); | |||
| $entity->setName($data->name); | |||
| $entity->setStatus($data->status); | |||
| $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->setProductName($data->product_name); | |||
| $entity->setProductAxicoName($data->product_axico_name); | |||
| $entity->setProductFabricName($data->product_fabric_name); | |||
| $entity->setProductFabricId($data->product_fabric_id); | |||
| $entity->setProductEan($data->product_ean); | |||
| $entity->setProductWarranty($data->product_warranty); | |||
| $entity->setProductEol($data->product_eol); | |||
| $entity->setProductNotes($data->product_notes); | |||
| $entity->setProductDescription($data->product_description); | |||
| $entity->setProductCategory($data->product_category); | |||
| $entity->setProductPrice($data->product_price); | |||
| $entity->setCurrency($data->currency); | |||
| $entity->setProductVtsz($data->product_vtsz); | |||
| $entity->setFilterable($data->filterable); | |||
| $entity->setFilterableRemarks($data->filterable_remarks); | |||
| $entity->setDefaultSetting($data->default_setting); | |||
| return $entity; | |||
| } | |||
| } | |||
| @@ -2,6 +2,7 @@ | |||
| namespace Drupal\arlista\Factory; | |||
| use Drupal\arlista\Factory\AbstractSpreadSheetFactory; | |||
| use Drupal\arlista\Factory\ComponentFactory; | |||
| use Drupal\arlista\Factory\ManufacturerFactory; | |||
| @@ -28,464 +29,485 @@ class SpreadSheetFactory extends AbstractSpreadSheetFactory { | |||
| private ?Category $category = null; | |||
| private ?Component $component = null; | |||
| /** | |||
| * Class constructor. | |||
| */ | |||
| public function __construct(ComponentFactory $componentFactory, | |||
| ManufacturerFactory $manufacturerFactory, CategoryFactory $categoryFactory, | |||
| ConfigFactoryInterface $configFactory) { | |||
| $this->componentFactory = $componentFactory; | |||
| $this->manufacturerFactory = $manufacturerFactory; | |||
| $this->categoryFactory = $categoryFactory; | |||
| $this->config = $configFactory->get('arlista.settings'); | |||
| /** | |||
| * Class constructor. | |||
| */ | |||
| public function __construct(ComponentFactory $componentFactory, | |||
| ManufacturerFactory $manufacturerFactory, CategoryFactory $categoryFactory, | |||
| ConfigFactoryInterface $configFactory) { | |||
| $this->componentFactory = $componentFactory; | |||
| $this->manufacturerFactory = $manufacturerFactory; | |||
| $this->categoryFactory = $categoryFactory; | |||
| $this->config = $configFactory->get('arlista.settings'); | |||
| } | |||
| } | |||
| public function getComponentFactory(): ComponentFactory { | |||
| return $this->componentFactory; | |||
| } | |||
| public function getComponentFactory() : ComponentFactory | |||
| { | |||
| return $this->componentFactory; | |||
| } | |||
| public function getManufacturerFactory(): ManufacturerFactory { | |||
| return $this->manufacturerFactory; | |||
| } | |||
| public function getManufacturerFactory() : ManufacturerFactory | |||
| { | |||
| return $this->manufacturerFactory; | |||
| } | |||
| public function getCategoryFactory(): CategoryFactory { | |||
| return $this->categoryFactory; | |||
| } | |||
| public function getCategoryFactory(): CategoryFactory | |||
| { | |||
| return $this->categoryFactory; | |||
| } | |||
| public function getComponent(): ?Component { | |||
| return $this->component; | |||
| } | |||
| public function getComponent(): ?Component | |||
| { | |||
| return $this->component; | |||
| } | |||
| public function setComponent(Component $component): void { | |||
| $this->component = $component; | |||
| } | |||
| public function setComponent(Component $component): void | |||
| { | |||
| $this->component = $component; | |||
| } | |||
| public function getCategory(): ?Category { | |||
| return $this->category; | |||
| } | |||
| public function getCategory(): ?Category | |||
| { | |||
| return $this->category; | |||
| } | |||
| public function setCategory(Category $category): void { | |||
| $this->category = $category; | |||
| } | |||
| public function setCategory(Category $category): void | |||
| { | |||
| $this->category = $category; | |||
| } | |||
| public function extractDataFromSpreadSheet(Spreadsheet $spreadSheet, array $sheetSettings): array { | |||
| public function extractDataFromSpreadSheet(Spreadsheet $spreadSheet, array $sheetSettings): array | |||
| { | |||
| if (empty($spreadSheet)) { | |||
| return []; | |||
| } | |||
| $result = []; | |||
| $worksheetCount = $spreadSheet->getSheetCount(); | |||
| if ($worksheetCount < 1) { | |||
| return $result; | |||
| } | |||
| if ($worksheetCount > count($sheetSettings)) { | |||
| $result['validation'] = ['A munkalapok száma nem felel meg az konfigurált munkalapok számának.']; | |||
| return $result; | |||
| } | |||
| $result['spreadSheet'] = $spreadSheet; | |||
| for ($i = 0; $i < $worksheetCount; $i++) { | |||
| $sheetSetting = $this->getSheetSettingByIndex($sheetSettings, $i); | |||
| if (empty($sheetSetting)) { | |||
| continue; | |||
| } | |||
| $result = $this->loadProductsOfWorkSheet($result, | |||
| $this->loadWorkSheetBySheetIndex($spreadSheet, $i), $sheetSetting); | |||
| if (isset($result['extracted'][$sheetSetting->getIndex()]['validation'])) { | |||
| return $result; | |||
| } | |||
| } | |||
| if (empty($spreadSheet)) { | |||
| return []; | |||
| return $result; | |||
| } | |||
| $result = []; | |||
| $worksheetCount = $spreadSheet->getSheetCount(); | |||
| if ($worksheetCount < 1) { | |||
| return $result; | |||
| private function getSheetSettingByIndex(array $sheetSettings, int $index): ?SheetSetting | |||
| { | |||
| foreach ($sheetSettings as $sheetSetting) { | |||
| if ($sheetSetting->getIndex() == $index) { | |||
| return $sheetSetting; | |||
| } | |||
| } | |||
| return null; | |||
| } | |||
| if($worksheetCount > count($sheetSettings)){ | |||
| $result['validation'] = ['A munkalapok száma nem felel meg az konfigurált munkalapok számának.']; | |||
| return $result; | |||
| public function loadWorkSheetBySheetIndex(Spreadsheet $spreadSheet, int $index): Worksheet | |||
| { | |||
| return $spreadSheet->getSheet($index); | |||
| } | |||
| public function loadProductsOfWorkSheet(array $result, Worksheet $workSheet, SheetSetting $sheetSetting): array | |||
| { | |||
| $result['extracted'][$sheetSetting->getIndex()]['workSheetName'] = empty($workSheet->getTitle()) ? $sheetSetting->getIndex() : $workSheet->getTitle(); | |||
| $result['extracted'][$sheetSetting->getIndex()]['products'] = []; | |||
| $cleanWorkSheetTitle = strtolower(preg_replace("/[^A-Za-z0-9 ]/", '', $workSheet->getTitle())); | |||
| $cleanSheetSettingName = strtolower(preg_replace("/[^A-Za-z0-9 ]/", '', $sheetSetting->getName())); | |||
| if (strcmp($cleanWorkSheetTitle, $cleanSheetSettingName) != 0) { | |||
| $result['extracted'][$sheetSetting->getIndex()]['validation'] = ['A munkalap neve nem megfelő. Ellenőrizze a konfigurációkat! Munkalap száma: ' . $sheetSetting->getIndex()]; | |||
| return $result; | |||
| } | |||
| $highestRow = $workSheet->getHighestRow(); | |||
| if (empty($highestRow)) { | |||
| $result['extracted'][$sheetSetting->getIndex()]['empty'] = true; | |||
| return $result; | |||
| } | |||
| for ($i = 1; $i <= $highestRow; ++$i) { | |||
| $product = new Product(); | |||
| $product->setName($workSheet->getCell($sheetSetting->getProductName() . $i)->getValue()); | |||
| $product->setFabricName($workSheet->getCell($sheetSetting->getProductFabricName() . $i)->getValue()); | |||
| $product->setAxicoName($sheetSetting->findProductAxicoName($workSheet, $i)); | |||
| $product->setFabricId($workSheet->getCell($sheetSetting->getProductFabricId() . $i)->getValue()); | |||
| $product->setPrice((float) ($workSheet->getCell($sheetSetting->getProductPrice() . $i)->getValue())); | |||
| $product->setNotes($workSheet->getCell($sheetSetting->getProductNotes() . $i)->getValue()); | |||
| $product->setDescription($workSheet->getCell($sheetSetting->getProductDescription() . $i)->getValue()); | |||
| $product->setWarranty((int) $workSheet->getCell($sheetSetting->getProductWarranty() . $i)->getValue()); | |||
| $product->setVtsz($workSheet->getCell($sheetSetting->getProductVtsz() . $i)->getValue()); | |||
| $product->setEan($workSheet->getCell($sheetSetting->getProductEan() . $i)->getValue()); | |||
| $product->setEol($workSheet->getCell($sheetSetting->getProductEol() . $i)->getValue()); | |||
| if ($product->isProduct()) { | |||
| /* | |||
| * Caution : | |||
| * This data is subject to change, be advised : | |||
| * - axico id and product categorising process might overwrite this data | |||
| */ | |||
| $product->setParentManufacturerId($sheetSetting->getManufacturerId()); | |||
| $product->setCurrency($sheetSetting->getCurrency()); | |||
| $product->setUploadedFileId($this->getUploadedFileid()); | |||
| $product->setSheetIndex($sheetSetting->getIndex()); | |||
| $product->setCorrectStatus(Status::ISMERETLEN); | |||
| $product->setPriceChanged(Status::PASSIVE); | |||
| $product->setPackingMaterial(PackingMaterial::UNKNOWN); | |||
| $product->setMeasureUnit(MeasureUnit::PIECE); | |||
| $product->setWidth(0.00); | |||
| $product->setLength(0.00); | |||
| $product->setHeight(0.00); | |||
| $product->setWeight(0.00); | |||
| $product->setPurchasePrice(0); | |||
| $product->setListPrice(0); | |||
| $product->setPriceDOne(0.00); | |||
| $product->setPriceDTwo(0.00); | |||
| $product->setPriceSpec(0.00); | |||
| $product->setPriceVSpec(0.00); | |||
| $product->setPriceDevDOne(0.00); | |||
| $product->setPriceDevDTwo(0.00); | |||
| $product->setPriceDevSpec(0.00); | |||
| $product->setPriceDevVSpec(0.00); | |||
| $product = $this->findWarrantyData($product); | |||
| $product->setPrevAxicoName(!empty($product->getAxicoName()) ? $product->getAxicoName() : ''); | |||
| $product->setPrevDescription(!empty($product->getDescription()) ? $product->getDescription() : ''); | |||
| $product->setPrevEol(!empty($product->getEol()) ? $product->getEol() : ''); | |||
| $product->setPrevFabricName(!empty($product->getFabricName()) ? $product->getFabricName() : ''); | |||
| $product->setPrevNotes(!empty($product->getNotes()) ? $product->getNotes() : ''); | |||
| $product->setPrevPrice(!empty($product->getPrice()) ? $product->getPrice() : 0.00); | |||
| $result['extracted'][$sheetSetting->getIndex()]['products'][$i] = $product; | |||
| } | |||
| } | |||
| if (isset($result['totalProducts'])) { | |||
| $result['totalProducts'] = $result['totalProducts'] + count($result['extracted'][$sheetSetting->getIndex()]['products']); | |||
| } else { | |||
| $result['totalProducts'] = count($result['extracted'][$sheetSetting->getIndex()]['products']); | |||
| } | |||
| $result['spreadSheet'] = $spreadSheet; | |||
| for ($i = 0; $i < $worksheetCount; $i++) { | |||
| $sheetSetting = $this->getSheetSettingByIndex($sheetSettings, $i); | |||
| if (empty($sheetSetting)) { | |||
| continue; | |||
| } | |||
| $result = $this->loadProductsOfWorkSheet($result, | |||
| $this->loadWorkSheetBySheetIndex($spreadSheet, $i), $sheetSetting); | |||
| if(isset($result['extracted'][$sheetSetting->getIndex()]['validation'])){ | |||
| return $result; | |||
| } | |||
| } | |||
| return $result; | |||
| } | |||
| private function getSheetSettingByIndex(array $sheetSettings, int $index): ?SheetSetting { | |||
| foreach ($sheetSettings as $sheetSetting) { | |||
| if ($sheetSetting->getIndex() == $index) { | |||
| return $sheetSetting; | |||
| } | |||
| } | |||
| return null; | |||
| } | |||
| public function loadWorkSheetBySheetIndex(Spreadsheet $spreadSheet, int $index): Worksheet { | |||
| return $spreadSheet->getSheet($index); | |||
| } | |||
| public function loadProductsOfWorkSheet(array $result, Worksheet $workSheet, SheetSetting $sheetSetting): array { | |||
| $result['extracted'][$sheetSetting->getIndex()]['workSheetName'] = empty($workSheet->getTitle()) ? $sheetSetting->getIndex() : $workSheet->getTitle(); | |||
| $result['extracted'][$sheetSetting->getIndex()]['products'] = []; | |||
| $cleanWorkSheetTitle = strtolower(preg_replace("/[^A-Za-z0-9 ]/", '', $workSheet->getTitle())); | |||
| $cleanSheetSettingName = strtolower(preg_replace("/[^A-Za-z0-9 ]/", '', $sheetSetting->getName())); | |||
| if(strcmp($cleanWorkSheetTitle,$cleanSheetSettingName) != 0){ | |||
| $result['extracted'][$sheetSetting->getIndex()]['validation'] = ['A munkalap neve nem megfelő. Ellenőrizze a konfigurációkat! Munkalap száma: ' . $sheetSetting->getIndex() ]; | |||
| return $result; | |||
| } | |||
| $highestRow = $workSheet->getHighestRow(); | |||
| if (empty($highestRow)) { | |||
| $result['extracted'][$sheetSetting->getIndex()]['empty'] = true; | |||
| return $result; | |||
| // Add default warranty value from config | |||
| private function findWarrantyData(Product $product): Product | |||
| { | |||
| if (empty($product->getWarranty())) { | |||
| $product->setWarranty($this->config->get('default_warranty')); | |||
| $product->setPrevWarranty($this->config->get('default_warranty')); | |||
| return $product; | |||
| } | |||
| $product->setPrevWarranty($product->getWarranty()); | |||
| return $product; | |||
| } | |||
| for ($i = 1; $i <= $highestRow; ++$i) { | |||
| $product = new Product(); | |||
| $product->setName($workSheet->getCell($sheetSetting->getProductName() . $i)->getValue()); | |||
| $product->setFabricName($workSheet->getCell($sheetSetting->getProductFabricName() . $i)->getValue()); | |||
| $product->setAxicoName($sheetSetting->findProductAxicoName($workSheet, $i)); | |||
| $product->setFabricId($workSheet->getCell($sheetSetting->getProductFabricId() . $i)->getValue()); | |||
| $product->setPrice((float) ($workSheet->getCell($sheetSetting->getProductPrice() . $i)->getValue())); | |||
| $product->setNotes($workSheet->getCell($sheetSetting->getProductNotes() . $i)->getValue()); | |||
| $product->setDescription($workSheet->getCell($sheetSetting->getProductDescription() . $i)->getValue()); | |||
| $product->setWarranty((int) $workSheet->getCell($sheetSetting->getProductWarranty() . $i)->getValue()); | |||
| $product->setVtsz($workSheet->getCell($sheetSetting->getProductVtsz() . $i)->getValue()); | |||
| $product->setEan($workSheet->getCell($sheetSetting->getProductEan() . $i)->getValue()); | |||
| $product->setEol($workSheet->getCell($sheetSetting->getProductEol() . $i)->getValue()); | |||
| if ($product->isProduct()) { | |||
| /* | |||
| * Caution : | |||
| * This data is subject to change, be advised : | |||
| * - axico id and product categorising process might overwrite this data | |||
| */ | |||
| $product->setParentManufacturerId($sheetSetting->getManufacturerId()); | |||
| $product->setCurrency($sheetSetting->getCurrency()); | |||
| $product->setUploadedFileId($this->getUploadedFileid()); | |||
| $product->setSheetIndex($sheetSetting->getIndex()); | |||
| $product->setCorrectStatus(Status::ISMERETLEN); | |||
| $product->setPriceChanged(Status::PASSIVE); | |||
| $product->setPackingMaterial(PackingMaterial::UNKNOWN); | |||
| $product->setMeasureUnit(MeasureUnit::PIECE); | |||
| $product->setWidth(0.00); | |||
| $product->setLength(0.00); | |||
| $product->setHeight(0.00); | |||
| $product->setWeight(0.00); | |||
| $product->setPurchasePrice(0); | |||
| $product->setListPrice(0); | |||
| $product->setPriceDOne(0.00); | |||
| $product->setPriceDTwo(0.00); | |||
| $product->setPriceSpec(0.00); | |||
| $product->setPriceVSpec(0.00); | |||
| $product->setPriceDevDOne(0.00); | |||
| $product->setPriceDevDTwo(0.00); | |||
| $product->setPriceDevSpec(0.00); | |||
| $product->setPriceDevVSpec(0.00); | |||
| $product = $this->findWarrantyData($product); | |||
| $product->setPrevAxicoName(!empty($product->getAxicoName()) ? $product->getAxicoName() : ''); | |||
| $product->setPrevDescription(!empty($product->getDescription()) ? $product->getDescription() : ''); | |||
| $product->setPrevEol(!empty($product->getEol()) ? $product->getEol() : ''); | |||
| $product->setPrevFabricName(!empty($product->getFabricName()) ? $product->getFabricName() : ''); | |||
| $product->setPrevNotes(!empty($product->getNotes()) ? $product->getNotes() : ''); | |||
| $product->setPrevPrice(!empty($product->getPrice()) ? $product->getPrice() : 0.00); | |||
| $result['extracted'][$sheetSetting->getIndex()]['products'][$i] = $product; | |||
| } | |||
| public function getManufacturer(): ?Manufacturer | |||
| { | |||
| return $this->manufacturer; | |||
| } | |||
| if (isset($result['totalProducts'])) { | |||
| $result['totalProducts'] = $result['totalProducts'] + count($result['extracted'][$sheetSetting->getIndex()]['products']); | |||
| } else { | |||
| $result['totalProducts'] = count($result['extracted'][$sheetSetting->getIndex()]['products']); | |||
| public function setManufacturer(Manufacturer $manufacturer): void | |||
| { | |||
| $this->manufacturer = $manufacturer; | |||
| } | |||
| return $result; | |||
| } | |||
| // Add default warranty value from config | |||
| private function findWarrantyData(Product $product): Product { | |||
| if (empty($product->getWarranty())) { | |||
| $product->setWarranty($this->config->get('default_warranty')); | |||
| $product->setPrevWarranty($this->config->get('default_warranty')); | |||
| return $product; | |||
| } | |||
| $product->setPrevWarranty($product->getWarranty()); | |||
| return $product; | |||
| } | |||
| public function getManufacturer(): ?Manufacturer { | |||
| return $this->manufacturer; | |||
| } | |||
| public function setManufacturer(Manufacturer $manufacturer): void { | |||
| $this->manufacturer = $manufacturer; | |||
| } | |||
| public function switchManufacturers(int $manufacturerId): void { | |||
| if (empty($this->getManufacturer())) { | |||
| $this->setManufacturer($this->getManufacturerFactory()->find($manufacturerId)); | |||
| return; | |||
| } | |||
| if ($this->getManufacturer()->getId() === $manufacturerId) { | |||
| return; | |||
| public function switchManufacturers(int $manufacturerId): void | |||
| { | |||
| if (empty($this->getManufacturer())) { | |||
| $this->setManufacturer($this->getManufacturerFactory()->find($manufacturerId)); | |||
| return; | |||
| } | |||
| if ($this->getManufacturer()->getId() === $manufacturerId) { | |||
| return; | |||
| } | |||
| $this->setManufacturer($this->getManufacturerFactory()->find($manufacturerId)); | |||
| } | |||
| $this->setManufacturer($this->getManufacturerFactory()->find($manufacturerId)); | |||
| } | |||
| public function switchCategories(int $categoryId): void { | |||
| if (empty($this->getCategory())) { | |||
| $this->setCategory($this->getCategoryFactory()->find($categoryId)); | |||
| return; | |||
| public function switchCategories(int $categoryId): void | |||
| { | |||
| if (empty($this->getCategory())) { | |||
| $this->setCategory($this->getCategoryFactory()->find($categoryId)); | |||
| return; | |||
| } | |||
| if ($this->getCategory()->getId() === $categoryId) { | |||
| return; | |||
| } | |||
| $this->setCategory($this->getCategoryFactory()->find($categoryId)); | |||
| } | |||
| if ($this->getCategory()->getId() === $categoryId) { | |||
| return; | |||
| } | |||
| $this->setCategory($this->getCategoryFactory()->find($categoryId)); | |||
| } | |||
| public function switchComponents(int $componentId): void { | |||
| if (empty($this->getComponent())) { | |||
| $this->setComponent($this->getComponentFactory()->find($componentId)); | |||
| return; | |||
| } | |||
| if ($this->getComponent()->getId() === $componentId) { | |||
| return; | |||
| } | |||
| $this->setComponent($this->getComponentFactory()->find($componentId)); | |||
| } | |||
| /** | |||
| * Get new files column names. | |||
| * | |||
| * The new file that will be generated can have only | |||
| * these column names. | |||
| * | |||
| * @return object | |||
| * Returns an object of std class with props 'A1'=>'Correctbe' ... | |||
| */ | |||
| public function getColumnNames() { | |||
| return (object) [ | |||
| 'columnNames' => [ | |||
| 'A1' => 'Correctbe', | |||
| 'B1' => 'Gyártó', | |||
| 'C1' => 'Gyártó cikkszám', | |||
| 'D1' => 'Gyártó megnevezés', | |||
| 'E1' => 'EAN', | |||
| 'F1' => 'Vámtarifaszám', | |||
| 'G1' => 'Axico cikkszám', | |||
| 'H1' => 'Axico megnevezés', | |||
| 'I1' => 'Garancia', | |||
| 'J1' => 'Lista nettó', | |||
| 'K1' => 'D2', | |||
| 'L1' => 'D1', | |||
| 'M1' => 'Spec', | |||
| 'N1' => 'Vsp', | |||
| 'O1' => 'Dev. D2', | |||
| 'P1' => 'Dev. D1', | |||
| 'Q1' => 'Dev. SP', | |||
| 'R1' => 'Dev. VSP', | |||
| 'S1' => 'Mértékegység', | |||
| 'T1' => 'Beszerzési ár', | |||
| 'U1' => 'Bekerülési ár', | |||
| 'V1' => 'Devizanem', | |||
| 'W1' => 'Webcsoport', | |||
| 'X1' => 'Főcsoport', | |||
| 'Y1' => 'Csoport kód', | |||
| 'Z1' => 'Megjegyzés', | |||
| 'AA1' => 'Árlistába', | |||
| 'AB1' => 'B2B', | |||
| 'AC1' => 'DFS', | |||
| 'AD1' => 'OMB', | |||
| 'AE1' => 'MilcS', | |||
| 'AF1' => 'BBX', | |||
| 'AG1' => 'SMC', | |||
| 'AH1' => 'Terméksúly', | |||
| 'AI1' => 'Cs. műanyag', | |||
| 'AJ1' => 'Cs. papír', | |||
| 'AK1' => 'Cs. fa', | |||
| 'AL1' => 'Szélesség', | |||
| 'AM1' => 'Hosszúság', | |||
| 'AN1' => 'Magasság', | |||
| ] | |||
| ]; | |||
| } | |||
| /** | |||
| * Add rows to excel file. | |||
| * | |||
| * @param $spreadSheet | |||
| * The spreadSheet. | |||
| * @param array $products | |||
| * The products | |||
| * @param string $manufacturer_name | |||
| * The manufacturers name. | |||
| * @param array $columns | |||
| * The column names. | |||
| * @param array $settings | |||
| * The manufacturers column settings if differs from default. | |||
| * | |||
| * @return mixed | |||
| */ | |||
| public function populateSpreadSheetCells(Spreadsheet $spreadSheet, array $products, string $manufacturerName, array $columns) { | |||
| foreach ($columns as $cell => $value) { | |||
| $spreadSheet = $this->fillColumnNames($spreadSheet, $cell, $value); | |||
| public function switchComponents(int $componentId): void | |||
| { | |||
| if (empty($this->getComponent())) { | |||
| $this->setComponent($this->getComponentFactory()->find($componentId)); | |||
| return; | |||
| } | |||
| if ($this->getComponent()->getId() === $componentId) { | |||
| return; | |||
| } | |||
| $this->setComponent($this->getComponentFactory()->find($componentId)); | |||
| } | |||
| $i = 4; | |||
| /* @var $product Product */ | |||
| foreach ($products as $product) { | |||
| $spreadSheet = $this->fillRow($spreadSheet, $i, $product); | |||
| $i++; | |||
| /** | |||
| * Get new files column names. | |||
| * | |||
| * The new file that will be generated can have only | |||
| * these column names. | |||
| * | |||
| * @return object | |||
| * Returns an object of std class with props 'A1'=>'Correctbe' ... | |||
| */ | |||
| public function getColumnNames() | |||
| { | |||
| return (object) [ | |||
| 'columnNames' => [ | |||
| 'A1' => 'Correctbe', | |||
| 'B1' => 'Gyártó', | |||
| 'C1' => 'Gyártó cikkszám', | |||
| 'D1' => 'Gyártó megnevezés', | |||
| 'E1' => 'EAN', | |||
| 'F1' => 'Vámtarifaszám', | |||
| 'G1' => 'Axico cikkszám', | |||
| 'H1' => 'Axico megnevezés', | |||
| 'I1' => 'Garancia', | |||
| 'J1' => 'Lista nettó', | |||
| 'K1' => 'D2', | |||
| 'L1' => 'D1', | |||
| 'M1' => 'Spec', | |||
| 'N1' => 'Vsp', | |||
| 'O1' => 'Dev. D2', | |||
| 'P1' => 'Dev. D1', | |||
| 'Q1' => 'Dev. SP', | |||
| 'R1' => 'Dev. VSP', | |||
| 'S1' => 'Mértékegység', | |||
| 'T1' => 'Beszerzési ár', | |||
| 'U1' => 'Bekerülési ár', | |||
| 'V1' => 'Devizanem', | |||
| 'W1' => 'Webcsoport', | |||
| 'X1' => 'Főcsoport', | |||
| 'Y1' => 'Csoport kód', | |||
| 'Z1' => 'Megjegyzés', | |||
| 'AA1' => 'Árlistába', | |||
| 'AB1' => 'B2B', | |||
| 'AC1' => 'DFS', | |||
| 'AD1' => 'OMB', | |||
| 'AE1' => 'MilcS', | |||
| 'AF1' => 'BBX', | |||
| 'AG1' => 'SMC', | |||
| 'AH1' => 'Terméksúly', | |||
| 'AI1' => 'Cs. műanyag', | |||
| 'AJ1' => 'Cs. papír', | |||
| 'AK1' => 'Cs. fa', | |||
| 'AL1' => 'Szélesség', | |||
| 'AM1' => 'Hosszúság', | |||
| 'AN1' => 'Magasság', | |||
| ], | |||
| ]; | |||
| } | |||
| /** | |||
| * Add rows to excel file. | |||
| * | |||
| * @param $spreadSheet | |||
| * The spreadSheet. | |||
| * @param array $products | |||
| * The products | |||
| * @param string $manufacturer_name | |||
| * The manufacturers name. | |||
| * @param array $columns | |||
| * The column names. | |||
| * @param array $settings | |||
| * The manufacturers column settings if differs from default. | |||
| * | |||
| * @return mixed | |||
| */ | |||
| public function populateSpreadSheetCells(Spreadsheet $spreadSheet, array $products, string $manufacturerName, array $columns) | |||
| { | |||
| foreach ($columns as $cell => $value) { | |||
| $spreadSheet = $this->fillColumnNames($spreadSheet, $cell, $value); | |||
| } | |||
| $i = 4; | |||
| /* @var $product Product */ | |||
| foreach ($products as $product) { | |||
| $spreadSheet = $this->fillRow($spreadSheet, $i, $product); | |||
| $i++; | |||
| } | |||
| $spreadSheet->getProperties() | |||
| ->setCreator("Correct Files Online") | |||
| ->setLastModifiedBy("-") | |||
| ->setTitle($manufacturerName . ' ' . date('d-m-Y', time()) . 'pricelist') | |||
| ->setSubject("Products for Correct") | |||
| ->setDescription("Automatically generated pricelist to update Correct database") | |||
| ->setKeywords("correct drupal office 2007 openxml php") | |||
| ->setCategory("Pricelist"); | |||
| foreach ($columns as $key => $value) { | |||
| $spreadSheet->getActiveSheet()->getColumnDimension(str_replace('1', '', $key))->setAutoSize(true); | |||
| } | |||
| return $spreadSheet; | |||
| } | |||
| $spreadSheet->getProperties() | |||
| ->setCreator("Correct Files Online") | |||
| ->setLastModifiedBy("-") | |||
| ->setTitle($manufacturerName . ' ' . date('d-m-Y', time()) . 'pricelist') | |||
| ->setSubject("Products for Correct") | |||
| ->setDescription("Automatically generated pricelist to update Correct database") | |||
| ->setKeywords("correct drupal office 2007 openxml php") | |||
| ->setCategory("Pricelist"); | |||
| /** | |||
| * Fill column names | |||
| * | |||
| * @param $spreadSheet SpreadSheet | |||
| * @param string $cell | |||
| * @param string $value | |||
| * | |||
| * @return void | |||
| */ | |||
| private function fillColumnNames(SpreadSheet $spreadSheet, string $cell, string $value): SpreadSheet | |||
| { | |||
| $spreadSheet->getActiveSheet()->getCell($cell)->setValue($value); | |||
| return $spreadSheet; | |||
| } | |||
| foreach ($columns as $key => $value) { | |||
| $spreadSheet->getActiveSheet()->getColumnDimension(str_replace('1', '', $key))->setAutoSize(true); | |||
| /** | |||
| * Fill excel row with data | |||
| * | |||
| * @param $spreadSheet SpreadSheet | |||
| * @param int $i | |||
| * @param $product Product | |||
| * | |||
| * @return SpreadSheet | |||
| */ | |||
| private function fillRow(SpreadSheet $spreadSheet, int $rowNum, Product $product): Spreadsheet | |||
| { | |||
| $this->switchManufacturers($product->getParentManufacturerId()); | |||
| if ($product->isComponentBased()) { | |||
| $this->switchComponents($product->getParentComponentId()); | |||
| } else { | |||
| $this->switchCategories($product->getParentCategoryId()); | |||
| } | |||
| $cellValuesByColumnNames = $this->getCellValuesByColumnNames($product); | |||
| foreach ($cellValuesByColumnNames as $key => $value) { | |||
| $spreadSheet->getActiveSheet()->getCell($key . $rowNum)->setValue($value); | |||
| } | |||
| // * EAN | |||
| $spreadSheet->getActiveSheet()->setCellValueExplicit('E' . $rowNum, (string) $product->getEan(), DataType::TYPE_STRING); | |||
| return $spreadSheet; | |||
| } | |||
| return $spreadSheet; | |||
| } | |||
| /** | |||
| * Fill column names | |||
| * | |||
| * @param $spreadSheet SpreadSheet | |||
| * @param string $cell | |||
| * @param string $value | |||
| * | |||
| * @return void | |||
| */ | |||
| private function fillColumnNames(SpreadSheet $spreadSheet, string $cell, string $value): SpreadSheet { | |||
| $spreadSheet->getActiveSheet()->getCell($cell)->setValue($value); | |||
| return $spreadSheet; | |||
| } | |||
| /** | |||
| * Fill excel row with data | |||
| * | |||
| * @param $spreadSheet SpreadSheet | |||
| * @param int $i | |||
| * @param $product Product | |||
| * | |||
| * @return SpreadSheet | |||
| */ | |||
| private function fillRow(SpreadSheet $spreadSheet, int $rowNum, Product $product): Spreadsheet { | |||
| $this->switchManufacturers($product->getParentManufacturerId()); | |||
| if ($product->isComponentBased()) { | |||
| $this->switchComponents($product->getParentComponentId()); | |||
| } else { | |||
| $this->switchCategories($product->getParentCategoryId()); | |||
| public function getCellValuesByColumnNames(Product $product): array | |||
| { | |||
| return [ | |||
| // CORRECT | |||
| 'A' => $product->getStatus(), | |||
| // MANUFACTURER SIF | |||
| 'B' => $product->isComponentBased() ? $this->getComponent()->getSif() : $this->getManufacturer()->getSif(), | |||
| // * FABRIC ID | |||
| 'C' => $product->getFabricId(), | |||
| // * FABRIC NAME | |||
| 'D' => $product->getFabricName(), | |||
| // * VTSZ | |||
| 'F' => '', | |||
| // * AXICO ID | |||
| 'G' => $product->getAxicoId(), | |||
| // * AXICO NAME | |||
| 'H' => $product->getAxicoName(), | |||
| // * WARRANTY | |||
| 'I' => $product->getWarranty() || $product->getWarranty() === 0 ? $product->getWarranty() : 60, | |||
| // * LIST PRICE | |||
| 'J' => $product->getListPrice(), | |||
| // * PRICE D2 | |||
| 'K' => $product->getPriceDTwo(), | |||
| // * PRICE D1 | |||
| 'L' => $product->getPriceDOne(), | |||
| // * PRICE SP | |||
| 'M' => $product->getPriceSpec(), | |||
| // * VSP | |||
| 'N' => $product->getPriceVSpec(), | |||
| // * DEV D2 | |||
| 'O' => $product->getPriceDevDTwo(), | |||
| // * DEV D1 | |||
| 'P' => $product->getPriceDevDOne(), | |||
| // * DEV SP | |||
| 'Q' => $product->getPriceDevSpec(), | |||
| // * DEV VSP | |||
| 'R' => $product->getPriceDevVSpec(), | |||
| // * MEASURE UNIT | |||
| //'S' => $product->getMeasureUnit() === MeasureUnit::UNDEFINED ? MeasureUnit::PIECE : $product->getMeasureUnit(), | |||
| 'S' => 'db', | |||
| // * PRICE | |||
| 'T' => $product->getPrice(), | |||
| // * PURCHASE PRICE - BEKERULESI AR | |||
| 'U' => $product->getPurchasePrice(), | |||
| // * CURRENCY | |||
| 'V' => $product->getCurrency(), | |||
| // * WEBGROUP | |||
| 'W' => 0, | |||
| // * MAINGROUP | |||
| 'X' => $product->isComponentBased() ? $this->getComponent()->getAxicoIdName() : $this->getCategory()->getAxicoIdName(), | |||
| // * GROUP | |||
| 'Y' => $product->isComponentBased() ? $this->getComponent()->getName() : $this->getCategory()->getName(), | |||
| // *NOTES | |||
| 'Z' => $product->getNotes() . ' - ' . $product->getDescription(), | |||
| // ARLISTABA/WEBRE | |||
| 'AA' => $product->getListed() ? 'T' : 'F', | |||
| // B2B | |||
| 'AB' => 'F', | |||
| // DFS | |||
| 'AC' => 'F', | |||
| // OMB | |||
| 'AD' => 'F', | |||
| // MilcS | |||
| 'AF' => 'F', | |||
| // BBX | |||
| 'AF' => $this->getManufacturer()->isAxicoIdNameSameAs('BBX') ? 'T' : 'F', | |||
| // SMC | |||
| 'AG' => $this->getManufacturer()->isAxicoIdNameSameAs('SUP') && $this->getManufacturer()->isComponentBased() ? 'T' : 'F', | |||
| // * WEIGHT | |||
| 'AH' => $product->getWeight(), | |||
| // PACKAGING MATERIAL PLASTIC | |||
| 'AI' => $product->getPackingMaterial() === PackingMaterial::PLASTIC ? 1 : 0, | |||
| // PACKAGING MATERIAL PAPER | |||
| 'AJ' => $product->getPackingMaterial() === PackingMaterial::PAPER ? 1 : 0, | |||
| // PACKAGING MATERIAL WOOD | |||
| 'AK' => $product->getPackingMaterial() === PackingMaterial::WOOD ? 1 : 0, | |||
| // width | |||
| 'AL' => $product->getWidth(), | |||
| // length | |||
| 'AM' => $product->getLength(), | |||
| // height | |||
| 'AN' => $product->getHeight(), | |||
| ]; | |||
| } | |||
| $cellValuesByColumnNames = $this->getCellValuesByColumnNames($product); | |||
| foreach ($cellValuesByColumnNames as $key => $value) { | |||
| $spreadSheet->getActiveSheet()->getCell($key . $rowNum)->setValue($value); | |||
| public function getWorkSheet(string $fileName, int $index): Worksheet | |||
| { | |||
| $moduleHandler = \Drupal::service('module_handler'); | |||
| $modulePath = $moduleHandler->getModule('arlista')->getPath(); | |||
| $spreadSheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($modulePath . '/' . $fileName); | |||
| return $spreadSheet->getSheet($index); | |||
| } | |||
| // * EAN | |||
| $spreadSheet->getActiveSheet()->setCellValueExplicit('E' . $rowNum, (string) $product->getEan(), DataType::TYPE_STRING); | |||
| return $spreadSheet; | |||
| } | |||
| public function getCellValuesByColumnNames(Product $product): array { | |||
| return [ | |||
| // CORRECT | |||
| 'A' => $product->getStatus(), | |||
| // MANUFACTURER SIF | |||
| 'B' => $product->isComponentBased() ? $this->getComponent()->getSif() : $this->getManufacturer()->getSif(), | |||
| // * FABRIC ID | |||
| 'C' => $product->getFabricId(), | |||
| // * FABRIC NAME | |||
| 'D' => $product->getFabricName(), | |||
| // * VTSZ | |||
| 'F' => '', | |||
| // * AXICO ID | |||
| 'G' => $product->getAxicoId(), | |||
| // * AXICO NAME | |||
| 'H' => $product->getAxicoName(), | |||
| // * WARRANTY | |||
| 'I' => $product->getWarranty() || $product->getWarranty() === 0 ? $product->getWarranty() : 60, | |||
| // * LIST PRICE | |||
| 'J' => $product->getListPrice(), | |||
| // * PRICE D2 | |||
| 'K' => $product->getPriceDTwo(), | |||
| // * PRICE D1 | |||
| 'L' => $product->getPriceDOne(), | |||
| // * PRICE SP | |||
| 'M' => $product->getPriceSpec(), | |||
| // * VSP | |||
| 'N' => $product->getPriceVSpec(), | |||
| // * DEV D2 | |||
| 'O' => $product->getPriceDevDTwo(), | |||
| // * DEV D1 | |||
| 'P' => $product->getPriceDevDOne(), | |||
| // * DEV SP | |||
| 'Q' => $product->getPriceDevSpec(), | |||
| // * DEV VSP | |||
| 'R' => $product->getPriceDevVSpec(), | |||
| // * MEASURE UNIT | |||
| //'S' => $product->getMeasureUnit() === MeasureUnit::UNDEFINED ? MeasureUnit::PIECE : $product->getMeasureUnit(), | |||
| 'S' => 'db', | |||
| // * PRICE | |||
| 'T' => $product->getPrice(), | |||
| // * PURCHASE PRICE - BEKERULESI AR | |||
| 'U' => $product->getPurchasePrice(), | |||
| // * CURRENCY | |||
| 'V' => $product->getCurrency(), | |||
| // * WEBGROUP | |||
| 'W' => 0, | |||
| // * MAINGROUP | |||
| 'X' => $product->isComponentBased() ? $this->getComponent()->getAxicoIdName() : $this->getCategory()->getAxicoIdName(), | |||
| // * GROUP | |||
| 'Y' => $product->isComponentBased() ? $this->getComponent()->getName() : $this->getCategory()->getName(), | |||
| // *NOTES | |||
| 'Z' => $product->getNotes() . ' - ' . $product->getDescription(), | |||
| // ARLISTABA/WEBRE | |||
| 'AA' => $product->getListed() ? 'T' : 'F', | |||
| // B2B | |||
| 'AB' => 'F', | |||
| // DFS | |||
| 'AC' => 'F', | |||
| // OMB | |||
| 'AD' => 'F', | |||
| // MilcS | |||
| 'AF' => 'F', | |||
| // BBX | |||
| 'AF' => $this->getManufacturer()->isAxicoIdNameSameAs('BBX') ? 'T' : 'F', | |||
| // SMC | |||
| 'AG' => $this->getManufacturer()->isAxicoIdNameSameAs('SUP') && $this->getManufacturer()->isComponentBased() ? 'T' : 'F', | |||
| // * WEIGHT | |||
| 'AH' => $product->getWeight(), | |||
| // PACKAGING MATERIAL PLASTIC | |||
| 'AI' => $product->getPackingMaterial() === PackingMaterial::PLASTIC ? 1 : 0, | |||
| // PACKAGING MATERIAL PAPER | |||
| 'AJ' => $product->getPackingMaterial() === PackingMaterial::PAPER ? 1 : 0, | |||
| // PACKAGING MATERIAL WOOD | |||
| 'AK' => $product->getPackingMaterial() === PackingMaterial::WOOD ? 1 : 0, | |||
| // width | |||
| 'AL' => $product->getWidth(), | |||
| // length | |||
| 'AM' => $product->getLength(), | |||
| // height | |||
| 'AN' => $product->getHeight(), | |||
| ]; | |||
| } | |||
| public function getWorkSheet(string $fileName, int $index): Worksheet { | |||
| $moduleHandler = \Drupal::service('module_handler'); | |||
| $modulePath = $moduleHandler->getModule('arlista')->getPath(); | |||
| $spreadSheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($modulePath . '/' . $fileName); | |||
| return $spreadSheet->getSheet($index); | |||
| } | |||
| } | |||
| @@ -85,6 +85,7 @@ class AxicoIdWarrantyList extends ArlistaAbstractForm { | |||
| function filterAxicoIds(array &$form, FormStateInterface $form_state) { | |||
| $form_state->setRedirect('arlista.warranty.list', ['filterx' => $form_state->getValue('filter') ? $form_state->getValue('filter') : 'mind']); | |||
| } | |||
| /** | |||
| * {@inheritdoc} | |||
| */ | |||
| @@ -76,13 +76,13 @@ class ConfirmProductActivate extends AbstractConfirmForm { | |||
| $uploadedProduct->setStatus(Status::ACTIVE); | |||
| $uploadedProduct->setWorkFlow(WorkFlow::ACTIVATED); | |||
| $uploadedProduct->setCorrectStatus(Status::FRISSITENDO); | |||
| $this->getProductFactory()->saveTo($uploadedProduct, 'arlista_manager_uploaded_product'); | |||
| $this->getProductFactory()->saveToDatabaseTable($uploadedProduct, 'arlista_manager_uploaded_product'); | |||
| } else { | |||
| $product->setParentManufacturerId($this->mid); | |||
| $product->setUploadedFileId($this->fid); | |||
| $product->setStatus(Status::ACTIVE); | |||
| $product->setWorkFlow(WorkFlow::ACTIVATED); | |||
| $this->getProductFactory()->saveTo($product, 'arlista_manager_active_product'); | |||
| $this->getProductFactory()->saveToDatabaseTable($product, 'arlista_manager_active_product'); | |||
| } | |||
| parent::addMessage($product->getAxicoId() . ' # ' . $product->getAxicoName() . ' - sikeresen aktiválva'); | |||
| @@ -61,7 +61,7 @@ class ConfirmProductDeactivate extends AbstractConfirmForm { | |||
| $product->setStatus(Status::PASSIVE); | |||
| $product->setWorkFlow(WorkFlow::DELETED); | |||
| $product->setCorrectStatus(Status::CORRECT_IMPORTED); | |||
| $this->getProductFactory()->saveTo($product, 'arlista_manager_active_product'); | |||
| $this->getProductFactory()->saveToDatabaseTable($product, 'arlista_manager_active_product'); | |||
| parent::addMessage($product->getAxicoName() ? $product->getAxicoName() : $product->getFabricName() . ' - ' . $product->getAxicoId() . ' - sikeresen passziválva'); | |||
| @@ -229,12 +229,6 @@ class ProductUploadedList extends ArlistaAbstractForm { | |||
| $enabledComponents[$component->getId()] = $component; | |||
| } | |||
| } | |||
| /* @var $enabledGroup EnabledGroup */ | |||
| /*foreach($enabledGroups as $enabledGroup) { | |||
| if (isset($enabledGroups[$component->getId()])) { | |||
| $enabledComponents[$component->getId()] = $component; | |||
| } | |||
| }*/ | |||
| $this->manufacturersList = $this->getComponentManufacturersList($enabledComponents); | |||
| $this->enabledComponents = $enabledComponents; | |||
| //$this->getCacheService()->setCachedDataByName([$this->getFormId(), $manufacturer->getId(), | |||
| @@ -70,7 +70,7 @@ class ProductService { | |||
| $liveProduct = $this->productFactory->findByAxicoIdInTable($product->getAxicoId(), 'arlista_manager_active_product'); | |||
| $liveProduct->copyPrices($product); | |||
| $this->productFactory->saveTo($liveProduct, 'arlista_manager_active_product'); | |||
| $this->productFactory->saveToDatabaseTable($liveProduct, 'arlista_manager_active_product'); | |||
| $this->productFactory->getCacheService()->resetCache(['arlista_product_edit_form', 'live', $liveProduct->getId()]); | |||
| } | |||
| } | |||