forked from mrimran/ecart
/
Rule.php
executable file
·110 lines (88 loc) · 2.74 KB
/
Rule.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
<?php
/**
* Mirasvit
*
* This source file is subject to the Mirasvit Software License, which is available at http://mirasvit.com/license/.
* Do not edit or add to this file if you wish to upgrade the to newer versions in the future.
* If you wish to customize this module for your needs.
* Please refer to http://www.magentocommerce.com for more information.
*
* @category Mirasvit
* @package Advanced Product Feeds
* @version 1.1.2
* @build 616
* @copyright Copyright (C) 2015 Mirasvit (http://mirasvit.com/)
*/
class Mirasvit_FeedExport_Model_Rule extends Mage_Rule_Model_Rule
{
const TYPE_ATTRIBUTE = 'attribute';
const TYPE_PERFORMANCE = 'performance';
protected $_productIds;
protected function _construct()
{
parent::_construct();
$this->_init('feedexport/rule');
$this->setIdFieldName('rule_id');
}
public function getConditionsInstance()
{
return Mage::getModel('feedexport/rule_condition_combine');
}
public function getActionsInstance()
{
return Mage::getModel('feedexport/rule_action_collection');
}
protected function _afterSave()
{
parent::_afterSave();
}
public function getProductIds()
{
return $this->_getResource()->getRuleProductIds($this->getId());
}
public function toString($format = '')
{
$this->load($this->getId());
$string = $this->getConditions()->asStringRecursive();
$string = nl2br(preg_replace('/ /', ' ', $string));
return $string;
}
/**
* @todo need create typical interface
*/
public function export()
{
$xml = $this->toXml(array('name', 'type', 'conditions_serialized', 'actions_serialized'));
$path = Mage::getSingleton('feedexport/config')->getRulePath().DS.$this->getName().'.xml';
file_put_contents($path, $xml);
return $path;
}
/**
* @todo need create typical interface
*/
public function import($filePath)
{
$content = file_get_contents($filePath);
$xml = new Varien_Simplexml_Element($content);
$template = $xml->asArray();
$model = $this->getCollection()
->addFieldToFilter('name', $template['name'])
->getFirstItem();
$model->addData($template)
->save();
return $model;
}
public function duplicate()
{
$ruleCopy = Mage::getModel('feedexport/rule')
->addData($this->getData())
->setRuleId(null)
->setName($this->getName().' (copy)')
->setIsActive(1)
->setCreatedAt(null)
->setUpdatedAt(null)
->setFeedIds(null)
->save();
return $this;
}
}