EC-CUBE / EC-CUBE/ec-cube

CartService::clear()カート削除後のセッションに保存するcart_keysが減らない問題

Open
#4,675 0 comments 0 reactions 0 assignees View on GitHub
bug:Low
Dominant language
PHP
Stars
788
Forks
719
Avg merge
3d 20h
Merged PRs (30d)
45

Description

## 概要(Overview)
ユーザーがカートを複数所持している状態でCartService::clearを実行した際にCartEntityは削除されるが、
sessionのカートキーが減らないために2回目以降のclearメソッド内のgetCartにてCartオブジェクトが取得できずnullになる。

結果、2回目以降の削除処理が行えない。

## 期待する内容(Expect) or 要望 (Requirement)
今の所商品追加や購入処理の時に整合性を保ってる???
clearメソッド実行後のcarts_keyを入れ直す処理の際に、削除したカートのカートキーをセッションから削除して欲しい。

## 再現手順(Procedure)
```php
public function removeAllCartItems()
{
$Carts = $this->cartService->getCarts();
dump($Carts);
$cartKeys = $this->session->get('cart_keys', []);
dump($cartKeys);

$this->cartService->clear();

$Carts = $this->cartService->getCarts();
dump($Carts);
$cartKeys = $this->session->get('cart_keys', []);
dump($cartKeys);
}
```

```
array:2 [▼
0 => Cart {#1317 ▼
-id: 286
-cart_key: "3_1"
}
1 => Cart {#1333 ▼
-id: 287
-cart_key: "3_2"
}
]
array:2 [▼
0 => "3_1"
1 => "3_2"
]
array:1 [▼
0 => Cart {#1333 ▼
-id: 287
-cart_key: "3_2"
}
]
array:2 [▼
0 => "3_1"
1 => "3_2"
]
```

### 環境 (environment)
+ EC-CUBE: 4.0.3
+ PHP: 7.2.2

Contributor guide

Open the contributing guide

Research direction

Start by locating CartService::clear(), getCart(), and the session handling for cart_keys, then compare the cart entities returned before and after clear(). Reproduce the two-cart case from removeAllCartItems() and verify that the session no longer contains the key for the deleted cart and that subsequent clearing can still retrieve the remaining cart.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.