質問編集履歴
3
タグの追加
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|
2
誤字修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,11 +14,11 @@
|
|
14
14
|
|
15
15
|
同じ仕様で同ページ内に複数個所、別カテゴリの新着商品を表示させたいのですが、
|
16
16
|
|
17
|
-
TwigExtension.php内と新規ブロックtwig内のどこをどのように修正すれば複数設置できますでしょうか?
|
17
|
+
TwigExtension.php内と新規ブロックtwig内(ここではnew_item_sec.twig)のどこをどのように修正すれば複数設置できますでしょうか?
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
-
|
21
|
+
よろしくお願いいたします。
|
22
22
|
|
23
23
|
|
24
24
|
|
1
ソースコードを載せました
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
##前提・実現したいこと
|
2
|
+
|
1
3
|
EC-CUBE4.0.3にてTOPページの新着商品ブロックのカスタマイズを行っております。
|
2
4
|
|
3
5
|
|
@@ -17,3 +19,315 @@
|
|
17
19
|
|
18
20
|
|
19
21
|
初歩的な質問かと思いますが、よろしくお願いいたします。
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
##TwigExtension.php ソースコード
|
26
|
+
|
27
|
+
```php
|
28
|
+
|
29
|
+
<?php
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
namespace Customize\Twig\Extension;
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
use Doctrine\Common\Collections;
|
38
|
+
|
39
|
+
use Doctrine\ORM\EntityManagerInterface;
|
40
|
+
|
41
|
+
use Eccube\Common\EccubeConfig;
|
42
|
+
|
43
|
+
use Eccube\Entity\Master\ProductStatus;
|
44
|
+
|
45
|
+
use Eccube\Entity\Product;
|
46
|
+
|
47
|
+
use Eccube\Entity\ProductClass;
|
48
|
+
|
49
|
+
use Eccube\Repository\ProductRepository;
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
class TwigExtension extends \Twig_Extension
|
54
|
+
|
55
|
+
{
|
56
|
+
|
57
|
+
/** @var EntityManagerInterface */
|
58
|
+
|
59
|
+
private $entityManager;
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
/**
|
64
|
+
|
65
|
+
* @var EccubeConfig
|
66
|
+
|
67
|
+
*/
|
68
|
+
|
69
|
+
protected $eccubeConfig;
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
/**
|
74
|
+
|
75
|
+
* @var ProductRepository
|
76
|
+
|
77
|
+
*/
|
78
|
+
|
79
|
+
private $productRepository;
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
/**
|
84
|
+
|
85
|
+
* TwigExtension constructor.
|
86
|
+
|
87
|
+
*
|
88
|
+
|
89
|
+
*/
|
90
|
+
|
91
|
+
public function __construct(
|
92
|
+
|
93
|
+
EntityManagerInterface $entityManager,
|
94
|
+
|
95
|
+
EccubeConfig $eccubeConfig,
|
96
|
+
|
97
|
+
ProductRepository $productRepository
|
98
|
+
|
99
|
+
) {
|
100
|
+
|
101
|
+
$this->entityManager = $entityManager;
|
102
|
+
|
103
|
+
$this->eccubeConfig = $eccubeConfig;
|
104
|
+
|
105
|
+
$this->productRepository = $productRepository;
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
/**
|
110
|
+
|
111
|
+
* Returns a list of functions to add to the existing list.
|
112
|
+
|
113
|
+
*
|
114
|
+
|
115
|
+
* @return array An array of functions
|
116
|
+
|
117
|
+
*/
|
118
|
+
|
119
|
+
public function getFunctions()
|
120
|
+
|
121
|
+
{
|
122
|
+
|
123
|
+
return array(
|
124
|
+
|
125
|
+
new \Twig_SimpleFunction('CustomizeNewProduct', array($this, 'getCustomizeNewProduct')),
|
126
|
+
|
127
|
+
);
|
128
|
+
|
129
|
+
}
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
/**
|
134
|
+
|
135
|
+
* Name of this extension
|
136
|
+
|
137
|
+
*
|
138
|
+
|
139
|
+
* @return string
|
140
|
+
|
141
|
+
*/
|
142
|
+
|
143
|
+
public function getName()
|
144
|
+
|
145
|
+
{
|
146
|
+
|
147
|
+
return 'CustomizeTwigExtension';
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
/**
|
154
|
+
|
155
|
+
*
|
156
|
+
|
157
|
+
* 新着商品3件返す
|
158
|
+
|
159
|
+
*
|
160
|
+
|
161
|
+
* @return Products|null
|
162
|
+
|
163
|
+
*/
|
164
|
+
|
165
|
+
public function getCustomizeNewProduct()
|
166
|
+
|
167
|
+
{
|
168
|
+
|
169
|
+
try {
|
170
|
+
|
171
|
+
// 既存のproductRepositoryを利用し、商品情報を取得
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
// 検索条件の新着順を定義
|
178
|
+
|
179
|
+
$searchData = array();
|
180
|
+
|
181
|
+
$qb = $this->entityManager->createQueryBuilder();
|
182
|
+
|
183
|
+
$query = $qb->select("plob")
|
184
|
+
|
185
|
+
->from("Eccube\Entity\Master\ProductListOrderBy", "plob")
|
186
|
+
|
187
|
+
->where('plob.id = :id')
|
188
|
+
|
189
|
+
->setParameter('id', $this->eccubeConfig['eccube_product_order_newer'])
|
190
|
+
|
191
|
+
->getQuery();
|
192
|
+
|
193
|
+
$searchData['orderby'] = $query->getOneOrNullResult();
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
// 新入荷商品を表示
|
198
|
+
|
199
|
+
$snkr_stock_id = 2;
|
200
|
+
|
201
|
+
$qb = $this->entityManager->createQueryBuilder();
|
202
|
+
|
203
|
+
$query = $qb->select("ctg")
|
204
|
+
|
205
|
+
->from("Eccube\Entity\Category", "ctg")
|
206
|
+
|
207
|
+
->where('ctg.id = :id')
|
208
|
+
|
209
|
+
->setParameter('id', $snkr_stock_id)
|
210
|
+
|
211
|
+
->getQuery();
|
212
|
+
|
213
|
+
$searchData['category_id'] = $query->getOneOrNullResult();
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
// 商品情報3件取得
|
218
|
+
|
219
|
+
$qb = $this->productRepository->getQueryBuilderBySearchData($searchData);
|
220
|
+
|
221
|
+
$query = $qb->setMaxResults(3)->getQuery();
|
222
|
+
|
223
|
+
$products = $query->getResult();
|
224
|
+
|
225
|
+
return $products;
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
} catch (\Exception $e) {
|
230
|
+
|
231
|
+
return null;
|
232
|
+
|
233
|
+
}
|
234
|
+
|
235
|
+
return null;
|
236
|
+
|
237
|
+
}
|
238
|
+
|
239
|
+
}
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
```
|
244
|
+
|
245
|
+
##new_item_sec.twig ソースコード
|
246
|
+
|
247
|
+
```twig
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
{% set Products = CustomizeNewProduct() %}
|
252
|
+
|
253
|
+
{% if Products|length > 0 %}
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
<div class="ec-role">
|
258
|
+
|
259
|
+
<div class="ec-newItemRole">
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
<div class="ec-secHeading">
|
264
|
+
|
265
|
+
<span class="ec-secHeading__en">{{ 'NEW ARRIVAL'|trans }}</span>
|
266
|
+
|
267
|
+
<span class="ec-secHeading__line"></span>
|
268
|
+
|
269
|
+
<span class="ec-secHeading__ja">{{ '新着商品'|trans }}</span>
|
270
|
+
|
271
|
+
</div>
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
<ul class="top-new-product">
|
276
|
+
|
277
|
+
{% for Product in Products %}
|
278
|
+
|
279
|
+
<li>
|
280
|
+
|
281
|
+
<a href="{{ url('product_detail', {'id': Product.id}) }}">
|
282
|
+
|
283
|
+
<img src="{{ asset(Product.main_list_image|no_image_product, 'save_image') }}">
|
284
|
+
|
285
|
+
<p class="ec-newItemRole__listItemTitle">{{ Product.name }}</p>
|
286
|
+
|
287
|
+
<p class="ec-newItemRole__listItemPrice">
|
288
|
+
|
289
|
+
{% if Product.hasProductClass %}
|
290
|
+
|
291
|
+
{% if Product.getPrice02Min == Product.getPrice02Max %}
|
292
|
+
|
293
|
+
{{ Product.getPrice02IncTaxMin|price }}
|
294
|
+
|
295
|
+
{% else %}
|
296
|
+
|
297
|
+
{{ Product.getPrice02IncTaxMin|price }} ~ {{ Product.getPrice02IncTaxMax|price }}
|
298
|
+
|
299
|
+
{% endif %}
|
300
|
+
|
301
|
+
{% else %}
|
302
|
+
|
303
|
+
{{ Product.getPrice02IncTaxMin|price }}
|
304
|
+
|
305
|
+
{% endif %}
|
306
|
+
|
307
|
+
</p>
|
308
|
+
|
309
|
+
</a>
|
310
|
+
|
311
|
+
</li>
|
312
|
+
|
313
|
+
{% endfor %}
|
314
|
+
|
315
|
+
</ul>
|
316
|
+
|
317
|
+
<div class="view-more-box">
|
318
|
+
|
319
|
+
<a class="ec-inlineBtn--top" href="{{ url('product_list') }}?category_id=7">VEW MORE</a>
|
320
|
+
|
321
|
+
</div>
|
322
|
+
|
323
|
+
</div>
|
324
|
+
|
325
|
+
</div>
|
326
|
+
|
327
|
+
</div>
|
328
|
+
|
329
|
+
{% endif %}
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
```
|