-
Notifications
You must be signed in to change notification settings - Fork 1
/
AbstractModel.php
77 lines (58 loc) · 2.04 KB
/
AbstractModel.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/*
* @author M2E Pro Developers Team
* @copyright 2011-2015 ESS-UA [M2E Pro]
* @license Commercial use is forbidden
*/
namespace Ess\M2ePro\Model;
use Magento\Framework\DataObject;
abstract class AbstractModel extends DataObject
{
protected $helperFactory;
protected $modelFactory;
//########################################
public function __construct(
\Ess\M2ePro\Helper\Factory $helperFactory,
\Ess\M2ePro\Model\Factory $modelFactory,
array $data = []
)
{
$this->helperFactory = $helperFactory;
$this->modelFactory = $modelFactory;
parent::__construct($data);
}
//########################################
public function getCacheLifetime()
{
return 60*60*24;
}
public function getCacheGroupTags()
{
$modelName = str_replace('Ess\M2ePro\Model\\', '', get_class($this));
$tags[] = $modelName;
if (strpos($modelName,'\\') !== false) {
$allComponents = $this->getHelper('Component')->getComponents();
$modelNameComponent = substr($modelName,0,strpos($modelName,'\\'));
if (in_array(strtolower($modelNameComponent), array_map('strtolower', $allComponents))) {
$modelNameOnlyModel = substr($modelName, strpos($modelName,'\\')+1);
$tags[] = $modelNameComponent;
$tags[] = $modelNameOnlyModel;
}
}
$tags = array_unique($tags);
$tags = array_map('strtolower',$tags);
return $tags;
}
//########################################
/**
* @param $helperName
* @param array $arguments
* @return \Magento\Framework\App\Helper\AbstractHelper
* @throws \Ess\M2ePro\Model\Exception\Logic
*/
protected function getHelper($helperName, array $arguments = [])
{
return $this->helperFactory->getObject($helperName, $arguments);
}
//########################################
}