Skip to content
Closed
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
8 changes: 6 additions & 2 deletions Helper/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public function validateProduct($product, $parent, $config)
}
}

$visibilityFilter = $filters['visibility'] ?? [];
$visibilityFilter = array_map('intval', $filters['visibility'] ?? []);
if (!empty($visibilityFilter) && in_array($product->getVisibility(), $visibilityFilter, true)) {
return true;
}
Expand Down Expand Up @@ -972,7 +972,11 @@ public function addAttributeData($attributes, $filters)
}
} catch (\Exception $e) {
$this->logger->addErrorLog('addAttributeData', $e->getMessage());
unset($attributes[$key]);
if (!empty($value['label'])) {
$attributes[$key]['type'] = null;
} else {
unset($attributes[$key]);
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions Model/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ public function __construct(
*/
public function add($row, $storeId)
{
if (empty($row['id'])) {
return;
}

$data = [];
$data['item_id'] = $storeId . sprintf('%08d', $row['id']);
$data['store_id'] = $storeId;
Expand Down
118 changes: 118 additions & 0 deletions Test/End-2-end/tests/feed/feed-generation.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

import { test, expect } from '@playwright/test';
import ChannableApi from 'Services/ChannableApi';

const api = new ChannableApi();

const FEED_TOKEN = process.env.CHANNABLE_TOKEN || 'e2e-test-token';
const STORE_ID = 1;

const CONFIG = {
'magmodules_channable/general/enable': '1',
};

test.describe('Feed Generation', () => {
test.beforeAll(async ({}, testInfo) => {
const baseURL = testInfo.project.use.baseURL!;
await api.setMagentoConfig(baseURL, CONFIG);
});

test('feed endpoint returns valid JSON without errors', async ({ request }) => {
const response = await request.get(`/channable/feed/json?id=${STORE_ID}&token=${FEED_TOKEN}&page=1`);

expect(response.status()).toBe(200);

const body = await response.json();
expect(body).not.toHaveProperty('error');
});

test('feed endpoint returns products array', async ({ request }) => {
const response = await request.get(`/channable/feed/json?id=${STORE_ID}&token=${FEED_TOKEN}&page=1`);

const body = await response.json();
expect(body).toHaveProperty('products');
expect(Array.isArray(body.products)).toBe(true);
});

test('feed products contain required id and title fields', async ({ request }) => {
const response = await request.get(`/channable/feed/json?id=${STORE_ID}&token=${FEED_TOKEN}&page=1`);

const body = await response.json();
const products = body.products ?? [];

// Skip if no products in feed (empty catalog)
if (products.length === 0) return;

for (const product of products) {
// Every product row must have an id and title
expect(product).toHaveProperty('id');
expect(product).toHaveProperty('title');
expect(product.id).toBeTruthy();
}
});

test('feed does not crash with visibility filter enabled', async ({ request }, testInfo) => {
const baseURL = testInfo.project.use.baseURL!;

// Enable visibility filter and include "Not Visible Individually" (value 1)
await api.setMagentoConfig(baseURL, {
...CONFIG,
'magmodules_channable/filter/visbility_enabled': '1',
'magmodules_channable/filter/visbility': '1',
});

const response = await request.get(`/channable/feed/json?id=${STORE_ID}&token=${FEED_TOKEN}&page=1`);

expect(response.status()).toBe(200);

const body = await response.json();
expect(body).not.toHaveProperty('error');

// Reset visibility filter
await api.setMagentoConfig(baseURL, {
...CONFIG,
'magmodules_channable/filter/visbility_enabled': '0',
});
});

test('feed returns empty for invalid token', async ({ request }) => {
const response = await request.get(`/channable/feed/json?id=${STORE_ID}&token=wrong-token&page=1`);

expect(response.status()).toBe(200);

const body = await response.json();
// Should return empty array, not an error page
expect(Array.isArray(body) || (typeof body === 'object' && Object.keys(body).length === 0)).toBe(true);
});

test('feed returns empty when module is disabled', async ({ request }, testInfo) => {
const baseURL = testInfo.project.use.baseURL!;

await api.setMagentoConfig(baseURL, {
'magmodules_channable/general/enable': '0',
});

const response = await request.get(`/channable/feed/json?id=${STORE_ID}&token=${FEED_TOKEN}&page=1`);

expect(response.status()).toBe(200);

const body = await response.json();
expect(Array.isArray(body) || (typeof body === 'object' && Object.keys(body).length === 0)).toBe(true);

// Re-enable
await api.setMagentoConfig(baseURL, CONFIG);
});

test('single product feed via pid parameter', async ({ request }) => {
const response = await request.get(`/channable/feed/json?id=${STORE_ID}&token=${FEED_TOKEN}&pid=1`);

expect(response.status()).toBe(200);

const body = await response.json();
expect(body).not.toHaveProperty('error');
});
});
Loading