Beispiel #1
0
function upgrade_module_1_3_2_2($object)
{
    if (!Shop::isFeatureActive()) {
        $categories = SimpleBlogCategory::getCategories(Context::getContext()->language->id, false);
        foreach ($categories as $id_category => $category) {
            $instance = new SimpleBlogCategory($id_category, Context::getContext()->language->id);
            $instance->associateTo(Shop::getCompleteListOfShopsID());
            unset($instance);
        }
    }
    return true;
}
 /**
  * Launch the export process
  */
 public function launchExport()
 {
     // Addition of a secured token
     if (!Tools::getValue('token') || Tools::getValue('token') != Tools::getAdminToken('DataExtractorController')) {
         return;
     }
     @ini_set('max_execution_time', '3000');
     @ini_set('max_input_time', '3000');
     @ini_set('memory_limit', '384M');
     $oDataExtractor = false;
     $aPrediggoConfigs = array();
     $oContext = Context::getContext();
     foreach (Shop::getCompleteListOfShopsID() as $iIDShop) {
         $oContext->shop = new Shop((int) $iIDShop);
         $aPrediggoConfigs[(int) $iIDShop] = new PrediggoConfig($oContext);
     }
     // Launch Customers export process
     $params = array('aPrediggoConfigs' => array());
     foreach ($aPrediggoConfigs as $iIDShop => $oPrediggoConfig) {
         if ($oPrediggoConfig->customers_file_generation) {
             $params['aPrediggoConfigs'][$iIDShop] = $oPrediggoConfig;
         }
     }
     if (count($params['aPrediggoConfigs'])) {
         $oDataExtractor = new CustomerExtractorToXML($this->sRepositoryPath, $params, (int) $this->oPrediggoConfig->logs_file_generation);
         $this->lauchFileExport($oDataExtractor);
     }
     // Launch Orders export process
     $params = array('aPrediggoConfigs' => array());
     foreach ($aPrediggoConfigs as $iIDShop => $oPrediggoConfig) {
         if ($oPrediggoConfig->orders_file_generation) {
             $params['aPrediggoConfigs'][$iIDShop] = $oPrediggoConfig;
         }
     }
     if (count($params['aPrediggoConfigs'])) {
         $oDataExtractor = new OrderExtractorToXML($this->sRepositoryPath, $params, (int) $this->oPrediggoConfig->logs_file_generation);
         $this->lauchFileExport($oDataExtractor);
     }
     // Launch Products export process
     $params = array('aPrediggoConfigs' => array());
     foreach ($aPrediggoConfigs as $iIDShop => $oPrediggoConfig) {
         if ($oPrediggoConfig->products_file_generation) {
             $params['aPrediggoConfigs'][$iIDShop] = $oPrediggoConfig;
         }
     }
     if (count($params['aPrediggoConfigs'])) {
         $oDataExtractor = new ProductExtractorToXML($this->sRepositoryPath, $params, (int) $this->oPrediggoConfig->logs_file_generation);
         $this->lauchFileExport($oDataExtractor);
     }
 }
 /**
  * Get view 
  *
  * @return string
  */
 public function initContent()
 {
     if (Context::getContext()->employee->id_profile == Configuration::get('APH_PROFILE_SITE_OWNER')) {
         $shops = array();
         //$_shops = Shop::getShops(true, null, true);
         $_shops = Shop::getCompleteListOfShopsID();
         foreach ($_shops as $id_shop) {
             if ($id_shop == Configuration::get('PS_SHOP_DEFAULT')) {
                 continue;
             }
             $shop = new Shop($id_shop);
             $shops[$id_shop] = $shop->name;
         }
         asort($shops);
         $this->context->smarty->assign('shops', $shops);
     }
     if ($this->display == 'edit') {
         $obj = $this->loadObject(true);
         $this->context->smarty->assign(array('obj' => $obj));
         // Selected products
         $selected_products = array();
         $products = AphTool::getProducts($obj->id);
         if (!empty($products)) {
             foreach ($products as $product) {
                 $selected_products[] = $product['id_product'];
             }
         }
     }
     if ($this->display == 'add' || $this->display == 'edit') {
         // Generate category selection tree
         $tree = new HelperTreeProducts('products-tree', $this->l('Seleziona servizio'));
         $tree->setInputName('checkBoxProductAsso_tool');
         if (!empty($selected_products)) {
             $tree->setAttribute('selected_products', $selected_products);
             $tree->setSelectedProducts($selected_products);
         }
         $tree->setUseShopRestriction(true);
         $this->context->smarty->assign('product_tree', $tree->render());
         $languages = Language::getLanguages(true);
         $this->context->smarty->assign(array("id_lang_default" => Configuration::get('PS_LANG_DEFAULT'), 'tpl_dir' => $this->tpl_dir, "languages" => $languages));
         $this->content .= $this->context->smarty->fetch(_PS_MODULE_DIR_ . $this->module->name . "/views/templates/admin/controllers/tools/form.tpl");
     }
     parent::initContent();
 }
Beispiel #4
0
 private function duplicateMultistoreTab($id_tab)
 {
     $tab = new IqitMenuTab($id_tab);
     $shops = Shop::getCompleteListOfShopsID();
     foreach ($shops as $shop_id) {
         if ($this->context->shop->id == $shop_id) {
             continue;
         }
         $newobject = $tab->duplicateObject();
         $newobject->associateToShop($shop_id);
     }
 }
 public function productImport($offset = false, $limit = false, &$crossStepsVariables = false, $validateOnly = false, $moreStep = 0)
 {
     if ($moreStep == 1) {
         return $this->productImportAccessories($offset, $limit, $crossStepsVariables);
     }
     $this->receiveTab();
     $handle = $this->openCsvFile($offset);
     if (!$handle) {
         return false;
     }
     $default_language_id = (int) Configuration::get('PS_LANG_DEFAULT');
     $id_lang = Language::getIdByIso(Tools::getValue('iso_lang'));
     if (!Validate::isUnsignedId($id_lang)) {
         $id_lang = $default_language_id;
     }
     AdminImportController::setLocale();
     $shop_ids = Shop::getCompleteListOfShopsID();
     $force_ids = Tools::getValue('forceIDs');
     $match_ref = Tools::getValue('match_ref');
     $regenerate = Tools::getValue('regenerate');
     $shop_is_feature_active = Shop::isFeatureActive();
     if (!$validateOnly) {
         Module::setBatchMode(true);
     }
     $accessories = array();
     if ($crossStepsVariables !== false && array_key_exists('accessories', $crossStepsVariables)) {
         $accessories = $crossStepsVariables['accessories'];
     }
     $line_count = 0;
     for ($current_line = 0; ($line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator)) && (!$limit || $current_line < $limit); $current_line++) {
         $line_count++;
         if ($this->convert) {
             $line = $this->utf8EncodeArray($line);
         }
         if (count($line) == 1 && $line[0] == null) {
             $this->warnings[] = $this->l('There is an empty row in the file that won\'t be imported.');
             continue;
         }
         $info = AdminImportController::getMaskedRow($line);
         $this->productImportOne($info, $default_language_id, $id_lang, $force_ids, $regenerate, $shop_is_feature_active, $shop_ids, $match_ref, $accessories, $validateOnly);
     }
     $this->closeCsvFile($handle);
     if (!$validateOnly) {
         Module::processDeferedFuncCall();
         Module::processDeferedClearCache();
         Tag::updateTagCount();
     }
     if ($crossStepsVariables !== false) {
         $crossStepsVariables['accessories'] = $accessories;
     }
     return $line_count;
 }
    public static function addSqlAssociation($table, $alias, $identifier, $inner_join = true, $on = null, $shops = false)
    {
        if (version_compare(_PS_VERSION_, '1.5.0.0', '>=') && Shop::isFeatureActive()) {
            if ($shops == 'all') {
                $ids_shop = array_values(Shop::getCompleteListOfShopsID());
            } else {
                if (is_array($shops) && sizeof($shops)) {
                    $ids_shop = array_values($shops);
                } else {
                    if (is_numeric($shops)) {
                        $ids_shop = array($shops);
                    } else {
                        $ids_shop = array_values(Shop::getContextListShopID());
                    }
                }
            }
            $table_alias = $alias . '_shop';
            if (strpos($table, '.') !== false) {
                list($table_alias, $table) = explode('.', $table);
            }
            $sql = ($inner_join ? ' INNER' : ' LEFT') . ' JOIN `' . _DB_PREFIX_ . $table . '_shop` ' . $table_alias . '
						ON ' . $table_alias . '.' . $identifier . ' = ' . $alias . '.' . $identifier . '
						AND ' . $table_alias . '.id_shop IN (' . implode(', ', $ids_shop) . ') ' . ($on ? ' AND ' . $on : '');
            return $sql;
        }
        return;
    }
Beispiel #7
0
 /**
  * Adds current object to the database
  *
  * @param bool $auto_date
  * @param bool $null_values
  *
  * @return bool Insertion result
  * @throws PrestaShopDatabaseException
  * @throws PrestaShopException
  */
 public function add($auto_date = true, $null_values = false)
 {
     if (isset($this->id) && !$this->force_id) {
         unset($this->id);
     }
     // @hook actionObject*AddBefore
     Hook::exec('actionObjectAddBefore', array('object' => $this));
     Hook::exec('actionObject' . get_class($this) . 'AddBefore', array('object' => $this));
     // Automatically fill dates
     if ($auto_date && property_exists($this, 'date_add')) {
         $this->date_add = date('Y-m-d H:i:s');
     }
     if ($auto_date && property_exists($this, 'date_upd')) {
         $this->date_upd = date('Y-m-d H:i:s');
     }
     if (Shop::isTableAssociated($this->def['table'])) {
         $id_shop_list = Shop::getContextListShopID();
         if (count($this->id_shop_list) > 0) {
             $id_shop_list = $this->id_shop_list;
         }
     }
     // Database insertion
     if (Shop::checkIdShopDefault($this->def['table'])) {
         $this->id_shop_default = in_array(Configuration::get('PS_SHOP_DEFAULT'), $id_shop_list) == true ? Configuration::get('PS_SHOP_DEFAULT') : min($id_shop_list);
     }
     if (!($result = Db::getInstance()->insert($this->def['table'], $this->getFields(), $null_values))) {
         return false;
     }
     // Get object id in database
     $this->id = Db::getInstance()->Insert_ID();
     // Database insertion for multishop fields related to the object
     if (Shop::isTableAssociated($this->def['table'])) {
         $fields = $this->getFieldsShop();
         $fields[$this->def['primary']] = (int) $this->id;
         foreach ($id_shop_list as $id_shop) {
             $fields['id_shop'] = (int) $id_shop;
             $result &= Db::getInstance()->insert($this->def['table'] . '_shop', $fields, $null_values);
         }
     }
     if (!$result) {
         return false;
     }
     // Database insertion for multilingual fields related to the object
     if (!empty($this->def['multilang'])) {
         $fields = $this->getFieldsLang();
         if ($fields && is_array($fields)) {
             $shops = Shop::getCompleteListOfShopsID();
             $asso = Shop::getAssoTable($this->def['table'] . '_lang');
             foreach ($fields as $field) {
                 foreach (array_keys($field) as $key) {
                     if (!Validate::isTableOrIdentifier($key)) {
                         throw new PrestaShopException('key ' . $key . ' is not table or identifier');
                     }
                 }
                 $field[$this->def['primary']] = (int) $this->id;
                 if ($asso !== false && $asso['type'] == 'fk_shop') {
                     foreach ($shops as $id_shop) {
                         $field['id_shop'] = (int) $id_shop;
                         $result &= Db::getInstance()->insert($this->def['table'] . '_lang', $field);
                     }
                 } else {
                     $result &= Db::getInstance()->insert($this->def['table'] . '_lang', $field);
                 }
             }
         }
     }
     // @hook actionObject*AddAfter
     Hook::exec('actionObjectAddAfter', array('object' => $this));
     Hook::exec('actionObject' . get_class($this) . 'AddAfter', array('object' => $this));
     return $result;
 }
Beispiel #8
0
<?php

/*
 *  2015-2016 DOGS
 *  @author J.Podracky, L.Fisher
 *  @copyright  2015-2016 F2FCREATIVE
 */
if (!defined('_PS_ADMIN_DIR_')) {
    define('_PS_ADMIN_DIR_', getcwd());
}
include _PS_ADMIN_DIR_ . '/../config/config.inc.php';
if (isset($_GET['secure_key'])) {
    $secureKey = md5(_COOKIE_KEY_ . Configuration::get('PS_SHOP_NAME'));
    if (!empty($secureKey) && $secureKey === $_GET['secure_key']) {
        $shop_ids = Shop::getCompleteListOfShopsID();
        foreach ($shop_ids as $shop_id) {
            Shop::setContext(Shop::CONTEXT_SHOP, (int) $shop_id);
            Currency::refreshCurrencies();
        }
    }
}
Beispiel #9
0
    /**
     * Connect module to a hook
     *
     * @param string $hook_name Hook name
     * @param array $shop_list List of shop linked to the hook (if null, link hook to all shops)
     * @return bool result
     */
    public function registerHook($hook_name, $shop_list = null)
    {
        $return = true;
        if (is_array($hook_name)) {
            $hook_names = $hook_name;
        } else {
            $hook_names = array($hook_name);
        }
        foreach ($hook_names as $hook_name) {
            // Check hook name validation and if module is installed
            if (!Validate::isHookName($hook_name)) {
                throw new PrestaShopException('Invalid hook name');
            }
            if (!isset($this->id) || !is_numeric($this->id)) {
                return false;
            }
            // Retrocompatibility
            $hook_name_bak = $hook_name;
            if ($alias = Hook::getRetroHookName($hook_name)) {
                $hook_name = $alias;
            }
            Hook::exec('actionModuleRegisterHookBefore', array('object' => $this, 'hook_name' => $hook_name));
            // Get hook id
            $id_hook = Hook::getIdByName($hook_name);
            $live_edit = Hook::getLiveEditById((int) Hook::getIdByName($hook_name_bak));
            // If hook does not exist, we create it
            if (!$id_hook) {
                $new_hook = new Hook();
                $new_hook->name = pSQL($hook_name);
                $new_hook->title = pSQL($hook_name);
                $new_hook->live_edit = (bool) preg_match('/^display/i', $new_hook->name);
                $new_hook->position = (bool) $new_hook->live_edit;
                $new_hook->add();
                $id_hook = $new_hook->id;
                if (!$id_hook) {
                    return false;
                }
            }
            // If shop lists is null, we fill it with all shops
            if (is_null($shop_list)) {
                $shop_list = Shop::getCompleteListOfShopsID();
            }
            $shop_list_employee = Shop::getShops(true, null, true);
            foreach ($shop_list as $shop_id) {
                // Check if already register
                $sql = 'SELECT hm.`id_module`
					FROM `' . _DB_PREFIX_ . 'hook_module` hm, `' . _DB_PREFIX_ . 'hook` h
					WHERE hm.`id_module` = ' . (int) $this->id . ' AND h.`id_hook` = ' . $id_hook . '
					AND h.`id_hook` = hm.`id_hook` AND `id_shop` = ' . (int) $shop_id;
                if (Db::getInstance()->getRow($sql)) {
                    continue;
                }
                // Get module position in hook
                $sql = 'SELECT MAX(`position`) AS position
					FROM `' . _DB_PREFIX_ . 'hook_module`
					WHERE `id_hook` = ' . (int) $id_hook . ' AND `id_shop` = ' . (int) $shop_id;
                if (!($position = Db::getInstance()->getValue($sql))) {
                    $position = 0;
                }
                // Register module in hook
                $return &= Db::getInstance()->insert('hook_module', array('id_module' => (int) $this->id, 'id_hook' => (int) $id_hook, 'id_shop' => (int) $shop_id, 'position' => (int) ($position + 1)));
                if (!in_array($shop_id, $shop_list_employee)) {
                    $where = '`id_module` = ' . (int) $this->id . ' AND `id_shop` = ' . (int) $shop_id;
                    $return &= Db::getInstance()->delete('module_shop', $where);
                }
            }
            Hook::exec('actionModuleRegisterHookAfter', array('object' => $this, 'hook_name' => $hook_name));
        }
        return $return;
    }
    public function productImport()
    {
        $this->receiveTab();
        $handle = $this->openCsvFile();
        $default_language_id = (int) Configuration::get('PS_LANG_DEFAULT');
        $id_lang = Language::getIdByIso(Tools::getValue('iso_lang'));
        if (!Validate::isUnsignedId($id_lang)) {
            $id_lang = $default_language_id;
        }
        AdminImportController::setLocale();
        $shop_ids = Shop::getCompleteListOfShopsID();
        for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator); $current_line++) {
            if (Tools::getValue('convert')) {
                $line = $this->utf8EncodeArray($line);
            }
            $info = AdminImportController::getMaskedRow($line);
            if (Tools::getValue('forceIDs') && isset($info['id']) && (int) $info['id']) {
                $product = new Product((int) $info['id']);
            } elseif (Tools::getValue('match_ref') && array_key_exists('reference', $info)) {
                $datas = Db::getInstance()->getRow('
						SELECT p.`id_product`
						FROM `' . _DB_PREFIX_ . 'product` p
						' . Shop::addSqlAssociation('product', 'p') . '
						WHERE p.`reference` = "' . pSQL($info['reference']) . '"
					');
                if (isset($datas['id_product']) && $datas['id_product']) {
                    $product = new Product((int) $datas['id_product']);
                } else {
                    $product = new Product();
                }
            } elseif (array_key_exists('id', $info) && (int) $info['id'] && Product::existsInDatabase((int) $info['id'], 'product')) {
                $product = new Product((int) $info['id']);
            } else {
                $product = new Product();
            }
            if (isset($product->id) && $product->id && Product::existsInDatabase((int) $product->id, 'product')) {
                $product->loadStockData();
                $category_data = Product::getProductCategories((int) $product->id);
                if (is_array($product->category)) {
                    foreach ($category_data as $tmp) {
                        $product->category[] = $tmp;
                    }
                }
            }
            AdminImportController::setEntityDefaultValues($product);
            AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $product);
            if (!Shop::isFeatureActive()) {
                $product->shop = 1;
            } elseif (!isset($product->shop) || empty($product->shop)) {
                $product->shop = implode($this->multiple_value_separator, Shop::getContextListShopID());
            }
            if (!Shop::isFeatureActive()) {
                $product->id_shop_default = 1;
            } else {
                $product->id_shop_default = (int) Context::getContext()->shop->id;
            }
            // link product to shops
            $product->id_shop_list = array();
            foreach (explode($this->multiple_value_separator, $product->shop) as $shop) {
                if (!empty($shop) && !is_numeric($shop)) {
                    $product->id_shop_list[] = Shop::getIdByName($shop);
                } elseif (!empty($shop)) {
                    $product->id_shop_list[] = $shop;
                }
            }
            if ((int) $product->id_tax_rules_group != 0) {
                if (Validate::isLoadedObject(new TaxRulesGroup($product->id_tax_rules_group))) {
                    $address = $this->context->shop->getAddress();
                    $tax_manager = TaxManagerFactory::getManager($address, $product->id_tax_rules_group);
                    $product_tax_calculator = $tax_manager->getTaxCalculator();
                    $product->tax_rate = $product_tax_calculator->getTotalRate();
                } else {
                    $this->addProductWarning('id_tax_rules_group', $product->id_tax_rules_group, Tools::displayError('Invalid tax rule group ID. You first need to create a group with this ID.'));
                }
            }
            if (isset($product->manufacturer) && is_numeric($product->manufacturer) && Manufacturer::manufacturerExists((int) $product->manufacturer)) {
                $product->id_manufacturer = (int) $product->manufacturer;
            } elseif (isset($product->manufacturer) && is_string($product->manufacturer) && !empty($product->manufacturer)) {
                if ($manufacturer = Manufacturer::getIdByName($product->manufacturer)) {
                    $product->id_manufacturer = (int) $manufacturer;
                } else {
                    $manufacturer = new Manufacturer();
                    $manufacturer->name = $product->manufacturer;
                    if (($field_error = $manufacturer->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $manufacturer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $manufacturer->add()) {
                        $product->id_manufacturer = (int) $manufacturer->id;
                    } else {
                        $this->errors[] = sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), $manufacturer->name, isset($manufacturer->id) && !empty($manufacturer->id) ? $manufacturer->id : 'null');
                        $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
                    }
                }
            }
            if (isset($product->supplier) && is_numeric($product->supplier) && Supplier::supplierExists((int) $product->supplier)) {
                $product->id_supplier = (int) $product->supplier;
            } elseif (isset($product->supplier) && is_string($product->supplier) && !empty($product->supplier)) {
                if ($supplier = Supplier::getIdByName($product->supplier)) {
                    $product->id_supplier = (int) $supplier;
                } else {
                    $supplier = new Supplier();
                    $supplier->name = $product->supplier;
                    $supplier->active = true;
                    if (($field_error = $supplier->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $supplier->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $supplier->add()) {
                        $product->id_supplier = (int) $supplier->id;
                        $supplier->associateTo($product->id_shop_list);
                    } else {
                        $this->errors[] = sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), $supplier->name, isset($supplier->id) && !empty($supplier->id) ? $supplier->id : 'null');
                        $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
                    }
                }
            }
            if (isset($product->price_tex) && !isset($product->price_tin)) {
                $product->price = $product->price_tex;
            } elseif (isset($product->price_tin) && !isset($product->price_tex)) {
                $product->price = $product->price_tin;
                // If a tax is already included in price, withdraw it from price
                if ($product->tax_rate) {
                    $product->price = (double) number_format($product->price / (1 + $product->tax_rate / 100), 6, '.', '');
                }
            } elseif (isset($product->price_tin) && isset($product->price_tex)) {
                $product->price = $product->price_tex;
            }
            if (!Configuration::get('PS_USE_ECOTAX')) {
                $product->ecotax = 0;
            }
            if (isset($product->category) && is_array($product->category) && count($product->category)) {
                $product->id_category = array();
                // Reset default values array
                foreach ($product->category as $value) {
                    if (is_numeric($value)) {
                        if (Category::categoryExists((int) $value)) {
                            $product->id_category[] = (int) $value;
                        } else {
                            $this->errors[] = sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), $category_to_create->name[$default_language_id], isset($category_to_create->id) && !empty($category_to_create->id) ? $category_to_create->id : 'null');
                            $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
                            $category_to_create = new Category();
                            $category_to_create->id = (int) $value;
                            $category_to_create->name = AdminImportController::createMultiLangField($value);
                            $category_to_create->active = 1;
                            $category_to_create->id_parent = Configuration::get('PS_HOME_CATEGORY');
                            // Default parent is home for unknown category to create
                            $category_link_rewrite = Tools::link_rewrite($category_to_create->name[$default_language_id]);
                            $category_to_create->link_rewrite = AdminImportController::createMultiLangField($category_link_rewrite);
                            if (($field_error = $category_to_create->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $category_to_create->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $category_to_create->add()) {
                                $product->id_category[] = (int) $category_to_create->id;
                            } else {
                                $this->errors[] = sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), $category_to_create->name[$default_language_id], isset($category_to_create->id) && !empty($category_to_create->id) ? $category_to_create->id : 'null');
                                $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
                            }
                        }
                    } elseif (is_string($value) && !empty($value)) {
                        $category = Category::searchByPath($default_language_id, trim($value), $this, 'productImportCreateCat');
                        if ($category['id_category']) {
                            $product->id_category[] = (int) $category['id_category'];
                        } else {
                            $this->errors[] = sprintf(Tools::displayError('%1$s cannot be saved'), trim($value));
                        }
                    }
                }
            }
            if (!isset($product->id_category_default) || !$product->id_category_default) {
                $product->id_category_default = isset($product->id_category[0]) ? (int) $product->id_category[0] : (int) Configuration::get('PS_HOME_CATEGORY');
            }
            $link_rewrite = is_array($product->link_rewrite) && isset($product->link_rewrite[$id_lang]) ? trim($product->link_rewrite[$id_lang]) : '';
            $valid_link = Validate::isLinkRewrite($link_rewrite);
            if (isset($product->link_rewrite[$id_lang]) && empty($product->link_rewrite[$id_lang]) || !$valid_link) {
                $link_rewrite = Tools::link_rewrite($product->name[$id_lang]);
                if ($link_rewrite == '') {
                    $link_rewrite = 'friendly-url-autogeneration-failed';
                }
            }
            if (!$valid_link) {
                $this->warnings[] = sprintf(Tools::displayError('Rewrite link for %1$s (ID: %2$s) was re-written as %3$s.'), $product->name[$id_lang], isset($info['id']) && !empty($info['id']) ? $info['id'] : 'null', $link_rewrite);
            }
            if (!(Tools::getValue('match_ref') || Tools::getValue('forceIDs')) || !(is_array($product->link_rewrite) && count($product->link_rewrite) && !empty($product->link_rewrite[$id_lang]))) {
                $product->link_rewrite = AdminImportController::createMultiLangField($link_rewrite);
            }
            // replace the value of separator by coma
            if ($this->multiple_value_separator != ',') {
                if (is_array($product->meta_keywords)) {
                    foreach ($product->meta_keywords as &$meta_keyword) {
                        if (!empty($meta_keyword)) {
                            $meta_keyword = str_replace($this->multiple_value_separator, ',', $meta_keyword);
                        }
                    }
                }
            }
            // Convert comma into dot for all floating values
            foreach (Product::$definition['fields'] as $key => $array) {
                if ($array['type'] == Product::TYPE_FLOAT) {
                    $product->{$key} = str_replace(',', '.', $product->{$key});
                }
            }
            // Indexation is already 0 if it's a new product, but not if it's an update
            $product->indexed = 0;
            $res = false;
            $field_error = $product->validateFields(UNFRIENDLY_ERROR, true);
            $lang_field_error = $product->validateFieldsLang(UNFRIENDLY_ERROR, true);
            if ($field_error === true && $lang_field_error === true) {
                // check quantity
                if ($product->quantity == null) {
                    $product->quantity = 0;
                }
                // If match ref is specified && ref product && ref product already in base, trying to update
                if (Tools::getValue('match_ref') && $product->reference && $product->existsRefInDatabase($product->reference)) {
                    $datas = Db::getInstance()->getRow('
						SELECT product_shop.`date_add`, p.`id_product`
						FROM `' . _DB_PREFIX_ . 'product` p
						' . Shop::addSqlAssociation('product', 'p') . '
						WHERE p.`reference` = "' . pSQL($product->reference) . '"
					');
                    $product->id = (int) $datas['id_product'];
                    $product->date_add = pSQL($datas['date_add']);
                    $res = $product->update();
                } elseif ($product->id && Product::existsInDatabase((int) $product->id, 'product')) {
                    $datas = Db::getInstance()->getRow('
						SELECT product_shop.`date_add`
						FROM `' . _DB_PREFIX_ . 'product` p
						' . Shop::addSqlAssociation('product', 'p') . '
						WHERE p.`id_product` = ' . (int) $product->id);
                    $product->date_add = pSQL($datas['date_add']);
                    $res = $product->update();
                }
                // If no id_product or update failed
                $product->force_id = (bool) Tools::getValue('forceIDs');
                if (!$res) {
                    if (isset($product->date_add) && $product->date_add != '') {
                        $res = $product->add(false);
                    } else {
                        $res = $product->add();
                    }
                }
                if ($product->getType() == Product::PTYPE_VIRTUAL) {
                    StockAvailable::setProductOutOfStock((int) $product->id, 1);
                } else {
                    StockAvailable::setProductOutOfStock((int) $product->id, (int) $product->out_of_stock);
                }
            }
            $shops = array();
            $product_shop = explode($this->multiple_value_separator, $product->shop);
            foreach ($product_shop as $shop) {
                if (empty($shop)) {
                    continue;
                }
                $shop = trim($shop);
                if (!empty($shop) && !is_numeric($shop)) {
                    $shop = Shop::getIdByName($shop);
                }
                if (in_array($shop, $shop_ids)) {
                    $shops[] = $shop;
                } else {
                    $this->addProductWarning(Tools::safeOutput($info['name']), $product->id, $this->l('Shop is not valid'));
                }
            }
            if (empty($shops)) {
                $shops = Shop::getContextListShopID();
            }
            // If both failed, mysql error
            if (!$res) {
                $this->errors[] = sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), isset($info['name']) && !empty($info['name']) ? Tools::safeOutput($info['name']) : 'No Name', isset($info['id']) && !empty($info['id']) ? Tools::safeOutput($info['id']) : 'No ID');
                $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
            } else {
                // Product supplier
                if (isset($product->id) && $product->id && isset($product->id_supplier) && property_exists($product, 'supplier_reference')) {
                    $id_product_supplier = (int) ProductSupplier::getIdByProductAndSupplier((int) $product->id, 0, (int) $product->id_supplier);
                    if ($id_product_supplier) {
                        $product_supplier = new ProductSupplier($id_product_supplier);
                    } else {
                        $product_supplier = new ProductSupplier();
                    }
                    $product_supplier->id_product = (int) $product->id;
                    $product_supplier->id_product_attribute = 0;
                    $product_supplier->id_supplier = (int) $product->id_supplier;
                    $product_supplier->product_supplier_price_te = $product->wholesale_price;
                    $product_supplier->product_supplier_reference = $product->supplier_reference;
                    $product_supplier->save();
                }
                // SpecificPrice (only the basic reduction feature is supported by the import)
                if (!Shop::isFeatureActive()) {
                    $info['shop'] = 1;
                } elseif (!isset($info['shop']) || empty($info['shop'])) {
                    $info['shop'] = implode($this->multiple_value_separator, Shop::getContextListShopID());
                }
                // Get shops for each attributes
                $info['shop'] = explode($this->multiple_value_separator, $info['shop']);
                $id_shop_list = array();
                foreach ($info['shop'] as $shop) {
                    if (!empty($shop) && !is_numeric($shop)) {
                        $id_shop_list[] = (int) Shop::getIdByName($shop);
                    } elseif (!empty($shop)) {
                        $id_shop_list[] = $shop;
                    }
                }
                if (isset($info['reduction_price']) && $info['reduction_price'] > 0 || isset($info['reduction_percent']) && $info['reduction_percent'] > 0) {
                    foreach ($id_shop_list as $id_shop) {
                        $specific_price = SpecificPrice::getSpecificPrice($product->id, $id_shop, 0, 0, 0, 1, 0, 0, 0, 0);
                        if (is_array($specific_price) && isset($specific_price['id_specific_price'])) {
                            $specific_price = new SpecificPrice((int) $specific_price['id_specific_price']);
                        } else {
                            $specific_price = new SpecificPrice();
                        }
                        $specific_price->id_product = (int) $product->id;
                        $specific_price->id_specific_price_rule = 0;
                        $specific_price->id_shop = $id_shop;
                        $specific_price->id_currency = 0;
                        $specific_price->id_country = 0;
                        $specific_price->id_group = 0;
                        $specific_price->price = -1;
                        $specific_price->id_customer = 0;
                        $specific_price->from_quantity = 1;
                        $specific_price->reduction = isset($info['reduction_price']) && $info['reduction_price'] ? $info['reduction_price'] : $info['reduction_percent'] / 100;
                        $specific_price->reduction_type = isset($info['reduction_price']) && $info['reduction_price'] ? 'amount' : 'percentage';
                        $specific_price->from = isset($info['reduction_from']) && Validate::isDate($info['reduction_from']) ? $info['reduction_from'] : '0000-00-00 00:00:00';
                        $specific_price->to = isset($info['reduction_to']) && Validate::isDate($info['reduction_to']) ? $info['reduction_to'] : '0000-00-00 00:00:00';
                        if (!$specific_price->save()) {
                            $this->addProductWarning(Tools::safeOutput($info['name']), $product->id, $this->l('Discount is invalid'));
                        }
                    }
                }
                if (isset($product->tags) && !empty($product->tags)) {
                    if (isset($product->id) && $product->id) {
                        $tags = Tag::getProductTags($product->id);
                        if (is_array($tags) && count($tags)) {
                            if (!empty($product->tags)) {
                                $product->tags = explode($this->multiple_value_separator, $product->tags);
                            }
                            if (is_array($product->tags) && count($product->tags)) {
                                foreach ($product->tags as $key => $tag) {
                                    if (!empty($tag)) {
                                        $product->tags[$key] = trim($tag);
                                    }
                                }
                                $tags[$id_lang] = $product->tags;
                                $product->tags = $tags;
                            }
                        }
                    }
                    // Delete tags for this id product, for no duplicating error
                    Tag::deleteTagsForProduct($product->id);
                    if (!is_array($product->tags) && !empty($product->tags)) {
                        $product->tags = AdminImportController::createMultiLangField($product->tags);
                        foreach ($product->tags as $key => $tags) {
                            $is_tag_added = Tag::addTags($key, $product->id, $tags, $this->multiple_value_separator);
                            if (!$is_tag_added) {
                                $this->addProductWarning(Tools::safeOutput($info['name']), $product->id, $this->l('Tags list is invalid'));
                                break;
                            }
                        }
                    } else {
                        foreach ($product->tags as $key => $tags) {
                            $str = '';
                            foreach ($tags as $one_tag) {
                                $str .= $one_tag . $this->multiple_value_separator;
                            }
                            $str = rtrim($str, $this->multiple_value_separator);
                            $is_tag_added = Tag::addTags($key, $product->id, $str, $this->multiple_value_separator);
                            if (!$is_tag_added) {
                                $this->addProductWarning(Tools::safeOutput($info['name']), (int) $product->id, 'Invalid tag(s) (' . $str . ')');
                                break;
                            }
                        }
                    }
                }
                //delete existing images if "delete_existing_images" is set to 1
                if (isset($product->delete_existing_images)) {
                    if ((bool) $product->delete_existing_images) {
                        $product->deleteImages();
                    }
                }
                if (isset($product->image) && is_array($product->image) && count($product->image)) {
                    $product_has_images = (bool) Image::getImages($this->context->language->id, (int) $product->id);
                    foreach ($product->image as $key => $url) {
                        $url = trim($url);
                        $error = false;
                        if (!empty($url)) {
                            $url = str_replace(' ', '%20', $url);
                            $image = new Image();
                            $image->id_product = (int) $product->id;
                            $image->position = Image::getHighestPosition($product->id) + 1;
                            $image->cover = !$key && !$product_has_images ? true : false;
                            // file_exists doesn't work with HTTP protocol
                            if (($field_error = $image->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $image->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $image->add()) {
                                // associate image to selected shops
                                $image->associateTo($shops);
                                if (!AdminImportController::copyImg($product->id, $image->id, $url, 'products', !Tools::getValue('regenerate'))) {
                                    $image->delete();
                                    $this->warnings[] = sprintf(Tools::displayError('Error copying image: %s'), $url);
                                }
                            } else {
                                $error = true;
                            }
                        } else {
                            $error = true;
                        }
                        if ($error) {
                            $this->warnings[] = sprintf(Tools::displayError('Product #%1$d: the picture (%2$s) cannot be saved.'), $image->id_product, $url);
                        }
                    }
                }
                if (isset($product->id_category)) {
                    $product->updateCategories(array_map('intval', $product->id_category));
                }
                $product->checkDefaultAttributes();
                if (!$product->cache_default_attribute) {
                    Product::updateDefaultAttribute($product->id);
                }
                // Features import
                $features = get_object_vars($product);
                if (isset($features['features']) && !empty($features['features'])) {
                    foreach (explode($this->multiple_value_separator, $features['features']) as $single_feature) {
                        if (empty($single_feature)) {
                            continue;
                        }
                        $tab_feature = explode(':', $single_feature);
                        $feature_name = isset($tab_feature[0]) ? trim($tab_feature[0]) : '';
                        $feature_value = isset($tab_feature[1]) ? trim($tab_feature[1]) : '';
                        $position = isset($tab_feature[2]) ? (int) $tab_feature[2] - 1 : false;
                        $custom = isset($tab_feature[3]) ? (int) $tab_feature[3] : false;
                        if (!empty($feature_name) && !empty($feature_value)) {
                            $id_feature = (int) Feature::addFeatureImport($feature_name, $position);
                            $id_product = null;
                            if (Tools::getValue('forceIDs') || Tools::getValue('match_ref')) {
                                $id_product = (int) $product->id;
                            }
                            $id_feature_value = (int) FeatureValue::addFeatureValueImport($id_feature, $feature_value, $id_product, $id_lang, $custom);
                            Product::addFeatureProductImport($product->id, $id_feature, $id_feature_value);
                        }
                    }
                }
                // clean feature positions to avoid conflict
                Feature::cleanPositions();
                // set advanced stock managment
                if (isset($product->advanced_stock_management)) {
                    if ($product->advanced_stock_management != 1 && $product->advanced_stock_management != 0) {
                        $this->warnings[] = sprintf(Tools::displayError('Advanced stock management has incorrect value. Not set for product %1$s '), $product->name[$default_language_id]);
                    } elseif (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $product->advanced_stock_management == 1) {
                        $this->warnings[] = sprintf(Tools::displayError('Advanced stock management is not enabled, cannot enable on product %1$s '), $product->name[$default_language_id]);
                    } else {
                        $product->setAdvancedStockManagement($product->advanced_stock_management);
                    }
                    // automaticly disable depends on stock, if a_s_m set to disabled
                    if (StockAvailable::dependsOnStock($product->id) == 1 && $product->advanced_stock_management == 0) {
                        StockAvailable::setProductDependsOnStock($product->id, 0);
                    }
                }
                // Check if warehouse exists
                if (isset($product->warehouse) && $product->warehouse) {
                    if (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) {
                        $this->warnings[] = sprintf(Tools::displayError('Advanced stock management is not enabled, warehouse not set on product %1$s '), $product->name[$default_language_id]);
                    } else {
                        if (Warehouse::exists($product->warehouse)) {
                            // Get already associated warehouses
                            $associated_warehouses_collection = WarehouseProductLocation::getCollection($product->id);
                            // Delete any entry in warehouse for this product
                            foreach ($associated_warehouses_collection as $awc) {
                                $awc->delete();
                            }
                            $warehouse_location_entity = new WarehouseProductLocation();
                            $warehouse_location_entity->id_product = $product->id;
                            $warehouse_location_entity->id_product_attribute = 0;
                            $warehouse_location_entity->id_warehouse = $product->warehouse;
                            if (WarehouseProductLocation::getProductLocation($product->id, 0, $product->warehouse) !== false) {
                                $warehouse_location_entity->update();
                            } else {
                                $warehouse_location_entity->save();
                            }
                            StockAvailable::synchronize($product->id);
                        } else {
                            $this->warnings[] = sprintf(Tools::displayError('Warehouse did not exist, cannot set on product %1$s.'), $product->name[$default_language_id]);
                        }
                    }
                }
                // stock available
                if (isset($product->depends_on_stock)) {
                    if ($product->depends_on_stock != 0 && $product->depends_on_stock != 1) {
                        $this->warnings[] = sprintf(Tools::displayError('Incorrect value for "depends on stock" for product %1$s '), $product->name[$default_language_id]);
                    } elseif ((!$product->advanced_stock_management || $product->advanced_stock_management == 0) && $product->depends_on_stock == 1) {
                        $this->warnings[] = sprintf(Tools::displayError('Advanced stock management not enabled, cannot set "depends on stock" for product %1$s '), $product->name[$default_language_id]);
                    } else {
                        StockAvailable::setProductDependsOnStock($product->id, $product->depends_on_stock);
                    }
                    // This code allows us to set qty and disable depends on stock
                    if (isset($product->quantity) && (int) $product->quantity) {
                        // if depends on stock and quantity, add quantity to stock
                        if ($product->depends_on_stock == 1) {
                            $stock_manager = StockManagerFactory::getManager();
                            $price = str_replace(',', '.', $product->wholesale_price);
                            if ($price == 0) {
                                $price = 1.0E-6;
                            }
                            $price = round(floatval($price), 6);
                            $warehouse = new Warehouse($product->warehouse);
                            if ($stock_manager->addProduct((int) $product->id, 0, $warehouse, (int) $product->quantity, 1, $price, true)) {
                                StockAvailable::synchronize((int) $product->id);
                            }
                        } else {
                            if (Shop::isFeatureActive()) {
                                foreach ($shops as $shop) {
                                    StockAvailable::setQuantity((int) $product->id, 0, (int) $product->quantity, (int) $shop);
                                }
                            } else {
                                StockAvailable::setQuantity((int) $product->id, 0, (int) $product->quantity, (int) $this->context->shop->id);
                            }
                        }
                    }
                } else {
                    if (Shop::isFeatureActive()) {
                        foreach ($shops as $shop) {
                            StockAvailable::setQuantity((int) $product->id, 0, (int) $product->quantity, (int) $shop);
                        }
                    } else {
                        StockAvailable::setQuantity((int) $product->id, 0, (int) $product->quantity, (int) $this->context->shop->id);
                    }
                }
            }
        }
        $this->closeCsvFile($handle);
    }
Beispiel #11
0
 public function prepareModuleSettings()
 {
     // Database
     $sql = array();
     include dirname(__FILE__) . '/init/install_sql.php';
     foreach ($sql as $s) {
         if (!Db::getInstance()->Execute($s)) {
             die('Error while creating DB');
         }
     }
     /**
     
             Update to 1.6.0.6 problem
     
             **/
     $sql = 'SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'tab`';
     $tab_columns = Db::getInstance()->executeS($sql);
     $createColumn = true;
     foreach ($tab_columns as $column) {
         if ($column['Field'] == 'hide_host_mode') {
             $createColumn = false;
         }
     }
     if ($createColumn == true) {
         Db::getInstance()->query('ALTER TABLE `' . _DB_PREFIX_ . 'tab` ADD `hide_host_mode` tinyint(1) NOT NULL DEFAULT 0 AFTER  `active`');
     }
     /**
     
             Tabs
     
             **/
     // Tabs
     $parent_tab = new Tab();
     $parent_tab->name = array();
     foreach (Language::getLanguages(true) as $lang) {
         $parent_tab->name[$lang['id_lang']] = $this->l('Blog for PrestaShop');
     }
     $parent_tab->class_name = 'AdminSimpleBlog';
     $parent_tab->id_parent = 0;
     $parent_tab->module = $this->name;
     $parent_tab->add();
     // Categories
     $tab = new Tab();
     $tab->name = array();
     foreach (Language::getLanguages(true) as $lang) {
         $tab->name[$lang['id_lang']] = $this->l('Categories');
     }
     $tab->class_name = 'AdminSimpleBlogCategories';
     $tab->id_parent = $parent_tab->id;
     $tab->module = $this->name;
     $tab->add();
     // Posts
     $tab = new Tab();
     $tab->name = array();
     foreach (Language::getLanguages(true) as $lang) {
         $tab->name[$lang['id_lang']] = $this->l('Posts');
     }
     $tab->class_name = 'AdminSimpleBlogPosts';
     $tab->id_parent = $parent_tab->id;
     $tab->module = $this->name;
     $tab->add();
     // Authors
     // $tab = new Tab();
     // $tab->name = array();
     // foreach (Language::getLanguages(true) as $lang)
     //     $tab->name[$lang['id_lang']] = $this->l('Authors');
     // $tab->class_name = 'AdminSimpleBlogAuthors';
     // $tab->id_parent = $parent_tab->id;
     // $tab->module = $this->name;
     // $tab->add();
     // Comments
     $tab = new Tab();
     $tab->name = array();
     foreach (Language::getLanguages(true) as $lang) {
         $tab->name[$lang['id_lang']] = $this->l('Comments');
     }
     $tab->class_name = 'AdminSimpleBlogComments';
     $tab->id_parent = $parent_tab->id;
     $tab->module = $this->name;
     $tab->add();
     // Tags
     $tab = new Tab();
     $tab->name = array();
     foreach (Language::getLanguages(true) as $lang) {
         $tab->name[$lang['id_lang']] = $this->l('Tags');
     }
     $tab->class_name = 'AdminSimpleBlogTags';
     $tab->id_parent = $parent_tab->id;
     $tab->module = $this->name;
     $tab->add();
     // Settings
     $tab = new Tab();
     $tab->name = array();
     foreach (Language::getLanguages(true) as $lang) {
         $tab->name[$lang['id_lang']] = $this->l('Settings');
     }
     $tab->class_name = 'AdminSimpleBlogSettings';
     $tab->id_parent = $parent_tab->id;
     $tab->module = $this->name;
     $tab->add();
     $id_lang = $this->context->language->id;
     // Default category
     $simple_blog_category = new SimpleBlogCategory();
     foreach (Language::getLanguages(true) as $lang) {
         $simple_blog_category->name[$lang['id_lang']] = 'News';
     }
     foreach (Language::getLanguages(true) as $lang) {
         $simple_blog_category->link_rewrite[$lang['id_lang']] = 'news';
     }
     $simple_blog_category->add();
     $simple_blog_category->associateTo(Shop::getCompleteListOfShopsID());
     // Post Types
     $default_post_type = new SimpleBlogPostType();
     $default_post_type->name = 'Post';
     $default_post_type->slug = 'post';
     $default_post_type->description = 'Default type of post';
     $default_post_type->add();
     $gallery_post_type = new SimpleBlogPostType();
     $gallery_post_type->name = 'Gallery';
     $gallery_post_type->slug = 'gallery';
     $gallery_post_type->add();
     $external_url_post_type = new SimpleBlogPostType();
     $external_url_post_type->name = 'External URL';
     $external_url_post_type->slug = 'url';
     $external_url_post_type->add();
     $video_post_type = new SimpleBlogPostType();
     $video_post_type->name = 'Video';
     $video_post_type->slug = 'video';
     $video_post_type->add();
     // Settings
     Configuration::updateValue('PH_BLOG_POSTS_PER_PAGE', '10');
     Configuration::updateValue('PH_BLOG_FB_COMMENTS', '1');
     Configuration::updateValue('PH_BLOG_SLUG', 'blog');
     Configuration::updateValue('PH_BLOG_COLUMNS', 'prestashop');
     Configuration::updateValue('PH_BLOG_LAYOUT', 'default');
     Configuration::updateValue('PH_BLOG_LIST_LAYOUT', 'grid');
     Configuration::updateValue('PH_BLOG_GRID_COLUMNS', '2');
     Configuration::updateValue('PH_BLOG_MAIN_TITLE', array($this->context->language->id => 'Blog - whats new?'));
     Configuration::updateValue('PH_BLOG_LOAD_FA', '0');
     Configuration::updateValue('PH_BLOG_DISPLAY_AUTHOR', '1');
     Configuration::updateValue('PH_BLOG_DISPLAY_DATE', '1');
     Configuration::updateValue('PH_BLOG_DISPLAY_THUMBNAIL', '1');
     Configuration::updateValue('PH_BLOG_DISPLAY_CATEGORY', '1');
     Configuration::updateValue('PH_BLOG_DISPLAY_SHARER', '1');
     Configuration::updateValue('PH_BLOG_DISPLAY_TAGS', '1');
     Configuration::updateValue('PH_BLOG_DISPLAY_DESCRIPTION', '1');
     // Thumbnails
     Configuration::updateValue('PH_BLOG_THUMB_METHOD', '1');
     Configuration::updateValue('PH_BLOG_THUMB_X', '600');
     Configuration::updateValue('PH_BLOG_THUMB_Y', '300');
     Configuration::updateValue('PH_BLOG_THUMB_X_WIDE', '900');
     Configuration::updateValue('PH_BLOG_THUMB_Y_WIDE', '350');
     // Recent Posts
     Configuration::updateValue('PH_RECENTPOSTS_NB', '4');
     Configuration::updateValue('PH_RECENTPOSTS_CAT', '0');
     Configuration::updateValue('PH_RECENTPOSTS_POSITION', 'home');
     Configuration::updateValue('PH_RECENTPOSTS_LAYOUT', 'grid');
     // @Since 1.1.4
     // Category description
     Configuration::updateValue('PH_BLOG_DISPLAY_CAT_DESC', '1');
     // @since 1.1.5
     Configuration::updateValue('PH_BLOG_POST_BY_AUTHOR', '1');
     // @since 1.1.7
     Configuration::updateValue('PH_BLOG_FB_INIT', '1');
     // @since 1.1.8
     Configuration::updateValue('PH_BLOG_DISPLAY_FEATURED', '1');
     // @since 1.1.9
     //Configuration::updateValue('PH_BLOG_INSTALL', '1');
     // @since 1.1.9.5
     Configuration::updateValue('PH_BLOG_DISPLAY_BREADCRUMBS', '1');
     // @since 1.2.0.0
     Configuration::updateValue('PH_BLOG_DISPLAY_CATEGORY_IMAGE', '1');
     Configuration::updateValue('PH_BLOG_DISPLAY_LIKES', '1');
     Configuration::updateValue('PH_BLOG_DISPLAY_VIEWS', '1');
     Configuration::updateValue('PH_CATEGORY_IMAGE_X', '900');
     Configuration::updateValue('PH_CATEGORY_IMAGE_Y', '250');
     Configuration::updateValue('PH_CATEGORY_SORTBY', 'position');
     // @since 1.2.0.6
     Configuration::updateValue('PH_BLOG_DATEFORMAT', 'd M Y, H:i');
     Configuration::updateValue('PH_RECENTPOSTS_GRID_COLUMNS', '2');
     Configuration::updateValue('PH_RELATEDPOSTS_GRID_COLUMNS', '2');
     /**
             
             Update 1.2.2.0 - 07.2014
     
             **/
     // Comments
     Configuration::updateGlobalValue('PH_BLOG_NATIVE_COMMENTS', '1');
     Configuration::updateGlobalValue('PH_BLOG_COMMENT_NOTIFICATIONS', '1');
     // Authors
     Configuration::updateGlobalValue('PH_BLOG_NEW_AUTHORS', '0');
     Configuration::updateGlobalValue('PH_BLOG_AUTHOR_INFO', '1');
     /**
             
             Update 1.2.2.3 - 08.2014
     
             **/
     Configuration::updateGlobalValue('PH_BLOG_COMMENT_AUTO_APPROVAL', '0');
     /**
             
             Update 1.2.2.4 - 08.2014
     
             **/
     /**
             
             Update 1.2.2.5 - 08.2014
     
             **/
     Configuration::updateGlobalValue('PH_BLOG_COMMENT_ALLOW', '1');
     Configuration::updateGlobalValue('PH_BLOG_COMMENT_STUFF_HIGHLIGHT', '1');
     Configuration::updateGlobalValue('PH_BLOG_COMMENT_NOTIFY_EMAIL', Configuration::get('PS_SHOP_EMAIL'));
     /**
             
             Update 1.2.2.6 - 09.2014
     
             **/
     Configuration::updateGlobalValue('PH_BLOG_FACEBOOK_MODERATOR', '');
     Configuration::updateGlobalValue('PH_BLOG_FACEBOOK_APP_ID', '');
     Configuration::updateGlobalValue('PH_BLOG_FACEBOOK_COLOR_SCHEME', 'light');
     /**
     
             Update 1.2.2.8 - 09.2014
     
             **/
     Configuration::updateGlobalValue('PH_BLOG_DISPLAY_MORE', '1');
     /**
     
             Update 1.2.2.9 - 09.2014
     
             **/
     Configuration::updateGlobalValue('PH_BLOG_MASONRY_LAYOUT', '0');
     /**
     
             Update 1.3.1.6 - 10.2014
     
             **/
     if (function_exists('date_default_timezone_get')) {
         $timezone = @date_default_timezone_get();
     } else {
         $timezone = 'Europe/Warsaw';
     }
     Configuration::updateGlobalValue('PH_BLOG_TIMEZONE', $timezone);
     /**
     
             Update 1.3.1.9 - 11.2014
     
             **/
     Configuration::updateGlobalValue('PH_BLOG_LOAD_FONT_AWESOME', 1);
     Configuration::updateGlobalValue('PH_BLOG_LOAD_BXSLIDER', 1);
     Configuration::updateGlobalValue('PH_BLOG_LOAD_MASONRY', 1);
     Configuration::updateGlobalValue('PH_BLOG_LOAD_FITVIDS', 1);
     /**
     
             Update 1.3.2.5 - 01.2015
     
             **/
     Configuration::updateGlobalValue('PH_BLOG_DISPLAY_RELATED', 1);
     /**
     
             Update 1.3.2.8 - 02.2015
     
             **/
     Configuration::updateGlobalValue('PH_BLOG_COMMENT_ALLOW_GUEST', false);
     Configuration::updateGlobalValue('PH_BLOG_COMMENTS_RECAPTCHA', true);
     Configuration::updateGlobalValue('PH_BLOG_COMMENTS_RECAPTCHA_SITE_KEY', '');
     Configuration::updateGlobalValue('PH_BLOG_COMMENTS_RECAPTCHA_SECRET_KEY', '');
     Configuration::updateGlobalValue('PH_BLOG_COMMENTS_RECAPTCHA_THEME', 'light');
     /**
     
             Update 1.3.2.9 - 02.2015
     
             **/
     Configuration::updateGlobalValue('PH_BLOG_RELATED_PRODUCTS_USE_DEFAULT_LIST', false);
     /**
     
             Update 1.3.3 - 02.2015
     
             **/
     Configuration::updateGlobalValue('PH_BLOG_ADVERTISING', true);
     /**
     
             Update 1.4.0 - 06.2015
     
             **/
     Configuration::updateGlobalValue('PH_BLOG_COMMENTS_SYSTEM', 'native');
     Configuration::updateGlobalValue('PH_BLOG_DISQUS_SHORTNAME', 'blogforprestashop');
     /**
             
                 For theme developers - you're welcome!
     
             **/
     if (file_exists(_PS_MODULE_DIR_ . 'ph_simpleblog/init/my-install.php')) {
         include_once _PS_MODULE_DIR_ . 'ph_simpleblog/init/my-install.php';
     }
     return true;
 }
 function generateCss()
 {
     $menus = AdvancedTopMenuClass::getMenus($this->_cookie->id_lang, true, true);
     $columnsWrap = AdvancedTopMenuColumnWrapClass::getColumnsWrap();
     $css = array();
     foreach ($menus as $menu) {
         if ($menu['txt_color_menu_tab']) {
             $css[] = '.advtm_menu_' . $menu['id_menu'] . ' .advtm_menu_span_' . $menu['id_menu'] . ', .advtm_menu_' . $menu['id_menu'] . ' a .advtm_menu_span_' . $menu['id_menu'] . ' {color:' . htmlentities($menu['txt_color_menu_tab'], ENT_COMPAT, 'UTF-8') . '!important;}';
         }
         if ($menu['txt_color_menu_tab_hover']) {
             $css[] = '.advtm_menu_' . $menu['id_menu'] . ' a:hover .advtm_menu_span_' . $menu['id_menu'] . ', .advtm_menu_' . $menu['id_menu'] . ' a.advtm_menu_actif .advtm_menu_span_' . $menu['id_menu'] . ', .advtm_menu_' . $menu['id_menu'] . ':hover > a.a-niveau1 .advtm_menu_span_' . $menu['id_menu'] . ' {color:' . htmlentities($menu['txt_color_menu_tab_hover'], ENT_COMPAT, 'UTF-8') . '!important;}';
             //ie6
             $css[] = '* html .advtm_menu_' . $menu['id_menu'] . ' a:hover .advtm_menu_span_' . $menu['id_menu'] . ', * html .advtm_menu_' . $menu['id_menu'] . ' a.advtm_menu_actif .advtm_menu_span_' . $menu['id_menu'] . ' {color:' . htmlentities($menu['txt_color_menu_tab_hover'], ENT_COMPAT, 'UTF-8') . '!important;}';
         }
         if ($menu['fnd_color_menu_tab']) {
             $menu['fnd_color_menu_tab'] = explode($this->gradient_separator, $menu['fnd_color_menu_tab']);
             if (isset($menu['fnd_color_menu_tab'][1])) {
                 $color1 = htmlentities($menu['fnd_color_menu_tab'][0], ENT_COMPAT, 'UTF-8');
                 $color2 = htmlentities($menu['fnd_color_menu_tab'][1], ENT_COMPAT, 'UTF-8');
                 $css[] = '.advtm_menu_' . $menu['id_menu'] . ' a .advtm_menu_span_' . $menu['id_menu'] . ' {background-color: ' . $color1 . ';filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=\'' . $color1 . '\', endColorstr=\'' . $color2 . '\')!important; background: -webkit-gradient(linear, left top, left bottom, from(' . $color1 . '), to(' . $color2 . '))!important;background: -moz-linear-gradient(top, ' . $color1 . ', ' . $color2 . ')!important; background: -ms-linear-gradient(top, ' . $color1 . ', ' . $color2 . ')!important; background: -o-linear-gradient(top, ' . $color1 . ', ' . $color2 . ')!important; background: linear-gradient(top, ' . $color1 . ', ' . $color2 . ')!important;}';
             } else {
                 $css[] = '.advtm_menu_' . $menu['id_menu'] . ' a .advtm_menu_span_' . $menu['id_menu'] . ' {background-color:' . htmlentities($menu['fnd_color_menu_tab'][0], ENT_COMPAT, 'UTF-8') . '!important;filter: none!important; background: ' . htmlentities($menu['fnd_color_menu_tab'][0], ENT_COMPAT, 'UTF-8') . '!important;background: ' . htmlentities($menu['fnd_color_menu_tab'][0], ENT_COMPAT, 'UTF-8') . '!important;}';
             }
         }
         if ($menu['fnd_color_menu_tab_over']) {
             $menu['fnd_color_menu_tab_over'] = explode($this->gradient_separator, $menu['fnd_color_menu_tab_over']);
             if (isset($menu['fnd_color_menu_tab_over'][1])) {
                 $color1 = htmlentities($menu['fnd_color_menu_tab_over'][0], ENT_COMPAT, 'UTF-8');
                 $color2 = htmlentities($menu['fnd_color_menu_tab_over'][1], ENT_COMPAT, 'UTF-8');
                 $css[] = '.advtm_menu_' . $menu['id_menu'] . ' a:hover .advtm_menu_span_' . $menu['id_menu'] . ', .advtm_menu_' . $menu['id_menu'] . ' a.advtm_menu_actif .advtm_menu_span_' . $menu['id_menu'] . ', .advtm_menu_' . $menu['id_menu'] . ':hover > a.a-niveau1 .advtm_menu_span_' . $menu['id_menu'] . ' {background-color: ' . $color1 . '!important;filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=\'' . $color1 . '\', endColorstr=\'' . $color2 . '\')!important; background: -webkit-gradient(linear, left top, left bottom, from(' . $color1 . '), to(' . $color2 . '))!important;background: -moz-linear-gradient(top, ' . $color1 . ', ' . $color2 . ')!important; background: -ms-linear-gradient(top, ' . $color1 . ', ' . $color2 . ')!important; background: -o-linear-gradient(top, ' . $color1 . ', ' . $color2 . ')!important; background: linear-gradient(top, ' . $color1 . ', ' . $color2 . ')!important;}';
                 $css[] = '* html .advtm_menu_' . $menu['id_menu'] . ' a:hover .advtm_menu_span_' . $menu['id_menu'] . ', * html .advtm_menu_' . $menu['id_menu'] . ' a.advtm_menu_actif .advtm_menu_span_' . $menu['id_menu'] . ' {background-color:transparent!important;background:transparent!important;filter:none!important;filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=\'' . $color1 . '\', endColorstr=\'' . $color2 . '\')!important;}';
             } else {
                 $css[] = '.advtm_menu_' . $menu['id_menu'] . ' a:hover .advtm_menu_span_' . $menu['id_menu'] . ', .advtm_menu_' . $menu['id_menu'] . ' a.advtm_menu_actif .advtm_menu_span_' . $menu['id_menu'] . ', .advtm_menu_' . $menu['id_menu'] . ':hover > a.a-niveau1 .advtm_menu_span_' . $menu['id_menu'] . ' {background-color:' . htmlentities($menu['fnd_color_menu_tab_over'][0], ENT_COMPAT, 'UTF-8') . '!important;filter: none!important; background: ' . htmlentities($menu['fnd_color_menu_tab_over'][0], ENT_COMPAT, 'UTF-8') . '!important;background: ' . htmlentities($menu['fnd_color_menu_tab_over'][0], ENT_COMPAT, 'UTF-8') . '!important;}';
                 //ie6
                 $css[] = '* html .advtm_menu_' . $menu['id_menu'] . ' a:hover .advtm_menu_span_' . $menu['id_menu'] . ', .advtm_menu_' . $menu['id_menu'] . ' a.advtm_menu_actif .advtm_menu_span_' . $menu['id_menu'] . ' {background-color:' . htmlentities($menu['fnd_color_menu_tab_over'][0], ENT_COMPAT, 'UTF-8') . '!important;filter:none!important;}';
                 $css[] = '* html .advtm_menu_' . $menu['id_menu'] . ' a:hover, .advtm_menu_' . $menu['id_menu'] . ' a.advtm_menu_actif {filter:none!important;}';
             }
         }
         if ($menu['border_size_tab']) {
             $css[] = 'li.advtm_menu_' . $menu['id_menu'] . ' a.a-niveau1 {border-width:' . htmlentities($menu['border_size_tab'], ENT_COMPAT, 'UTF-8') . '!important;}';
         }
         if ($menu['border_color_tab']) {
             $css[] = 'li.advtm_menu_' . $menu['id_menu'] . ' a.a-niveau1 {border-color:' . htmlentities($menu['border_color_tab'], ENT_COMPAT, 'UTF-8') . '!important;}';
         }
         if ($menu['width_submenu']) {
             $css[] = '.advtm_menu_' . $menu['id_menu'] . ' .adtm_sub {width:' . htmlentities($menu['width_submenu'], ENT_COMPAT, 'UTF-8') . 'px!important;}';
         } elseif ($menu['width_submenu'] === '0') {
             $css[] = '.advtm_menu_' . $menu['id_menu'] . ' .adtm_sub {width:auto!important;}';
         }
         if ($menu['minheight_submenu']) {
             $css[] = '.advtm_menu_' . $menu['id_menu'] . ' .adtm_sub {min-height:' . htmlentities($menu['minheight_submenu'], ENT_COMPAT, 'UTF-8') . 'px!important;}';
             $css[] = '* html .advtm_menu_' . $menu['id_menu'] . ' .adtm_sub {height:' . htmlentities($menu['minheight_submenu'], ENT_COMPAT, 'UTF-8') . 'px!important;}';
             $css[] = '#adtm_menu .advtm_menu_' . $menu['id_menu'] . ' div.adtm_column_wrap {min-height:' . htmlentities($menu['minheight_submenu'], ENT_COMPAT, 'UTF-8') . 'px!important;}';
             $css[] = '* html #adtm_menu .advtm_menu_' . $menu['id_menu'] . ' div.adtm_column_wrap {height:' . htmlentities($menu['minheight_submenu'], ENT_COMPAT, 'UTF-8') . 'px!important;}';
         } elseif ($menu['minheight_submenu'] === '0') {
             $css[] = '.advtm_menu_' . $menu['id_menu'] . ' .adtm_sub {height:auto!important;min-height:0!important;}';
             $css[] = '#adtm_menu .advtm_menu_' . $menu['id_menu'] . ' div.adtm_column_wrap {height:auto!important;min-height:0!important;}';
         }
         if ($menu['position_submenu']) {
             if (intval($menu['position_submenu']) == 1 || intval($menu['position_submenu']) == 3) {
                 $css[] = '#adtm_menu ul#menu li.advtm_menu_' . $menu['id_menu'] . ':hover, #adtm_menu ul#menu li.advtm_menu_' . $menu['id_menu'] . ' a.a-niveau1:hover {position:relative!important;}';
             } elseif (intval($menu['position_submenu']) == 2) {
                 $css[] = '#adtm_menu ul#menu li.advtm_menu_' . $menu['id_menu'] . ':hover, #adtm_menu ul#menu li.advtm_menu_' . $menu['id_menu'] . ' a.a-niveau1:hover {position:static!important;}';
             }
             if (intval($menu['position_submenu']) == 3) {
                 $css[] = '#adtm_menu ul#menu li.advtm_menu_' . $menu['id_menu'] . ':hover div.adtm_sub {left:auto!important;right:0!important;}';
                 $css[] = '#adtm_menu ul#menu li.advtm_menu_' . $menu['id_menu'] . ' a:hover div.adtm_sub {left:auto!important;right:1px!important;}';
             }
         }
         if ($menu['fnd_color_submenu']) {
             $menu['fnd_color_submenu'] = explode($this->gradient_separator, $menu['fnd_color_submenu']);
             if (isset($menu['fnd_color_submenu'][1])) {
                 $color1 = htmlentities($menu['fnd_color_submenu'][0], ENT_COMPAT, 'UTF-8');
                 $color2 = htmlentities($menu['fnd_color_submenu'][1], ENT_COMPAT, 'UTF-8');
                 $css[] = '.advtm_menu_' . $menu['id_menu'] . ' .adtm_sub {background-color: ' . $color1 . ';filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=\'' . $color1 . '\', endColorstr=\'' . $color2 . '\')!important; background: -webkit-gradient(linear, left top, left bottom, from(' . $color1 . '), to(' . $color2 . '))!important;background: -moz-linear-gradient(top, ' . $color1 . ', ' . $color2 . ')!important; background: -ms-linear-gradient(top, ' . $color1 . ', ' . $color2 . ')!important; background: -o-linear-gradient(top, ' . $color1 . ', ' . $color2 . ')!important; background: linear-gradient(top, ' . $color1 . ', ' . $color2 . ')!important;}';
             } else {
                 $css[] = '.advtm_menu_' . $menu['id_menu'] . ' .adtm_sub {background-color:' . htmlentities($menu['fnd_color_submenu'][0], ENT_COMPAT, 'UTF-8') . '!important;filter: none!important; background: ' . htmlentities($menu['fnd_color_submenu'][0], ENT_COMPAT, 'UTF-8') . '!important;background: ' . htmlentities($menu['fnd_color_submenu'][0], ENT_COMPAT, 'UTF-8') . '!important;}';
             }
         }
         if ($menu['border_color_submenu']) {
             $css[] = '.advtm_menu_' . $menu['id_menu'] . ' div.adtm_sub {border-color:' . htmlentities($menu['border_color_submenu'], ENT_COMPAT, 'UTF-8') . '!important;}';
         }
         if ($menu['border_size_submenu']) {
             $css[] = '.advtm_menu_' . $menu['id_menu'] . ' div.adtm_sub {border-width:' . htmlentities($menu['border_size_submenu'], ENT_COMPAT, 'UTF-8') . '!important;}';
         }
     }
     foreach ($columnsWrap as $columnWrap) {
         if ($columnWrap['bg_color']) {
             $columnWrap['bg_color'] = explode($this->gradient_separator, $columnWrap['bg_color']);
             if (isset($columnWrap['bg_color'][1])) {
                 $color1 = htmlentities($columnWrap['bg_color'][0], ENT_COMPAT, 'UTF-8');
                 $color2 = htmlentities($columnWrap['bg_color'][1], ENT_COMPAT, 'UTF-8');
                 $css[] = '.advtm_column_wrap_td_' . $columnWrap['id_wrap'] . ' {background-color: ' . $color1 . ';filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=\'' . $color1 . '\', endColorstr=\'' . $color2 . '\')!important; background: -webkit-gradient(linear, left top, left bottom, from(' . $color1 . '), to(' . $color2 . '))!important;background: -moz-linear-gradient(top, ' . $color1 . ', ' . $color2 . ')!important; background: -ms-linear-gradient(top, ' . $color1 . ', ' . $color2 . ')!important; background: -o-linear-gradient(top, ' . $color1 . ', ' . $color2 . ')!important; background: linear-gradient(top, ' . $color1 . ', ' . $color2 . ')!important;}';
             } else {
                 $css[] = '.advtm_column_wrap_td_' . $columnWrap['id_wrap'] . ' {background-color:' . htmlentities($columnWrap['bg_color'][0], ENT_COMPAT, 'UTF-8') . '!important;filter: none!important; background: ' . htmlentities($columnWrap['bg_color'][0], ENT_COMPAT, 'UTF-8') . '!important;background: ' . htmlentities($columnWrap['bg_color'][0], ENT_COMPAT, 'UTF-8') . '!important;}';
             }
         }
         if ($columnWrap['txt_color_column']) {
             $css[] = '.advtm_column_wrap_' . $columnWrap['id_wrap'] . ' span.column_wrap_title, .advtm_column_wrap_' . $columnWrap['id_wrap'] . ' span.column_wrap_title a {color:' . htmlentities($columnWrap['txt_color_column'], ENT_COMPAT, 'UTF-8') . '!important;}';
         }
         if ($columnWrap['txt_color_column_over']) {
             $css[] = '.advtm_column_wrap_' . $columnWrap['id_wrap'] . ' span.column_wrap_title a:hover {color:' . htmlentities($columnWrap['txt_color_column_over'], ENT_COMPAT, 'UTF-8') . '!important;}';
         }
         if ($columnWrap['txt_color_element']) {
             $css[] = '.advtm_column_wrap_' . $columnWrap['id_wrap'] . ', .advtm_column_wrap_' . $columnWrap['id_wrap'] . ' a {color:' . htmlentities($columnWrap['txt_color_element'], ENT_COMPAT, 'UTF-8') . '!important;}';
         }
         if ($columnWrap['txt_color_element_over']) {
             $css[] = '.advtm_column_wrap_' . $columnWrap['id_wrap'] . ' a:hover {color:' . htmlentities($columnWrap['txt_color_element_over'], ENT_COMPAT, 'UTF-8') . '!important;}';
         }
         if ($columnWrap['width']) {
             $css[] = '.advtm_column_wrap_' . $columnWrap['id_wrap'] . ' {width:' . htmlentities($columnWrap['width'], ENT_COMPAT, 'UTF-8') . 'px!important;}';
         }
     }
     $advanced_css_file = dirname(__FILE__) . '/' . self::ADVANCED_CSS_FILE;
     $old_advanced_css_file_exists = file_exists($advanced_css_file);
     $ids_shop = array(1);
     if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) {
         $ids_shop = array_values(Shop::getCompleteListOfShopsID());
     }
     foreach ($ids_shop as $id_shop) {
         $advanced_css_file_shop = str_replace('.css', '-' . $id_shop . '.css', $advanced_css_file);
         if (!$old_advanced_css_file_exists && !file_exists($advanced_css_file_shop)) {
             file_put_contents($advanced_css_file_shop, file_get_contents(dirname(__FILE__) . '/' . self::ADVANCED_CSS_FILE_RESTORE));
         } else {
             if ($old_advanced_css_file_exists && sizeof($ids_shop) == 1 && !file_exists($advanced_css_file_shop)) {
                 file_put_contents($advanced_css_file_shop, file_get_contents(dirname(__FILE__) . '/' . self::ADVANCED_CSS_FILE));
                 @unlink(dirname(__FILE__) . '/' . self::ADVANCED_CSS_FILE);
             } else {
                 if (!file_exists($advanced_css_file_shop)) {
                     file_put_contents($advanced_css_file_shop, file_get_contents(dirname(__FILE__) . '/' . self::ADVANCED_CSS_FILE_RESTORE));
                 }
             }
         }
     }
     $ids_shop = array(1);
     if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) {
         $ids_shop = array_values(Shop::getCompleteListOfShopsID());
     }
     $specific_css_file = array();
     foreach ($ids_shop as $id_shop) {
         $specific_css_file[] = str_replace('.css', '-' . $id_shop . '.css', dirname(__FILE__) . '/' . self::DYN_CSS_FILE);
     }
     if (sizeof($css) && sizeof($specific_css_file)) {
         foreach ($specific_css_file as $value) {
             file_put_contents($value, implode("\n", $css));
         }
     } else {
         if (!sizeof($css) && sizeof($specific_css_file)) {
             foreach ($specific_css_file as $value) {
                 file_put_contents($value, '');
             }
         }
     }
 }
 public function postProcess()
 {
     $this->_setFields();
     // set default configuration to default channel & dafault configuration for backup and upgrade
     // (can be modified in expert mode)
     $config = $this->getConfig('channel');
     if ($config === false) {
         $config = array();
         $config['channel'] = Upgrader::DEFAULT_CHANNEL;
         $this->writeConfig($config);
         if (class_exists('Configuration', false)) {
             Configuration::updateValue('PS_UPGRADE_CHANNEL', $config['channel']);
         }
         $this->writeConfig(array('PS_AUTOUP_PERFORMANCE' => '1', 'PS_AUTOUP_CUSTOM_MOD_DESACT' => '1', 'PS_AUTOUP_UPDATE_DEFAULT_THEME' => '1', 'PS_AUTOUP_CHANGE_DEFAULT_THEME' => '0', 'PS_AUTOUP_KEEP_MAILS' => '0', 'PS_AUTOUP_BACKUP' => '1', 'PS_AUTOUP_KEEP_IMAGES' => '0'));
     }
     if (Tools14::isSubmit('putUnderMaintenance')) {
         foreach (Shop::getCompleteListOfShopsID() as $id_shop) {
             Configuration::updateValue('PS_SHOP_ENABLE', 0, false, null, (int) $id_shop);
         }
         Configuration::updateGlobalValue('PS_SHOP_ENABLE', 0);
     }
     if (Tools14::isSubmit('customSubmitAutoUpgrade')) {
         $config_keys = array_keys(array_merge($this->_fieldsUpgradeOptions, $this->_fieldsBackupOptions));
         $config = array();
         foreach ($config_keys as $key) {
             if (isset($_POST[$key])) {
                 $config[$key] = $_POST[$key];
             }
         }
         $res = $this->writeConfig($config);
         if ($res) {
             Tools14::redirectAdmin($this->currentIndex . '&conf=6&token=' . Tools14::getValue('token'));
         }
     }
     if (Tools14::isSubmit('deletebackup')) {
         $res = false;
         $name = Tools14::getValue('name');
         $filelist = scandir($this->backupPath);
         foreach ($filelist as $filename) {
             // the following will match file or dir related to the selected backup
             if (!empty($filename) && $filename[0] != '.' && $filename != 'index.php' && $filename != '.htaccess' && preg_match('#^(auto-backupfiles_|)' . preg_quote($name) . '(\\.zip|)$#', $filename, $matches)) {
                 if (is_file($this->backupPath . DIRECTORY_SEPARATOR . $filename)) {
                     $res &= unlink($this->backupPath . DIRECTORY_SEPARATOR . $filename);
                 } elseif (!empty($name) && is_dir($this->backupPath . DIRECTORY_SEPARATOR . $name . DIRECTORY_SEPARATOR)) {
                     $res = self::deleteDirectory($this->backupPath . DIRECTORY_SEPARATOR . $name . DIRECTORY_SEPARATOR);
                 }
             }
         }
         if ($res) {
             Tools14::redirectAdmin($this->currentIndex . '&conf=1&token=' . Tools14::getValue('token'));
         } else {
             $this->_errors[] = sprintf($this->l('Error when trying to delete backups %s'), $name);
         }
     }
     parent::postProcess();
 }
 /**
  * Get view 
  *
  * @return string
  */
 public function initContent()
 {
     $features = array();
     //$_features = FeatureValue::getFeatureValuesWithLang( (int)Context::getContext()->language->id, Configuration::get('APH_FEATURE_DURATION') );
     $services_duration = json_decode(Configuration::get('APH_SERVICES_DURATION'), true);
     foreach ($services_duration as $id_feature_value => $duration) {
         if ($duration >= 120) {
             $features[$id_feature_value] = $duration / 60 . ' ore';
         } else {
             $features[$id_feature_value] = $duration . ' minuti';
         }
     }
     $this->context->smarty->assign('features', $features);
     $currency = $this->context->currency;
     $this->context->smarty->assign('currency', $currency);
     if (Context::getContext()->employee->id_profile == Configuration::get('APH_PROFILE_SITE_OWNER')) {
         $shops = array();
         //$_shops = Shop::getShops(true, null, true);
         $_shops = Shop::getCompleteListOfShopsID();
         foreach ($_shops as $id_shop) {
             if ($id_shop == Configuration::get('PS_SHOP_DEFAULT')) {
                 continue;
             }
             $shop = new Shop($id_shop);
             $shops[$id_shop] = $shop->name;
         }
         asort($shops);
         $this->context->smarty->assign('shops', $shops);
     }
     if ($this->display == 'edit') {
         list($this->id_product, $this->id_shop) = explode('-', Tools::getValue('id_ps'));
         $obj = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('SELECT a.*,pl.name,j.id_feature_value FROM `' . _DB_PREFIX_ . 'product_shop` a' . ' JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON pl.`id_product` = a.`id_product` AND pl.`id_shop`=' . $this->id_shop . ' AND pl.`id_lang`= ' . (int) Context::getContext()->language->id . ' JOIN `' . _DB_PREFIX_ . 'feature_product` j ON j.`id_product` = a.`id_product`' . ' AND j.`id_feature`=' . Configuration::get('APH_FEATURE_DURATION') . ' AND a.`id_shop`=' . $this->id_shop . ' AND a.`id_product`=' . $this->id_product);
         if ($obj['id_service_duration'] <= 0) {
             $obj['id_service_duration'] = $obj['id_feature_value'];
         }
         $this->context->smarty->assign(array('obj' => $obj));
         $this->content .= $this->context->smarty->fetch(_PS_MODULE_DIR_ . $this->module->name . "/views/templates/admin/controllers/long_prices/form.tpl");
     } elseif ($this->display == 'add') {
         $languages = Language::getLanguages(true);
         $this->context->smarty->assign(array("id_lang_default" => Configuration::get('PS_LANG_DEFAULT'), 'tpl_dir' => $this->tpl_dir, "languages" => $languages));
         $this->content .= $this->context->smarty->fetch(_PS_MODULE_DIR_ . $this->module->name . "/views/templates/admin/controllers/long_prices/form.tpl");
     }
     parent::initContent();
 }
Beispiel #15
0
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*  @author    Benichou <*****@*****.**>
*  @copyright 2015 Benichou
*  @license   http://opensource.org/licenses/MIT  The MIT License (MIT)
*/
include dirname(__FILE__) . '/../../config/config.inc.php';
include dirname(__FILE__) . '/../../init.php';
if (!Module::isInstalled('blocknetreviews')) {
    die('Module not installed');
}
$blocknetreviews = Module::getInstanceByName('blocknetreviews');
/* Check if the module is enabled */
if ($blocknetreviews->active) {
    /* Check if the requested shop exists */
    $list_id_shop = Shop::getCompleteListOfShopsID();
    $id_shop = isset($_GET['id_shop']) && in_array($_GET['id_shop'], $list_id_shop) ? (int) $_GET['id_shop'] : (int) Configuration::get('PS_SHOP_DEFAULT');
    die($blocknetreviews->upateShopRating((int) $id_shop));
}
Beispiel #16
0
 private function _writeRewriteRule()
 {
     if ($this->checkRewriteRule()) {
         return true;
     }
     if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) {
         $htaccess_source = file_get_contents($this->_htFile);
         $dest_rule = 'index.php?fc=module&module=pm_advancedsearch4&controller=advancedsearch4&isolang=$1&id_seo=$2&seo_url=$3';
     } else {
         $htaccess_source = Configuration::get('PS_HTACCESS_SPECIFIC');
         $dest_rule = __PS_BASE_URI__ . 'modules/pm_advancedsearch4/advancedsearch4.php?isolang=$1&id_seo=$2&seo_url=$3';
         $dest_rule_2 = __PS_BASE_URI__ . 'modules/pm_advancedsearch4/advancedsearch4.php?';
     }
     if (preg_match('#\\^\\(\\[a-z\\]\\{2\\}\\)\\/s/#', $htaccess_source)) {
         $PS_HTACCESS_SPECIFIC = preg_replace('#\\^\\(\\[a-z\\]\\{2\\}\\)\\/s/#', '^([a-z]{2})?/?s/', $htaccess_source);
     } else {
         if (preg_match('#\\#START AS4 RULES#', $htaccess_source)) {
             $htaccess_source = preg_replace('#\\#START AS4 RULES(.*)\\#END AS4 RULES\\n?#s', '', $htaccess_source);
         }
         $PS_HTACCESS_SPECIFIC = '#START AS4 RULES (Do not remove)' . "\n";
         if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) {
             $PS_HTACCESS_SPECIFIC .= '<IfModule mod_rewrite.c>' . "\n" . 'RewriteEngine on' . "\n";
         }
         $PS_HTACCESS_SPECIFIC .= 'RewriteRule ^as4_seositemap.xml$ modules/pm_advancedsearch4/sitemap/seositemap.xml [L]' . "\n";
         $PS_HTACCESS_SPECIFIC .= 'RewriteRule ^as4_seositemap-([0-9]+).xml$ modules/pm_advancedsearch4/sitemap/seositemap-$1.xml [L]' . "\n";
         if (version_compare(_PS_VERSION_, '1.5.0.0', '>=') && Shop::isFeatureActive()) {
             foreach (array_values(Shop::getCompleteListOfShopsID()) as $id_shop) {
                 $shopUrl = new Shop($id_shop);
                 $base_uri = $shopUrl->virtual_uri;
                 $PS_HTACCESS_SPECIFIC .= 'RewriteCond %{QUERY_STRING} !^controller=products-comparison [NC]' . "\n";
                 $PS_HTACCESS_SPECIFIC .= 'RewriteRule ^' . str_replace('\\-', '-', preg_quote($base_uri)) . '([a-z]{2})?/?s/([0-9]+)/([a-zA-Z0-9/_-]*) ' . $dest_rule . ' [QSA,L]' . "\n";
             }
         } else {
             if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) {
                 $PS_HTACCESS_SPECIFIC .= 'RewriteCond %{QUERY_STRING} !^controller=products-comparison [NC]' . "\n";
             }
             $PS_HTACCESS_SPECIFIC .= 'RewriteRule ^([a-z]{2})?/?s/([0-9]+)/([a-zA-Z0-9/_-]*) ' . $dest_rule . ' [QSA,L]' . "\n";
             $PS_HTACCESS_SPECIFIC .= 'RewriteCond %{QUERY_STRING} ^isolang=([a-z]{2})&id_seo=([0-9]+)&seo_url=([a-zA-Z0-9/_-]*).*p=([0-9]+)$' . "\n";
             $PS_HTACCESS_SPECIFIC .= 'RewriteRule ^advancedsearch4.php ' . __PS_BASE_URI__ . '%1/s/%2/%3?p=%4 [R=301,L]' . "\n";
             $PS_HTACCESS_SPECIFIC .= 'RewriteCond %{QUERY_STRING} ^isolang=([a-z]{2})&id_seo=([0-9]+)&seo_url=([a-zA-Z0-9/_-]*)' . "\n";
             $PS_HTACCESS_SPECIFIC .= 'RewriteRule ^advancedsearch4.php ' . __PS_BASE_URI__ . '%1/s/%2/%3? [R=301,L]' . "\n";
             $PS_HTACCESS_SPECIFIC .= 'RewriteCond %{QUERY_STRING} ^id_seo=([0-9]+)&seo_url=([a-zA-Z0-9/_-]*).*p=([0-9]+)$' . "\n";
             $PS_HTACCESS_SPECIFIC .= 'RewriteRule ^advancedsearch4.php ' . __PS_BASE_URI__ . 's/%1/%2?p=%3 [R=301,L]' . "\n";
             $PS_HTACCESS_SPECIFIC .= 'RewriteCond %{QUERY_STRING} ^id_seo=([0-9]+)&seo_url=([a-zA-Z0-9/_-]*)' . "\n";
             $PS_HTACCESS_SPECIFIC .= 'RewriteRule ^advancedsearch4.php ' . __PS_BASE_URI__ . 's/%1/%2? [R=301,L]' . "\n";
         }
         if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) {
             $PS_HTACCESS_SPECIFIC .= '</IfModule>' . "\n";
         }
         $PS_HTACCESS_SPECIFIC .= '#END AS4 RULES' . "\n";
         $PS_HTACCESS_SPECIFIC .= $htaccess_source;
     }
     if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) {
         return file_put_contents($this->_htFile, $PS_HTACCESS_SPECIFIC);
     } else {
         Configuration::updateValue('PS_HTACCESS_SPECIFIC', $PS_HTACCESS_SPECIFIC, true);
         if (Tools::generateHtaccess($this->_htFile, Configuration::get('PS_REWRITING_SETTINGS'), Configuration::get('PS_HTACCESS_CACHE_CONTROL'), $PS_HTACCESS_SPECIFIC, Configuration::get('PS_HTACCESS_DISABLE_MULTIVIEWS'))) {
             return true;
         }
     }
     return false;
 }
 /**
  * @param Product $product
  * @throws Exception
  * @throws SmartyException
  */
 public function initFormInformations($employee)
 {
     if (!$this->default_form_language) {
         $this->getLanguages();
     }
     $data = $this->createTemplate($this->tpl_form);
     $available_profiles = Profile::getProfiles($this->context->language->id);
     // if employee is not SuperAdmin (id_profile = 1), don't make it possible to select the admin profile
     foreach ($available_profiles as $i => $profile) {
         if (!in_array($available_profiles[$i]['id_profile'], array(Configuration::get('APH_PROFILE_STORE_EMPLOYEE'), Configuration::get('APH_PROFILE_STORE_OWNER'), Configuration::get('APH_PROFILE_STORE_MANAGER')))) {
             unset($available_profiles[$i]);
         }
     }
     $shops = array();
     if (Configuration::get('PS_SHOP_DEFAULT') == Context::getContext()->shop->id) {
         //$_shops = Shop::getShops(true, null, true);
         $_shops = Shop::getCompleteListOfShopsID();
         foreach ($_shops as $id_shop) {
             if ($id_shop == Configuration::get('PS_SHOP_DEFAULT')) {
                 continue;
             }
             $shop = new Shop($id_shop);
             $shops[$id_shop] = $shop->name;
         }
         asort($shops);
     }
     $data->assign(array('id_lang_default' => Configuration::get('PS_LANG_DEFAULT'), 'id_shop' => Context::getContext()->shop->id, 'profiles' => $available_profiles, 'languages' => $this->_languages, 'shops' => $shops, 'default_form_language' => $this->default_form_language));
     $employee_props = array('active');
     foreach ($employee_props as $prop) {
         $employee->{$prop} = $this->getFieldValue($employee, $prop);
     }
     $data->assign(array('ad' => dirname($_SERVER['PHP_SELF']), 'id_lang' => $this->context->language->id, 'dipendente' => $employee, 'token' => $this->token, 'link' => $this->context->link, 'display' => $this->display));
     $data->assign($this->tpl_form_vars);
     $this->tpl_form_vars['dipendente'] = $employee;
     $this->tpl_form_vars['custom_form'] = $data->fetch();
 }