バージョン選択

フォーラム

メニュー

オンライン状況

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

サイト内検索

質問 > フロント機能 > カート情報の取得箇所について

フロント機能

新規スレッドを追加する

スレッド表示 | 新しいものから 前のトピック | 次のトピック | 下へ
投稿者 スレッド
yoshiaki
投稿日時: 2016/6/29 13:45
対応状況: −−−
半人前
登録日: 2016/6/22
居住地:
投稿: 11
カート情報の取得箇所について
初歩的なことなのかもしれませんが、まだ勉強し始めでいろいろと調べたりソースを追いながらになってしまうため認識の誤り等があった場合はヒントなどをいただければと思っています。

商品を選択するとカートに、選択した商品が入っているかと思うのですが
その商品の情報というのはセッションが持っているという形でしょうか?

src\Eccube\ControllerProviderのFrontControllerProvider.phpから
// cart
$c->match('/cart', '\Eccube\Controller\CartController::index')->bind('cart');
$c->post('/cart/add', '\Eccube\Controller\CartController::add')->bind('cart_add');
$c->put('/cart/up/{productClassId}', '\Eccube\Controller\CartController::up')->bind('cart_up')->assert('productClassId', '\d+');
$c->put('/cart/down/{productClassId}', '\Eccube\Controller\CartController::down')->bind('cart_down')->assert('productClassId', '\d+');
// setquantity deprecated since 3.0.0, to be removed in 3.1
$c->put('/cart/setQuantity/{productClassId}/{quantity}', '\Eccube\Controller\CartController::setQuantity')->bind('cart_set_quantity')->assert('productClassId', '\d+')->assert('quantity', '\d+');
$c->put('/cart/remove/{productClassId}', '\Eccube\Controller\CartController::remove')->bind('cart_remove')->assert('productClassId', '\d+');
$c->match('/cart/buystep', '\Eccube\Controller\CartController::buystep')->bind('cart_buystep');

このようにカートに関する部分を確認し、CartController.phpの各メソッドが呼ばれるということがわかり
カート画面を見る場合はcontrollerのindexメソッドということも理解ができました。

indexメソッドの最初で
$Cart = $app['eccube.service.cart']->getCart();
このように書かれているため、
CartService.phpのgetCartメソッドを呼び出し処理が行われるかと思います。

この、CartService.phpのコンストラクタ部分にて
$this->app = $app;
$this->session = $app['session'];
$this->entityManager = $app['orm.em'];
if ($this->session->has('cart')) {
$this->cart = $this->session->get('cart');
} else {
$this->cart = new \Eccube\Entity\Cart();
}
$this->loadProductClassFromCart();
$this->BaseInfo = $app['eccube.repository.base_info']->get();

この部分でセッションからカートの情報をとってきていると思うのですが認識はあっているでしょうか?

お願いいたします。
tacky
投稿日時: 2016/6/29 15:21
対応状況: −−−
長老
登録日: 2015/10/3
居住地: Tokyo
投稿: 277
Re: カート情報の取得箇所について
上記認識であっていると思います。

補足としましては。

src/Eccube/Controller/ProductController.php
270行目あたりにカートに商品をセットする記述があります。
$app['eccube.service.cart']->addProduct($addCartData['product_class_id'], $addCartData['quantity'])->save();

src/Eccube/Service/CartService.phpの
addProductで商品の在庫や支払い・商品種別等などをチェックした後、
function save()でセッションにセットしています。
return $this->session->set('cart', $this->cart);

その後おっしゃるとおりgetCart()で取得しています。
yoshiaki
投稿日時: 2016/6/29 15:40
対応状況: −−−
半人前
登録日: 2016/6/22
居住地:
投稿: 11
Re: カート情報の取得箇所について
認識としてはあっていたようでほっとしております。

補足の部分もこちらから聞いていたわけではないのに
ご丁寧に教えてくださりありがとうございます。
スレッド表示 | 新しいものから 前のトピック | 次のトピック | トップ


 



ログイン


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

統計情報

総メンバー数は88,904名です
総投稿数は110,006件です

投稿数ランキング

1
seasoft
7367
2
468
3217
3
AMUAMU
2712
4
nanasess
2313
5
umebius
2085
6
yuh
1819
7
h_tanaka
1646
8
red
1570
9
mcontact
1296
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.