1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* File: Catalogue.php |
4
|
|
|
* |
5
|
|
|
* @author Maciej Sławik <[email protected]> |
6
|
|
|
* Github: https://github.com/maciejslawik |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace MSlwk\ICatalogue\Model\ResourceModel; |
10
|
|
|
|
11
|
|
|
use Magento\Framework\Model\AbstractModel; |
12
|
|
|
use Magento\Framework\Model\ResourceModel\Db\AbstractDb; |
13
|
|
|
use Magento\Framework\Model\ResourceModel\Db\Context; |
14
|
|
|
use MSlwk\ICatalogue\Api\Catalogue\ImageInterface; |
15
|
|
|
use MSlwk\ICatalogue\Api\Catalogue\StoreInterface; |
16
|
|
|
use MSlwk\ICatalogue\Api\CatalogueInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class Location |
20
|
|
|
* |
21
|
|
|
* @package MSlwk\ICatalogue\Model\ResourceModel |
22
|
|
|
*/ |
23
|
|
|
class Catalogue extends AbstractDb |
24
|
|
|
{ |
25
|
|
|
const CATALOGUE_TABLE = 'mslwk_icatalogue_catalogue'; |
26
|
|
|
const CATALOGUE_STORE_TABLE = 'mslwk_icatalogue_catalogue_store'; |
27
|
|
|
const CATALOGUE_IMAGE_TABLE = 'mslwk_icatalogue_catalogue_image'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var ImageInterface |
31
|
|
|
*/ |
32
|
|
|
protected $imageRelation; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var StoreInterface |
36
|
|
|
*/ |
37
|
|
|
protected $storeRelation; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Location constructor. |
41
|
|
|
* |
42
|
|
|
* @param ImageInterface $imageRelation |
43
|
|
|
* @param StoreInterface $storeRelation |
44
|
|
|
* @param Context $context |
45
|
|
|
* @param null $connectionName |
46
|
|
|
*/ |
47
|
|
|
public function __construct( |
48
|
|
|
ImageInterface $imageRelation, |
49
|
|
|
StoreInterface $storeRelation, |
50
|
|
|
Context $context, |
51
|
|
|
$connectionName = null |
52
|
|
|
) { |
53
|
|
|
$this->imageRelation = $imageRelation; |
54
|
|
|
$this->storeRelation = $storeRelation; |
55
|
|
|
parent::__construct($context, $connectionName); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @inheritdoc |
60
|
|
|
*/ |
61
|
|
|
protected function _construct() |
62
|
|
|
{ |
63
|
|
|
$this->_init(self::CATALOGUE_TABLE, CatalogueInterface::CATALOGUE_ID); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @inheritdoc |
68
|
|
|
*/ |
69
|
|
|
protected function _afterLoad(AbstractModel $object) |
70
|
|
|
{ |
71
|
|
|
$this->loadStoreRelation($object); |
72
|
|
|
$this->loadImages($object); |
73
|
|
|
return parent::_afterLoad($object); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @inheritdoc |
78
|
|
|
*/ |
79
|
|
|
protected function _afterSave(AbstractModel $object) |
80
|
|
|
{ |
81
|
|
|
$this->saveStoreRelation($object); |
82
|
|
|
$this->saveImages($object); |
83
|
|
|
return parent::_afterSave($object); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param AbstractModel $object |
88
|
|
|
* @return void |
89
|
|
|
*/ |
90
|
|
|
protected function loadStoreRelation(AbstractModel $object) |
91
|
|
|
{ |
92
|
|
|
$this->storeRelation->loadStores($object); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @param AbstractModel $object |
97
|
|
|
* @return void |
98
|
|
|
*/ |
99
|
|
|
protected function saveStoreRelation(AbstractModel $object) |
100
|
|
|
{ |
101
|
|
|
$this->storeRelation->saveStores($object); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @param AbstractModel $object |
106
|
|
|
* @return void |
107
|
|
|
*/ |
108
|
|
|
protected function loadImages(AbstractModel $object) |
109
|
|
|
{ |
110
|
|
|
$this->imageRelation->loadImages($object); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @param AbstractModel $object |
115
|
|
|
* @return void |
116
|
|
|
*/ |
117
|
|
|
protected function saveImages(AbstractModel $object) |
118
|
|
|
{ |
119
|
|
|
$this->imageRelation->saveImages($object); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|