-
Notifications
You must be signed in to change notification settings - Fork 1
/
Abstract.php
133 lines (118 loc) · 4.1 KB
/
Abstract.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
/**
* MagPleasure Ltd.
*
* NOTICE OF LICENSE
*
* This source file is subject to the EULA
* that is bundled with this package in the file LICENSE-CE.txt.
* It is also available through the world-wide-web at this URL:
* http://www.magpleasure.com/LICENSE-CE.txt
*
* =================================================================
* MAGENTO EDITION USAGE NOTICE
* =================================================================
* This package designed for Magento COMMUNITY edition
* MagPleasure does not guarantee correct work of this extension
* on any other Magento edition except Magento COMMUNITY edition.
* Magpleasure does not provide extension support in case of
* incorrect edition usage.
* =================================================================
*
* @category MagPleasure
* @package Magpleasure_Common
* @version 0.8.1
* @copyright Copyright (c) 2012-2015 MagPleasure Ltd. (http://www.magpleasure.com)
* @license http://www.magpleasure.com/LICENSE-CE.txt
*/
/** @method Magpleasure_Common_Model_Resource_Abstract getResource() */
class Magpleasure_Common_Model_Abstract extends Mage_Core_Model_Abstract
{
/**
* Helper
*
* @return Magpleasure_Common_Helper_Data
*/
protected function _commonHelper()
{
return Mage::helper('magpleasure');
}
/**
* Load Abstract Model by few key fields
*
* @param array $data
* @return Magpleasure_Common_Model_Resource_Abstract
*/
public function loadByFewFields(array $data)
{
$this->getResource()->loadByFewFields($this, $data);
return $this;
}
/**
* Retrieves Entity Label
*
* @param int|null $storeId
* @return string
*/
public function getLabel($storeId = null)
{
if ($this->getResource()->getUseStoreLabels()){
if (!$storeId){
$storeId = Mage::app()->getStore()->getId();
}
return $this->getData('store_label_'.$storeId) ? $this->getData('store_label_'.$storeId) : $this->getData('label');
} else {
return parent::getLabel();
}
}
/**
* Check object state (true - if it is object without id on object just created)
* This method can help detect if object just created in _afterSave method
* problem is what in after save onject has id and we can't detect what object was
* created in this transaction
*
* @param bool $flag
* @return bool
*/
public function isObjectNew($flag=null)
{
if ($flag !== null) {
$this->_isObjectNew = $flag;
}
if ($this->_isObjectNew !== null) {
return $this->_isObjectNew;
}
return !(bool)$this->getId();
}
protected function _afterDeleteCommitIndexProcess()
{
if ($type = $this->_commonHelper()->getSearchCore()->getSearchableType($this->getResourceName())){
/** @var $indexer Mage_Index_Model_Indexer */
$indexer = Mage::getSingleton('index/indexer');
$indexer->processEntityAction($this, $type->getTypeCode(), Mage_Index_Model_Event::TYPE_DELETE);
}
}
protected function _afterDeleteCommit()
{
parent::_afterDeleteCommit();
if ($this->_commonHelper()->isSearchCoreEnabled()){
$this->_afterDeleteCommitIndexProcess();
}
}
protected function _afterSaveIndexerProcess()
{
if ($type = $this->_commonHelper()->getSearchCore()->getSearchableType($this->getResourceName())){
/** @var $indexer Mage_Index_Model_Indexer */
$indexer = Mage::getSingleton('index/indexer');
$indexer->processEntityAction($this, $type->getTypeCode(), Mage_Index_Model_Event::TYPE_SAVE);
}
return $this;
}
protected function _afterSave()
{
parent::_afterSave();
if ($this->_commonHelper()->isSearchCoreEnabled()){
$this->_afterSaveIndexerProcess();
}
}
}