検索キーワードを入力:

EC-cube:カゴの中ブロックに商品名や商品写真を表示させる

調べて出てきた情報が古かったので、Forumのramrun様をリスペクトしてここに覚え書きしときます。
元記事を読んで分からないときにだけお読み下さい。
あくまでもコピペ+改良版です。1系をお使いの方はフォーラムをご覧下さい。

ソース見にくいですがソース右上のクリップボードにコピーとか色々試して見て下さい。

/bloc/cart.tplブロックファイル

これもフォーラムのじゃちょっと動きがおかしかったので少し編集してます。
[sourcecode language=”php”]
<!–{*
* Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
*
* http://www.lockon.co.jp/
*}–>
<!–▼現在のカゴの中ここから–>
<div class="sb-base">

<!–★タイトル★–>
<h4><img src="<!–{$smarty.const.URL_DIR}–>img/side/title_cartin.jpg" alt="現在のカゴの中" /></h4>

<div class="sb-main">
<div class="sb-content">

<!–★商品点数★–>
<div><span class="fs10">商品数:<!–{$arrCartList.0.TotalQuantity|number_format|default:0}–>点</span></div>

<!–{if $arrCartList.0.TotalQuantity > 0}–>
<form name="form2" id="form2" method="post" action="<!–{$smarty.const.URL_DIR}–>frontparts/bloc/cart_delitem.php">
<input type="hidden" name="mode" value="delete" />
<input type="hidden" name="cart_no" value="" />
<!–{section name=cnt loop=$arrCartList}–>
<div style="margin-bottom:5px">
<!–★商品画像★–>
<div style="width:50px;float:left"><a href="<!–{$smarty.const.URL_DIR}–>cart/index.php">
//↓rewrited by chibiの覚え書き
<img src="<!–{$smarty.const.SITE_URL}–>resize_image.php?image=<!–{$arrCartList[cnt].img}–>&width=48&height=48" alt="<!–{$arrCartList[cnt].product_name|escape}–>" />
</a></div>

<div style="width:95px;float:right">
<!–★商品名★–>
<div style="color:#4a6fa6;font-size:14px">
<strong><!–{$arrCartList[cnt].product_name|escape}–></strong>
</div>

<!–★販売価格×数量★–>
<div style="text-align:right;font-size:12px">
<!–{$arrCartList[cnt].price|sfPreTax:$arrInfo.tax:$arrInfo.tax_rule|number_format|default:0}–>円×<!–{$arrCartList[cnt].quantity|escape}–>
<a href="<!–{$smarty.const.URL_DIR}–>frontparts/bloc/cart_delitem.php" onclick="fnFormModeSubmit(‘form2’, ‘delete’, ‘cart_no’, ‘<!–{$arrCartList[cnt].cart_no}–>’); return false;"><img src="<!–{$smarty.const.URL_DIR}–>img/contents/icon_delete.jpg" alt="この商品の購入を取り消す" /></a>
</div>
</div><br style="clear:both" />
</div>
<!–{/section}–>
</form>
<!–{/if}–>
<!–★区切り線★–>
<hr />
<!–★合計★–>
<div style="margin-bottom:5px;text-align:right">
<span class="redst"><span class="fs14">合計:<!–{$arrCartList.0.ProductsTotal|number_format|default:0}–>円</span></span>
</div>
<!–★カゴの中に商品がある場合にのみ表示★–>
<!–{if $arrCartList.0.TotalQuantity > 0 and $arrCartList.0.free_rule > 0}–>
<div style="margin-bottom:10px">
<span class="fs10">
<!–{if $arrCartList.0.deliv_free > 0}–>
送料手数料無料まであと<!–{$arrCartList.0.deliv_free|number_format|default:0}–>円(税込)です。
<!–{else}–>
現在、送料は「<span class="redst">無料</span>」です。
<!–{/if}–>
</span>
</div>
<!–{/if}–>
<!–★ボタン★–>
<div style="margin-top:5px;text-align:center">
<a href="<!–{$smarty.const.URL_DIR}–>cart/index.php" onmouseover="chgImg(‘<!–{$smarty.const.URL_DIR}–>img/side/button_cartin_on.gif’,’button_cartin’);" onmouseout="chgImg(‘<!–{$smarty.const.URL_DIR}–>img/side/button_cartin.gif’,’button_cartin’);"><img src="<!–{$smarty.const.URL_DIR}–>img/side/button_cartin.gif" alt="カゴの中を見る" name="button_cartin" /></a>
</div>
</div>
</div>
<div class="sb-bottom"></div>
</div>
<!–▲現在のカゴの中ここまで–>
[/sourcecode]

data/class/pages/frontparts/bloc/LC_Page_FrontParts_Bloc_Cart.php

フォーラムではeccube/html/frontparts/bloc/cart.phpとなっているファイルですが、2系ではdata/class/pages/frontparts/bloc/LC_Page_FrontParts_Bloc_Cart.phpこのファイルを編集。
編集する場所はここ!!のとこでw
[sourcecode language=”php”]
if (count($_SESSION[$objCart->key]) > 0){
// カート情報を取得
$arrCartList = $objCart->getCartList();

// カート内の商品ID一覧を取得
$arrAllProductID = $objCart->getAllProductID();
// 商品が1つ以上入っている場合には商品名称を取得
if (count($arrAllProductID) > 0){
$objQuery = new SC_Query();
$arrVal = array();
$sql = "";
//↓ここ!!!
$sql = "SELECT product_id,name,main_list_image FROM dtb_products WHERE product_id IN ( ?";
$arrVal = array($arrAllProductID[0]);
for($i = 1 ; $i < count($arrAllProductID) ; $i++){
$sql.= " ,? ";
array_push($arrVal, $arrAllProductID[$i]);
}
$sql.= " )";
//↓ここから!!!
$arrProduct_list = $objQuery->getAll($sql, $arrVal);

$item_list = array();
for($i = 0; $i < count($arrProduct_list); $i++){
$item_list[$arrProduct_list[$i][‘product_id’]][‘name’] = $arrProduct_list[$i][‘name’];
$item_list[$arrProduct_list[$i][‘product_id’]][‘main_list_image’] = $arrProduct_list[$i][‘main_list_image’];
}
for($i = 0; $i < count($arrCartList); $i++){
$arrCartList[$i][‘product_name’] = $item_list[$arrCartList[$i][‘id’][0]][‘name’];
$arrCartList[$i][‘img’] = $item_list[$arrCartList[$i][‘id’][0]][‘main_list_image’];
}
//↑ここまで!!!
}
// 店舗情報の取得
$arrInfo = $objSiteInfo->data;
// 購入金額合計
$ProductsTotal = $objCart->getAllProductsTotal($arrInfo);

// 合計個数
$TotalQuantity = $objCart->getTotalQuantity();[sourcecode=""]

// 送料無料までの金額
$arrCartList[0][‘ProductsTotal’] = $ProductsTotal;
$arrCartList[0][‘TotalQuantity’] = $TotalQuantity;
$deliv_free = $arrInfo[‘free_rule’] – $ProductsTotal;
$arrCartList[0][‘free_rule’] = $arrInfo[‘free_rule’];
$arrCartList[0][‘deliv_free’] = $deliv_free;

$objSubPage->arrCartList = $arrCartList;
//↓ここ!!!
$objSubPage->arrInfo = $arrInfo;
}
[/sourcecode]

/html/frontparts/bloc/cart_delitem.php

ファイルを新規に作成
[sourcecode language=”php”]
<?php

require_once("../../require.php");

$objCartSess = new SC_CartSession("", false);

switch($_POST[‘mode’]) {
case ‘up’:
$objCartSess->upQuantity($_POST[‘cart_no’]);
header("Location: " . URL_DIR);
break;
case ‘down’:
$objCartSess->downQuantity($_POST[‘cart_no’]);
header("Location: " . URL_DIR);
break;
case ‘delete’:
$objCartSess->delProduct($_POST[‘cart_no’]);
header("Location: " . URL_DIR);
break;
default:
header("Location: " . URL_DIR);
break;
}

?>
[/sourcecode]
以上で出来ると思います。
ちなみに、フォーラムに書いてある、eccube/html/products/list.phpとeccube/html/products/detail.phpは編集しなくてもいいと思ったので見てません。
というか、編集前にテストしたら全然問題ないので見てませんw

About Little

WordPressをいじくり倒して早10年。一人ぼっちでひたすらソースとにらめっこ厨。 有り難いことに、Welcart/WP e-commerce/WooCommerce/EC-Cube等で多数ECサイトを制作させていただいたけど、ふと気付いた、ちゃんと売れるのか。 効果的に売れるようにするためにはどうしたらいいのか。ということでお勉強を兼ねてECサイトも運営中。
2009年8月10日

Related Posts

0 comments found

Comments for: EC-cube:カゴの中ブロックに商品名や商品写真を表示させる

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です