-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplugin2.php
160 lines (126 loc) · 7.32 KB
/
plugin2.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
<?php
/**
* Печатает поля для добавления вариантов и свойств при редактировании документов.
* @author SerovAlexander <serov.sh@gmail.com>
*/
$e = &$modx->Event;
$output = '';
#######################################################
if ($e->name == 'OnDocFormRender') {
if (isset($_REQUEST['mshop']) && $_REQUEST['mshop'] == 1) {
require_once MODX_BASE_PATH . 'assets/modules/shop/models/MShopModel.class.php';
$mshop = new MShopModel($modx);
global $content;
if (isset($_POST['mshop_redirect']))
$redirect = $_POST['mshop_redirect'];
else
$redirect = 'index.php?a=' . $_GET['last_a'] . '&id=' . $_GET['last_id'] . '&view=' . $_GET['last_view'] . '&mshop_pid=' . $_GET['mshop_pid'];
$output.='<script type="text/javascript">
var html = \'<br /><input type="text" name="mshop_parent" value="' . $content['mshop_parent'] . '" />\';
$j("#mutate input[name=parent]").after(html);
$j("#Button4 a").attr("onClick", "documentDirty=false;document.location.href=\'' . $redirect . '\';");
$j("#Button3").remove();
$j("#Button5").remove();
$j("#Button6").remove();
</script>';
if (is_array($mshop->product_template)) {
if (!in_array($content['template'], $mshop->product_template)) {
$e->output($output);
return '';
}
} else {
if ($content['template'] != $mshop->product_template) {
$e->output($output);
return '';
}
}
$output.='
<style type="text/css">
#mutate .mshop input.mshop {
width: 100px;
}
</style>
<script type="text/javascript">
function addMShopVariant() {
count = $j(".mshop_variants").size();
count = count+1;
var newRow = $j("<tr class=mshop_variants> <td><input type=text class=mshop name=mshop_variant[new"+count+"][name]></td> <td><input type=text class=mshop name=mshop_variant[new"+count+"][article]></td> <td><input type=text class=mshop name=mshop_variant[new"+count+"][price]></td> <td><input type=text class=mshop name=mshop_variant[new"+count+"][stock]></td><td><input type=text class=mshop name=mshop_variant[new"+count+"][unit]></td> <td><a href=\'javascript:;\' onclick=\"$j(this).parents(\'tr\').remove();\">Удалить</a></td></tr>");
$j(".mshop_variants:last").after(newRow);
return false;
}
function removeMShopVariant(id_variant) {
r = $j("#removeMShopVariant").val();
$j("#removeMShopVariant").val(r+","+id_variant);
}
</script>
<div class="sectionHeader mshopr" style="margin: auto 20px;">Параметры магазина</div>'; //lang
$output.='<div class="sectionBody mshop" style="margin: auto 20px;">
<h3>Варианты товара</h3>
<table id="MShopVariants"><tr class="mshop_variants">
<th>Название</th>
<th>Артикул</th>
<th>Цена</th>
<th>Склад</th>
<th>Ед.Измерения</th>
<th></th>
</tr>
'; //lang
if (isset($_REQUEST['mshop_id']) && is_numeric($_REQUEST['mshop_id'])) {
$variants = $mshop->document->getVariants($_REQUEST['mshop_id']);
foreach ($variants as $variant) {
$output.='<tr class="mshop_variants"><td><input type="text" class="mshop" name="mshop_variant[' . $variant['id'] . '][name]" value="' . $variant['name'] . '"></td>';
$output.='<td><input class="mshop" type="text" name="mshop_variant[' . $variant['id'] . '][article]" value="' . $variant['article'] . '"></td>';
$output.='<td><input class="mshop" type="text" name="mshop_variant[' . $variant['id'] . '][price]" value="' . $variant['price'] . '"> </td>';
$output.='<td><input class="mshop" type="text" name="mshop_variant[' . $variant['id'] . '][stock]" value="' . $variant['stock'] . '"> </td>';
$output.='<td><input class="mshop" type="text" name="mshop_variant[' . $variant['id'] . '][unit]" value="' . $variant['unit'] . '"> </td>';
$output.='<td><a href="javascript:;" onclick="$j(this).parents(\'tr\').remove();removeMShopVariant(' . $variant['id'] . ');">Удалить</a></td></tr>'; //lang
}
} else {
$output.='<tr class="mshop_variants"><td><input type="text" class="mshop" name="mshop_variant[new1][name]" value=""></td>';
$output.='<td><input class="mshop" type="text" name="mshop_variant[new1][article]" value=""></td>';
$output.='<td><input class="mshop" type="text" name="mshop_variant[new1][price]" value=""> </td>';
$output.='<td><input class="mshop" type="text" name="mshop_variant[new1][stock]" value=""> </td>';
$output.='<td><input class="mshop" type="text" name="mshop_variant[new1][unit]" value=""> </td>';
$output.='<td><a href="javascript:;" onclick="$j(this).parents(\'tr\').remove();">Удалить</a></td></tr>'; //lang
}
$output.='</table>
<input type="hidden" id="removeMShopVariant" name="remove_mshop_variants" value="0">
<a href="javascript:;" onclick="addMShopVariant();">Добавить вариант</a>'; //lang
$brands = $mshop->brand->getBrands();
$output.='<br/> <label>Бренд:<select name="mshop_brand">';
$selected = '';
if (is_array($brands)) {
foreach ($brands as $b) {
if (isset($content['id_brand']) && $content['id_brand'] == $b['id'])
$selected = 'selected';
$output.='<option value="' . $b['id'] . '" ' . $selected . '>' . $b['pagetitle'] . '</option>';
$selected = '';
}
}
$output.='</select></label>';
$output.='<h2>Свойства</h2>';
$prs = $mshop->property->getProperties($content['mshop_parent']);
foreach ($prs as $pr) {
$p = $pr['property'];
if (empty($p['options'])) {
$value = isset($content['mshop_properies'][$p['id']]) ? $content['mshop_properies'][$p['id']] : '';
$output.='<label>' . $p['name'] . ': <input type="text" name="mshop_properties[' . $p['id'] . ']" value="' . $value . '"></label> <br/>';
} elseif (is_array($p['options'])) {
$output.='<label>' . $p['name'] . ':<select name="mshop_properties[' . $p['id'] . ']">';
$selected = '';
foreach ($p['options'] as $o) {
if (isset($content['mshop_properies'][$p['id']]) && $content['mshop_properies'][$p['id']] == $o)
$selected = 'selected';
$output.='<option value="' . $o . '" ' . $selected . '>' . $o . '</option>';
$selected = '';
}
$output.='</select></label><br/>';
}
}
$output.='</div>';
}
}
#######################################################
$e->output($output);
$modx->clearCache();
?>