private function isTransactionUpdated(Cart $cart)
    {
        if (false === $this->session->has('transaction-id')) {
            return false;
        }

        /** @var TransactionRepository $transactionRepository */
        $transactionRepository = $this->manager->getRepository('EcommerceBundle:Transaction');

        /** @var Order $order */
        $transaction = $transactionRepository->find($this->session->get('transaction-id'));

        /** @var ArrayCollection $cartItems */
        $cartItems = $cart->getItems();
        /** @var ArrayCollection $orderItems */
        $productPurchases = $transaction->getItems();

        if ($cartItems->count() !== $productPurchases->count()) {
            return false;
        }

        for ($i=0; $i<$cartItems->count(); $i++) {
            /** @var CartItem $cartItem */
            $cartItem = $cartItems[$i];
            /** @var OrderItem $orderItem */
            $productPurchase = $productPurchases[$i];

            if ($cartItem->getProduct()->getId() !== $productPurchase->getProduct()->getId() ||
                $cartItem->getQuantity() !== $productPurchase->getQuantity()) {
                return false;
            }
        }

        return true;
    }
private function isTransactionUpdated(Cart $cart)
    {
        if (false === $this->session->has('transaction-id')) {
            return false;
        }

        /** @var TransactionRepository $transactionRepository */
        $transactionRepository = $this->manager->getRepository('EcommerceBundle:Transaction');

        /** @var Order $order */
        $transaction = $transactionRepository->find($this->session->get('transaction-id'));

        /** @var ArrayCollection $cartItems */
        $cartItems = $cart->getItems();
        /** @var ArrayCollection $orderItems */
        $productPurchases = $transaction->getItems();

        if ($cartItems->count() !== $productPurchases->count()) {
            return false;
        }

        for ($i=0; $i<$cartItems->count(); $i++) {
            /** @var CartItem $cartItem */
            $cartItem = $cartItems[$i];
            /** @var OrderItem $orderItem */
            $productPurchase = $productPurchases[$i];

            if ($cartItem->getProduct()->getId() !== $productPurchase->getProduct()->getId() ||
                $cartItem->getQuantity() !== $productPurchase->getQuantity()) {
                return false;
            }
        }

        return true;
    }
private function isTransactionUpdated ( Cart $ cart ) { if ( false === $ this -> session -> has ( 'transaction-id' ) ) { return false ; } /** @var TransactionRepository $transactionRepository */ $ transactionRepository = $ this -> manager -> getRepository ( 'EcommerceBundle:Transaction' ) ; /** @var Order $order */ $ transaction = $ transactionRepository -> find ( $ this -> session -> get ( 'transaction-id' ) ) ; /** @var ArrayCollection $cartItems */ $ cartItems = $ cart -> getItems ( ) ; /** @var ArrayCollection $orderItems */ $ productPurchases = $ transaction -> getItems ( ) ; if ( $ cartItems -> count ( ) !== $ productPurchases -> count ( ) ) { return false ; } for ( $ i = 0 ; $ i < $ cartItems -> count ( ) ; $ i ++ ) { /** @var CartItem $cartItem */ $ cartItem = $ cartItems [ $ i ] ; /** @var OrderItem $orderItem */ $ productPurchase = $ productPurchases [ $ i ] ; if ( $ cartItem -> getProduct ( ) -> getId ( ) !== $ productPurchase -> getProduct ( ) -> getId ( ) || $ cartItem -> getQuantity ( ) !== $ productPurchase -> getQuantity ( ) ) { return false ; } } return true ; }
Compare current cart with current transaction

@param CartInterface $cart

@return boolean
Compare current cart with current transaction