first commit

This commit is contained in:
2025-08-02 16:30:27 +02:00
commit 23646bfcee
14851 changed files with 1750626 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
VarioBundle:
resource: "@VarioBundle/Controller/"
type: annotation

View File

@@ -0,0 +1,31 @@
parameters:
vario.wsdl: http://90.176.72.161:1025/wsdl/IVarioSOAPService
vario.client_number: 1
vario.products.default_label_id: 16
vario.stores: []
vario.pricelists: []
vario.settings:
wsdl: '%vario.wsdl%'
client_number: '%vario.client_number%'
products:
default_label_id: '%vario.products.default_label_id%'
stores: '%vario.stores%'
pricelists: '%vario.pricelists%'
services:
_defaults:
autowire: true
autoconfigure: true
public: true
External\VarioBundle\:
resource: ../../{Admin/Tabs,Admin/Actions,Command,Controller,Email,Synchronizers,Uploaders,Util}
External\VarioBundle\Util\SynchronizerLocator:
arguments: [ !tagged_locator { tag: 'vario.synchronizer', index_by: 'key', default_index_method: 'getType' } ]
External\VarioBundle\SoapClient: ~
External\VarioBundle\Util\VarioConfig:
arguments: [ '%vario.settings%' ]

View File

@@ -0,0 +1,34 @@
<?php
namespace External\VarioBundle\Resources\script;
use External\VarioBundle\Util\SynchronizerLocator;
use KupShop\AdminBundle\Util\Script\Script;
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
class RunVarioSynchronizationScript extends Script
{
protected static $name = '[Vario] Run synchronization';
protected static $defaultParameters = [
'type' => 'otProductSimple',
'forceSync' => null,
];
protected function run(array $arguments)
{
$locator = ServiceContainer::getService(SynchronizerLocator::class);
$this->log('Running...');
$synchronizer = $locator->getServiceByType($arguments['type']);
if (!empty($arguments['forceSync'])) {
$synchronizer->setForceSync($arguments['forceSync']);
}
$synchronizer->setDebug(true);
$synchronizer->sync();
$this->log('Done');
}
}
return RunVarioSynchronizationScript::class;

View File

@@ -0,0 +1,45 @@
<?php
namespace External\VarioBundle\Resources\script;
use External\VarioBundle\Synchronizers\OrderSynchronizer;
use KupShop\AdminBundle\Util\Script\Script;
use KupShop\KupShopBundle\Context\ContextManager;
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
class VarioSendOrderScript extends Script
{
protected static $name = '[Vario] Send Order to Vario';
protected static $defaultParameters = [
'format' => 'json',
'dryRun' => true,
'orderID' => null,
];
protected function run(array $arguments)
{
$contextManager = ServiceContainer::getService(ContextManager::class);
$orderSynchronizer = ServiceContainer::getService(OrderSynchronizer::class);
$this->log('Running '.($arguments['dryRun'] ? 'in DRY RUN' : 'in PRODUCTION mode').'... ');
$order = new \Order();
$order->createFromDB($arguments['orderID']);
$contextManager->activateOrder($order, function () use ($arguments, $order, $orderSynchronizer) {
$order->fetchItems();
if ($arguments['dryRun']) {
$data = $orderSynchronizer->createDocumentObject($order);
$this->log($arguments['format'] === 'json' ? json_encode($data, JSON_PRETTY_PRINT) : print_r($data, true));
} else {
$result = $orderSynchronizer->syncOrder($order);
$this->log($result ? 'OK' : 'ERROR');
}
});
$this->log('Done');
}
}
return VarioSendOrderScript::class;

View File

@@ -0,0 +1,53 @@
<?php
namespace External\VarioBundle\Resources\script;
use External\VarioBundle\Synchronizers\ProductSynchronizer;
use KupShop\AdminBundle\Util\Script\Script;
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
use Query\Operator;
class VarioStoreItemsSync extends Script
{
protected static $name = '[Vario] Store Items Sync';
protected static $defaultParameters = [
'productId' => '',
'startFrom' => 218,
];
protected function run(array $arguments)
{
$productSynchronizer = ServiceContainer::getService(ProductSynchronizer::class);
// aktivní produkty tedy skrytý nebo viditelný
$productIds = sqlQueryBuilder()
->select('vp.id_product, vp.id_vario')
->from('vario_products', 'vp')
->innerJoin('vp', 'products', 'p', 'vp.id_product = p.id')
->where(Operator::not(Operator::equals(['p.figure' => 'O'])));
// pokud je předán productId, tak se přidá podmínka
if (!empty($arguments['productId'])) {
$productIds->andWhere(Operator::equals(['id_product' => $arguments['productId']]));
}
if (!empty($arguments['startFrom'])) {
$productIds->andWhere('vp.id_product >= :startFrom')
->setParameter('startFrom', $arguments['startFrom']);
}
$productIds->orderBy('vp.id_product', 'ASC');
$productIds = $productIds->execute()->fetchAllKeyValue();
foreach ($productIds as $productId => $varioId) {
sqlGetConnection()->transactional(function () use ($productId, $varioId, $productSynchronizer) {
// Smazání položek skladu pro produkt - provest update quantity na 0
sqlQueryBuilder()
->update('stores_items')
->directValues(['quantity' => 0])
->where(Operator::equals(['id_product' => $productId]))
->execute();
// Zavolání forceSync z productSynchronizer
$productSynchronizer->forceSyncSupply($varioId);
});
$this->log('Synchronizace položek skladu pro produkt: '.$productId.' dokončena');
}
}
}
return VarioStoreItemsSync::class;

View File

@@ -0,0 +1,191 @@
<?php
namespace External\VarioBundle\Resources\upgrade;
class MappingTablesUpgrade extends \UpgradeNew
{
protected $priority = 1200;
private $tables = [
'vario_products' => [
'id_column' => 'id_product',
'references' => 'products(id)',
'unsigned' => false,
],
'vario_sections' => [
'id_column' => 'id_section',
'references' => 'sections(id)',
'unsigned' => false,
],
'vario_variations' => [
'id_column' => 'id_variation',
'references' => 'products_variations(id)',
'unsigned' => false,
],
'vario_stores' => [
'id_column' => 'id_store',
'references' => 'stores(id)',
'unsigned' => false,
],
'vario_pricelists' => [
'id_column' => 'id_pricelist',
'references' => 'pricelists(id)',
'unsigned' => false,
],
'vario_orders' => [
'id_column' => 'id_order',
'references' => 'orders(id)',
'unsigned' => true,
],
];
public function check_mappingTablesExists()
{
return $this->checkTableExists('vario_products');
}
/** Vario: create mapping tables */
public function upgrade_mappingTablesExists()
{
foreach ($this->tables as $table => $options) {
$unsigned = '';
if ($options['unsigned']) {
$unsigned = 'UNSIGNED';
}
sqlQuery("CREATE TABLE {$table} (
id_vario VARCHAR(100) PRIMARY KEY,
{$options['id_column']} INT(11) {$unsigned} NOT NULL,
FOREIGN KEY ({$options['id_column']}) REFERENCES {$options['references']}
ON DELETE CASCADE ON UPDATE CASCADE
);");
}
$this->upgradeOK();
}
public function check_PaidSentColumn()
{
return $this->checkColumnExists('vario_orders', 'paid_sent');
}
/** Add column vario_orders.paid_sent */
public function upgrade_PaidSentColumn()
{
sqlQuery('ALTER TABLE vario_orders ADD COLUMN paid_sent TINYINT DEFAULT NULL');
$this->upgradeOK();
}
public function check_VarioOrdersDataColumn()
{
return $this->checkColumnExists('vario_orders', 'data');
}
/** Add column vario_orders.data */
public function upgrade_VarioOrdersDataColumn()
{
sqlQuery('ALTER TABLE vario_orders ADD COLUMN data MEDIUMTEXT DEFAULT NULL');
$this->upgradeOK();
}
public function check_PrimaryKeyInVarioVariations()
{
return !$this->checkIndexNameExists('vario_variations', 'PRIMARY');
}
/** Drop primary key in vario_variations */
public function upgrade_PrimaryKeyInVarioVariations()
{
sqlQuery('ALTER TABLE vario_variations DROP PRIMARY KEY ');
$this->upgradeOK();
}
public function check_VarioDocumentsTable()
{
return $this->checkTableExists('vario_documents');
}
/** Add vario_documents table */
public function upgrade_VarioDocumentsTable()
{
sqlQuery('CREATE TABLE vario_documents (
id_vario VARCHAR(100) PRIMARY KEY,
status VARCHAR(100) DEFAULT NULL
);');
$this->upgradeOK();
}
public function check_VarioProductsForeignKey()
{
return $this->checkForeignKeyExists('vario_products', 'id_product');
}
/** Add foreign key to 'vario_products' */
public function upgrade_VarioProductsForeignKey()
{
sqlQuery('ALTER TABLE vario_products ADD CONSTRAINT vario_products_ibfk1 FOREIGN KEY (id_product) REFERENCES products(id) ON DELETE CASCADE ON UPDATE CASCADE');
$this->upgradeOK();
}
public function check_VarioSectionsParent()
{
return $this->checkColumnExists('vario_sections', 'parent');
}
/** Add 'parent' column into 'vario_sections' */
public function upgrade_VarioSectionsParent()
{
sqlQuery('ALTER TABLE vario_sections ADD COLUMN parent VARCHAR(100) DEFAULT NULL');
$this->upgradeOK();
}
public function check_VarioSectionsOrder()
{
return $this->checkColumnExists('vario_sections', 'position');
}
/** Add 'position' column into 'vario_sections' */
public function upgrade_VarioSectionsOrder()
{
sqlQuery('ALTER TABLE vario_sections ADD COLUMN position INT(11) DEFAULT 0');
$this->upgradeOK();
}
public function check_VarioStoresDisabledColumn()
{
return $this->checkColumnExists('vario_stores', 'disabled');
}
/** add 'disabled' column into 'vario_stores' table */
public function upgrade_VarioStoresDisabledColumn()
{
sqlQuery('ALTER TABLE vario_stores ADD COLUMN disabled TINYINT DEFAULT 0');
$this->upgradeOK();
}
public function check_VarioDelayedUpdate(): bool
{
return $this->checkTableExists('vario_delayed_update');
}
/** Create table vario_delayed_update */
public function upgrade_VarioDelayedUpdate(): void
{
sqlQuery(
'CREATE TABLE vario_delayed_update (
id_vario VARCHAR(100),
type VARCHAR(25) NOT NULL
);'
);
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,51 @@
<?php
namespace External\VarioBundle\Resources\upgrade;
class UsersUpgrade extends \UpgradeNew
{
public function check_idVario()
{
return $this->checkColumnExists('users', 'id_vario');
}
/** add column 'id_vario' into 'users' table */
public function upgrade_idVario()
{
sqlQuery('ALTER TABLE users ADD COLUMN id_vario VARCHAR(150) DEFAULT NULL');
$this->upgradeOK();
}
public function check_VarioIdentifier()
{
return $this->checkColumnExists('users', 'vario_identifier');
}
/** add column 'vario_identifier' into 'users' table */
public function upgrade_VarioIdentifier()
{
sqlQuery('ALTER TABLE users ADD COLUMN vario_identifier VARCHAR(150) DEFAULT NULL');
$this->upgradeOK();
}
public function check_VarioUsers(): bool
{
return $this->checkTableExists('vario_users');
}
/** Add vario_users table */
public function upgrade_VarioUsers(): void
{
sqlQuery('CREATE TABLE vario_users (
id_vario VARCHAR(100) PRIMARY KEY,
id_user INT(11) UNSIGNED NOT NULL,
identifier VARCHAR(50) NOT NULL,
FOREIGN KEY (id_user) REFERENCES users (id)
ON DELETE CASCADE ON UPDATE CASCADE
);');
$this->upgradeOK();
}
}