Skip to content

Commit

Permalink
Filter out confidential products from RelatedProducts
Browse files Browse the repository at this point in the history
  • Loading branch information
Lasse Lehtinen committed Jan 23, 2024
1 parent b1da9d0 commit 7461734
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Groschen.php
Original file line number Diff line number Diff line change
Expand Up @@ -2034,8 +2034,12 @@ public function getRelatedProducts()
$relatedProducts = new Collection;

foreach ($this->getWorkLevel()->productions as $production) {
// Do not add current product
if (isset($production->isbn) && $production->isbn !== $this->productNumber) {
// Do not add current product or confidential products
if (isset($production->isbn)) {
$relatedProductGroschen = new Groschen($production->isbn);
}

if (isset($production->isbn) && $production->isbn !== $this->productNumber && isset($relatedProductGroschen) && $relatedProductGroschen->isConfidential() === false) {
$relatedProducts->push([
'ProductRelationCode' => '06',
'ProductIdentifiers' => [
Expand Down
17 changes: 17 additions & 0 deletions tests/GroschenIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2076,6 +2076,23 @@ public function testGettingRelatedProducts()
$this->assertCount(0, $groschen->getRelatedProducts()->where('ProductRelationCode', '06'));
}

public function testGettingRelatedProductSoThatPrivateProductsAreNotIncluded()
{
$groschen = new Groschen('9789510282373');

$relation = [
'ProductRelationCode' => '06',
'ProductIdentifiers' => [
[
'ProductIDType' => '03',
'IDValue' => 9789510421543,
],
],
];

$this->assertNotContains($relation, $groschen->getRelatedProducts());
}

/**
* Getting related products without GTIN
*
Expand Down

0 comments on commit 7461734

Please sign in to comment.