Skip to content

Commit

Permalink
Added stock() method to filter by stock level
Browse files Browse the repository at this point in the history
  • Loading branch information
aimeos committed Dec 7, 2020
1 parent b7775a0 commit 4e1b507
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
Expand Up @@ -305,6 +305,20 @@ public function sort( string $key = null ) : \Aimeos\Controller\Frontend\Product
}


/**
* Adds minimum stock level for filtering
*
* @param string|int|float|null Minimum stock level
* @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface
* @since 2021.01
*/
public function stock( $minvalue )
{
$this->controller->stock( $minvalue );
return $this;
}


/**
* Adds supplier IDs for filtering
*
Expand Down
9 changes: 9 additions & 0 deletions controller/frontend/src/Controller/Frontend/Product/Iface.php
Expand Up @@ -174,6 +174,15 @@ public function slice( int $start, int $limit ) : Iface;
*/
public function sort( string $key = null ) : Iface;

/**
* Adds minimum stock level for filtering
*
* @param string|int|float|null Minimum stock level
* @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface
* @since 2021.01
*/
public function stock( $minvalue );

/**
* Adds supplier IDs for filtering
*
Expand Down
18 changes: 18 additions & 0 deletions controller/frontend/src/Controller/Frontend/Product/Standard.php
Expand Up @@ -425,6 +425,24 @@ public function sort( string $key = null ) : Iface
}


/**
* Adds minimum stock level for filtering
*
* @param string|int|float|null Minimum stock level
* @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface
* @since 2021.01
*/
public function stock( $minvalue )
{
$this->conditions['stock'] = $this->filter->or( [
$this->filter->is( 'stock.stocklevel', '>=', $minvalue ),
$this->filter->is( 'stock.stocklevel', '==', null )
] );

return $this;
}


/**
* Adds supplier IDs for filtering
*
Expand Down
Expand Up @@ -198,6 +198,12 @@ public function testSort()
}


public function testStock()
{
$this->assertSame( $this->object, $this->object->stock( 123 ) );
}


public function testSupplier()
{
$this->assertSame( $this->object, $this->object->supplier( [1], 'default' ) );
Expand Down
Expand Up @@ -300,6 +300,15 @@ public function testSortRelevanceSupplier()
}


public function testStock()
{
$this->assertEquals( 6, count( $this->object->stock( 0 )->search() ) );
$this->assertEquals( 6, count( $this->object->stock( '1' )->search() ) );
$this->assertEquals( 6, count( $this->object->stock( 1.5 )->search() ) );
$this->assertEquals( 6, count( $this->object->stock( null )->search() ) );
}


public function testSupplier()
{
$manager = \Aimeos\MShop::create( $this->context, 'supplier' );
Expand Down

0 comments on commit 4e1b507

Please sign in to comment.