Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

load product into merchandise

  • Loading branch information...
commit c3b043233d7e7ab14d0080b822297aa9dc2d3132 1 parent 7428427
Richard Shank authored September 05, 2012
14  lib/Vespolina/Entity/Product/Merchandise.php
@@ -11,6 +11,7 @@
11 11
 use Vespolina\Entity\Pricing\PricingSet;
12 12
 use Vespolina\Entity\Product\BaseProduct;
13 13
 use Vespolina\Entity\Product\MerchandiseInterface;
  14
+use Vespolina\Entity\Product\ProductInterface;
14 15
 
15 16
 class Merchandise extends BaseProduct implements MerchandiseInterface
16 17
 {
@@ -24,6 +25,19 @@ class Merchandise extends BaseProduct implements MerchandiseInterface
24 25
     protected $store;
25 26
     protected $terms;
26 27
 
  28
+    public function __construct(ProductInterface $product)
  29
+    {
  30
+        $this->product = $product;
  31
+        $rc = new \ReflectionClass(get_parent_class($this));
  32
+        $properties = $rc->getProperties();
  33
+        foreach ($properties as $property) {
  34
+            $property->setAccessible(true);
  35
+            $value = $property->getValue($product);
  36
+            $property->setValue($this, $value);
  37
+            $property->setAccessible(false);
  38
+        }
  39
+    }
  40
+
27 41
     /**
28 42
      * @inheritdoc
29 43
      */
2  lib/Vespolina/Entity/Product/Product.php
@@ -10,9 +10,9 @@
10 10
 
11 11
 use Vespolina\Entity\Identifier\IdentifierInterface;
12 12
 use Vespolina\Entity\Product\FeatureInterface;
13  
-use Vespolina\ProductBundle\Model\Identifier\ProductIdentifierSetInterface;
14 13
 use Vespolina\Entity\Product\OptionInterface;
15 14
 use Vespolina\Entity\Product\OptionGroupInterface;
  15
+use Vespolina\Entity\Product\ProductInterface;
16 16
 
17 17
 /**
18 18
  * @author Richard D Shank <develop@zestic.com>
38  tests/Entity/Product/MerchandiseTest.php
... ...
@@ -0,0 +1,38 @@
  1
+<?php
  2
+
  3
+use Vespolina\Entity\Product\Product;
  4
+use Vespolina\Entity\Product\Merchandise;
  5
+
  6
+class MerchandiseTest extends \PHPUnit_Framework_TestCase
  7
+{
  8
+    public function testConstructor()
  9
+    {
  10
+        $product = $this->createProduct();
  11
+        $merchandise = new Merchandise($product);
  12
+
  13
+        $this->assertSame($product, $merchandise->getProduct(), 'product should be set in merchandise');
  14
+
  15
+        // product properties should be copied to merchandise
  16
+        $properties = get_class_vars('Vespolina\Entity\Product\BaseProduct');
  17
+        foreach ($properties as $property) {
  18
+            $function = 'get' . ucfirst($property);
  19
+            $this->assertSame($merchandise->$function(), $product->$function());
  20
+        }
  21
+    }
  22
+
  23
+    protected function createProduct()
  24
+    {
  25
+        $product = new Product();
  26
+        $rc = new \ReflectionClass($product);
  27
+        $properties = $rc->getProperties();
  28
+        $chars = range('a', 'z');
  29
+        foreach ($properties as $property) {
  30
+            $property->setAccessible(true);
  31
+            shuffle($chars);
  32
+            $parts = array_slice($chars, 0, 8);
  33
+            $property->setValue($product, implode('', $parts));
  34
+        }
  35
+
  36
+        return $product;
  37
+    }
  38
+}

0 notes on commit c3b0432

Please sign in to comment.
Something went wrong with that request. Please try again.