バージョン選択

フォーラム

メニュー

オンライン状況

56 人のユーザが現在オンラインです。 (45 人のユーザが フォーラム を参照しています。)
登録ユーザ: 1
ゲスト: 55
neha9873 もっと...

サイト内検索

質問 > フロント機能 > Block/cart.twigの問題

フロント機能

新規スレッドを追加する

スレッド表示 | 新しいものから 前のトピック | 次のトピック | 下へ
投稿者 スレッド
acxAura
投稿日時: 2022/10/11 18:33
対応状況: 開発中
半人前
登録日: 2022/10/6
居住地:
投稿: 17
Block/cart.twigの問題
▼テンプレート
[EC-CUBE] EC-CUBEの4.1.2
[レンタルサーバ] localhost


お世話になっております
現在、Block/cart.twigのイメージを他のイメージに変えようと思って、Controller/Block/CartController.phpを修正して、

if ($route == 'block_cart_sp') {
return $this->render('Block/nav_sp.twig', [
'totalQuantity' => $totalQuantity,
'totalPrice' => $totalPrice,
'Carts' => $Carts,
'images' => $custom_images
]);
} else {
return $this->render('Block/cart.twig', [
'totalQuantity' => $totalQuantity,
'totalPrice' => $totalPrice,
'Carts' => $Carts,
'images' => $custom_images
]);
}
’images'というのを追加しました

しかし、Block/cart.twigに
<img src="{{ asset(images[idx]|no_image_product, 'save_image') }}" alt="{{ Product.name }}">

こうimagesを入れても、variable "images" does not existというエラーが出ます。
Block/CartControllerから貰ったimagesというvariableを認識されてないと思ってます。

でも、
{% set Carts = get_all_carts() %}
{% set totalPrice = get_carts_total_price() %}
{% set totalQuantity = get_carts_total_quantity() %}
というCartServiceExtensionを使ってるのを見て、よくわからなくなりました...

どうすればimagesを認識させようにできますか?


nanasess
投稿日時: 2022/10/11 23:41
対応状況: −−−
登録日: 2006/9/9
居住地:
投稿: 2313
Re: Block/cart.twigの問題

asset(images[idx]|no_image_product, 'save_image')


は、 html/upload/save_image 以下の images[idx] を参照するという意味です。

$custom_images の画像は html/upload/save_image 以下に格納されていますでしょうか?
acxAura
投稿日時: 2022/10/12 0:22
対応状況: −−−
半人前
登録日: 2022/10/6
居住地:
投稿: 17
Re: Block/cart.twigの問題
ご回答ありがとうございます
はい、$custom_images の画像は html/upload/save_image 以下に格納されていますが、
Variable "images" does not exist.というえーらが出てます。
多分Block/cart.twigがBlock/CartControllerから貰った変数を認識してないと思います...
$custom_imageをチェックするためにcart.twig中のimagesを全部消して、
twigでdump(images)を書いてみたんですが、同じエラーが出ました
nanasess
投稿日時: 2022/10/12 12:01
対応状況: −−−
登録日: 2006/9/9
居住地:
投稿: 2313
Re: Block/cart.twigの問題
すみません、Block/CartController はカートの更新時にしか使用していませんでした。
Eccube\Twig\Extension\CartServiceExtension に custom_image 用の TwigFunction を追加してみるのはどうでしょうか?
acxAura
投稿日時: 2022/10/12 13:34
対応状況: −−−
半人前
登録日: 2022/10/6
居住地:
投稿: 17
Re: Block/cart.twigの問題
ご回答ありがとうございます
Controller/CartController.phpにimage_routeという関数を作って、
そのreturn valueをCartServiceExtensionに作った

public function get_image_route(){
$images = ........
return $images;
}
に伝えたいですが、どうやってできるかわからないです...
伝えたら$imagesをBlock/cart.twigに{% set images = get_image_route()%}
に設定できますが...


これがCartControllerに作った関数です

$Carts = $this->cartService->getCarts();
        $doct = $this->getDoctrine()->getManager();
        $custom_images = array();
        $Custom_product = $this->customProductRepository->customProductFindByName();
        
        $Product = $doct->getRepository(Product::class)->find($Custom_product[0]->getId());
        foreach ($Carts as $Cart) {
            $items = $Cart->getCartItems();
            foreach($items as $item ){
                if($item->getProductClass()->getProduct()->getId() == $Product->getId()){
                    $custom = $item->getProductClass()->getCode();
                    
                    $custom = $doct->getRepository(CustomRing::class)->find($custom);
                    $ring = $doct->getRepository(Ring::class)->find($custom->getRingBaseId());
                    $upload_directory= $this->getParameter('uploads_directory'); 
                    $ring_shape = $ring->getRingShape();
                    $ring_type = $ring->getRingType();
                    $upload = $upload_directory.'/customRing/ring/'.$ring_shape.'/'.$ring_type.'/';
                    $images = glob($upload."*.{jpg,png,jpeg,JPG,JPEG,PNG}", GLOB_BRACE);
                    for($i=0;$i<count($images);$i++){
                        $aa = explode('save_image/', $images[$i]);
                        $images[$i] = $aa[1];
                    }
                    array_push($custom_images,$images[0]);
                }
            }
        }
        return $custom_images;


nanasess
投稿日時: 2022/10/17 10:33
対応状況: −−−
登録日: 2006/9/9
居住地:
投稿: 2313
Re: Block/cart.twigの問題
複雑な処理になりますので、このスペースで説明するのは難しいです。

インテグレートパートナーなどにご依頼ください
https://www.ec-cube.net/integrate/partner/
スレッド表示 | 新しいものから 前のトピック | 次のトピック | トップ


 



ログイン


EC-CUBE公式 Amazon Payプラグイン

統計情報

総メンバー数は88,699名です
総投稿数は109,943件です

投稿数ランキング

1
seasoft
7367
2
468
3217
3
AMUAMU
2712
4
nanasess
2313
5
umebius
2085
6
yuh
1819
7
h_tanaka
1638
8
red
1570
9
mcontact
1283
10
tsuji
958
11
fukap
907
12
shutta
835
13
tao_s
799
14 ramrun 789
15 karin 689
16 sumida 641
17
homan
633
18 DELIGHT 572
19
patapata
502
20
flealog
485


ネットショップの壺

EC-CUBEインテグレートパートナー

Copyright© EC-CUBE CO.,LTD. All Rights Reserved.