public function basketAddProduct(BasketInterface $basket, ProductInterface $product, BasketElementInterface $basketElement)
{
$event = new AddBasketElementEvent($basket, $basketElement, $product, $this);
$this->getEventDispatcher()->dispatch(BasketEvents::PRE_ADD_PRODUCT, $event);
if ($basket->hasProduct($product)) {
return false;
}
if ($product->isMaster() && $this->hasVariations($product)) {
throw new InvalidProductException(sprintf("You can't add '%s' to the basket as it is a master product with variations.", $product->getSku()));
}
$basketElementOptions = $product->getOptions();
// add the default product options to the basket element
if (is_array($basketElementOptions) && !empty($basketElementOptions)) {
foreach ($basketElementOptions as $option => $value) {
$basketElement->setOption($option, $value);
}
}
$this->updateComputationPricesFields($basket, $basketElement, $product);
$basket->addBasketElement($basketElement);
$event = new AddBasketElementEvent($basket, $basketElement, $product, $this);
$this->getEventDispatcher()->dispatch(BasketEvents::POST_ADD_PRODUCT, $event);
return $event->getBasketElement();
}