public function basketMergeProduct(BasketInterface $basket, ProductInterface $product, BasketElementInterface $newBasketElement)
    {
        $event = new AddBasketElementEvent($basket, $newBasketElement, $product, $this);
        $this->getEventDispatcher()->dispatch(BasketEvents::PRE_MERGE_PRODUCT, $event);

        if (!$basket->hasProduct($product)) {
            return false;
        }

        $basketElement = $basket->getElement($product);
        if (!$basketElement) {
            throw new \RuntimeException('no basket element related to product.id : %s', $product->getId());
        }

        $basketElement->setQuantity($basketElement->getQuantity() + $newBasketElement->getQuantity());

        $this->updateComputationPricesFields($basket, $basketElement, $product);

        $event = new AddBasketElementEvent($basket, $basketElement, $product, $this);
        $this->getEventDispatcher()->dispatch(BasketEvents::POST_MERGE_PRODUCT, $event);

        return $event->getBasketElement();
    }
public function basketMergeProduct(BasketInterface $basket, ProductInterface $product, BasketElementInterface $newBasketElement)
    {
        $event = new AddBasketElementEvent($basket, $newBasketElement, $product, $this);
        $this->getEventDispatcher()->dispatch(BasketEvents::PRE_MERGE_PRODUCT, $event);

        if (!$basket->hasProduct($product)) {
            return false;
        }

        $basketElement = $basket->getElement($product);
        if (!$basketElement) {
            throw new \RuntimeException('no basket element related to product.id : %s', $product->getId());
        }

        $basketElement->setQuantity($basketElement->getQuantity() + $newBasketElement->getQuantity());

        $this->updateComputationPricesFields($basket, $basketElement, $product);

        $event = new AddBasketElementEvent($basket, $basketElement, $product, $this);
        $this->getEventDispatcher()->dispatch(BasketEvents::POST_MERGE_PRODUCT, $event);

        return $event->getBasketElement();
    }
public function basketMergeProduct ( BasketInterface $ basket , ProductInterface $ product , BasketElementInterface $ newBasketElement ) { $ event = new AddBasketElementEvent ( $ basket , $ newBasketElement , $ product , $ this ) ; $ this -> getEventDispatcher ( ) -> dispatch ( BasketEvents :: PRE_MERGE_PRODUCT , $ event ) ; if ( ! $ basket -> hasProduct ( $ product ) ) { return false ; } $ basketElement = $ basket -> getElement ( $ product ) ; if ( ! $ basketElement ) { throw new \ RuntimeException ( 'no basket element related to product.id : %s' , $ product -> getId ( ) ) ; } $ basketElement -> setQuantity ( $ basketElement -> getQuantity ( ) + $ newBasketElement -> getQuantity ( ) ) ; $ this -> updateComputationPricesFields ( $ basket , $ basketElement , $ product ) ; $ event = new AddBasketElementEvent ( $ basket , $ basketElement , $ product , $ this ) ; $ this -> getEventDispatcher ( ) -> dispatch ( BasketEvents :: POST_MERGE_PRODUCT , $ event ) ; return $ event -> getBasketElement ( ) ; }
Merge a product with another when the product is already present into the basket.


@param \Sonata\Component\Basket\BasketInterface        $basket
@param \Sonata\Component\Product\ProductInterface      $product
@param \Sonata\Component\Basket\BasketElementInterface $newBasketElement

@throws \RuntimeException

@return bool|\Sonata\Component\Basket\BasketElementInterface
Merge a product with another when the product is already present into the basket .