Skip to content

Commit

Permalink
Feat/manu supply etc (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
synicko authored Aug 8, 2023
1 parent 0f4cfb7 commit 8d1efb4
Show file tree
Hide file tree
Showing 24 changed files with 1,005 additions and 7 deletions.
18 changes: 18 additions & 0 deletions config/front/decorator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,21 @@ services:
public: true
arguments:
- '@PrestaShop\Module\PsEventbus\Repository\ConfigurationRepository'

PrestaShop\Module\PsEventbus\Decorator\ManufacturerDecorator:
class: PrestaShop\Module\PsEventbus\Decorator\ManufacturerDecorator
public: true
arguments:
- '@PrestaShop\Module\PsEventbus\Repository\ConfigurationRepository'

PrestaShop\Module\PsEventbus\Decorator\SupplierDecorator:
class: PrestaShop\Module\PsEventbus\Decorator\SupplierDecorator
public: true
arguments:
- '@PrestaShop\Module\PsEventbus\Repository\ConfigurationRepository'

PrestaShop\Module\PsEventbus\Decorator\ProductSupplierDecorator:
class: PrestaShop\Module\PsEventbus\Decorator\ProductSupplierDecorator
public: true
arguments:
- '@PrestaShop\Module\PsEventbus\Repository\ConfigurationRepository'
22 changes: 22 additions & 0 deletions config/front/provider.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@ services:
- '@PrestaShop\Module\PsEventbus\Repository\ModuleRepository'
- '@PrestaShop\Module\PsEventbus\Repository\ShopRepository'

PrestaShop\Module\PsEventbus\Provider\ProductSupplierDataProvider:
class: PrestaShop\Module\PsEventbus\Provider\ProductSupplierDataProvider
public: true
arguments:
- '@PrestaShop\Module\PsEventbus\Repository\ProductSupplierRepository'
- '@PrestaShop\Module\PsEventbus\Decorator\ProductSupplierDecorator'

PrestaShop\Module\PsEventbus\Provider\ProductDataProvider:
class: PrestaShop\Module\PsEventbus\Provider\ProductDataProvider
public: true
arguments:
- '@PrestaShop\Module\PsEventbus\Repository\ProductRepository'
- '@PrestaShop\Module\PsEventbus\Decorator\ProductDecorator'
- '@PrestaShop\Module\PsEventbus\Provider\ProductSupplierDataProvider'
- '@PrestaShop\Module\PsEventbus\Repository\LanguageRepository'

PrestaShop\Module\PsEventbus\Provider\CategoryDataProvider:
Expand Down Expand Up @@ -108,3 +116,17 @@ services:
- '@PrestaShop\Module\PsEventbus\Repository\StockMvtRepository'
- '@PrestaShop\Module\PsEventbus\Decorator\StockDecorator'
- '@PrestaShop\Module\PsEventbus\Formatter\ArrayFormatter'

PrestaShop\Module\PsEventbus\Provider\ManufacturerDataProvider:
class: PrestaShop\Module\PsEventbus\Provider\ManufacturerDataProvider
public: true
arguments:
- '@PrestaShop\Module\PsEventbus\Repository\ManufacturerRepository'
- '@PrestaShop\Module\PsEventbus\Decorator\ManufacturerDecorator'

PrestaShop\Module\PsEventbus\Provider\SupplierDataProvider:
class: PrestaShop\Module\PsEventbus\Provider\SupplierDataProvider
public: true
arguments:
- '@PrestaShop\Module\PsEventbus\Repository\SupplierRepository'
- '@PrestaShop\Module\PsEventbus\Decorator\SupplierDecorator'
20 changes: 20 additions & 0 deletions config/front/repository.yml
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,23 @@ services:
public: true
arguments:
- '@ps_eventbus.db'

PrestaShop\Module\PsEventbus\Repository\ManufacturerRepository:
class: PrestaShop\Module\PsEventbus\Repository\ManufacturerRepository
public: true
arguments:
- '@ps_eventbus.db'
- '@ps_eventbus.context'

PrestaShop\Module\PsEventbus\Repository\SupplierRepository:
class: PrestaShop\Module\PsEventbus\Repository\SupplierRepository
public: true
arguments:
- '@ps_eventbus.db'
- '@ps_eventbus.context'

PrestaShop\Module\PsEventbus\Repository\ProductSupplierRepository:
class: PrestaShop\Module\PsEventbus\Repository\ProductSupplierRepository
public: true
arguments:
- '@ps_eventbus.db'
25 changes: 25 additions & 0 deletions controllers/front/apiManufacturers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

use PrestaShop\Module\PsEventbus\Config\Config;
use PrestaShop\Module\PsEventbus\Controller\AbstractApiController;
use PrestaShop\Module\PsEventbus\Provider\ManufacturerDataProvider;

class ps_EventbusApiManufacturersModuleFrontController extends AbstractApiController
{
public $type = Config::COLLECTION_MANUFACTURERS;

/**
* @return void
*
* @throws PrestaShopException
*/
public function postProcess()
{
/** @var ManufacturerDataProvider $manufacturerDataProvider */
$manufacturerDataProvider = $this->module->getService(ManufacturerDataProvider::class);

$response = $this->handleDataSync($manufacturerDataProvider);

$this->exitWithResponse($response);
}
}
25 changes: 25 additions & 0 deletions controllers/front/apiSuppliers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

use PrestaShop\Module\PsEventbus\Config\Config;
use PrestaShop\Module\PsEventbus\Controller\AbstractApiController;
use PrestaShop\Module\PsEventbus\Provider\SupplierDataProvider;

class ps_EventbusApiSuppliersModuleFrontController extends AbstractApiController
{
public $type = Config::COLLECTION_SUPPLIERS;

/**
* @return void
*
* @throws PrestaShopException
*/
public function postProcess()
{
/** @var SupplierDataProvider $supplierDataProvider */
$supplierDataProvider = $this->module->getService(SupplierDataProvider::class);

$response = $this->handleDataSync($supplierDataProvider);

$this->exitWithResponse($response);
}
}
124 changes: 124 additions & 0 deletions ps_eventbus.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ class Ps_eventbus extends Module
'actionObjectImageAddAfter',
'actionObjectImageDeleteAfter',
'actionObjectImageUpdateAfter',
'actionObjectManufacturerAddAfter',
'actionObjectManufacturerDeleteAfter',
'actionObjectManufacturerUpdateAfter',
'actionObjectOrderAddAfter',
'actionObjectOrderUpdateAfter',
'actionObjectProductAddAfter',
Expand All @@ -100,6 +103,9 @@ class Ps_eventbus extends Module
'actionObjectStoreAddAfter',
'actionObjectStoreDeleteAfter',
'actionObjectStoreUpdateAfter',
'actionObjectSupplierAddAfter',
'actionObjectSupplierDeleteAfter',
'actionObjectSupplierUpdateAfter',
'actionObjectTaxAddAfter',
'actionObjectTaxDeleteAfter',
'actionObjectTaxRulesGroupAddAfter',
Expand Down Expand Up @@ -279,6 +285,124 @@ public function hookActionObjectImageUpdateAfter($parameters)
}
}

/**
* @param array $parameters
*
* @return void
*/
public function hookActionObjectManufacturerDeleteAfter($parameters)
{
$manufacturer = $parameters['object'];
if (isset($manufacturer->id)) {
// $this->sendLiveSync(['manufacturers'], $manufacturer->id, 'delete');
$this->insertDeletedObject(
$manufacturer->id,
Config::COLLECTION_MANUFACTURERS,
date(DATE_ATOM),
$this->shopId
);
}
}

/**
* @param array $parameters
*
* @return void
*/
public function hookActionObjectManufacturerAddAfter($parameters)
{
$manufacturer = $parameters['object'];
if (isset($manufacturer->id)) {
// $this->sendLiveSync(['manufacturers'], $manufacturer->id, 'upsert');
$this->insertIncrementalSyncObject(
$manufacturer->id,
Config::COLLECTION_MANUFACTURERS,
date(DATE_ATOM),
$this->shopId,
true
);
}
}

/**
* @param array $parameters
*
* @return void
*/
public function hookActionObjectManufacturerUpdateAfter($parameters)
{
$manufacturer = $parameters['object'];
if (isset($manufacturer->id)) {
// $this->sendLiveSync(['manufacturers'], $manufacturer->id, 'upsert');
$this->insertIncrementalSyncObject(
$manufacturer->id,
Config::COLLECTION_MANUFACTURERS,
date(DATE_ATOM),
$this->shopId,
true
);
}
}

/**
* @param array $parameters
*
* @return void
*/
public function hookActionObjectSupplierDeleteAfter($parameters)
{
$supplier = $parameters['object'];
if (isset($supplier->id)) {
// $this->sendLiveSync(['suppliers'], $supplier->id, 'delete');
$this->insertDeletedObject(
$supplier->id,
Config::COLLECTION_SUPPLIERS,
date(DATE_ATOM),
$this->shopId
);
}
}

/**
* @param array $parameters
*
* @return void
*/
public function hookActionObjectSupplierAddAfter($parameters)
{
$supplier = $parameters['object'];
if (isset($supplier->id)) {
// $this->sendLiveSync(['suppliers'], $supplier->id, 'upsert');
$this->insertIncrementalSyncObject(
$supplier->id,
Config::COLLECTION_SUPPLIERS,
date(DATE_ATOM),
$this->shopId,
true
);
}
}

/**
* @param array $parameters
*
* @return void
*/
public function hookActionObjectSupplierUpdateAfter($parameters)
{
$supplier = $parameters['object'];
if (isset($supplier->id)) {
// $this->sendLiveSync(['suppliers'], $supplier->id, 'upsert');
$this->insertIncrementalSyncObject(
$supplier->id,
Config::COLLECTION_SUPPLIERS,
date(DATE_ATOM),
$this->shopId,
true
);
}
}

/**
* @param array $parameters
*
Expand Down
3 changes: 3 additions & 0 deletions src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class Config
public const COLLECTION_WISHLIST_PRODUCTS = 'wishlist_products';
public const COLLECTION_STOCKS = 'stocks';
public const COLLECTION_STOCK_MVTS = 'stock_movements';
public const COLLECTION_MANUFACTURERS = 'manufacturers';
public const COLLECTION_SUPPLIERS = 'suppliers';
public const COLLECTION_PRODUCT_SUPPLIERS = 'product_suppliers';

/**
* @param mixed $message
Expand Down
1 change: 1 addition & 0 deletions src/Decorator/CurrencyDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ private function castPropertyValues(array &$currency)
$currency['id_currency'] = (int) $currency['id_currency'];
$currency['conversion_rate'] = (float) $currency['conversion_rate'];
$currency['deleted'] = (bool) $currency['deleted'];
$currency['precision'] = (int) $currency['precision'];
$currency['active'] = (bool) $currency['active'];
}
}
46 changes: 46 additions & 0 deletions src/Decorator/ManufacturerDecorator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace PrestaShop\Module\PsEventbus\Decorator;

use PrestaShop\Module\PsEventbus\Repository\ConfigurationRepository;

class ManufacturerDecorator
{
/**
* @var string
*/
private $timezone;

public function __construct(
ConfigurationRepository $configurationRepository
) {
$this->timezone = (string) $configurationRepository->get('PS_TIMEZONE');
}

/**
* @param array $manufacturers
*
* @return void
*/
public function decorateManufacturers(array &$manufacturers)
{
foreach ($manufacturers as &$manufacturer) {
$this->castPropertyValues($manufacturer);
}
}

/**
* @param array $manufacturer
*
* @return void
*/
private function castPropertyValues(array &$manufacturer)
{
$manufacturer['id_manufacturer'] = (int) $manufacturer['id_manufacturer'];
$manufacturer['active'] = (bool) $manufacturer['active'];
$manufacturer['id_lang'] = (int) $manufacturer['id_lang'];
$manufacturer['id_shop'] = (int) $manufacturer['id_shop'];
$manufacturer['created_at'] = (new \DateTime($manufacturer['created_at'], new \DateTimeZone($this->timezone)))->format('Y-m-d\TH:i:sO');
$manufacturer['updated_at'] = (new \DateTime($manufacturer['updated_at'], new \DateTimeZone($this->timezone)))->format('Y-m-d\TH:i:sO');
}
}
2 changes: 2 additions & 0 deletions src/Decorator/ProductDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ private function addCategoryTree(array &$product)
private function castPropertyValues(array &$product)
{
$product['id_product'] = (int) $product['id_product'];
$product['id_manufacturer'] = (int) $product['id_manufacturer'];
$product['id_supplier'] = (int) $product['id_supplier'];
$product['id_attribute'] = (int) $product['id_attribute'];
$product['id_category_default'] = (int) $product['id_category_default'];
$product['quantity'] = (int) $product['quantity'];
Expand Down
Loading

0 comments on commit 8d1efb4

Please sign in to comment.