Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: pseventbus v4 order cart rules #347

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ To check the module healthiness (authentified route):

```sh
BASE_URL="http://localhost:8000"
curl -s -L "$BASE_URL/index.php?fc=module&module=ps_eventbus&controller=apiFront&shop_content=healthcheck&job_id=valid-job-stuff" | jq .
curl -s -L "$BASE_URL/index.php?fc=module&module=ps_eventbus&controller=apiFront&is_e2e=1&shop_content=healthcheck&job_id=valid-job-stuff" | jq .
{
"prestashop_version": "1.6.1.24",
"ps_eventbus_version": "0.0.0",
Expand All @@ -66,7 +66,7 @@ To check the fallback route (unauthentified):

```sh
BASE_URL="http://localhost:8000"
curl -s -L "$BASE_URL/index.php?fc=module&module=ps_eventbus&controller=apiFront&shop_content=healthcheck" | jq .
curl -s -L "$BASE_URL/index.php?fc=module&module=ps_eventbus&controller=apiFront&is_e2e=1&shop_content=healthcheck" | jq .
{
"ps_account": true,
"is_valid_jwt": true,
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions config/admin/services.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
imports:
- { resource: ../common/common.yml }
- { resource: ../common/repository.yml }
- { resource: ../common/new-repository.yml }
- { resource: ../front/services.yml }

services:
Expand Down
8 changes: 8 additions & 0 deletions config/common/new-repository.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
PrestaShop\Module\PsEventbus\Repository\NewRepository\OrderRepository:
class: PrestaShop\Module\PsEventbus\Repository\NewRepository\OrderRepository
public: true

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

PrestaShop\Module\PsEventbus\Repository\NewRepositoryTemp\OrderRepository:
class: PrestaShop\Module\PsEventbus\Repository\NewRepositoryTemp\OrderRepository
public: true

PrestaShop\Module\PsEventbus\Repository\OrderDetailsRepository:
class: PrestaShop\Module\PsEventbus\Repository\OrderDetailsRepository
public: true
Expand All @@ -82,10 +78,6 @@ services:
class: PrestaShop\Module\PsEventbus\Repository\OrderHistoryRepository
public: true

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

PrestaShop\Module\PsEventbus\Repository\CartRepository:
class: PrestaShop\Module\PsEventbus\Repository\CartRepository
public: true
Expand Down
9 changes: 8 additions & 1 deletion config/front/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ imports:
- { resource: ../common/common.yml }
- { resource: ../common/decorator.yml }
- { resource: ../common/repository.yml }
- { resource: ../common/new-repository.yml }
- { resource: ../common/builder.yml }

services:
Expand Down Expand Up @@ -56,6 +57,12 @@ services:
class: PrestaShop\Module\PsEventbus\Service\ShopContent\OrdersService
public: true
arguments:
- '@PrestaShop\Module\PsEventbus\Repository\NewRepositoryTemp\OrderRepository'
- '@PrestaShop\Module\PsEventbus\Repository\NewRepository\OrderRepository'
- '@PrestaShop\Module\PsEventbus\Repository\OrderHistoryRepository'
- '@PrestaShop\Module\PsEventbus\Formatter\ArrayFormatter'

PrestaShop\Module\PsEventbus\Service\ShopContent\OrderCartRulesService:
class: PrestaShop\Module\PsEventbus\Service\ShopContent\OrderCartRulesService
public: true
arguments:
- '@PrestaShop\Module\PsEventbus\Repository\NewRepository\OrderCartRuleRepository'
5 changes: 4 additions & 1 deletion controllers/front/apiFront.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public function postProcess()
/** @var bool $debug */
$debug = Tools::getValue('debug') == 1;

/** @var bool $ise2e */
$ise2e = Tools::getValue('is_e2e') == 1;

/** @var Ps_eventbus $module */
$module = Module::getInstanceByName('ps_eventbus');

Expand All @@ -38,6 +41,6 @@ public function postProcess()
// edit shopContent for matching Config.php const
$shopContentEdited = str_replace('-', '_', $shopContent);

$frontApiService->handleDataSync($shopContentEdited, $jobId, $langIso, $limit, $isFull, $debug);
$frontApiService->handleDataSync($shopContentEdited, $jobId, $langIso, $limit, $isFull, $debug, $ise2e);
}
}
2 changes: 1 addition & 1 deletion e2e-env/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ services:
"-sI",
"-H",
"Host: localhost:8000",
"http://localhost:80/index.php?fc=module&module=ps_eventbus&controller=apiFront&shop_content=healthcheck",
"http://localhost:80/index.php?fc=module&module=ps_eventbus&controller=apiFront&is_e2e=1&shop_content=healthcheck",
]
interval: 30s
volumes:
Expand Down
4 changes: 2 additions & 2 deletions e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import testConfig from './helpers/test.config';
import request from 'supertest';

const controller = 'categories';
const endpoint = `/index.php?fc=module&module=ps_eventbus&controller=apiFront&shop_content=${shopContent}&limit=5`;
const endpoint = `/index.php?fc=module&module=ps_eventbus&controller=apiFront&is_e2e=1&shop_content=${shopContent}&limit=5`;

describe('CategoriesShopContent', () => {
it(`${shopContent} should upload to collector`, async () => {
// arrange
const url = `${testConfig.prestashopUrl}/index.php?fc=module&module=ps_eventbus&controller=apiFront&shop_content=${shopContent}&limit=5&full=1&job_id=${jobId}`;
const url = `${testConfig.prestashopUrl}/index.php?fc=module&module=ps_eventbus&controller=apiFront&is_e2e=1&shop_content=${shopContent}&limit=5&full=1&job_id=${jobId}`;
// jobId starting with "valid-job-" will be considered valid by the mock sync-api and will always return 201;
// other values will be rejected by the mock
const jobId = 'valid-job-1'
Expand Down
12 changes: 6 additions & 6 deletions e2e/src/full-sync.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { ShopContent, shopContentList } from "./helpers/shop-contents";
expect.extend(matchers);

// these ShopContent will be excluded from the following test suite
const EXCLUDED_API: ShopContent[] = ["google-taxonomies"];
const EXCLUDED_API: ShopContent[] = ["taxonomies"];

// FIXME : these api can't send anything to the mock api because the database is empty from the factory
const MISSING_TEST_DATA: ShopContent[] = [
Expand Down Expand Up @@ -64,8 +64,8 @@ describe('Full Sync', () => {
});

// TODO : some versions of prestashop include ps_facebook out of the box, this test can't reliably be run for all versions
describe.skip("google-taxonomies", () => {
const shoContent = "google-taxonomies";
describe.skip("taxonomies", () => {
const shoContent = "taxonomies";

// TODO : apiGoogleTaxonomies requires an additional module to be present : devise a specific test setup for this endpoint
it.skip(`${shoContent} should accept full sync`, async () => {});
Expand All @@ -74,7 +74,7 @@ describe('Full Sync', () => {

it(`${shoContent} should reject full sync when ps_facebook is not installed`, async () => {
// arrange
const url = `${testConfig.prestashopUrl}/index.php?fc=module&module=ps_eventbus&controller=apiFront&shop_content=${shoContent}&limit=5&full=1&job_id=${jobId}`;
const url = `${testConfig.prestashopUrl}/index.php?fc=module&module=ps_eventbus&controller=apiFront&is_e2e=1&shop_content=${shoContent}&limit=5&full=1&job_id=${jobId}`;

const callId = { 'call_id': Math.random().toString(36).substring(2, 11) };

Expand All @@ -101,7 +101,7 @@ describe('Full Sync', () => {
describe.each(shopContents)("%s", (shopContent) => {
it(`${shopContent} should accept full sync`, async () => {
// arrange
const url = `${testConfig.prestashopUrl}/index.php?fc=module&module=ps_eventbus&controller=apiFront&shop_content=${shopContent}&limit=5&full=1&job_id=${jobId}`;
const url = `${testConfig.prestashopUrl}/index.php?fc=module&module=ps_eventbus&controller=apiFront&is_e2e=1&shop_content=${shopContent}&limit=5&full=1&job_id=${jobId}`;

const callId = { 'call_id': Math.random().toString(36).substring(2, 11) };

Expand Down Expand Up @@ -133,7 +133,7 @@ describe('Full Sync', () => {
} else {
it(`${shopContent} should upload to collector`, async () => {
// arrange
const url = `${testConfig.prestashopUrl}/index.php?fc=module&module=ps_eventbus&controller=apiFront&shop_content=${shopContent}&limit=5&full=1&job_id=${jobId}`;
const url = `${testConfig.prestashopUrl}/index.php?fc=module&module=ps_eventbus&controller=apiFront&is_e2e=1&shop_content=${shopContent}&limit=5&full=1&job_id=${jobId}`;
const message$ = probe({ url: `/upload/${jobId}` });

const callId = { 'call_id': Math.random().toString(36).substring(2, 11) };
Expand Down
2 changes: 1 addition & 1 deletion e2e/src/helpers/data-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export async function getShopHealthCheck(options?: {
healthCheck = cachedHealthCheck;
} else {
const res = await axios.get<HealthCheck>(
`${testConfig.prestashopUrl}/index.php?fc=module&module=ps_eventbus&controller=apiFront&shop_content=healthcheck&job_id=valid-job-healthcheck`
`${testConfig.prestashopUrl}/index.php?fc=module&module=ps_eventbus&controller=apiFront&is_e2e=1&shop_content=healthcheck&job_id=valid-job-healthcheck`
);
healthCheck = res.data;
cachedHealthCheck = healthCheck;
Expand Down
2 changes: 1 addition & 1 deletion e2e/src/helpers/mock-probe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export function doFullSync(jobId: string, shopContent: ShopContent, options?: Mo
const callId = { 'call_id': Math.random().toString(36).substring(2, 11) };

const requestNext = (full: number) => axios.post<PsEventbusSyncResponse>(
`${testConfig.prestashopUrl}/index.php?fc=module&module=ps_eventbus&controller=apiFront&shop_content=${shopContent}&limit=5&full=${full}&job_id=${jobId}`,
`${testConfig.prestashopUrl}/index.php?fc=module&module=ps_eventbus&controller=apiFront&is_e2e=1&shop_content=${shopContent}&limit=5&full=${full}&job_id=${jobId}`,
callId,
{
headers: {
Expand Down
2 changes: 1 addition & 1 deletion e2e/src/helpers/shop-contents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const shopContentMapping = {
'specific_prices': 'specific-prices',
'custom_product_carriers' : 'custom-product-carriers',
'customers': 'customers',
'taxonomies': 'google-taxonomies',
'taxonomies': 'taxonomies',
'modules': 'modules',
'orders': 'orders',
'order_details': 'order-details',
Expand Down
2 changes: 1 addition & 1 deletion e2e/src/reject-invalid-job-id.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('Reject invalid job-id', () => {
it.each(shopContents)(`%s should return 454 with an invalid job id (sync-api status 454)`, async (shopContent) => {
expect.assertions(6);
// arrange
const url = `${testConfig.prestashopUrl}/index.php?fc=module&module=ps_eventbus&controller=apiFront&shop_content=${shopContent}&limit=5&job_id=${jobId}`
const url = `${testConfig.prestashopUrl}/index.php?fc=module&module=ps_eventbus&controller=apiFront&is_e2e=1&shop_content=${shopContent}&limit=5&job_id=${jobId}`
const message$ = probe({params: {id: jobId}});

//act
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace PrestaShop\Module\PsEventbus\Repository\NewRepositoryTemp;
namespace PrestaShop\Module\PsEventbus\Repository\NewRepository;

use PrestaShop\Module\PsEventbus\Service\CommonService;

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

namespace PrestaShop\Module\PsEventbus\Repository\NewRepository;

class OrderCartRuleRepository extends AbstractRepository implements RepositoryInterface
{
const TABLE_NAME = 'order_cart_rule';

/**
* @return mixed
*
* @throws \PrestaShopException
*/
public function generateBaseQuery()
{
$this->query = new \DbQuery();

$this->query->from(self::TABLE_NAME, 'ocr');

$this->query->select('ocr.id_order_cart_rule');
$this->query->select('ocr.id_order');
$this->query->select('ocr.id_cart_rule');
$this->query->select('ocr.id_order_invoice');
$this->query->select('ocr.name');
$this->query->select('ocr.value');
$this->query->select('ocr.value_tax_excl');
$this->query->select('ocr.free_shipping');

if (defined('_PS_VERSION_') && version_compare(_PS_VERSION_, '1.7.7.0', '>=')) {
$this->query->select('ocr.deleted');
}
}

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

$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 getContentsForIncremental($limit, $contentIds, $langIso, $debug)
{
$this->generateBaseQuery();

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

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

/**
* @param int $offset
* @param string $langIso
* @param bool $debug
*
* @return int
*
* @throws \PrestaShopException
* @throws \PrestaShopDatabaseException
*/
public function countFullSyncContentLeft($offset, $langIso, $debug)
{
$result = $this->getContentsForFull($offset, 1, $langIso, $debug);

if (!is_array($result) || empty($result)) {
return 0;
}

return count($result);
}
}
Loading
Loading