public function previewAction()
 {
     $id = $this->getParam("id");
     $product = CoreShopProduct::getById($id);
     $this->disableLayout();
     if ($product instanceof $product) {
         $this->view->product = $product;
     } else {
         throw new \Exception(sprintf("Product with id %s not found", $id));
     }
 }
 public function addAction()
 {
     $product_id = $this->getParam("product", null);
     $amount = $this->getParam("amount", 1);
     $product = CoreShopProduct::getById($product_id);
     $isAllowed = true;
     $result = Plugin::getEventManager()->trigger('cart.preAdd', $this, array("product" => $product, "cart" => $this->cart, "request" => $this->getRequest()), function ($v) {
         return is_bool($v);
     });
     if ($result->stopped()) {
         $isAllowed = $result->last();
     }
     if ($isAllowed) {
         if ($product instanceof CoreShopProduct && $product->getEnabled() && $product->getAvailableForOrder()) {
             $item = $this->cart->addItem($product, $amount);
             Plugin::getEventManager()->trigger('cart.postAdd', $this, array("request" => $this->getRequest(), "product" => $product, "cart" => $this->cart, "cartItem" => $item));
             $this->_helper->json(array("success" => true, "cart" => $this->cart->toArray()));
         }
     } else {
         $this->_helper->json(array("success" => false, "message" => 'not allowed'));
     }
     $this->_helper->json(array("success" => false, "cart" => $this->cart->toArray()));
 }