EC-CUBE] 4.0.4
[レンタルサーバ] AWS
[OS] Linux
[PHP] 7.3.14
[データベース] MySQL 5.7.28
[WEBサーバ] Apache/2.4.25
[ブラウザ] Chrome
[現象]
カート画面でセレクトボックスなどを使って
商品単位での商品の個数を変更したいのですが
バック側の処理は、
下記のように
CartController.phpの
handleCartItem
を変更するだけで可能でしょうか?
宜しくお願いいたします
/**
* カート明細の加算/減算/削除を行う.
*
* - 加算
* - 明細の個数を1増やす
* - 減算
* - 明細の個数を1減らす
* - 個数が0になる場合は、明細を削除する
* - 削除
* - 明細を削除する
*
* @Route(
* path="/cart/{operation}/{productClassId}/{changeAmount},
* name="cart_handle_item",
* methods={"PUT"},
* requirements={
* "operation": "up|down|remove|change",
* "productClassId": "\d+",
* "changeAmount": "\d+"
* }
* )
*/
public function handleCartItem($operation, $productClassId,$chanheAmount)
{
log_info('カート明細操作開始', ['operation' => $operation, 'product_class_id' => $productClassId]);
$this->isTokenValid();
/** @var ProductClass $ProductClass */
$ProductClass = $this->productClassRepository->find($productClassId);
if (is_null($ProductClass)) {
log_info('商品が存在しないため、カート画面へredirect', ['operation' => $operation, 'product_class_id' => $productClassId]);
return $this->redirectToRoute('cart');
}
// 明細の増減・削除
switch ($operation) {
case 'up':
$this->cartService->addProduct($ProductClass, 1);
break;
case 'down':
$this->cartService->addProduct($ProductClass, -1);
break;
case 'remove':
$this->cartService->removeProduct($ProductClass);
break;
//個数変更商品単位個数指定変更
case 'change':
$nowAmount = "現在のカートの数";
$differenceAmount = $nowAmount - $chanheAmount;
$this->cartService->addProduct($ProductClass,$differenceAmount);
break;
//個数変更商品単位個数指定変更
}
// カートを取得して明細の正規化を実行
$Carts = $this->cartService->getCarts();
$this->execPurchaseFlow($Carts);
log_info('カート演算処理終了', ['operation' => $operation, 'product_class_id' => $productClassId]);
return $this->redirectToRoute('cart');
}