/
Combine.php
185 lines (171 loc) · 6.66 KB
/
Combine.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?php
/**
* Magento Enterprise Edition
*
* NOTICE OF LICENSE
*
* This source file is subject to the Magento Enterprise Edition End User License Agreement
* that is bundled with this package in the file LICENSE_EE.txt.
* It is also available through the world-wide-web at this URL:
* http://www.magento.com/license/enterprise-edition
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magento.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magento.com for more information.
*
* @category Enterprise
* @package Enterprise_CustomerSegment
* @copyright Copyright (c) 2006-2014 X.commerce, Inc. (http://www.magento.com)
* @license http://www.magento.com/license/enterprise-edition
*/
/**
* Segment conditions container
*
* @category Enterprise
* @package Enterprise_CustomerSegment
* @author Magento Core Team <core@magentocommerce.com>
*/
class Enterprise_CustomerSegment_Model_Segment_Condition_Combine
extends Enterprise_CustomerSegment_Model_Condition_Combine_Abstract
{
/**
* Initialize model
*/
public function __construct()
{
parent::__construct();
$this->setType('enterprise_customersegment/segment_condition_combine');
}
/**
* Get inherited conditions selectors
*
* @return array
*/
public function getNewChildSelectOptions()
{
$conditions = array(
array(
// Subconditions combo
'value' => 'enterprise_customersegment/segment_condition_combine',
'label' => Mage::helper('enterprise_customersegment')->__('Conditions Combination'),
'available_in_guest_mode' => true
),
array(
// Customer address combo
'value' => 'enterprise_customersegment/segment_condition_customer_address',
'label' => Mage::helper('enterprise_customersegment')->__('Customer Address')
),
// Customer attribute group
Mage::getModel('enterprise_customersegment/segment_condition_customer')->getNewChildSelectOptions(),
// Shopping cart group
Mage::getModel('enterprise_customersegment/segment_condition_shoppingcart')->getNewChildSelectOptions(),
array(
'value' => array(
array(
// Product list combo
'value' => 'enterprise_customersegment/segment_condition_product_combine_list',
'label' => Mage::helper('enterprise_customersegment')->__('Product List'),
'available_in_guest_mode' => true
),
array(
// Product history combo
'value' => 'enterprise_customersegment/segment_condition_product_combine_history',
'label' => Mage::helper('enterprise_customersegment')->__('Product History'),
'available_in_guest_mode' => true
)
),
'label' => Mage::helper('enterprise_customersegment')->__('Products'),
'available_in_guest_mode' => true
),
// Sales group
Mage::getModel('enterprise_customersegment/segment_condition_sales')->getNewChildSelectOptions(),
);
$conditions = array_merge_recursive(parent::getNewChildSelectOptions(), $conditions);
return $this->_prepareConditionAccordingApplyToValue($conditions);
}
/**
* Prepare base condition select which related with current condition combine
*
* @param $customer
* @param $website
* @return Varien_Db_Select
*/
protected function _prepareConditionsSql($customer, $website)
{
$select = parent::_prepareConditionsSql($customer, $website);
$select->limit(1);
return $select;
}
/**
* Prepare Condition According to ApplyTo Value
*
* @param array $conditions
* @return array
*/
protected function _prepareConditionAccordingApplyToValue(array $conditions)
{
$returnedConditions = null;
switch ($this->getRule()->getApplyTo()) {
case Enterprise_CustomerSegment_Model_Segment::APPLY_TO_VISITORS:
$returnedConditions = $this->_removeUnnecessaryConditions($conditions);
break;
case Enterprise_CustomerSegment_Model_Segment::APPLY_TO_VISITORS_AND_REGISTERED:
$returnedConditions = $this->_markConditions($conditions);
break;
case Enterprise_CustomerSegment_Model_Segment::APPLY_TO_REGISTERED:
$returnedConditions = $conditions;
break;
default:
Mage::throwException(Mage::helper('enterprise_customersegment')->__('Wrong "ApplyTo" type'));
break;
}
return $returnedConditions;
}
/**
* Remove unnecessary conditions
*
* @param array $conditionsList
* @return array
*/
protected function _removeUnnecessaryConditions(array $conditionsList)
{
$conditionResult = $conditionsList;
foreach ($conditionResult as $key => $condition) {
if ($key == 0 && isset($condition['value']) && $condition['value'] == '') {
continue;
}
if (array_key_exists('available_in_guest_mode', $condition) && $condition['available_in_guest_mode']) {
if (is_array($conditionResult[$key]['value'])) {
$conditionResult[$key]['value'] = $this->_removeUnnecessaryConditions($condition['value']);
}
} else {
unset($conditionResult[$key]);
}
}
return $conditionResult;
}
/**
* Mark condition with asterisk
*
* @param array $conditionsList
* @return array
*/
protected function _markConditions(array $conditionsList)
{
$conditionResult = $conditionsList;
foreach ($conditionResult as $key => $condition) {
if (array_key_exists('available_in_guest_mode', $condition) && $condition['available_in_guest_mode']) {
$conditionResult[$key]['label'] .= '*';
if (is_array($conditionResult[$key]['value'])) {
$conditionResult[$key]['value'] = $this->_markConditions($condition['value']);
}
}
}
return $conditionResult;
}
}