This is the API docs for LemonStand V1, which has been discontinued. LemonStand is now a cloud based platform, available at lemonstand.com.

LemonStand API

shop:onBeforeAddToCart event

Triggered by Shop_Cart
Author LemonStand eCommerce Inc.

Event handler signature

public void event_onBeforeAddToCart(string $cart_name, Shop_Product $product, integer $quantity, array $options, array $extra_options, array $custom_data, array $bundle_data, array $master_bundle_data)
$cart_name string specifies the cart name.
$product Shop_Product specifies the product object.
$quantity integer specifies the cart item quantity.
$options array an array of product options.
$extra_options array an array of product extra options.
$custom_data array an associative array of custom field names and values.
$bundle_data array bundle data associated with the product.
$master_bundle_data array master bundle data associated with the product.
Triggered before a product is added to the cart. You can use the event handler to perform custom validation when a customer clicks the Add to Cart button. Inside the handler you can trigger an exception in order to prevent adding a product to the cart. Usage example:
public function subscribeEvents()
{
  Backend::$events->addEvent('shop:onBeforeAddToCart', $this, 'before_add');
}

public function before_add($cart_name, $product, $quantity, $options, $extra_options, $custom_data, $bundle_data, $master_bundle_data)
{
  traceLog('Add '.$product->name);
  if ($product->sku == '123')
    throw new Phpr_ApplicationException('You cannot add this product to the cart!');
}