Example #1
0
 /**
  * product shown in frontend
  * @param Event $event
  * @param File $file
  * @param View $view
  */
 public function onProductPrepare($event, $file, View $view)
 {
     static $products;
     if (!$products) {
         $products = [];
     }
     if (!empty($file->id) && $file->get('cart_active')) {
         if (!($product = Product::where(['item_id = ?', 'item_model = ?'], [$file->id, 'Bixie\\Download\\Model\\File'])->first())) {
             $product = Product::createNew(['item_id' => $file->id, 'item_model' => 'Bixie\\Download\\Model\\File']);
         }
         $file->product = $product;
         $products[$file->id] = $product;
         $view->script('bixie-cart');
         $view->data('$cart', ['products' => $products, 'periods' => self::$periods]);
     }
 }