Permalink
Browse files

load product into merchandise

  • Loading branch information...
1 parent 7428427 commit c3b043233d7e7ab14d0080b822297aa9dc2d3132 @iampersistent iampersistent committed Sep 5, 2012
@@ -11,6 +11,7 @@
use Vespolina\Entity\Pricing\PricingSet;
use Vespolina\Entity\Product\BaseProduct;
use Vespolina\Entity\Product\MerchandiseInterface;
+use Vespolina\Entity\Product\ProductInterface;
class Merchandise extends BaseProduct implements MerchandiseInterface
{
@@ -24,6 +25,19 @@ class Merchandise extends BaseProduct implements MerchandiseInterface
protected $store;
protected $terms;
+ public function __construct(ProductInterface $product)
+ {
+ $this->product = $product;
+ $rc = new \ReflectionClass(get_parent_class($this));
+ $properties = $rc->getProperties();
+ foreach ($properties as $property) {
+ $property->setAccessible(true);
+ $value = $property->getValue($product);
+ $property->setValue($this, $value);
+ $property->setAccessible(false);
+ }
+ }
+
/**
* @inheritdoc
*/
@@ -10,9 +10,9 @@
use Vespolina\Entity\Identifier\IdentifierInterface;
use Vespolina\Entity\Product\FeatureInterface;
-use Vespolina\ProductBundle\Model\Identifier\ProductIdentifierSetInterface;
use Vespolina\Entity\Product\OptionInterface;
use Vespolina\Entity\Product\OptionGroupInterface;
+use Vespolina\Entity\Product\ProductInterface;
/**
* @author Richard D Shank <develop@zestic.com>
@@ -0,0 +1,38 @@
+<?php
+
+use Vespolina\Entity\Product\Product;
+use Vespolina\Entity\Product\Merchandise;
+
+class MerchandiseTest extends \PHPUnit_Framework_TestCase
+{
+ public function testConstructor()
+ {
+ $product = $this->createProduct();
+ $merchandise = new Merchandise($product);
+
+ $this->assertSame($product, $merchandise->getProduct(), 'product should be set in merchandise');
+
+ // product properties should be copied to merchandise
+ $properties = get_class_vars('Vespolina\Entity\Product\BaseProduct');
+ foreach ($properties as $property) {
+ $function = 'get' . ucfirst($property);
+ $this->assertSame($merchandise->$function(), $product->$function());
+ }
+ }
+
+ protected function createProduct()
+ {
+ $product = new Product();
+ $rc = new \ReflectionClass($product);
+ $properties = $rc->getProperties();
+ $chars = range('a', 'z');
+ foreach ($properties as $property) {
+ $property->setAccessible(true);
+ shuffle($chars);
+ $parts = array_slice($chars, 0, 8);
+ $property->setValue($product, implode('', $parts));
+ }
+
+ return $product;
+ }
+}

0 comments on commit c3b0432

Please sign in to comment.