forked from vadimjustus/easy-shipping-rules
/
Custommethod.php
105 lines (92 loc) · 3.04 KB
/
Custommethod.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
<?php
/**
* This file is part of the "Easy Shipping Rules" module for Magento eCommerce
* developed by (c) Matheus Gontijo <matheus@matheusgontijo.com>
*/
/**
* Custom Method model
*
* @method string getName()
* @method MatheusGontijo_EasyShippingRules_Model_Custommethod setEasyshippingrulesCarrierId(int $value)
* @method int getEasyshippingrulesCarrierId()
* @method MatheusGontijo_EasyShippingRules_Model_Custommethod setName(string $value)
* @method string getDescription()
* @method MatheusGontijo_EasyShippingRules_Model_Custommethod setDescription(string $value)
* @method int getIsActive()
* @method MatheusGontijo_EasyShippingRules_Model_Custommethod setIsActive(int $value)
* @method string getConditionsSerialized()
* @method MatheusGontijo_EasyShippingRules_Model_Custommethod setConditionsSerialized(string $value)
* @method string getPricePercentage()
* @method MatheusGontijo_EasyShippingRules_Model_Custommethod setPricePercentage(string $value)
* @method string getCreatedAt()
* @method MatheusGontijo_EasyShippingRules_Model_Custommethod setCreatedAt(string $value)
* @method string getUpdatedAt()
* @method MatheusGontijo_EasyShippingRules_Model_Custommethod setUpdatedAt(string $value)
*
* @category MatheusGontijo
* @package MatheusGontijo_EasyShippingRules
* @author Matheus Gontijo <matheus@matheusgontijo.com>
* @license OSL v3.0
*/
class MatheusGontijo_EasyShippingRules_Model_Custommethod
extends Mage_Core_Model_Abstract
{
/**
* Constructor
*/
protected function _construct()
{
parent::_construct();
$this->_init('easyshippingrules/custommethod');
$this->setIdFieldName('easyshippingrules_custom_method_id');
}
/**
* Processing object before save data
*
* @return Mage_Core_Model_Abstract
*/
protected function _beforeSave()
{
parent::_beforeSave();
if (!$this->getEasyshippingrulesCarrierId()) {
$this->setEasyshippingrulesCarrierId(null);
}
$storeId = $this->getStoreId();
if ($storeId === null) {
$this->setStoreId(Mage::app()->getStore()->getId());
}
return $this;
}
/**
* Retrieve array of custom rules
*
* @return array
*/
public function getRules()
{
if (!$this->hasRules()) {
$rules = array();
$collection = Mage::getModel('easyshippingrules/rule')
->getCollection()
->addCustomMethodFilter($this);
foreach ($collection as $rule) {
$rules[] = $rule;
}
$this->setRules($rules);
}
return $this->getData('rules');
}
/**
* Retrieve array of shipping rule ids
*
* @return array
*/
public function getLinkRuleIds()
{
if (!$this->hasLinkRuleIds()) {
$ruleIds = $this->getResource()->getLinkRuleIds($this);
$this->setLinkRuleIds($ruleIds);
}
return $this->getData('link_rule_ids');
}
}