예제 #1
0
 public function delete()
 {
     if (!Module::isInstalled('agilemultipleseller')) {
         return parent::delete();
     }
     if (!$this->can_edit()) {
         return false;
     }
     if (!parent::delete()) {
         return false;
     }
     AgileSellerManager::deleteObjectOwner($this->table, $this->id);
     return true;
 }
예제 #2
0
 public function __construct($id = null, $id_lang = null, $id_shop = null)
 {
     parent::__construct($id, $id_lang, $id_shop);
     $classname = get_class($this);
     if (!isset(self::$debug_list[$classname])) {
         self::$debug_list[$classname] = array();
     }
     $class_list = array('ObjectModel', 'ObjectModelCore', $classname, $classname . 'Core');
     $backtrace = debug_backtrace();
     foreach ($backtrace as $trace_id => $row) {
         if (!isset($backtrace[$trace_id]['class']) || !in_array($backtrace[$trace_id]['class'], $class_list)) {
             break;
         }
     }
     $trace_id--;
     self::$debug_list[$classname][] = array('file' => @$backtrace[$trace_id]['file'], 'line' => @$backtrace[$trace_id]['line']);
 }
예제 #3
0
 /**
  * Caches data about required objects fields in memory
  *
  * @param bool $all If true, caches required fields of all object classes.
  */
 public function cacheFieldsRequiredDatabase($all = true)
 {
     if (!is_array(self::$fieldsRequiredDatabase)) {
         $fields = $this->getfieldsRequiredDatabase((bool) $all);
         if ($fields) {
             foreach ($fields as $row) {
                 self::$fieldsRequiredDatabase[$row['object_name']][(int) $row['id_required_field']] = pSQL($row['field_name']);
             }
         } else {
             self::$fieldsRequiredDatabase = array();
         }
     }
 }
예제 #4
0
    /**
     * Build object
     *
     * @param integer $id Existing object id in order to load object (optional)
     * @param integer $id_lang Required if object is multilingual (optional)
     */
    public function __construct($id = null, $id_lang = null)
    {
        if ($id_lang != null && Language::getLanguage((int) $id_lang)) {
            $this->id_lang = (int) $id_lang;
        } elseif ($id_lang != null) {
            $this->id_lang = _PS_LANG_DEFAULT_;
        }
        /* Connect to database and check SQL table/identifier */
        if (!Validate::isTableOrIdentifier($this->identifier . $this->table)) {
            die(Tools::displayError());
        }
        /* Load object from database if object id is present */
        if ($id) {
            $this->identifier = pSQL($this->identifier);
            if (!isset(self::$_cache[$this->table][(int) $id][(int) $id_lang])) {
                self::$_cache[$this->table][(int) $id][(int) $id_lang] = Db::getInstance()->getRow('
				SELECT *
				FROM `' . _DB_PREFIX_ . $this->table . '` a ' . ($id_lang ? 'LEFT JOIN `' . pSQL(_DB_PREFIX_ . $this->table) . '_lang` b ON (a.`' . $this->identifier . '` = b.`' . $this->identifier . '` AND `id_lang` = ' . (int) $id_lang . ')' : '') . ' WHERE a.`' . $this->identifier . '` = ' . (int) $id);
            }
            $result = self::$_cache[$this->table][(int) $id][(int) $id_lang];
            if ($result) {
                $this->id = (int) $id;
                foreach ($result as $key => $value) {
                    if (key_exists($key, $this)) {
                        $this->{$key} = $value;
                    }
                }
                /* Join multilingual tables */
                if (!$id_lang && method_exists($this, 'getTranslationsFieldsChild')) {
                    $result = Db::getInstance()->ExecuteS('
					SELECT *
					FROM `' . pSQL(_DB_PREFIX_ . $this->table) . '_lang`
					WHERE `' . $this->identifier . '` = ' . (int) $id);
                    if ($result) {
                        foreach ($result as $row) {
                            foreach ($row as $key => $value) {
                                if (key_exists($key, $this) && $key != $this->identifier) {
                                    if (!is_array($this->{$key})) {
                                        $this->{$key} = array();
                                    }
                                    $this->{$key}[(int) $row['id_lang']] = $value;
                                }
                            }
                        }
                    }
                }
            }
        }
        if (!isset(self::$fieldsRequiredDatabase)) {
            self::$fieldsRequiredDatabase = array();
            if ($fields = $this->getfieldsRequiredDatabase(true)) {
                foreach ($fields as $row) {
                    self::$fieldsRequiredDatabase[$row['object_name']][(int) $row['id_required_field']] = pSQL($row['field_name']);
                }
            }
        }
    }
예제 #5
0
 /**
  * @see ObjectModel
  */
 public function __construct($id = null, $id_lang = null, $id_shop = null)
 {
     // calls parent
     parent::__construct($id, $id_lang, $id_shop);
     if ((int) $this->id != 0) {
         $res = $this->getWebserviceObjectList(null, ' AND ' . $this->def['primary'] . ' = ' . (int) $this->id, null, null, true);
         if (isset($res[0])) {
             foreach ($this->tables_assoc as $key => $param) {
                 $this->{$key} = $res[0][$key];
             }
         }
     }
 }
예제 #6
0
    /**
     * Build object
     *
     * @param int $id Existing object id in order to load object (optional)
     * @param int $id_lang Required if object is multilingual (optional)
     * @param int $id_shop ID shop for objects with multishop on langs
     */
    public function __construct($id = null, $id_lang = null, $id_shop = null)
    {
        if (!ObjectModel::$db) {
            ObjectModel::$db = Db::getInstance();
        }
        $this->def = self::getDefinition($this);
        $this->setDefinitionRetrocompatibility();
        if ($id_lang !== null) {
            $this->id_lang = Language::getLanguage($id_lang) !== false ? $id_lang : Configuration::get('PS_LANG_DEFAULT');
        }
        if ($id_shop && $this->isMultishop()) {
            $this->id_shop = (int) $id_shop;
            $this->get_shop_from_context = false;
        }
        if ($this->isMultishop() && !$this->id_shop) {
            $this->id_shop = Context::getContext()->shop->id;
        }
        if (!Validate::isTableOrIdentifier($this->def['primary']) || !Validate::isTableOrIdentifier($this->def['table'])) {
            throw new PrestaShopException('Identifier or table format not valid for class ' . get_class($this));
        }
        if ($id) {
            // Load object from database if object id is present
            $cache_id = 'objectmodel_' . $this->def['table'] . '_' . (int) $id . '_' . (int) $id_shop . '_' . (int) $id_lang;
            if (!Cache::isStored($cache_id)) {
                $sql = new DbQuery();
                $sql->from($this->def['table'], 'a');
                $sql->where('a.' . $this->def['primary'] . ' = ' . (int) $id);
                // Get lang informations
                if ($id_lang) {
                    $sql->leftJoin($this->def['table'] . '_lang', 'b', 'a.' . $this->def['primary'] . ' = b.' . $this->def['primary'] . ' AND b.id_lang = ' . (int) $id_lang);
                    if ($this->id_shop && !empty($this->def['multilang_shop'])) {
                        $sql->where('b.id_shop = ' . $this->id_shop);
                    }
                }
                // Get shop informations
                if (Shop::isTableAssociated($this->def['table'])) {
                    $sql->leftJoin($this->def['table'] . '_shop', 'c', 'a.' . $this->def['primary'] . ' = c.' . $this->def['primary'] . ' AND c.id_shop = ' . (int) $this->id_shop);
                }
                if ($row = ObjectModel::$db->getRow($sql)) {
                    Cache::store($cache_id, $row);
                }
            }
            $result = Cache::retrieve($cache_id);
            if ($result) {
                $this->id = (int) $id;
                foreach ($result as $key => $value) {
                    if (array_key_exists($key, $this)) {
                        $this->{$key} = $value;
                    }
                }
                if (!$id_lang && isset($this->def['multilang']) && $this->def['multilang']) {
                    $sql = 'SELECT * FROM `' . pSQL(_DB_PREFIX_ . $this->def['table']) . '_lang`
							WHERE `' . $this->def['primary'] . '` = ' . (int) $id . ($this->id_shop && $this->isLangMultishop() ? ' AND `id_shop` = ' . $this->id_shop : '');
                    $result = ObjectModel::$db->executeS($sql);
                    if ($result) {
                        foreach ($result as $row) {
                            foreach ($row as $key => $value) {
                                if (array_key_exists($key, $this) && $key != $this->def['primary']) {
                                    if (!is_array($this->{$key})) {
                                        $this->{$key} = array();
                                    }
                                    $this->{$key}[$row['id_lang']] = $value;
                                }
                            }
                        }
                    }
                }
            }
        }
        if (!is_array(self::$fieldsRequiredDatabase)) {
            $fields = $this->getfieldsRequiredDatabase(true);
            if ($fields) {
                foreach ($fields as $row) {
                    self::$fieldsRequiredDatabase[$row['object_name']][(int) $row['id_required_field']] = pSQL($row['field_name']);
                }
            } else {
                self::$fieldsRequiredDatabase = array();
            }
        }
    }
예제 #7
0
    /**
     * Build object
     *
     * @param integer $id Existing object id in order to load object (optional)
     * @param integer $id_lang Required if object is multilingual (optional)
     */
    public function __construct($id = NULL, $id_lang = NULL)
    {
        if ($id_lang != NULL && Validate::isLoadedObject(new Language($id_lang))) {
            $this->id_lang = $id_lang;
        } elseif ($id_lang != NULL) {
            $this->id_lang = Configuration::get('PS_LANG_DEFAULT');
        }
        /* Connect to database and check SQL table/identifier */
        if (!Validate::isTableOrIdentifier($this->identifier) or !Validate::isTableOrIdentifier($this->table)) {
            die(Tools::displayError());
        }
        $this->identifier = pSQL($this->identifier);
        /* Load object from database if object id is present */
        if ($id) {
            if (!isset(self::$_cache[$this->table][(int) $id][(int) $id_lang])) {
                self::$_cache[$this->table][(int) $id][(int) $id_lang] = Db::getInstance()->getRow('
				SELECT *
				FROM `' . _DB_PREFIX_ . $this->table . '` a ' . ($id_lang ? 'LEFT JOIN `' . pSQL(_DB_PREFIX_ . $this->table) . '_lang` b ON (a.`' . $this->identifier . '` = b.`' . $this->identifier . '` AND `id_lang` = ' . (int) $id_lang . ')' : '') . ' WHERE a.`' . $this->identifier . '` = ' . (int) $id);
            }
            $result = self::$_cache[$this->table][(int) $id][(int) $id_lang];
            if ($result) {
                $this->id = (int) $id;
                foreach ($result as $key => $value) {
                    if (key_exists($key, $this)) {
                        $this->{$key} = $value;
                    }
                }
                /* Join multilingual tables */
                if (!$id_lang and method_exists($this, 'getTranslationsFieldsChild')) {
                    $result = Db::getInstance()->ExecuteS('
					SELECT * 
					FROM `' . pSQL(_DB_PREFIX_ . $this->table) . '_lang` 
					WHERE `' . $this->identifier . '` = ' . (int) $id);
                    if ($result) {
                        foreach ($result as $row) {
                            foreach ($row as $key => $value) {
                                if (key_exists($key, $this) and $key != $this->identifier) {
                                    if (!is_array($this->{$key})) {
                                        $this->{$key} = array();
                                    }
                                    // Todo: stripslashes() MUST BE removed in 1.4.6 and later, but is kept in 1.4.5 for a compatibility issue
                                    $this->{$key}[(int) $row['id_lang']] = stripslashes($value);
                                }
                            }
                        }
                    }
                }
            }
        }
        if (!is_array(self::$fieldsRequiredDatabase)) {
            $fields = $this->getfieldsRequiredDatabase(true);
            if ($fields) {
                foreach ($fields as $row) {
                    self::$fieldsRequiredDatabase[$row['object_name']][(int) $row['id_required_field']] = pSQL($row['field_name']);
                }
            } else {
                self::$fieldsRequiredDatabase = array();
            }
        }
    }
예제 #8
0
 /**
  * Process customization collection
  *
  * @param object $product
  * @param array $data
  *
  * @return bool
  */
 public function processProductCustomization($product, $data)
 {
     //remove customization field langs
     foreach ($product->getCustomizationFieldIds() as $customizationFiled) {
         \Db::getInstance()->execute('DELETE FROM ' . _DB_PREFIX_ . 'customization_field_lang WHERE `id_customization_field` = ' . (int) $customizationFiled['id_customization_field']);
     }
     //remove customization for the product
     \Db::getInstance()->execute('DELETE FROM ' . _DB_PREFIX_ . 'customization_field WHERE `id_product` = ' . (int) $product->id);
     //create new customizations
     $countFieldText = 0;
     $countFieldFile = 0;
     $productCustomizableValue = 0;
     $hasRequiredField = false;
     $shopList = \ShopCore::getContextListShopID();
     if ($data) {
         foreach ($data as $customization) {
             if ($customization['require']) {
                 $hasRequiredField = true;
             }
             //create label
             \Db::getInstance()->execute('INSERT INTO `' . _DB_PREFIX_ . 'customization_field` (`id_product`, `type`, `required`)
                 VALUES (' . (int) $product->id . ', ' . (int) $customization['type'] . ', ' . ($customization['require'] ? 1 : 0) . ')');
             $id_customization_field = (int) \Db::getInstance()->Insert_ID();
             // Create multilingual label name
             $langValues = '';
             foreach (\LanguageCore::getLanguages() as $language) {
                 $name = $customization['label'][$language['id_lang']];
                 foreach ($shopList as $id_shop) {
                     $langValues .= '(' . (int) $id_customization_field . ', ' . (int) $language['id_lang'] . ', ' . $id_shop . ',\'' . $name . '\'), ';
                 }
             }
             \Db::getInstance()->execute('INSERT INTO `' . _DB_PREFIX_ . 'customization_field_lang` (`id_customization_field`, `id_lang`, `id_shop`, `name`) VALUES ' . rtrim($langValues, ', '));
             if ($customization['type'] == 0) {
                 $countFieldFile++;
             } else {
                 $countFieldText++;
             }
         }
         $productCustomizableValue = $hasRequiredField ? 2 : 1;
     }
     //update product count fields labels
     \Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . 'product` SET `customizable` = ' . $productCustomizableValue . ', `uploadable_files` = ' . (int) $countFieldFile . ', `text_fields` = ' . (int) $countFieldText . ' WHERE `id_product` = ' . (int) $product->id);
     //update product_shop count fields labels
     \ObjectModelCore::updateMultishopTable('product', array('customizable' => $productCustomizableValue, 'uploadable_files' => (int) $countFieldFile, 'text_fields' => (int) $countFieldText), 'a.id_product = ' . (int) $product->id);
     \ConfigurationCore::updateGlobalValue('PS_CUSTOMIZATION_FEATURE_ACTIVE', '1');
 }