Skip to content

Commit

Permalink
Fixed searching products containing one of the attribute IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
aimeos committed Feb 6, 2019
1 parent bc07853 commit 9d7ab52
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
12 changes: 8 additions & 4 deletions controller/frontend/src/Controller/Frontend/Product/Standard.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,18 @@ public function oneOf( $attrIds )

foreach( $attrIds as $key => $entry )
{
if( is_array( $entry ) && ( $ids = array_unique( $this->validateIds( $entry ) ) ) !== [] ) {
$this->conditions[] = $this->filter->compare( '==', 'index.attribute.id', $ids );
if( is_array( $entry ) && ( $ids = array_unique( $this->validateIds( $entry ) ) ) !== [] )
{
$func = $this->filter->createFunction( 'index.attribute:oneof', [$ids] );
$this->conditions[] = $this->filter->compare( '!=', $func, null );
unset( $attrIds[$key] );
}
}

if( ( $ids = array_unique( $this->validateIds( $attrIds ) ) ) !== [] ) {
$this->conditions[] = $this->filter->compare( '==', 'index.attribute.id', $ids );
if( ( $ids = array_unique( $this->validateIds( $attrIds ) ) ) !== [] )
{
$func = $this->filter->createFunction( 'index.attribute:oneof', [$ids] );
$this->conditions[] = $this->filter->compare( '!=', $func, null );
}

return $this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ public function testOneOf()
$manager = \Aimeos\MShop::create( $this->context, 'attribute' );

$length = $manager->findItem( '30', [], 'product', 'length' )->getId();
$width = $manager->findItem( '29', [], 'product', 'width' )->getId();
$width = $manager->findItem( '30', [], 'product', 'width' )->getId();

$this->assertEquals( 4, count( $this->object->oneOf( [$length, $width] )->search() ) );
$this->assertEquals( 3, count( $this->object->oneOf( [$length, $width] )->search() ) );
}


Expand All @@ -103,9 +103,9 @@ public function testOneOfList()
$manager = \Aimeos\MShop::create( $this->context, 'attribute' );

$length = $manager->findItem( '30', [], 'product', 'length' )->getId();
$width = $manager->findItem( '29', [], 'product', 'width' )->getId();
$width = $manager->findItem( '30', [], 'product', 'width' )->getId();

$this->assertEquals( 4, count( $this->object->oneOf( [[$length, $width]] )->search() ) );
$this->assertEquals( 1, count( $this->object->oneOf( [[$length], [$width]] )->search() ) );
}


Expand Down

0 comments on commit 9d7ab52

Please sign in to comment.