getInstance() public static method

获取数据库单例实例
Author: Seven Du (lovevipdsw@vip.qq.com)
public static getInstance ( $config = null ) : object
return object self
    public function init()
    {
        if (Tools::getValue('supplier_rewrite')) {
            $name_supplier = str_replace('-', '%', Tools::getValue('supplier_rewrite'));
            //
            // TODO:: need to core update Prestashop code and
            // DB for link_rewrite for suppliers
            // Should we use the Mysql FullText Index Search ??
            //
            $sql = 'SELECT sp.`id_supplier`
				FROM `' . _DB_PREFIX_ . 'supplier` sp
				LEFT JOIN `' . _DB_PREFIX_ . 'supplier_shop` s ON (sp.`id_supplier` = s.`id_supplier`)
				WHERE sp.`name` LIKE \'' . $name_supplier . '\'';
            if (Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP) {
                $sql .= ' AND s.`id_shop` = ' . (int) Shop::getContextShopID();
            }
            $id_supplier = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
            if ($id_supplier > 0) {
                $_GET['id_supplier'] = $id_supplier;
            } else {
                //TODO: Do we need to send 404?
                header('HTTP/1.1 404 Not Found');
                header('Status: 404 Not Found');
            }
        }
        parent::init();
    }
 public function __construct()
 {
     parent::__construct();
     $this->db = Db::getInstance();
     $this->max_size = 800000;
     //每卷800左右
 }
function ecotax_tax_application_fix()
{
    if (!Db::getInstance()->execute('SELECT `ecotax_tax_rate` FROM `' . _DB_PREFIX_ . 'order_detail` LIMIT 1')) {
        return Db::getInstance()->execute('ALTER TABLE `' . _DB_PREFIX_ . 'order_detail` ADD `ecotax_tax_rate` DECIMAL(5, 3) NOT NULL AFTER `ecotax`');
    }
    return true;
}
Example #4
0
    public function get($limit = 10, $noloadid = 0)
    {
        global $cookie;
        $_content = array();
        if (isset($cookie->viewed) && strlen($cookie->viewed) > 0) {
            $_content = explode(",", $cookie->viewed);
        }
        $product_ids = array();
        $content_num = count($_content);
        if ($content_num > 0) {
            $j = 0;
            for ($i = $content_num - 1; $i >= 0; $i--) {
                if ($_content[$i] != $noloadid) {
                    $product_ids[] = $_content[$i];
                    $j++;
                }
                if ($j >= $limit) {
                    break;
                }
            }
        } else {
            return false;
        }
        if (count($product_ids) == 0) {
            return false;
        }
        $result = Db::getInstance()->ExecuteS('SELECT p.*,b.name AS brand FROM `' . _DB_PREFIX_ . 'product` p
		LEFT JOIN `' . _DB_PREFIX_ . 'brand` b ON b.id_brand=p.id_brand
		WHERE id_product IN(' . implode(',', array_map('intval', $product_ids)) . ')');
        if (!$result) {
            return false;
        }
        return Product::reLoad($result);
    }
function id_currency_country_fix()
{
    if (!Db::getInstance()->execute('SELECT `id_currency` FROM `' . _DB_PREFIX_ . 'country` LIMIT 1')) {
        return Db::getInstance()->execute('ALTER TABLE `' . _DB_PREFIX_ . 'country` ADD `id_currency` INT NOT NULL DEFAULT \'0\' AFTER `id_zone`');
    }
    return true;
}
Example #6
0
 function uninstall()
 {
     if (!parent::uninstall()) {
         return false;
     }
     return Db::getInstance()->Execute('DROP TABLE `' . _DB_PREFIX_ . 'location_coords`');
 }
 public function uninstall()
 {
     if (!parent::uninstall() || !Db::getInstance()->execute('DROP TABLE `' . _DB_PREFIX_ . 'favorite_product`')) {
         return false;
     }
     return true;
 }
/**
 * 2007-2015 PrestaShop
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@prestashop.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
 * versions in the future. If you wish to customize PrestaShop for your
 * needs please refer to http://www.prestashop.com for more information.
 *
 * @author    PrestaShop SA <*****@*****.**>
 * @copyright 2007-2015 PrestaShop SA
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
 * International Registered Trademark & Property of PrestaShop SA
 */
function add_default_restrictions_modules_groups()
{
    $res = true;
    // Table module_group had another use in previous versions, we need to clean it up.
    $res &= Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'module_group`');
    $groups = Db::getInstance()->executeS('
		SELECT `id_group`
		FROM `' . _DB_PREFIX_ . 'group`');
    $modules = Db::getInstance()->executeS('
		SELECT m.*
		FROM `' . _DB_PREFIX_ . 'module` m');
    $shops = Db::getInstance()->executeS('
		SELECT `id_shop`
		FROM `' . _DB_PREFIX_ . 'shop`');
    foreach ($groups as $group) {
        if (!is_array($modules) || !is_array($shops)) {
            return false;
        } else {
            $sql = 'INSERT INTO `' . _DB_PREFIX_ . 'module_group` (`id_module`, `id_shop`, `id_group`) VALUES ';
            foreach ($modules as $mod) {
                foreach ($shops as $s) {
                    $sql .= '("' . (int) $mod['id_module'] . '", "' . (int) $s . '", "' . (int) $group['id_group'] . '"),';
                }
            }
            // removing last comma to avoid SQL error
            $sql = substr($sql, 0, strlen($sql) - 1);
            $res &= Db::getInstance()->execute($sql);
        }
    }
    return $res;
}
    public function renderView()
    {
        $badges_feature = new Collection('badge', $this->context->language->id);
        $badges_feature->where('type', '=', 'feature');
        $badges_feature->orderBy('id_group');
        $badges_feature->orderBy('group_position');
        $badges_achievement = new Collection('badge', $this->context->language->id);
        $badges_achievement->where('type', '=', 'achievement');
        $badges_achievement->orderBy('id_group');
        $badges_achievement->orderBy('group_position');
        $badges_international = new Collection('badge', $this->context->language->id);
        $badges_international->where('type', '=', 'international');
        $badges_international->orderBy('id_group');
        $badges_international->orderBy('group_position');
        $groups = array();
        $query = new DbQuery();
        $query->select('DISTINCT(b.`id_group`), bl.group_name, b.type');
        $query->from('badge', 'b');
        $query->join('
			LEFT JOIN `' . _DB_PREFIX_ . 'badge_lang` bl ON bl.`id_badge` = b.`id_badge`');
        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
        foreach ($result as $res) {
            $groups['badges_' . $res['type']][$res['id_group']] = $res['group_name'];
        }
        $badges_type = array('badges_feature' => array('name' => $this->l('Features'), 'badges' => $badges_feature), 'badges_achievement' => array('name' => $this->l('Achievements'), 'badges' => $badges_achievement), 'badges_international' => array('name' => $this->l('International'), 'badges' => $badges_international));
        $levels = array(1 => $this->l('1. Beginner'), 2 => $this->l('2. Pro'), 3 => $this->l('3. Expert'), 4 => $this->l('4. Wizard'), 5 => $this->l('5. Guru'), 6 => $this->l('6. Legend'));
        $this->tpl_view_vars = array('badges_type' => $badges_type, 'current_level_percent' => (int) Configuration::get('GF_CURRENT_LEVEL_PERCENT'), 'current_level' => (int) Configuration::get('GF_CURRENT_LEVEL'), 'groups' => $groups, 'levels' => $levels);
        return parent::renderView();
    }
Example #10
0
function upgrade_module_1_3_2_11($object)
{
    $themes = Theme::getThemes();
    $theme_meta_value = array();
    foreach ($object->controllers as $controller) {
        $page = 'module-' . $object->name . '-' . $controller;
        $result = Db::getInstance()->getValue('SELECT * FROM ' . _DB_PREFIX_ . 'meta WHERE page="' . pSQL($page) . '"');
        if ((int) $result > 0) {
            continue;
        }
        $meta = new Meta();
        $meta->page = $page;
        $meta->configurable = 0;
        $meta->save();
        if ((int) $meta->id > 0) {
            foreach ($themes as $theme) {
                $theme_meta_value[] = array('id_theme' => $theme->id, 'id_meta' => $meta->id, 'left_column' => (int) $theme->default_left_column, 'right_column' => (int) $theme->default_right_column);
            }
        } else {
            $object->_errors[] = sprintf(Tools::displayError('Unable to install controller: %s'), $controller);
        }
    }
    if (count($theme_meta_value) > 0) {
        return Db::getInstance()->insert('theme_meta', $theme_meta_value);
    }
    return true;
}
Example #11
0
    public function getOrderTaxes($products = false, $slip = false)
    {
        if (!$products) {
            $products = $slip && Validate::isLoadedObject($slip) ? $slip->getProducts() : $this->getProducts();
        }
        $taxes = array();
        $id_order_details = array();
        $defTaxName = null;
        $defTaxRate = 0;
        if (is_array($products) && count($products)) {
            foreach ($products as $product) {
                array_push($id_order_details, (int) $product['id_order_detail']);
            }
        }
        if (count($id_order_details)) {
            $order_taxes = Db::getInstance()->ExecuteS('
				SELECT
					od.*,
					odt.*,
					t.`rate`,
					tl.`name`
				FROM
					`' . _DB_PREFIX_ . 'order_detail` od
				LEFT JOIN
					`' . _DB_PREFIX_ . 'order_detail_tax` odt ON
					(
						od.`id_order_detail` = odt.`id_order_detail`
					)
				LEFT JOIN
					`' . _DB_PREFIX_ . 'tax` t ON
					(
						t.`id_tax` = odt.`id_tax`
					)
				LEFT JOIN
					`' . _DB_PREFIX_ . 'tax_lang` tl ON
					(
						t.`id_tax` = tl.`id_tax` AND
						tl.`id_lang` = ' . (int) $this->id_lang . '
					)
				WHERE odt.`id_order_detail` IN (' . implode(',', $id_order_details) . ')
			');
            if ($order_taxes && count($order_taxes)) {
                foreach ($order_taxes as $order_tax) {
                    if (!array_key_exists($order_tax['name'], $taxes)) {
                        $taxes[$order_tax['name']] = array('total' => 0, 'total_net' => 0, 'total_vat' => 0, 'rate' => (double) $order_tax['rate'], 'percentage' => 0);
                    }
                    $taxes[$order_tax['name']]['total_net'] += (double) $order_tax['total_price_tax_excl'];
                    $taxes[$order_tax['name']]['total_vat'] += (double) $order_tax['total_price_tax_incl'];
                    $taxes[$order_tax['name']]['total'] += $order_tax['total_price_tax_incl'] - (double) $order_tax['total_price_tax_excl'];
                }
            }
        }
        if (count($taxes)) {
            foreach ($taxes as &$tax) {
                $tax['percentage'] = 100 / ($this->total_products_wt / $tax['total_vat']);
            }
            return $taxes;
        }
        return false;
    }
function p1540_add_missing_columns()
{
    $errors = array();
    $id_module = Db::getInstance()->getValue('SELECT id_module FROM `' . _DB_PREFIX_ . 'module` WHERE name LIKE "loyalty"');
    if ($id_module) {
        $list_fields = Db::getInstance()->executeS('SHOW FIELDS FROM `' . _DB_PREFIX_ . 'loyalty`');
        foreach ($list_fields as $k => $field) {
            $list_fields[$k] = $field['Field'];
        }
        if (in_array('id_discount', $list_fields)) {
            if (!Db::getInstance()->execute('ALTER TABLE `' . _DB_PREFIX_ . 'loyalty` CHANGE `id_discount` `id_cart_rule` INT( 10 ) UNSIGNED NULL DEFAULT NULL')) {
                $errors[] = Db::getInstance()->getMsgError();
            }
        }
    }
    $id_module = Db::getInstance()->getValue('SELECT id_module FROM `' . _DB_PREFIX_ . 'module` WHERE name LIKE "blocklayered"');
    if ($id_module) {
        $list_fields = Db::getInstance()->executeS('SHOW FIELDS FROM `' . _DB_PREFIX_ . 'layered_product_attribute`');
        foreach ($list_fields as $k => $field) {
            $list_fields[$k] = $field['Field'];
        }
        if (!in_array('id_shop', $list_fields)) {
            if (!Db::getInstance()->execute('ALTER TABLE `' . _DB_PREFIX_ . 'layered_product_attribute` ADD `id_shop` INT( 10 ) UNSIGNED NOT NULL DEFAULT "1" AFTER `id_attribute_group` ')) {
                $errors[] = Db::getInstance()->getMsgError();
            }
        }
    }
    if (count($errors)) {
        return array('error' => 1, 'msg' => implode(',', $errors));
    }
}
Example #13
0
    private function getOrigins($dateBetween)
    {
        $directLink = $this->l('Direct link');
        $sql = 'SELECT http_referer
				FROM ' . _DB_PREFIX_ . 'connections
				WHERE 1
					' . Shop::addSqlRestriction() . '
					AND date_add BETWEEN ' . $dateBetween;
        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->query($sql);
        $websites = array($directLink => 0);
        while ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->nextRow($result)) {
            if (!isset($row['http_referer']) || empty($row['http_referer'])) {
                ++$websites[$directLink];
            } else {
                $website = preg_replace('/^www./', '', parse_url($row['http_referer'], PHP_URL_HOST));
                if (!isset($websites[$website])) {
                    $websites[$website] = 1;
                } else {
                    ++$websites[$website];
                }
            }
        }
        arsort($websites);
        return $websites;
    }
function ps1604_update_employee_date()
{
    if (defined('_PS_CREATION_DATE_')) {
        return Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . 'employee` SET stats_date_from = \'' . addslashes(_PS_CREATION_DATE_) . '\' WHERE `stats_date_from` < \'' . addslashes(_PS_CREATION_DATE_) . '\'');
    }
    return true;
}
Example #15
0
 public function getOne()
 {
     $conn = Db::getInstance();
     $advertNumber = $_GET['id'];
     $oneAdvert = $conn->query("SELECT * FROM tbl_advert LEFT JOIN tbl_user ON tbl_advert.fk_user_id=tbl_user.user_id WHERE tbl_advert.advert_id={$advertNumber}");
     return $oneAdvert;
 }
Example #16
0
function upgrade_module_2_0_14($module)
{
    Db::getInstance()->execute('
				CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'amz_orders` (
				`id` int(11) NOT NULL AUTO_INCREMENT,
                `id_order` int(11) NOT NULL,
				`amazon_auth_reference_id` varchar(255) NOT NULL,
				`amazon_authorization_id` varchar(255) NOT NULL,
				`amazon_order_reference_id` varchar(255) NOT NULL,
				`amazon_capture_id` varchar(255) NOT NULL,
				`amazon_capture_reference_id` varchar(255) NOT NULL,
				PRIMARY KEY (`id`)
		) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
				');
    Db::getInstance()->execute('
				CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'amz_address` (
				`id` int(11) NOT NULL AUTO_INCREMENT,
                `id_address` int(11) NOT NULL,
				`amazon_order_reference_id` varchar(255) NOT NULL,
				PRIMARY KEY (`id`)
		) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
				');
    Db::getInstance()->execute('
				CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'amz_customer` (
				`id` int(11) NOT NULL AUTO_INCREMENT,
                `id_customer` int(11) NOT NULL,
				`amazon_customer_id` varchar(255) NOT NULL,
				PRIMARY KEY (`id`)
		) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
				');
    return true;
}
Example #17
0
 protected function changePassword()
 {
     $token = Tools::getValue('token');
     $id_customer = (int) Tools::getValue('id_customer');
     if ($email = Db::getInstance()->getValue('SELECT `email` FROM ' . _DB_PREFIX_ . 'customer c WHERE c.`secure_key` = \'' . pSQL($token) . '\' AND c.id_customer = ' . $id_customer)) {
         $customer = new Customer();
         $customer->getByEmail($email);
         if (!Validate::isLoadedObject($customer)) {
             $this->errors[] = $this->trans('Customer account not found', array(), 'Shop.Notifications.Error');
         } elseif (!$customer->active) {
             $this->errors[] = $this->trans('You cannot regenerate the password for this account.', array(), 'Shop.Notifications.Error');
         }
         // Case if both password params not posted or different, then "change password" form is not POSTED, show it.
         if (!Tools::isSubmit('passwd') || !Tools::isSubmit('confirmation') || ($passwd = Tools::getValue('passwd')) !== ($confirmation = Tools::getValue('confirmation')) || !Validate::isPasswd($passwd) || !Validate::isPasswd($confirmation)) {
             // Check if passwords are here anyway, BUT does not match the password validation format
             if (Tools::isSubmit('passwd') || Tools::isSubmit('confirmation')) {
                 $this->errors[] = $this->trans('The password and its confirmation do not match.', array(), 'Shop.Notifications.Error');
             }
             $this->context->smarty->assign(['customer_email' => $customer->email, 'customer_token' => $token, 'id_customer' => $id_customer, 'reset_token' => Tools::getValue('reset_token')]);
             $this->setTemplate('customer/password-new');
         } else {
             // Both password fields posted. Check if all is right and store new password properly.
             if (!Tools::getValue('reset_token') || strtotime($customer->last_passwd_gen . '+' . (int) Configuration::get('PS_PASSWD_TIME_FRONT') . ' minutes') - time() > 0) {
                 Tools::redirect('index.php?controller=authentication&error_regen_pwd');
             } else {
                 // To update password, we must have the temporary reset token that matches.
                 if ($customer->getValidResetPasswordToken() !== Tools::getValue('reset_token')) {
                     $this->errors[] = $this->trans('The password change request expired. You should ask for a new one.', array(), 'Shop.Notifications.Error');
                 } else {
                     try {
                         $crypto = new Hashing();
                     } catch (\PrestaShop\PrestaShop\Adapter\CoreException $e) {
                         $this->errors[] = $this->trans('An error occurred with your account, which prevents us from updating the new password. Please report this issue using the contact form.', array(), 'Shop.Notifications.Error');
                         return false;
                     }
                     $customer->passwd = $crypto->encrypt($password = Tools::getValue('passwd'), _COOKIE_KEY_);
                     $customer->last_passwd_gen = date('Y-m-d H:i:s', time());
                     if ($customer->update()) {
                         Hook::exec('actionPasswordRenew', array('customer' => $customer, 'password' => $password));
                         $customer->removeResetPasswordToken();
                         $customer->update();
                         $mail_params = ['{email}' => $customer->email, '{lastname}' => $customer->lastname, '{firstname}' => $customer->firstname];
                         if (Mail::Send($this->context->language->id, 'password', Mail::l('Your new password'), $mail_params, $customer->email, $customer->firstname . ' ' . $customer->lastname)) {
                             $this->context->smarty->assign(['customer_email' => $customer->email]);
                             $this->success[] = $this->trans('Your password has been successfully reset and a confirmation has been sent to your email address: %s', array($customer->email), 'Shop.Notifications.Success');
                             $this->context->updateCustomer($customer);
                             $this->redirectWithNotifications('index.php?controller=my-account');
                         } else {
                             $this->errors[] = $this->trans('An error occurred while sending the email.', array(), 'Shop.Notifications.Error');
                         }
                     } else {
                         $this->errors[] = $this->trans('An error occurred with your account, which prevents us from updating the new password. Please report this issue using the contact form.', array(), 'Shop.Notifications.Error');
                     }
                 }
             }
         }
     } else {
         $this->errors[] = $this->trans('We cannot regenerate your password with the data you\'ve submitted', array(), 'Shop.Notifications.Error');
     }
 }
 public static function getVersion($label)
 {
     return Db::getInstance()->getValue('
     SELECT `version` FROM `' . _DB_PREFIX_ . 'help_access`
     WHERE `label` = \'' . pSQL($label) . '\'
     ');
 }
function updateproductcomments()
{
    if (Db::getInstance()->executeS('SELECT * FROM ' . _DB_PREFIX_ . 'product_comment') !== false) {
        Db::getInstance()->execute('CREATE TABLE IF NOT EXISTS ' . _DB_PREFIX_ . 'product_comment_criterion_lang (
											`id_product_comment_criterion` INT( 11 ) UNSIGNED NOT NULL ,
											`id_lang` INT(11) UNSIGNED NOT NULL ,
											`name` VARCHAR(64) NOT NULL ,
											PRIMARY KEY ( `id_product_comment_criterion` , `id_lang` )
											) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8');
        Db::getInstance()->execute('CREATE TABLE IF NOT EXISTS ' . _DB_PREFIX_ . 'product_comment_criterion_category (
											  `id_product_comment_criterion` int(10) unsigned NOT NULL,
											  `id_category` int(10) unsigned NOT NULL,
											  PRIMARY KEY(`id_product_comment_criterion`, `id_category`),
											  KEY `id_category` (`id_category`)
											) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8');
        Db::getInstance()->execute('ALTER TABLE ' . _DB_PREFIX_ . 'product_comment ADD `id_guest` INT(11) NULL AFTER `id_customer`');
        Db::getInstance()->execute('ALTER TABLE ' . _DB_PREFIX_ . 'product_comment ADD `customer_name` varchar(64) NULL AFTER `content`');
        Db::getInstance()->execute('ALTER TABLE ' . _DB_PREFIX_ . 'product_comment ADD `deleted` tinyint(1) NOT NULL AFTER `validate`');
        Db::getInstance()->execute('ALTER TABLE ' . _DB_PREFIX_ . 'product_comment ADD INDEX (id_customer)');
        Db::getInstance()->execute('ALTER TABLE ' . _DB_PREFIX_ . 'product_comment ADD INDEX (id_guest)');
        Db::getInstance()->execute('ALTER TABLE ' . _DB_PREFIX_ . 'product_comment ADD INDEX (id_product)');
        Db::getInstance()->execute('ALTER TABLE ' . _DB_PREFIX_ . 'product_comment_criterion DROP `id_lang`');
        Db::getInstance()->execute('ALTER TABLE ' . _DB_PREFIX_ . 'product_comment_criterion DROP `name`');
        Db::getInstance()->execute('ALTER TABLE ' . _DB_PREFIX_ . 'product_comment_criterion ADD `id_product_comment_criterion_type` tinyint(1) NOT NULL AFTER `id_product_comment_criterion`');
        Db::getInstance()->execute('ALTER TABLE ' . _DB_PREFIX_ . 'product_comment_criterion ADD `active` tinyint(1) NOT NULL AFTER `id_product_comment_criterion_type`');
        Db::getInstance()->execute('ALTER IGNORE TABLE `' . _DB_PREFIX_ . 'product_comment` ADD `title` VARCHAR(64) NULL AFTER `id_guest`;');
    }
}
Example #20
0
function upgrade_cms_15()
{
    $res = true;
    // note : cms_shop table is required and independant of blockcms module
    // /!\ : _cms_shop is the wrong table name (fixed in 1.5.0.12.sql : upgrade_cms_15_rename() )
    $res &= Db::getInstance()->execute('CREATE TABLE `' . _DB_PREFIX_ . '_cms_shop` (
`id_cms` INT( 11 ) UNSIGNED NOT NULL,
`id_shop` INT( 11 ) UNSIGNED NOT NULL ,
  PRIMARY KEY (`id_cms`, `id_shop`),
	KEY `id_shop` (`id_shop`)
) ENGINE=' . _MYSQL_ENGINE_ . '  DEFAULT CHARSET=utf8;');
    // /!\ : _cms_shop and _cms are wrong tables name (fixed in 1.5.0.12.sql : upgrade_cms_15_rename() )
    $res &= Db::getInstance()->execute('INSERT INTO `' . _DB_PREFIX_ . '_cms_shop` (id_shop, id_cms)
	 	(SELECT 1, id_cms FROM ' . _DB_PREFIX_ . '_cms)');
    // cms_block table is blockcms module dependant. Don't update table that does not exists
    // /!\ : _module is the wrong table name (fixed in 1.5.0.12.sql : upgrade_cms_15_rename() )
    $id_module_cms = Db::getInstance()->getValue('SELECT id_module from `' . _DB_PREFIX_ . '_module
		WHERE name="blockcms"`');
    if (!$id_module_cms) {
        return $res;
    }
    // /!\ : _cms_block is the wrong table name (fixed in 1.5.0.12.sql : upgrade_cms_15_rename() )
    $res &= Db::getInstance()->execute('ALTER TABLE `' . _DB_PREFIX_ . '._cms_block`
		ADD `id_shop` INT(11) UNSIGNED NOT NULL DEFAULT "1" AFTER `id_cms_block`');
    return $res;
}
Example #21
0
function upgrade_module_1_0_6($module)
{
    if (Db::getInstance()->ExecuteS('SHOW COLUMNS FROM `' . _DB_PREFIX_ . $module->name . '` LIKE \'one_shot\'') == false) {
        Db::getInstance()->Execute('ALTER TABLE `' . _DB_PREFIX_ . $module->name . '` ADD `one_shot` BOOLEAN NOT NULL DEFAULT 0 AFTER `updated_at`');
    }
    return $module;
}
Example #22
0
 public function getAmount($order_id)
 {
     $amount = Db::getInstance()->execute('
                     select total_paid from  `' . _DB_PREFIX_ . 'orders`
                     WHERE `id_order` = ' . $order_id);
     return $amount;
 }
function add_order_state($conf_name, $name, $invoice, $send_email, $color, $unremovable, $logable, $delivery, $template = null)
{
    $name_lang = array();
    $template_lang = array();
    foreach (explode('|', $name) as $item) {
        $temp = explode(':', $item);
        $name_lang[$temp[0]] = $temp[1];
    }
    if ($template) {
        foreach (explode('|', $template) as $item) {
            $temp = explode(':', $item);
            $template_lang[$temp[0]] = $temp[1];
        }
    }
    Db::getInstance()->Execute('
		INSERT INTO `' . _DB_PREFIX_ . 'order_state` (`invoice`, `send_email`, `color`, `unremovable`, `logable`, `delivery`) 
		VALUES (' . (int) $invoice . ', ' . (int) $send_email . ', \'' . pSQL($color) . '\', ' . (int) $unremovable . ', ' . (int) $logable . ', ' . (int) $delivery . ')');
    $id_order_state = Db::getInstance()->getValue('
		SELECT MAX(`id_order_state`)
		FROM `' . _DB_PREFIX_ . 'order_state`
	');
    foreach (Language::getLanguages() as $lang) {
        Db::getInstance()->Execute('
		INSERT IGNORE INTO `' . _DB_PREFIX_ . 'order_state_lang` (`id_lang`, `id_order_state`, `name`, `template`) 
		VALUES (' . (int) $lang['id_lang'] . ', ' . (int) $id_order_state . ', \'' . pSQL(isset($name_lang[$lang['iso_code']]) ? $name_lang[$lang['iso_code']] : $name_lang['en']) . '\', \'' . pSQL(isset($template_lang[$lang['iso_code']]) ? $template_lang[$lang['iso_code']] : (isset($template_lang['en']) ? $template_lang['en'] : '')) . '\')
		');
    }
    Configuration::updateValue($conf_name, $id_order_state);
}
function p15013_add_missing_columns()
{
    $errors = array();
    $db = Db::getInstance();
    $id_module = $db->getValue('SELECT id_module FROM `' . _DB_PREFIX_ . 'module` WHERE name="statssearch"');
    if ($id_module) {
        $list_fields = Db::getInstance()->executeS('SHOW FIELDS FROM `' . _DB_PREFIX_ . 'statssearch`');
        foreach ($list_fields as $k => $field) {
            $list_fields[$k] = $field['Field'];
        }
        if (!in_array('id_group_shop', $list_fields)) {
            if (!Db::getInstance()->execute('ALTER TABLE `' . _DB_PREFIX_ . 'statssearch`
				ADD `id_group_shop` INT(10) NOT NULL default "1" AFTER id_statssearch')) {
                $errors[] = $db->getMsgError();
            }
        }
        if (!in_array('id_shop', $list_fields)) {
            if (!Db::getInstance()->execute('ALTER TABLE `' . _DB_PREFIX_ . 'statssearch`
				ADD `id_shop` INT(10) NOT NULL default "1" AFTER id_statssearch')) {
                $errors[] = $db->getMsgError();
            }
        }
    }
    if (count($errors)) {
        return array('error' => 1, 'msg' => implode(',', $errors));
    }
}
Example #25
0
function add_new_tab($className, $name, $id_parent)
{
    $array = array();
    foreach (explode('|', $name) as $item) {
        $temp = explode(':', $item);
        $array[$temp[0]] = $temp[1];
    }
    if (!(int) Db::getInstance()->getValue('SELECT count(id_tab) FROM `' . _DB_PREFIX_ . 'tab` WHERE `class_name` = \'' . pSQL($className) . '\' ')) {
        Db::getInstance()->Execute('INSERT INTO `' . _DB_PREFIX_ . 'tab` (`id_parent`, `class_name`, `module`, `position`) VALUES (' . (int) $id_parent . ', \'' . pSQL($className) . '\', \'\', 
									(SELECT MAX(t.position)+ 1 FROM `' . _DB_PREFIX_ . 'tab` t WHERE t.id_parent = ' . (int) $id_parent . '))');
    }
    $languages = Db::getInstance()->executeS('SELECT * FROM `' . _DB_PREFIX_ . 'lang`');
    foreach ($languages as $lang) {
        Db::getInstance()->Execute('
		INSERT IGNORE INTO `' . _DB_PREFIX_ . 'tab_lang` (`id_lang`, `id_tab`, `name`) 
		VALUES (' . (int) $lang['id_lang'] . ', (
				SELECT `id_tab`
				FROM `' . _DB_PREFIX_ . 'tab`
				WHERE `class_name` = \'' . pSQL($className) . '\' LIMIT 0,1
			), \'' . pSQL(isset($array[$lang['iso_code']]) ? $array[$lang['iso_code']] : $array['en']) . '\')
		');
    }
    Db::getInstance()->Execute('INSERT IGNORE INTO `' . _DB_PREFIX_ . 'access` (`id_profile`, `id_tab`, `view`, `add`, `edit`, `delete`) 
								(SELECT `id_profile`, (
								SELECT `id_tab`
								FROM `' . _DB_PREFIX_ . 'tab`
								WHERE `class_name` = \'' . pSQL($className) . '\' LIMIT 0,1
								), 1, 1, 1, 1 FROM `' . _DB_PREFIX_ . 'profile` )');
}
    /**
     * Returns module content
     *
     * @param array $params Parameters
     * @return string Content
     */
    function hookHome($params)
    {
        global $smarty, $cookie;
        /*  ONLY FOR THEME OLDER THAN v1.0 */
        global $link;
        $smarty->assign(array('categories' => Category::getHomeCategories(intval($params['cookie']->id_lang), true), 'link' => $link));
        /* ELSE */
        $id_customer = intval($params['cookie']->id_customer);
        $maxdepth = 1;
        if (!($result = Db::getInstance()->ExecuteS('
		SELECT DISTINCT c.*, cl.*
		FROM `' . _DB_PREFIX_ . 'category` c 
		LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = ' . intval($params['cookie']->id_lang) . ')
		LEFT JOIN `' . _DB_PREFIX_ . 'category_group` cg ON (cg.`id_category` = c.`id_category`)
		WHERE 1' . (intval($maxdepth) != 0 ? ' AND `level_depth` <= ' . intval($maxdepth) : '') . '
		AND (c.`active` = 1 OR c.`id_category`= 1)
		AND cg.`id_group` ' . (!$cookie->id_customer ? '= 1' : 'IN (SELECT id_group FROM ' . _DB_PREFIX_ . 'customer_group WHERE id_customer = ' . intval($cookie->id_customer) . ')') . '
		ORDER BY `level_depth` ASC, cl.`name` ASC'))) {
            return;
        }
        $resultParents = array();
        $resultIds = array();
        foreach ($result as $row) {
            ${$row}['name'] = Category::hideCategoryPosition($row['name']);
            $resultParents[$row['id_parent']][] = $row;
            $resultIds[$row['id_category']] = $row;
        }
        $blockCategTree = $this->getTree($resultParents, $resultIds, 1);
        $smarty->assign('blockCategTree', $blockCategTree);
        return $this->display(__FILE__, 'home_menu.tpl');
    }
    public static function getIdEbayZonesByIdEbayShipping($id_ebay_profile, $id_ebay_shipping)
    {
        return Db::getInstance()->ExecuteS('SELECT id_ebay_zone
			FROM ' . _DB_PREFIX_ . 'ebay_shipping_international_zone
			WHERE `id_ebay_profile` = ' . (int) $id_ebay_profile . ' 
            AND id_ebay_shipping = "' . (int) $id_ebay_shipping . '"');
    }
    public function reOrderPositions()
    {
        $id_slide = $this->id;
        $context = Context::getContext();
        $id_shop = $context->shop->id;
        $max = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
			SELECT MAX(hss.`position`) as position
			FROM `' . _DB_PREFIX_ . 'tmleftbanner_slides` hss, `' . _DB_PREFIX_ . 'tmleftbanner` hs
			WHERE hss.`id_tmleftbanner_slides` = hs.`id_tmleftbanner_slides` AND hs.`id_shop` = ' . (int) $id_shop);
        if ((int) $max == (int) $id_slide) {
            return true;
        }
        $rows = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
			SELECT hss.`position` as position, hss.`id_tmleftbanner_slides` as id_slide
			FROM `' . _DB_PREFIX_ . 'tmleftbanner_slides` hss
			LEFT JOIN `' . _DB_PREFIX_ . 'tmleftbanner` hs ON (hss.`id_tmleftbanner_slides` = hs.`id_tmleftbanner_slides`)
			WHERE hs.`id_shop` = ' . (int) $id_shop . ' AND hss.`position` > ' . (int) $this->position);
        foreach ($rows as $row) {
            $current_slide = new leftBanner($row['id_slide']);
            --$current_slide->position;
            $current_slide->update();
            unset($current_slide);
        }
        return true;
    }
function cms_block()
{
    if (!Db::getInstance()->execute('SELECT `display_store` FROM `' . _DB_PREFIX_ . 'cms_block` LIMIT 1')) {
        return Db::getInstance()->execute('ALTER TABLE `' . _DB_PREFIX_ . 'cms_block` ADD `display_store` TINYINT NOT NULL DEFAULT \'1\'');
    }
    return true;
}
Example #30
0
 public function getTemporaryShouldAllowUseLegacyPage($page = null)
 {
     // Dev mode: always shown
     if (_PS_MODE_DEV_) {
         return true;
     }
     $version = \Db::getInstance()->getValue('SELECT `value` FROM `' . _DB_PREFIX_ . 'configuration` WHERE `name` = "PS_INSTALL_VERSION"');
     if (!$version) {
         return false;
     }
     $installVersion = explode('.', $version);
     $currentVersion = explode('.', _PS_VERSION_);
     // Prod mode, depends on the page
     switch ($page) {
         case 'product':
             // never show it for Product page in production mode.
             return false;
         default:
             // show only for 1.7.x
             if ($currentVersion[0] != '1' || $currentVersion[1] != '7') {
                 return false;
             }
             // show only if upgrade from older version than current one
             if ($installVersion[0] >= $currentVersion[0] || $installVersion[1] >= $currentVersion[1]) {
                 return false;
             }
     }
     return true;
 }