Skip to content

Commit

Permalink
Allow filtering products by stock level
Browse files Browse the repository at this point in the history
  • Loading branch information
aimeos committed Dec 7, 2020
1 parent 6db677d commit 04e688a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/mshoplib/src/MShop/Product/Manager/Standard.php
Expand Up @@ -444,7 +444,15 @@ public function getSearchAttributes( bool $withsub = true ) : array
*/
$path = 'mshop/product/manager/submanagers';

return $this->getSearchAttributesBase( $this->searchConfig, $path, [], $withsub );
$list = $this->getSearchAttributesBase( $this->searchConfig, $path, [], $withsub );

if( $withsub )
{
$manager = \Aimeos\MShop::create( $this->getContext(), 'stock' );
$list = array_merge( $list, $manager->getSearchAttributes( $withsub ) );
}

return $list;
}


Expand Down
1 change: 1 addition & 0 deletions lib/mshoplib/src/MShop/Stock/Manager/Standard.php
Expand Up @@ -26,6 +26,7 @@ class Standard
'stock.id' => array(
'code' => 'stock.id',
'internalcode' => 'msto."id"',
'internaldeps' => ['LEFT JOIN "mshop_stock" AS msto ON mpro."id" = msto."prodid"'],
'label' => 'ID',
'type' => 'integer',
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT,
Expand Down
26 changes: 26 additions & 0 deletions lib/mshoplib/tests/MShop/Product/Manager/StandardTest.php
Expand Up @@ -476,6 +476,32 @@ public function testSearchItemsLimit()
}


public function testSearchItemsStock()
{
$total = 0;
$search = $this->object->filter();
$search->setConditions( $search->compare( '>', 'stock.stocklevel', 0 ) );
$search->slice( 0, 1 );

$results = $this->object->search( $search, [], $total );
$this->assertEquals( 1, count( $results ) );
$this->assertEquals( 13, $total );
}


public function testSearchItemsStockUnlimited()
{
$total = 0;
$search = $this->object->filter();
$search->setConditions( $search->compare( '==', 'stock.stocklevel', null ) );
$search->slice( 0, 1 );

$results = $this->object->search( $search, [], $total );
$this->assertEquals( 1, count( $results ) );
$this->assertEquals( 7, $total );
}


public function testGetSubManager()
{
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'lists' ) );
Expand Down

0 comments on commit 04e688a

Please sign in to comment.