質問編集履歴
1
PHPファイルの更新、twigの追加
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
EC-CUBE3の
|
1
|
+
EC-CUBE3で在庫の表示
|
test
CHANGED
@@ -1,81 +1,289 @@
|
|
1
|
-
現在EC-CUBE3で
|
1
|
+
現在EC-CUBE3で開発をしています。
|
2
2
|
|
3
3
|
管理画面の商品マスターで「検索する」を押した時に在庫数を取得し、在庫が0の商品に「在庫切れ」アイコンを表示するということをやりたいです。
|
4
4
|
|
5
5
|
|
6
6
|
|
7
|
+
|
8
|
+
|
7
|
-
|
9
|
+
コントローラー下記のように作成しましたが、twigにうまくデータが渡せません。
|
8
|
-
|
10
|
+
|
9
|
-
```
|
11
|
+
```php
|
12
|
+
|
10
|
-
|
13
|
+
<?php
|
14
|
+
|
15
|
+
namespace Eccube\Controller\Admin\Product;
|
16
|
+
|
17
|
+
|
18
|
+
|
11
|
-
a
|
19
|
+
class ProductController extends AbstractController
|
20
|
+
|
12
|
-
|
21
|
+
{
|
22
|
+
|
23
|
+
public function index(Application $app, Request $request, $page_no = null)
|
24
|
+
|
25
|
+
{
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
$builder = $app['form.factory']
|
30
|
+
|
31
|
+
->createBuilder('admin_search_product');
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
$event = new EventArgs(
|
36
|
+
|
37
|
+
array(
|
38
|
+
|
39
|
+
'builder' => $builder,
|
40
|
+
|
41
|
+
),
|
42
|
+
|
43
|
+
$request
|
44
|
+
|
45
|
+
);
|
46
|
+
|
47
|
+
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_PRODUCT_INDEX_INITIALIZE, $event);
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
$searchForm = $builder->getForm();
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
$pagination = array();
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
$disps = $app['eccube.repository.master.disp']->findAll();
|
60
|
+
|
61
|
+
$pageMaxis = $app['eccube.repository.master.page_max']->findAll();
|
62
|
+
|
63
|
+
$page_count = $app['config']['default_page_count'];
|
64
|
+
|
65
|
+
$page_status = null;
|
66
|
+
|
67
|
+
$active = false;
|
68
|
+
|
69
|
+
$stock = null;
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
if ('POST' === $request->getMethod()) {
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
$searchForm->handleRequest($request);
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
if ($searchForm->isValid()) {
|
82
|
+
|
83
|
+
$searchData = $searchForm->getData();
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
// paginator
|
88
|
+
|
89
|
+
$qb = $app['eccube.repository.product']->getQueryBuilderBySearchDataForAdmin($searchData);
|
90
|
+
|
91
|
+
$page_no = 1;
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
$event = new EventArgs(
|
96
|
+
|
97
|
+
array(
|
98
|
+
|
99
|
+
'qb' => $qb,
|
100
|
+
|
101
|
+
'searchData' => $searchData,
|
102
|
+
|
103
|
+
),
|
104
|
+
|
105
|
+
$request
|
106
|
+
|
107
|
+
);
|
108
|
+
|
109
|
+
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_PRODUCT_INDEX_SEARCH, $event);
|
110
|
+
|
111
|
+
$searchData = $event->getArgument('searchData');
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
$pagination = $app['paginator']()->paginate(
|
116
|
+
|
117
|
+
$qb,
|
118
|
+
|
119
|
+
$page_no,
|
120
|
+
|
121
|
+
$page_count,
|
122
|
+
|
123
|
+
array('wrap-queries' => true)
|
124
|
+
|
125
|
+
);
|
126
|
+
|
127
|
+
// ここから
|
128
|
+
|
129
|
+
foreach ($pagination as $value) {
|
130
|
+
|
131
|
+
$Product = $app['eccube.repository.product']->find($value['id']);
|
132
|
+
|
133
|
+
if (!$Product) {
|
134
|
+
|
135
|
+
throw new NotFoundHttpException();
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
$has_class = $Product->hasProductClass();
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
if (!$has_class) {
|
144
|
+
|
145
|
+
$ProductClasses = $Product->getProductClasses();
|
146
|
+
|
13
|
-
|
147
|
+
$ProductClass = $ProductClasses[0];
|
148
|
+
|
14
|
-
|
149
|
+
$BaseInfo = $app['eccube.repository.base_info']->get();
|
150
|
+
|
151
|
+
if ($BaseInfo->getOptionProductTaxRule() == Constant::ENABLED && $ProductClass->getTaxRule() && !$ProductClass->getTaxRule()->getDelFlg()) {
|
152
|
+
|
153
|
+
$ProductClass->setTaxRate($ProductClass->getTaxRule()->getTaxRate());
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
$ProductStock = $ProductClasses[0]->getProductStock();
|
158
|
+
|
159
|
+
}
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
if ($ProductStock['stock'] === '0'){
|
164
|
+
|
15
|
-
|
165
|
+
$stock[] = '在庫切れ';
|
166
|
+
|
16
|
-
|
167
|
+
} else {
|
168
|
+
|
17
|
-
|
169
|
+
$stock[] = '';
|
170
|
+
|
171
|
+
}
|
172
|
+
|
173
|
+
}
|
174
|
+
|
175
|
+
// ここまで実装
|
176
|
+
|
177
|
+
// sessionのデータ保持
|
178
|
+
|
179
|
+
$session->set('eccube.admin.product.search', $searchData);
|
180
|
+
|
181
|
+
}
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
return $app->render('Product/index.twig', array(
|
188
|
+
|
189
|
+
'searchForm' => $searchForm->createView(),
|
190
|
+
|
191
|
+
'pagination' => $pagination,
|
192
|
+
|
193
|
+
'disps' => $disps,
|
194
|
+
|
195
|
+
'pageMaxis' => $pageMaxis,
|
196
|
+
|
197
|
+
'page_no' => $page_no,
|
198
|
+
|
199
|
+
'page_status' => $page_status,
|
200
|
+
|
201
|
+
'page_count' => $page_count,
|
202
|
+
|
203
|
+
'active' => $active,
|
204
|
+
|
205
|
+
//'stock' => $stock
|
206
|
+
|
207
|
+
));
|
208
|
+
|
209
|
+
}
|
18
210
|
|
19
211
|
```
|
20
212
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
use
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
{
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
pri
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
{
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
}
|
76
|
-
|
77
|
-
}
|
213
|
+
```twig
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
{% for Product in pagination %}
|
218
|
+
|
219
|
+
<div id="result_list__item--{{ Product.id }}" class="item_box tr">
|
220
|
+
|
221
|
+
<div id="result_list__id--{{ Product.id }}" class="item_id td">
|
222
|
+
|
223
|
+
{{Product.id}}
|
224
|
+
|
225
|
+
</div>
|
226
|
+
|
227
|
+
<div id="result_list__image--{{ Product.id }}" class="item_photo td">
|
228
|
+
|
229
|
+
<a href="{{ url('admin_product_product_edit', { id : Product.id }) }}">
|
230
|
+
|
231
|
+
<img src="{{ app.config.image_save_urlpath }}/{{ Product.mainFileName|no_image_product }}" />
|
232
|
+
|
233
|
+
</a>
|
234
|
+
|
235
|
+
</div>
|
236
|
+
|
237
|
+
<div id="result_list__name--{{ Product.id }}" class="item_detail td">
|
238
|
+
|
239
|
+
<a href="{{ url('admin_product_product_edit', { id : Product.id }) }}">
|
240
|
+
|
241
|
+
{{ Product.name }}
|
242
|
+
|
243
|
+
</a>
|
244
|
+
|
245
|
+
{{ stock }}
|
246
|
+
|
247
|
+
<br>
|
248
|
+
|
249
|
+
<span id="result_list__code--{{ Product.id }}">
|
250
|
+
|
251
|
+
{{ Product.code_min }}
|
252
|
+
|
253
|
+
{% if Product.code_min != Product.code_max %} ~ {{ Product.code_max }}
|
254
|
+
|
255
|
+
{% endif %}
|
256
|
+
|
257
|
+
</span>
|
258
|
+
|
259
|
+
</div>
|
260
|
+
|
261
|
+
<div id="result_list__item_menu_box--{{ Product.id }}"class="icon_edit td">
|
262
|
+
|
263
|
+
<div id="result_list__item_menu_toggle--{{ Product.id }}" class="dropdown">
|
264
|
+
|
265
|
+
<a class="dropdown-toggle" data-toggle="dropdown"><svg class="cb cb-ellipsis-h"><use xlink:href="#cb-ellipsis-h"></svg></a>
|
266
|
+
|
267
|
+
<ul id="result_list__item_menu--{{ Product.id }}" class="dropdown-menu dropdown-menu-right">
|
268
|
+
|
269
|
+
<li><a href="{{ url('admin_product_product_class', { id : Product.id }) }}">規格</a></li>
|
270
|
+
|
271
|
+
<li><a href="{{ url('admin_product_product_display', {'id' : Product.id}) }}" target="_blank">確認</a></li>
|
272
|
+
|
273
|
+
<li><a href="{{ url('admin_product_product_copy', {'id' : Product.id}) }}" {{ csrf_token_for_anchor() }} data-method="post" data-message="商品情報を複製してもよろしいですか?">複製</a></li>
|
274
|
+
|
275
|
+
<li><a href="{{ url('admin_product_product_delete', {'id' : Product.id}) }}" {{ csrf_token_for_anchor() }} data-method="delete" data-message="商品情報を削除してもよろしいですか?">削除</a></li>
|
276
|
+
|
277
|
+
</ul>
|
278
|
+
|
279
|
+
</div>
|
280
|
+
|
281
|
+
</div>
|
282
|
+
|
283
|
+
</div><!-- /.item_box -->
|
284
|
+
|
285
|
+
{% endfor %}
|
78
286
|
|
79
287
|
```
|
80
288
|
|
81
|
-
PHP
|
289
|
+
PHP側でpaginationに在庫情報を入れて渡そうとしましたがうまくいかず、レンダリングする箇所で在庫情報を渡すとArrayと表示されてうまくいきません。どうすればいいでしょうか?よろしくお願いします。
|