LemonStand Documentation

shop:onBeforeProductFileAdded event

The shop:onBeforeProductFileAdded event is triggered before a file is added to a product on the Product Details page. Inside the event handler you can validate the uploaded file and trigger an exception if it is needed. Please read this article to learn about implementing the file uploading on the product details page. The event handler should accept two parameters: the product object (Shop_Product) and the file object (Db_File).

Event handler example:

public function subscribeEvents()
{
  Backend::$events->addEvent('shop:onAfterProductFileAdded', $this, 'before_file_added');
}
 
public function before_file_added($product, $new_file)
{
  if ($product->list_uploaded_files()->count >= 3)
    throw new Phpr_ApplicationException('You cannot add more then 3 files');
}

Next: shop:onAfterProductFileAdded event
Previous: shop:onExtendProductsToolbar event
Return to Handling LemonStand events