Example #1
0
    /**
     * Create a feature from import
     *
     * @param int $id_feature Feature id
     * @param int $id_product Product id
     * @param array $value Feature Value
     */
    public static function addFeatureImport($name, $position = false)
    {
        $rq = Db::getInstance()->getRow('
			SELECT `id_feature`
			FROM ' . _DB_PREFIX_ . 'feature_lang
			WHERE `name` = \'' . pSQL($name) . '\'
			GROUP BY `id_feature`
		');
        if (empty($rq)) {
            // Feature doesn't exist, create it
            $feature = new Feature();
            $feature->name = array_fill_keys(Language::getIDs(), (string) $name);
            if ($position) {
                $feature->position = (int) $position;
            } else {
                $feature->position = Feature::getHigherPosition() + 1;
            }
            $feature->add();
            return $feature->id;
        } elseif (isset($rq['id_feature']) && $rq['id_feature']) {
            if (is_numeric($position) && ($feature = new Feature((int) $rq['id_feature']))) {
                $feature->position = (int) $position;
                if (Validate::isLoadedObject($feature)) {
                    $feature->update();
                }
            }
            return (int) $rq['id_feature'];
        }
    }
Example #2
0
    /**
     * Create a feature from import
     *
     * @param integer $id_feature Feature id
     * @param integer $id_product Product id
     * @param array $value Feature Value
     */
    public static function addFeatureImport($name, $position = false)
    {
        $rq = Db::getInstance()->getRow('
			SELECT `id_feature`
			FROM ' . _DB_PREFIX_ . 'feature_lang
			WHERE `name` = \'' . pSQL($name) . '\'
			GROUP BY `id_feature`
		');
        if (empty($rq)) {
            // Feature doesn't exist, create it
            $feature = new Feature();
            $languages = Language::getLanguages();
            foreach ($languages as $language) {
                $feature->name[$language['id_lang']] = strval($name);
            }
            if ($position) {
                $feature->position = (int) $position;
            } else {
                $feature->position = Feature::getHigherPosition() + 1;
            }
            $feature->add();
            return $feature->id;
        } else {
            if ($position && ($feature = new Feature((int) $rq['id_feature']))) {
                $feature->position = (int) $position;
                $feature->update();
            }
            return (int) $rq['id_feature'];
        }
    }