Skip to content

Commit

Permalink
Added customerid as default limitation for order base items
Browse files Browse the repository at this point in the history
  • Loading branch information
aimeos committed Mar 16, 2017
1 parent fbf9c4c commit 971278e
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 8 deletions.
11 changes: 6 additions & 5 deletions lib/mshoplib/src/MShop/Order/Manager/Base/Iface.php
Expand Up @@ -27,15 +27,15 @@ interface Iface
* @param string $type Basket type if a customer can have more than one basket
* @return \Aimeos\MShop\Order\Item\Base\Iface Shopping basket
*/
public function getSession( $type = '' );
public function getSession( $type = 'default' );

/**
* Returns the current lock status of the basket.
*
* @param string $type Basket type if a customer can have more than one basket
* @return integer Lock status (@see \Aimeos\MShop\Order\Manager\Base\Base)
*/
public function getSessionLock( $type = '' );
public function getSessionLock( $type = 'default' );

/**
* Saves the current shopping basket of the customer.
Expand All @@ -44,7 +44,7 @@ public function getSessionLock( $type = '' );
* @param string $type Order type if a customer can have more than one order at once
* @return null
*/
public function setSession( \Aimeos\MShop\Order\Item\Base\Iface $order, $type = '' );
public function setSession( \Aimeos\MShop\Order\Item\Base\Iface $order, $type = 'default' );

/**
* Locks or unlocks the session by setting the lock value.
Expand All @@ -55,7 +55,7 @@ public function setSession( \Aimeos\MShop\Order\Item\Base\Iface $order, $type =
* @return null
* @throws \Aimeos\MShop\Order\Exception if the lock value is invalid
*/
public function setSessionLock( $lock, $type = '' );
public function setSessionLock( $lock, $type = 'default' );

/**
* Creates a new basket containing the items from the order excluding the coupons.
Expand All @@ -65,9 +65,10 @@ public function setSessionLock( $lock, $type = '' );
* @param integer $baseId Base ID of the order to load
* @param integer $parts Bitmap of the basket parts that should be loaded
* @param boolean $fresh Create a new basket by copying the existing one and remove IDs
* @param boolean $default True to use default criteria, false for no limitation
* @return \Aimeos\MShop\Order\Item\Base\Iface Basket including all items
*/
public function load( $baseId, $parts = \Aimeos\MShop\Order\Manager\Base\Base::PARTS_ALL, $fresh = false );
public function load( $baseId, $parts = \Aimeos\MShop\Order\Manager\Base\Base::PARTS_ALL, $fresh = false, $default = false );

/**
* Saves the complete basket to the storage including the items attached.
Expand Down
35 changes: 32 additions & 3 deletions lib/mshoplib/src/MShop/Order/Manager/Base/Standard.php
Expand Up @@ -251,6 +251,30 @@ public function createItem()
}


/**
* Creates a search object
*
* @param boolean $default Add default criteria
* @return \Aimeos\MW\Criteria\Iface
*/
public function createSearch( $default = false )
{
$search = parent::createSearch( $default );

if( $default !== false )
{
$userId = $this->getContext()->getUserId();
$expr = [
$search->compare( '==', 'order.base.customerid', $userId ),
$search->getConditions(),
];
$search->setConditions( $search->combine( '&&', $expr ) );
}

return $search;
}


/**
* Removes multiple items specified by ids in the array.
*
Expand Down Expand Up @@ -837,12 +861,17 @@ public function searchItems( \Aimeos\MW\Criteria\Iface $search, array $ref = arr
* @param integer $id Base ID of the order to load
* @param integer $parts Bitmap of the basket parts that should be loaded
* @param boolean $fresh Create a new basket by copying the existing one and remove IDs
* @param boolean $default True to use default criteria, false for no limitation
* @return \Aimeos\MShop\Order\Item\Base\Iface Basket including all items
*/
public function load( $id, $parts = \Aimeos\MShop\Order\Manager\Base\Base::PARTS_ALL, $fresh = false )
public function load( $id, $parts = \Aimeos\MShop\Order\Manager\Base\Base::PARTS_ALL, $fresh = false, $default = false )
{
$search = $this->createSearch();
$search->setConditions( $search->compare( '==', 'order.base.id', $id ) );
$search = $this->createSearch( $default );
$expr = [
$search->compare( '==', 'order.base.id', $id ),
$search->getConditions(),
];
$search->setConditions( $search->combine( '&&', $expr ) );

$context = $this->getContext();
$dbm = $context->getDatabaseManager();
Expand Down
26 changes: 26 additions & 0 deletions lib/mshoplib/tests/MShop/Order/Manager/Base/StandardTest.php
Expand Up @@ -178,6 +178,20 @@ public function testCreateSearch()
}


public function testCreateSearchDefault()
{
$search = $this->object->createSearch( true );

$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $search );
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Expression\\Combine\\Iface', $search->getConditions() );

$list = $search->getConditions()->getExpressions();
$this->assertArrayHasKey( 0, $list );
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Expression\\Compare\\Iface', $list[0] );
$this->assertEquals( 'order.base.customerid', $list[0]->getName() );
}


public function testSearchItems()
{
$siteid = $this->context->getLocale()->getSiteId();
Expand Down Expand Up @@ -296,8 +310,11 @@ public function testSearchItems()

$this->assertEquals( 1, count( $result ) );
$this->assertEquals( 1, $total );
}


public function testSearchItemsTotal()
{
$search = $this->object->createSearch();
$conditions = array(
$search->compare( '>=', 'order.base.customerid', '' ),
Expand All @@ -316,6 +333,15 @@ public function testSearchItems()
}


public function testSearchItemsDefault()
{
$search = $this->object->createSearch( true );
$items = $this->object->searchItems( $search );

$this->assertEquals( 0, count( $items ) );
}


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

0 comments on commit 971278e

Please sign in to comment.