src/Frontend/Modules/Commerce/Ajax/UpdateProductCart.php
/**
     * Add or update the product in our cart.
     */
Add or update the product in our cart.
Add or update the product in our cart .
private function updateProductCart(): ?CartValue
    {
        $cartValueId = $this->getRequest()->request->getInt('cartValueId');
        if (!$amount = $this->getRequest()->request->getInt('amount')) {
            return null;
        }
        if ($amount < 1) {
            $amount = 1;
        }
        $cartValueRepository = $this->getCartValueRepository();
        if (!$cartValue = $cartValueRepository->getByCartAndId($this->cart, $cartValueId)) {
            return null;
        }
        $cartValue->setQuantity($amount);
        $cartValue->setTotal($cartValue->getPrice()->multiply($amount));
removeByIdAndCart($cartValue->getId(), $this->cart);
        return $cartValue;
    }
private function updateProductCart ( ) : ? CartValue { $ cartValueId = $ this -> getRequest ( ) -> request -> getInt ( 'cartValueId' ) ; if ( ! $ amount = $ this -> getRequest ( ) -> request -> getInt ( 'amount' ) ) { return null ; } if ( $ amount < 1 ) { $ amount = 1 ; } $ cartValueRepository = $ this -> getCartValueRepository ( ) ; if ( ! $ cartValue = $ cartValueRepository -> getByCartAndId ( $ this -> cart , $ cartValueId ) ) { return null ; } $ cartValue -> setQuantity ( $ amount ) ; $ cartValue -> setTotal ( $ cartValue -> getPrice ( ) -> multiply ( $ amount ) ) ; return $ cartValue ; }
Add or update the product in our cart.
Add or update the product in our cart .
// Retrieve our product //        $cartValueRepository-> //        $cartValue->save // Remove the value //        $this->cart->removeValue($cartValue); //        $cartValueRepository->removeByIdAndCart($cartValue->getId(), $this->cart);