Sonata\Component\Basket\BasketElementInterface::setOption PHP Method

setOption() public method

Define the option value.
public setOption ( string $name, mixed $value )
$name string
$value mixed
    public function setOption($name, $value);

Usage Example

 /**
  * Returns true if the basket element is still valid
  *
  * @param  \Sonata\Component\Basket\BasketInterface             $basket
  * @param  \Sonata\Component\Product\ProductInterface           $product
  * @param  \Sonata\Component\Basket\BasketElementInterface      $basketElement
  * @return bool|\Sonata\Component\Basket\BasketElementInterface
  */
 public function basketAddProduct(BasketInterface $basket, ProductInterface $product, BasketElementInterface $basketElement)
 {
     if ($basket->hasProduct($product)) {
         return false;
     }
     $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);
     return $basketElement;
 }
All Usage Examples Of Sonata\Component\Basket\BasketElementInterface::setOption