1717use Magento \Quote \Api \Data \CartInterface ;
1818use Magento \Quote \Api \Data \CartItemInterface ;
1919use Magento \Quote \Model \Quote \Item ;
20+ use Psr \Log \LoggerInterface ;
2021
2122class CartQuantityValidator implements CartQuantityValidatorInterface
2223{
@@ -32,12 +33,14 @@ class CartQuantityValidator implements CartQuantityValidatorInterface
3233 * @param StockRegistryInterface $stockRegistry
3334 * @param Config $config
3435 * @param ProductRepositoryInterface $productRepository
36+ * @param LoggerInterface $logger
3537 */
3638 public function __construct (
3739 private readonly CartItemRepositoryInterface $ cartItemRepository ,
38- private readonly StockRegistryInterface $ stockRegistry ,
39- private readonly Config $ config ,
40- private readonly ProductRepositoryInterface $ productRepository
40+ private readonly StockRegistryInterface $ stockRegistry ,
41+ private readonly Config $ config ,
42+ private readonly ProductRepositoryInterface $ productRepository ,
43+ private readonly LoggerInterface $ logger
4144 ) {
4245 }
4346
@@ -69,8 +72,8 @@ public function validateFinalCartQuantities(CartInterface $customerCart, CartInt
6972 $ sku = $ this ->getSkuFromItem ($ customerCartItem );
7073 $ product = $ this ->getProduct ((int ) $ customerCartItem ->getProduct ()->getId ());
7174 $ isAvailable = $ customerCartItem ->getChildren ()
72- ? $ this ->validateCompositeProductQty ($ guestCartItem , $ customerCartItem )
73- : $ this ->validateProductQty ($ product , $ sku , $ guestCartItem ->getQty (), $ customerCartItem ->getQty ());
75+ ? $ this ->isCompositeProductQtyValid ($ guestCartItem , $ customerCartItem )
76+ : $ this ->isProductQtyValid ($ product , $ sku , $ guestCartItem ->getQty (), $ customerCartItem ->getQty ());
7477
7578 if ($ this ->config ->getCartMergePreference () === Config::CART_PREFERENCE_GUEST ) {
7679 $ this ->safeDeleteCartItem ((int ) $ customerCart ->getId (), (int ) $ customerCartItem ->getItemId ());
@@ -126,7 +129,7 @@ private function getCurrentCartItemQty(float $guestQty, float $customerQty): flo
126129 * @param float $customerQty
127130 * @return bool
128131 */
129- private function validateProductQty (
132+ private function isProductQtyValid (
130133 ProductInterface $ product ,
131134 string $ sku ,
132135 float $ guestQty ,
@@ -151,7 +154,7 @@ private function validateProductQty(
151154 * @return bool
152155 * @throws NoSuchEntityException
153156 */
154- private function validateCompositeProductQty (
157+ private function isCompositeProductQtyValid (
155158 Item $ guestCartItem ,
156159 Item $ customerCartItem
157160 ): bool {
@@ -164,7 +167,7 @@ private function validateCompositeProductQty(
164167 $ customerItemQty = $ customerCartItem ->getQty () * $ customerChildItem ->getQty ();
165168 $ guestItemQty = $ guestCartItem ->getQty () * $ guestChildItems [$ sku ]->getQty ();
166169
167- if (!$ this ->validateProductQty ($ childProduct , $ sku , $ guestItemQty , $ customerItemQty )) {
170+ if (!$ this ->isProductQtyValid ($ childProduct , $ sku , $ guestItemQty , $ customerItemQty )) {
168171 return false ;
169172 }
170173 }
@@ -210,8 +213,8 @@ private function safeDeleteCartItem(int $cartId, int $itemId): void
210213 {
211214 try {
212215 $ this ->cartItemRepository ->deleteById ($ cartId , $ itemId );
213- } catch (NoSuchEntityException |CouldNotSaveException $ e ) { // phpcs:ignore
214- // Optionally log the error.
216+ } catch (NoSuchEntityException |CouldNotSaveException $ e ) {
217+ $ this -> logger -> error ( $ e );
215218 }
216219 }
217220}
0 commit comments