Example #1
0
 private function initAssociationsForm()
 {
     $app = JFactory::getApplication();
     /** prepare category tree **/
     $root = JeproshopCategoryModelCategory::getRootCategory();
     $default_category_id = $this->context->cookie->products_filter_category_id ? $this->context->cookie->products_filter_category_id : JeproshopContext::getContext()->shop->category_id;
     $categoryBox = $app->input->get('category_box', array($default_category_id));
     if (!$this->product->product_id || !$this->product->isAssociatedToShop()) {
         $selected_category = JeproshopCategoryModelCategory::getCategoryInformations($categoryBox, $this->context->controller->default_form_language);
     } else {
         if ($categoryBox) {
             $selected_category = JeproshopCategoryModelCategory::getCategoryInformations($categoryBox);
         } else {
             $selected_category = JeproshopProductModelProduct::getProductCategoriesFull($this->product->product_id, $this->context->controller->default_form_language);
         }
     }
     // Multishop block
     $feature_shop_active = JeproshopShopModelShop::isFeaturePublished();
     $this->assignRef('feature_shop_published', $feature_shop_active);
     /** Accessories **/
     $accessories = JeproshopProductModelProduct::getAccessoriesLight($this->context->language->lang_id, $this->product->product_id);
     $postAccessories = $app->input->get('input_accessories');
     if ($postAccessories) {
         $postAccessoriesTab = explode('-', $postAccessories);
         foreach ($postAccessoriesTab as $accessory_id) {
             $accessory = JeproshopProductModelProduct::getAccessoryById($accessory_id);
             if (!$this->hasThisAccessory($accessory_id, $accessories) && $accessory) {
                 $accessories[] = $accessory;
             }
         }
     }
     $this->assignRef('accessories', $accessories);
     $this->product->manufacturer_name = JeproshopManufacturerModelManufacturer::getNameById($this->product->manufacturer_id);
     $categories = array();
     foreach ($selected_category as $key => $category) {
         $categories[] = $key;
     }
     $manufacturers = JeproshopManufacturerModelManufacturer::getManufacturers($this->context->language->lang_id);
     $categories_tree = new JeproshopCategoriesTree('associated_categories_tree', JText::_('COM_JEPROSHOP_ASSOCIATED_CATEGORIES_LABEL'));
     $categories_tree->setTreeLayout('associated_categories')->setRootCategory((int) $root->category_id)->setUseCheckBox(true)->setSelectedCategories($categories);
     $this->assignRef('manufacturers', $manufacturers);
     $selected_category_ids = implode(',', array_keys($selected_category));
     $this->assignRef('selected_category_ids', $selected_category_ids);
     $this->assignRef('selected_category', $selected_category);
     $categoryId = $this->product->getDefaultCategoryId();
     $this->assignRef('default_category_id', $categoryId);
     $category_tree = $categories_tree->render();
     $this->assignRef('category_tree', $category_tree);
     $is_shop_context = JeproshopShopModelShop::getShopContext() == JeproshopShopModelShop::CONTEXT_SHOP;
     $this->assignRef('is_shop_context', $is_shop_context);
 }