Skip to content

Commit

Permalink
feat: pseventbus v4 currencies (#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
fox-john authored Sep 20, 2024
1 parent ea3c827 commit 4ac48de
Show file tree
Hide file tree
Showing 9 changed files with 263 additions and 203 deletions.
4 changes: 4 additions & 0 deletions config/common/new-repository.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,7 @@ services:
PrestaShop\Module\PsEventbus\Repository\NewRepository\CustomerRepository:
class: PrestaShop\Module\PsEventbus\Repository\NewRepository\CustomerRepository
public: true

PrestaShop\Module\PsEventbus\Repository\NewRepository\CurrencyRepository:
class: PrestaShop\Module\PsEventbus\Repository\NewRepository\CurrencyRepository
public: true
6 changes: 1 addition & 5 deletions config/common/repository.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ services:
arguments:
- '@=service("prestashop.adapter.legacy.context").getContext()'

PrestaShop\Module\PsEventbus\Repository\CurrencyRepository:
class: PrestaShop\Module\PsEventbus\Repository\CurrencyRepository
public: true

PrestaShop\Module\PsEventbus\Repository\ModuleRepository:
class: PrestaShop\Module\PsEventbus\Repository\ModuleRepository
public: true
Expand All @@ -29,10 +25,10 @@ services:
arguments:
- '@=service("prestashop.adapter.legacy.context").getContext()'
- '@PrestaShop\Module\PsEventbus\Service\PsAccountsAdapterService'
- '@PrestaShop\Module\PsEventbus\Repository\CurrencyRepository'
- '@PrestaShop\Module\PsEventbus\Repository\LanguageRepository'
- '@PrestaShop\Module\PsEventbus\Repository\ConfigurationRepository'
- '@PrestaShop\Module\PsEventbus\Repository\ShopRepository'
- '@PrestaShop\Module\PsEventbus\Service\ShopContent\CurrenciesService'
- '@PrestaShop\Module\PsEventbus\Handler\ErrorHandler\ErrorHandlerInterface'
- '%ps_eventbus.sync_api_url%'
- '%ps_eventbus.live_sync_api_url%'
Expand Down
6 changes: 6 additions & 0 deletions config/front/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,9 @@ services:
public: true
arguments:
- '@PrestaShop\Module\PsEventbus\Repository\NewRepository\CustomerRepository'

PrestaShop\Module\PsEventbus\Service\ShopContent\CurrenciesService:
class: PrestaShop\Module\PsEventbus\Service\ShopContent\CurrenciesService
public: true
arguments:
- '@PrestaShop\Module\PsEventbus\Repository\NewRepository\CurrencyRepository'
1 change: 1 addition & 0 deletions e2e/src/helpers/shop-contents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const shopContentMapping = {
product_carriers: "product-carriers",
categories: "categories",
customers: "customers",
currencies: "currencies",
} as const;

type ShopContentMapping = typeof shopContentMapping;
Expand Down
36 changes: 0 additions & 36 deletions src/Decorator/CurrencyDecorator.php

This file was deleted.

155 changes: 0 additions & 155 deletions src/Repository/CurrencyRepository.php

This file was deleted.

118 changes: 118 additions & 0 deletions src/Repository/NewRepository/CurrencyRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php

namespace PrestaShop\Module\PsEventbus\Repository\NewRepository;

class CurrencyRepository extends AbstractRepository implements RepositoryInterface
{
const TABLE_NAME = 'currency';

/**
* @param string $langIso
* @param bool $withSelecParameters
*
* @return mixed
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso, $withSelecParameters)
{
$this->generateMinimalQuery(self::TABLE_NAME, 'c');

if ($this->isCurrencyLangAvailable()) {
$this->query->innerJoin('currency_lang', 'cl', 'cl.id_currency = c.id_currency');
}

if ($withSelecParameters) {
$this->query
->select('c.id_currency')
->select('c.iso_code')
->select('c.conversion_rate')
->select('c.deleted')
->select('c.active')
;

if ($this->isCurrencyLangAvailable()) {
$this->query->select('cl.name');
} else {
$this->query->select('\'\' as name');
}

// https://github.com/PrestaShop/PrestaShop/commit/37807f66b40b0cebb365ef952e919be15e9d6b2f#diff-3f41d3529ffdbfd1b994927eb91826a32a0560697025a734cf128a2c8e092a45R124
if (defined('_PS_VERSION_') && version_compare(_PS_VERSION_, '1.7.6.0', '>=')) {
$this->query->select('c.precision');
}
}
}

/**
* @param int $offset
* @param int $limit
* @param string $langIso
* @param bool $debug
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForFull($offset, $limit, $langIso, $debug)
{
$this->generateFullQuery($langIso, true);

$this->query->limit((int) $limit, (int) $offset);

return $this->runQuery($debug);
}

/**
* @param int $limit
* @param array<mixed> $contentIds
* @param string $langIso
* @param bool $debug
*
* @return array<mixed>
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function retrieveContentsForIncremental($limit, $contentIds, $langIso, $debug)
{
$this->generateFullQuery($langIso, true);

$this->query
->where('c.id_currency IN(' . implode(',', array_map('intval', $contentIds)) . ')')
->limit($limit)
;

return $this->runQuery($debug);
}

/**
* @param int $offset
* @param int $limit
* @param string $langIso
*
* @return int
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function countFullSyncContentLeft($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, false);

$this->query->select('(COUNT(*) - ' . (int) $offset . ') as count');

$result = $this->runQuery(false);

return $result[0]['count'];
}

/**
* @return mixed
*/
private function isCurrencyLangAvailable()
{
return defined('_PS_VERSION_') && version_compare(_PS_VERSION_, '1.7.6', '>=');
}
}
Loading

0 comments on commit 4ac48de

Please sign in to comment.