1 <?php
2
3 /* --------------------------------------------------------------
4 ProductSettingsRepository.php 2015-12-07
5 Gambio GmbH
6 http://www.gambio.de
7 Copyright (c) 2015 Gambio GmbH
8 Released under the GNU General Public License (Version 2)
9 [http://www.gnu.org/licenses/gpl-2.0.html]
10 --------------------------------------------------------------
11 */
12
13 /**
14 * Class ProductSettingsRepository
15 *
16 * @category System
17 * @package Product
18 * @subpackage Repositories
19 */
20 class ProductSettingsRepository implements ProductSettingsRepositoryInterface
21 {
22 /**
23 * @var ProductSettingsRepositoryReaderInterface
24 */
25 protected $reader;
26
27 /**
28 * @var ProductSettingsRepositoryWriterInterface
29 */
30 protected $writer;
31
32
33 /**
34 * Initialize the product settings repository.
35 *
36 * @param ProductSettingsRepositoryReaderInterface $reader Instance to perform db read actions.
37 * @param ProductSettingsRepositoryWriterInterface $writer Instance to perform db write actions.
38 */
39 public function __construct(ProductSettingsRepositoryReaderInterface $reader,
40 ProductSettingsRepositoryWriterInterface $writer)
41 {
42 $this->reader = $reader;
43 $this->writer = $writer;
44 }
45
46
47 /**
48 * Saves product settings in the database by the given id.
49 *
50 * @param IdType $productId Id of product entity.
51 * @param ProductSettingsInterface $settings Settings entity with values to store.
52 *
53 * @return ProductSettingsRepositoryInterface|$this Same instance for chained method calls.
54 */
55 public function store(IdType $productId, ProductSettingsInterface $settings)
56 {
57 $this->writer->update($productId, $settings);
58
59 return $this;
60 }
61
62
63 /**
64 * Returns a product settings by the given product id.
65 *
66 * @param IdType $productId Id of product entity.
67 *
68 * @return ProductSettingsInterface Entity with product settings for the expected product id.
69 */
70 public function getProductSettingsById(IdType $productId)
71 {
72 return $this->reader->getById($productId);
73 }
74 }