Example #1
0
 /**
  * Assign template vars related to category.
  */
 protected function assignCategory()
 {
     // Assign category to the template
     if (($this->category === false || !Validate::isLoadedObject($this->category) || !$this->category->inShop() || !$this->category->isAssociatedToShop()) && Category::inShopStatic($this->product->id_category_default, $this->context->shop)) {
         $this->category = new Category((int) $this->product->id_category_default, (int) $this->context->language->id);
     }
     $sub_categories = array();
     if (Validate::isLoadedObject($this->category)) {
         $sub_categories = $this->category->getSubCategories($this->context->language->id, true);
         // various assignements before Hook::exec
         $this->context->smarty->assign(array('category' => $this->category, 'subCategories' => $sub_categories, 'id_category_current' => (int) $this->category->id, 'id_category_parent' => (int) $this->category->id_parent, 'return_category_name' => Tools::safeOutput($this->category->getFieldByLang('name')), 'categories' => Category::getHomeCategories($this->context->language->id, true, (int) $this->context->shop->id)));
     }
 }
 /**
  * Assign template vars related to category
  */
 protected function assignCategory()
 {
     // Assign category to the template
     if ($this->category !== false && Validate::isLoadedObject($this->category) && $this->category->inShop() && $this->category->isAssociatedToShop()) {
         $path = Tools::getPath($this->category->id, $this->product->name, true);
     } elseif (Category::inShopStatic($this->product->id_category_default, $this->context->shop)) {
         $this->category = new Category((int) $this->product->id_category_default);
         if (Validate::isLoadedObject($this->category) && $this->category->active && $this->category->isAssociatedToShop()) {
             $path = Tools::getPath((int) $this->product->id_category_default, $this->product->name);
         }
     }
     if (!isset($path) || !$path) {
         $path = Tools::getPath((int) $this->context->shop->id_category, $this->product->name);
     }
     // various assignements before Hook::exec
     $this->context->smarty->assign(array('path' => $path, 'category' => $this->category, 'subCategories' => $this->category->getSubCategories($this->context->language->id, true), 'id_category_current' => (int) $this->category->id, 'id_category_parent' => (int) $this->category->id_parent, 'return_category_name' => Tools::safeOutput($this->category->name), 'categories' => Category::getHomeCategories($this->context->language->id, true, (int) $this->context->shop->id)));
     $this->context->smarty->assign(array('HOOK_PRODUCT_FOOTER' => Hook::exec('displayFooterProduct', array('product' => $this->product, 'category' => $this->category))));
 }
Example #3
0
    public function __construct()
    {
        $this->bootstrap = true;
        $this->table = 'product';
        $this->className = 'Product';
        $this->lang = true;
        $this->explicitSelect = true;
        $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'icon' => 'icon-trash', 'confirm' => $this->l('Delete selected items?')));
        if (!Tools::getValue('id_product')) {
            $this->multishop_context_group = false;
        }
        parent::__construct();
        $this->imageType = 'jpg';
        $this->_defaultOrderBy = 'position';
        $this->max_file_size = (int) (Configuration::get('PS_LIMIT_UPLOAD_FILE_VALUE') * 1000000);
        $this->max_image_size = (int) Configuration::get('PS_PRODUCT_PICTURE_MAX_SIZE');
        $this->allow_export = true;
        // @since 1.5 : translations for tabs
        $this->available_tabs_lang = array('Informations' => $this->l('Information'), 'Pack' => $this->l('Pack'), 'VirtualProduct' => $this->l('Virtual Product'), 'Prices' => $this->l('Prices'), 'Seo' => $this->l('SEO'), 'Images' => $this->l('Images'), 'Associations' => $this->l('Associations'), 'Shipping' => $this->l('Shipping'), 'Combinations' => $this->l('Combinations'), 'Features' => $this->l('Features'), 'Customization' => $this->l('Customization'), 'Attachments' => $this->l('Attachments'), 'Quantities' => $this->l('Quantities'), 'Suppliers' => $this->l('Suppliers'), 'Warehouses' => $this->l('Warehouses'));
        $this->available_tabs = array('Quantities' => 6, 'Warehouses' => 14);
        if ($this->context->shop->getContext() != Shop::CONTEXT_GROUP) {
            $this->available_tabs = array_merge($this->available_tabs, array('Informations' => 0, 'Pack' => 7, 'VirtualProduct' => 8, 'Prices' => 1, 'Seo' => 2, 'Associations' => 3, 'Images' => 9, 'Shipping' => 4, 'Combinations' => 5, 'Features' => 10, 'Customization' => 11, 'Attachments' => 12, 'Suppliers' => 13));
        }
        // Sort the tabs that need to be preloaded by their priority number
        asort($this->available_tabs, SORT_NUMERIC);
        /* Adding tab if modules are hooked */
        $modules_list = Hook::getHookModuleExecList('displayAdminProductsExtra');
        if (is_array($modules_list) && count($modules_list) > 0) {
            foreach ($modules_list as $m) {
                $this->available_tabs['Module' . ucfirst($m['module'])] = 23;
                $this->available_tabs_lang['Module' . ucfirst($m['module'])] = Module::getModuleName($m['module']);
            }
        }
        if (Tools::getValue('reset_filter_category')) {
            $this->context->cookie->id_category_products_filter = false;
        }
        if (Shop::isFeatureActive() && $this->context->cookie->id_category_products_filter) {
            $category = new Category((int) $this->context->cookie->id_category_products_filter);
            if (!$category->inShop()) {
                $this->context->cookie->id_category_products_filter = false;
                Tools::redirectAdmin($this->context->link->getAdminLink('AdminProducts'));
            }
        }
        /* Join categories table */
        if ($id_category = (int) Tools::getValue('productFilter_cl!name')) {
            $this->_category = new Category((int) $id_category);
            $_POST['productFilter_cl!name'] = $this->_category->name[$this->context->language->id];
        } else {
            if ($id_category = (int) Tools::getValue('id_category')) {
                $this->id_current_category = $id_category;
                $this->context->cookie->id_category_products_filter = $id_category;
            } elseif ($id_category = $this->context->cookie->id_category_products_filter) {
                $this->id_current_category = $id_category;
            }
            if ($this->id_current_category) {
                $this->_category = new Category((int) $this->id_current_category);
            } else {
                $this->_category = new Category();
            }
        }
        $join_category = false;
        if (Validate::isLoadedObject($this->_category) && empty($this->_filter)) {
            $join_category = true;
        }
        $this->_join .= '
		LEFT JOIN `' . _DB_PREFIX_ . 'image` i ON (i.`id_product` = a.`id_product`)
		LEFT JOIN `' . _DB_PREFIX_ . 'stock_available` sav ON (sav.`id_product` = a.`id_product` AND sav.`id_product_attribute` = 0
		' . StockAvailable::addSqlShopRestriction(null, null, 'sav') . ') ';
        $alias = 'sa';
        $alias_image = 'image_shop';
        $id_shop = Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP ? (int) $this->context->shop->id : 'a.id_shop_default';
        $this->_join .= ' JOIN `' . _DB_PREFIX_ . 'product_shop` sa ON (a.`id_product` = sa.`id_product` AND sa.id_shop = ' . $id_shop . ')
				LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (' . $alias . '.`id_category_default` = cl.`id_category` AND b.`id_lang` = cl.`id_lang` AND cl.id_shop = ' . $id_shop . ')
				LEFT JOIN `' . _DB_PREFIX_ . 'shop` shop ON (shop.id_shop = ' . $id_shop . ') 
				LEFT JOIN `' . _DB_PREFIX_ . 'image_shop` image_shop ON (image_shop.`id_image` = i.`id_image` AND image_shop.`cover` = 1 AND image_shop.id_shop = ' . $id_shop . ')
				LEFT JOIN `' . _DB_PREFIX_ . 'product_download` pd ON (pd.`id_product` = a.`id_product`)';
        $this->_select .= 'shop.name as shopname, a.id_shop_default, ';
        $this->_select .= 'MAX(' . $alias_image . '.id_image) id_image, cl.name `name_category`, ' . $alias . '.`price`, 0 AS price_final, a.`is_virtual`, pd.`nb_downloadable`, sav.`quantity` as sav_quantity, ' . $alias . '.`active`, IF(sav.`quantity`<=0, 1, 0) badge_danger';
        if ($join_category) {
            $this->_join .= ' INNER JOIN `' . _DB_PREFIX_ . 'category_product` cp ON (cp.`id_product` = a.`id_product` AND cp.`id_category` = ' . (int) $this->_category->id . ') ';
            $this->_select .= ' , cp.`position`, ';
        }
        $this->_group = 'GROUP BY ' . $alias . '.id_product';
        $this->fields_list = array();
        $this->fields_list['id_product'] = array('title' => $this->l('ID'), 'align' => 'center', 'class' => 'fixed-width-xs', 'type' => 'int');
        $this->fields_list['image'] = array('title' => $this->l('Image'), 'align' => 'center', 'image' => 'p', 'orderby' => false, 'filter' => false, 'search' => false);
        $this->fields_list['name'] = array('title' => $this->l('Name'), 'filter_key' => 'b!name');
        $this->fields_list['reference'] = array('title' => $this->l('Reference'), 'align' => 'left');
        if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_SHOP) {
            $this->fields_list['shopname'] = array('title' => $this->l('Default shop'), 'filter_key' => 'shop!name');
        } else {
            $this->fields_list['name_category'] = array('title' => $this->l('Category'), 'filter_key' => 'cl!name');
        }
        $this->fields_list['price'] = array('title' => $this->l('Base price'), 'type' => 'price', 'align' => 'text-right', 'filter_key' => 'a!price');
        $this->fields_list['price_final'] = array('title' => $this->l('Final price'), 'type' => 'price', 'align' => 'text-right', 'havingFilter' => true, 'orderby' => false, 'search' => false);
        if (Configuration::get('PS_STOCK_MANAGEMENT')) {
            $this->fields_list['sav_quantity'] = array('title' => $this->l('Quantity'), 'type' => 'int', 'align' => 'text-right', 'filter_key' => 'sav!quantity', 'orderby' => true, 'badge_danger' => true);
        }
        $this->fields_list['active'] = array('title' => $this->l('Status'), 'active' => 'status', 'filter_key' => $alias . '!active', 'align' => 'text-center', 'type' => 'bool', 'class' => 'fixed-width-sm', 'orderby' => false);
        if ($join_category && (int) $this->id_current_category) {
            $this->fields_list['position'] = array('title' => $this->l('Position'), 'filter_key' => 'cp!position', 'align' => 'center', 'position' => 'position');
        }
    }