0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

カートの中にある商品を全て削除する

Posted at

商品をいっぱい入れたけど、カートの中を空にしたい!
eccube4ではデフォルトではカートを空にする機能はないので実装する必要があります。

CartController.php
declare(strict_types=1);
namespace Customize\Controller;

use Eccube\Controller\AbstractController;
use Eccube\Service\CartService;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Annotation\Route;

class CartController extends AbstractController
{
    protected $cartService;

    public function __construct(CartService $cartService)
    {
        $this->cartService = $cartService;
    }

    /**
     * カートの中にある商品を全て削除する
     * @Route("/cart/clear", name="cart_clear")
     */
    public function clear(): RedirectResponse
    {
        $this->cartService->clear();

        return $this->redirectToRoute('cart');
    }
}

後はhtml書いてあげればおk

<a href="{{ path('cart_clear') }}">カートを空にする</a>
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?