CartService::clear()カート削除後のセッションに保存するcart_keysが減らない問題
- 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
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