Code Duplication    Length = 22-24 lines in 2 locations

src/Handler/PutOptionBasedConfigurableItemToCartHandler.php 1 location

@@ 77-100 (lines=24) @@
74
    /**
75
     * @param PutOptionBasedConfigurableItemToCart $putConfigurableItemToCart
76
     */
77
    public function handle(PutOptionBasedConfigurableItemToCart $putConfigurableItemToCart)
78
    {
79
        $cart = $this->cartRepository->findOneBy(['tokenValue' => $putConfigurableItemToCart->orderToken()]);
80
81
        Assert::notNull($cart, 'Cart has not been found');
82
83
        /** @var ProductInterface $product */
84
        $product = $this->productRepository->findOneByCode($putConfigurableItemToCart->product());
85
86
        Assert::notNull($product, 'Product has not been found');
87
88
        $productVariant = $this->getVariant($putConfigurableItemToCart->options(), $product);
89
90
        /** @var OrderItemInterface $cartItem */
91
        $cartItem = $this->cartItemFactory->createForCart($cart);
92
        $cartItem->setVariant($productVariant);
93
        $this->orderItemModifier->modify($cartItem, $putConfigurableItemToCart->quantity());
94
95
        $cart->addItem($cartItem);
96
97
        $this->orderProcessor->process($cart);
98
99
        $this->manager->persist($cart);
100
    }
101
102
    /**
103
     * @param array $options

src/Handler/PutVariantBasedConfigurableItemToCartHandler.php 1 location

@@ 75-96 (lines=22) @@
72
    /**
73
     * @param PutVariantBasedConfigurableItemToCart $putConfigurableItemToCart
74
     */
75
    public function handle(PutVariantBasedConfigurableItemToCart $putConfigurableItemToCart)
76
    {
77
        $cart = $this->cartRepository->findOneBy(['tokenValue' => $putConfigurableItemToCart->orderToken()]);
78
79
        Assert::notNull($cart, 'Cart has not been found');
80
81
        /** @var ProductInterface $product */
82
        $productVariant = $this->productVariantRepository->findOneByCodeAndProductCode($putConfigurableItemToCart->productVariant(), $putConfigurableItemToCart->product());
83
84
        Assert::notNull($productVariant, 'Product variant has not been found');
85
86
        /** @var OrderItemInterface $cartItem */
87
        $cartItem = $this->cartItemFactory->createForCart($cart);
88
        $cartItem->setVariant($productVariant);
89
        $this->orderItemModifier->modify($cartItem, $putConfigurableItemToCart->quantity());
90
91
        $cart->addItem($cartItem);
92
93
        $this->orderProcessor->process($cart);
94
95
        $this->manager->persist($cart);
96
    }
97
}
98