opened
pdt256
username_0
At the present time, Services are are returning View objects. Originally this was desired in order to not expose Entities that had the ability to change state or produce database queries through lazy loaded proxies.

**[Service\Product::find()](https://github.com/inklabs/kommerce-core/blob/0dd4836a50b71c4c9bf99b6a27436a5b55623f82/src/Service/Product.php#L59)**
```php
    public function find($id)
    {
        $product = $this->productRepository->find($id);
        if ($product === null) {
            return null;
        }
        return $product->getView()
            ->withAllData($this->pricing)
            ->export();
    }
```

This results in tests that are much more difficult to manage in case of null objects. This extra test gets duplicated throughout the codebase.

**[test\Service\ProductTest::testFindMissing()](https://github.com/inklabs/kommerce-core/blob/0dd4836a50b71c4c9bf99b6a27436a5b55623f82/tests/Service/ProductTest.php#L65)**
```php
    public function testFind()
    {
        $product = $this->productService->find(1);
        $this->assertTrue($product instanceof View\Product);
    }
    public function testFindMissing()
    {
        $this->productRepository->setReturnValue(null);
        $product = $this->productService->find(1);
        $this->assertSame(null, $product);
    }
```

---

Returning just the Entity will clean up the tests and make for a simpler Service Layer.

**Service\Product::find():**
```php
    public function find($id)
    {
        return $this->productRepository->find($id);
    }
```

**test\Service\ProductTest::testFind()**
```php
    public function testFind()
    {
        $product = $this->productService->find(1);
        $this->assertTrue($product instanceof Entity\Product);
    }
```
Services should return Entities, not Views
issue
created
pdt256
username_0
In addition, we remove the dependency on Lib\Pricing in the Services.
comment
closed
pdt256
username_0
issue