Example #1
0
 /**
  * @param int $product_id
  * @param int $new_product_id
  * @return null
  */
 private function _clone_product_layout($product_id, $new_product_id)
 {
     if (!has_value($product_id) && !has_value($new_product_id)) {
         return null;
     }
     //clone layout for the product if present
     $lm = new ALayoutManager();
     $pages = $lm->getPages('pages/product/product', 'product_id', (int) $product_id);
     if (count($pages) && has_value($pages[0]['page_id'])) {
         $tmpl_id = $this->config->get('config_storefront_template');
         $src_layout_id = $pages[0]['layout_id'];
         $src_page_id = $pages[0]['page_id'];
         //create instance for source layout
         $lm = new ALayoutManager($tmpl_id, $src_page_id, $src_layout_id);
         //create new page
         $page_info = array('controller' => 'pages/product/product', 'key_param' => 'product_id', 'key_value' => $new_product_id);
         $product_info = $this->getProductDescriptions($new_product_id);
         if ($product_info) {
             foreach ($product_info as $language_id => $description) {
                 if (!has_value($language_id)) {
                     continue;
                 }
                 $page_info['page_descriptions'][$language_id] = $description;
             }
         }
         //save new page
         $new_page_id = $lm->savePage($page_info);
         $default_language_id = $this->language->getDefaultLanguageID();
         $layout_name = 'Product: ' . $product_info[$default_language_id]['name'];
         //create instance for new layout
         $lm = new ALayoutManager($tmpl_id, $new_page_id, '');
         $lm->clonePageLayout($src_layout_id, '', $layout_name);
     }
 }
 public function save()
 {
     if ($this->request->is_GET()) {
         $this->redirect($this->html->getSecureURL('catalog/product_layout'));
     }
     $page_controller = 'pages/product/product';
     $page_key_param = 'product_id';
     $product_id = $this->request->post['product_id'];
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->loadLanguage('catalog/product');
     if (!has_value($product_id)) {
         unset($this->session->data['success']);
         $this->session->data['warning'] = $this->language->get('error_product_not_found');
         $this->redirect($this->html->getSecureURL('catalog/product/update'));
     }
     // need to know if unique page existing
     $post_data = $this->request->post;
     $tmpl_id = $post_data['tmpl_id'];
     $layout = new ALayoutManager();
     $pages = $layout->getPages($page_controller, $page_key_param, $product_id);
     if (count($pages)) {
         $page_id = $pages[0]['page_id'];
         $layout_id = $pages[0]['layout_id'];
     } else {
         $page_info = array('controller' => $page_controller, 'key_param' => $page_key_param, 'key_value' => $product_id);
         $this->loadModel('catalog/product');
         $product_info = $this->model_catalog_product->getProductDescriptions($product_id);
         if ($product_info) {
             foreach ($product_info as $language_id => $description) {
                 if (!(int) $language_id) {
                     continue;
                 }
                 $page_info['page_descriptions'][$language_id] = $description;
             }
         }
         $page_id = $layout->savePage($page_info);
         $layout_id = '';
         // need to generate layout name
         $default_language_id = $this->language->getDefaultLanguageID();
         $post_data['layout_name'] = 'Product: ' . $product_info[$default_language_id]['name'];
     }
     //create new instance with specific template/page/layout data
     $layout = new ALayoutManager($tmpl_id, $page_id, $layout_id);
     if (has_value($post_data['layout_change'])) {
         //update layout request. Clone source layout
         $layout->clonePageLayout($post_data['layout_change'], $layout_id, $post_data['layout_name']);
         $this->session->data['success'] = $this->language->get('text_success_layout');
     } else {
         //save new layout
         $layout_data = $layout->prepareInput($post_data);
         if ($layout_data) {
             $layout->savePageLayout($layout_data);
             $this->session->data['success'] = $this->language->get('text_success_layout');
         }
     }
     $this->redirect($this->html->getSecureURL('catalog/product_layout', '&product_id=' . $product_id));
 }
 public function save()
 {
     if ($this->request->server['REQUEST_METHOD'] != 'POST') {
         $this->redirect($this->html->getSecureURL('catalog/manufacturer_layout'));
     }
     $page_controller = 'pages/product/manufacturer';
     $page_key_param = 'manufacturer_id';
     $manufacturer_id = (int) $this->request->post['manufacturer_id'];
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->loadLanguage('catalog/manufacturer');
     if (!has_value($manufacturer_id)) {
         $this->session->data['error'] = $this->language->get('error_product_not_found');
         $this->redirect($this->html->getSecureURL('catalog/manufacturer/update'));
     }
     $tmpl_id = $this->config->get('config_storefront_template');
     $post_data = $this->request->post;
     // need to know unique page existing
     $layout = new ALayoutManager();
     $pages = $layout->getPages($page_controller, $page_key_param, $manufacturer_id);
     if (count($pages)) {
         $page_id = $pages[0]['page_id'];
         $layout_id = $pages[0]['layout_id'];
     } else {
         $page_info = array('controller' => $page_controller, 'key_param' => $page_key_param, 'key_value' => $manufacturer_id);
         $languages = $this->language->getAvailableLanguages();
         $this->loadModel('catalog/manufacturer');
         $manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($manufacturer_id);
         if ($manufacturer_info) {
             foreach ($languages as $l) {
                 $page_info['page_descriptions'][$l['language_id']] = $manufacturer_info;
             }
         }
         $page_id = $layout->savePage($page_info);
         $layout_id = '';
         // need to generate layout name
         $post_data['layout_name'] = 'Manufacturer: ' . $manufacturer_info['name'];
     }
     //create new instance with specific template/page/layout data
     $layout = new ALayoutManager($tmpl_id, $page_id, $layout_id);
     if (has_value($post_data['layout_change'])) {
         //update layout request. Clone source layout
         $layout->clonePageLayout($post_data['layout_change'], $layout_id, $post_data['layout_name']);
     } else {
         //save new layout
         $post_data['controller'] = $page_controller;
         $layout->savePageLayout($post_data);
     }
     $this->session->data['success'] = $this->language->get('text_success_layout');
     $this->redirect($this->html->getSecureURL('catalog/manufacturer_layout', '&manufacturer_id=' . $manufacturer_id));
 }
 public function save_layout()
 {
     $page_controller = 'pages/content/content';
     $page_key_param = 'content_id';
     $content_id = $this->_get_content_id($this->request->get_or_post('content_id'));
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->acm = new AContentManager();
     if (!has_value($content_id)) {
         $this->redirect($this->html->getSecureURL('design/content'));
     }
     if ($this->request->is_POST()) {
         // need to know unique page existing
         $post_data = $this->request->post;
         $tmpl_id = $post_data['tmpl_id'];
         $layout = new ALayoutManager();
         $pages = $layout->getPages($page_controller, $page_key_param, $content_id);
         if (count($pages)) {
             $page_id = $pages[0]['page_id'];
             $layout_id = $pages[0]['layout_id'];
         } else {
             // create new page record
             $page_info = array('controller' => $page_controller, 'key_param' => $page_key_param, 'key_value' => $content_id);
             $default_language_id = $this->language->getDefaultLanguageID();
             $content_info = $this->acm->getContent($content_id, $default_language_id);
             if ($content_info) {
                 if ($content_info['title']) {
                     $page_info['page_descriptions'][$default_language_id]['name'] = $content_info['title'];
                 } else {
                     $page_info['page_descriptions'][$default_language_id]['name'] = 'Unnamed content page';
                 }
             }
             $page_id = $layout->savePage($page_info);
             $layout_id = '';
             // need to generate layout name
             $post_data['layout_name'] = 'Content: ' . $content_info['title'];
         }
         //create new instance with specific template/page/layout data
         $layout = new ALayoutManager($tmpl_id, $page_id, $layout_id);
         if (has_value($post_data['layout_change'])) {
             //update layout request. Clone source layout
             $layout->clonePageLayout($post_data['layout_change'], $layout_id, $post_data['layout_name']);
             $this->session->data['success'] = $this->language->get('text_success_layout');
         } else {
             //save new layout
             $layout_data = $layout->prepareInput($post_data);
             if ($layout_data) {
                 $layout->savePageLayout($layout_data);
                 $this->session->data['success'] = $this->language->get('text_success_layout');
             }
         }
         $this->redirect($this->html->getSecureURL('design/content/edit_layout', '&content_id=' . $content_id));
     }
     $this->redirect($this->html->getSecureURL('design/content/'));
 }
Example #5
0
 public function save_layout()
 {
     if ($this->request->server['REQUEST_METHOD'] != 'POST') {
         $this->redirect($this->html->getSecureURL('catalog/category'));
     }
     $page_controller = 'pages/product/category';
     $page_key_param = 'path';
     $category_id = (int) $this->request->get_or_post('category_id');
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->loadLanguage('catalog/category');
     if (!has_value($category_id)) {
         $this->redirect($this->html->getSecureURL('catalog/category'));
     }
     $url = '&category_id=' . $category_id;
     $tmpl_id = $this->config->get('config_storefront_template');
     // need to know unique page existing
     $post_data = $this->request->post;
     $layout = new ALayoutManager();
     $pages = $layout->getPages($page_controller, $page_key_param, $category_id);
     if (count($pages)) {
         $page_id = $pages[0]['page_id'];
         $layout_id = $pages[0]['layout_id'];
     } else {
         $page_info = array('controller' => $page_controller, 'key_param' => $page_key_param, 'key_value' => $category_id);
         $this->loadModel('catalog/category');
         $category_info = $this->model_catalog_category->getCategoryDescriptions($category_id);
         if ($category_info) {
             foreach ($category_info as $language_id => $description) {
                 if (!has_value($language_id)) {
                     continue;
                 }
                 $page_info['page_descriptions'][$language_id] = $description;
             }
         }
         $page_id = $layout->savePage($page_info);
         $layout_id = '';
         // need to generate layout name
         $default_language_id = $this->language->getDefaultLanguageID();
         $post_data['layout_name'] = 'Category: ' . $category_info[$default_language_id]['name'];
     }
     //create new instance with specific template/page/layout data
     $layout = new ALayoutManager($tmpl_id, $page_id, $layout_id);
     if (has_value($post_data['layout_change'])) {
         //update layout request. Clone source layout
         $layout->clonePageLayout($post_data['layout_change'], $layout_id, $post_data['layout_name']);
     } else {
         //save new layout
         $post_data['controller'] = $page_controller;
         $layout->savePageLayout($post_data);
     }
     $url .= '&layout_id=' . $layout_id;
     $this->session->data['success'] = $this->language->get('text_success_layout');
     $this->redirect($this->html->getSecureURL('catalog/category/edit_layout', $url));
 }