Sonata\Component\Basket\BasketInterface::getElement PHP Method

getElement() public method

return the BasketElement depends on the $product or the position from the element stacks.
public getElement ( Sonata\Component\Product\ProductInterface $product ) : Sonata\Component\Basket\BasketElementInterface
$product Sonata\Component\Product\ProductInterface
return Sonata\Component\Basket\BasketElementInterface
    public function getElement(ProductInterface $product);

Usage Example

 /**
  * 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
  */
 public function basketMergeProduct(BasketInterface $basket, ProductInterface $product, BasketElementInterface $newBasketElement)
 {
     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);
     return $basketElement;
 }
All Usage Examples Of Sonata\Component\Basket\BasketInterface::getElement