public function execute()
 {
     $id = waRequest::get('id', null, waRequest::TYPE_INT);
     $data = $this->getData($id);
     if (!isset($data['product_id']) && $id) {
         $data['product_id'] = $this->pages_model->select('product_id')->where('id=' . (int) $id)->fetchField('product_id');
     }
     $product = $this->getProduct($data['product_id']);
     // check rights
     if (!$this->product_model->checkRights($product)) {
         throw new waException(_w("Access denied"));
     }
     if ($id) {
         if (!$this->pages_model->update($id, $data)) {
             $this->errors[] = _w('Error saving product page');
             return;
         }
     } else {
         $id = $this->pages_model->add($data);
         if (!$id) {
             $this->errors[] = _w('Error saving product page');
             return;
         }
     }
     $page = $this->pages_model->getById($id);
     $page['name'] = htmlspecialchars($data['name']);
     $page['frontend_url'] = rtrim(wa()->getRouteUrl('/frontend/productPage', array('product_url' => $product['url'], 'page_url' => ''), true), '/');
     $page['preview_hash'] = $this->pages_model->getPreviewHash();
     $page['url_escaped'] = htmlspecialchars($data['url']);
     $this->response = $page;
 }
 public function execute()
 {
     $id = $this->get('id', true);
     $pages_model = new shopProductPagesModel();
     $page = $pages_model->getById($id);
     if (!$page) {
         throw new waAPIException('invalid_param', 'Product page not found', 404);
     }
     $this->response = $page;
 }
 public function execute()
 {
     $id = waRequest::post('id', null, waRequest::TYPE_INT);
     if (!$id) {
         throw new waException(_w("Unknown page"));
     }
     $product_pages_model = new shopProductPagesModel();
     $page = $product_pages_model->getById($id);
     if (!$page) {
         throw new waException(_w("Unknown page"));
     }
     // check rights
     $product_model = new shopProductModel();
     if (!$product_model->checkRights($page['product_id'])) {
         throw new waException(_w("Access denied"));
     }
     $product_pages_model->delete($id);
 }
 public function execute()
 {
     $id = waRequest::post('id', null, waRequest::TYPE_INT);
     if (!$id) {
         throw new waException(_w("Unknown page"));
     }
     $before_id = waRequest::post('before_id', null, waRequest::TYPE_INT);
     if ($id == $before_id) {
         $this->errors[] = _w("Page couldn't be inserted before itself");
     }
     $product_page_model = new shopProductPagesModel();
     $page = $product_page_model->getById($id);
     if (!$page) {
         throw new waException(_w("Unknown page"));
     }
     $product_model = new shopProductModel();
     if (!$product_model->checkRights($page['product_id'])) {
         throw new waException(_w("Access denied"));
     }
     if (!$product_page_model->move($id, $before_id)) {
         $this->errors[] = _w("Error when move");
     }
 }