Skip to content

Commit

Permalink
Make custom properties from customer table easily accessible
Browse files Browse the repository at this point in the history
  • Loading branch information
aimeos committed Sep 15, 2017
1 parent d5043c5 commit 5f83b42
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/mshoplib/config/mshop/customer.php
Expand Up @@ -380,7 +380,7 @@
mcus."birthday" AS "customer.birthday", mcus."status" AS "customer.status",
mcus."vdate" AS "customer.dateverified", mcus."password" AS "customer.password",
mcus."ctime" AS "customer.ctime", mcus."mtime" AS "customer.mtime",
mcus."editor" AS "customer.editor"
mcus."editor" AS "customer.editor", mcus.*
FROM "mshop_customer" AS mcus
:joins
WHERE :cond
Expand Down
30 changes: 30 additions & 0 deletions lib/mshoplib/src/MShop/Customer/Item/Base.php
Expand Up @@ -78,6 +78,36 @@ public function __construct( \Aimeos\MShop\Common\Item\Address\Iface $address, a
}


/**
* Returns the item property for the given name
*
* @param string $name Name of the property
* @return mixed|null Property value or null if property is unknown
*/
public function __get( $name )
{
if( isset( $this->data[$name] ) ) {
return $this->data[$name];
}
}


/**
* Tests if the item property for the given name is available
*
* @param string $name Name of the property
* @return boolean True if the property exists, false if not
*/
public function __isset( $name )
{
if( array_key_exists( $name, $this->data ) ) {
return true;
}

return false;
}


/**
* Returns the delivery address items of the customer
*
Expand Down
16 changes: 16 additions & 0 deletions lib/mshoplib/src/MShop/Customer/Item/Iface.php
Expand Up @@ -21,6 +21,22 @@
interface Iface
extends \Aimeos\MShop\Common\Item\ListRef\Iface
{
/**
* Returns the item property for the given name
*
* @param string $name Name of the property
* @return mixed|null Property value or null if property is unknown
*/
public function __get( $name );

/**
* Tests if the item property for the given name is available
*
* @param string $name Name of the property
* @return boolean True if the property exists, false if not
*/
public function __isset( $name );

/**
* Returns the label of the customer item.
*
Expand Down
17 changes: 15 additions & 2 deletions lib/mshoplib/tests/MShop/Customer/Item/StandardTest.php
Expand Up @@ -58,7 +58,8 @@ protected function setUp()
'customer.latitude' => '50.0',
'customer.mtime'=> '2010-01-05 00:00:05',
'customer.ctime'=> '2010-01-01 00:00:00',
'customer.editor' => 'unitTestUser'
'customer.editor' => 'unitTestUser',
'additional' => 'something',
);

$addresses = array(
Expand All @@ -75,6 +76,18 @@ protected function tearDown()
unset( $this->object, $this->address, $this->values );
}

public function testGet()
{
$this->assertEquals( 'something', $this->object->additional );
$this->assertNull( $this->object->missing );
}

public function testIsset()
{
$this->assertTrue( isset( $this->object->additional ) );
$this->assertFalse( isset( $this->object->missing ) );
}

public function testGetId()
{
$this->assertEquals( 541, $this->object->getId() );
Expand Down Expand Up @@ -336,7 +349,7 @@ public function testToArray()
{
$arrayObject = $this->object->toArray( true );

$this->assertEquals( count( $this->values ), count( $arrayObject ) );
$this->assertEquals( count( $this->values ) - 1, count( $arrayObject ) );

$this->assertEquals( $this->object->getId(), $arrayObject['customer.id'] );
$this->assertEquals( $this->object->getLabel(), $arrayObject['customer.label'] );
Expand Down

0 comments on commit 5f83b42

Please sign in to comment.