Esempio n. 1
0
    public static function getNbProductsLess($ebay_profile, $option, $ebay_sync_last_product)
    {
        if (version_compare(_PS_VERSION_, '1.5', '>')) {
            $sql = '
				SELECT COUNT(id_supplier) FROM(
					SELECT id_supplier
						FROM  `' . _DB_PREFIX_ . 'product` AS p
						INNER JOIN  `' . _DB_PREFIX_ . 'stock_available` AS s 
						ON p.id_product = s.id_product';
            if (version_compare(_PS_VERSION_, '1.5', '>')) {
                $sql .= ' 
						INNER JOIN  `' . _DB_PREFIX_ . 'product_shop` AS ps
						ON p.id_product = ps.id_product 
						AND ps.id_shop = ' . (int) $ebay_profile->id_shop;
            }
            $sql .= '   
						WHERE s.`quantity` >0
						AND  p.`active` =1
						AND  p.`id_category_default`
						IN (
							SELECT  `id_category`
							FROM  `' . _DB_PREFIX_ . 'ebay_category_configuration`
							WHERE  `id_category` >0
							AND  `id_ebay_category` >0
							AND  `id_ebay_profile` = ' . (int) $ebay_profile->id . ($ebay_profile->getConfiguration('EBAY_SYNC_PRODUCTS_MODE') != 'A' ? ' AND `sync` = 1' : '') . ')
						' . (Tools::getValue('option') == 1 ? EbaySynchronizer::_addSqlCheckProductInexistence('p') : '') . '
						AND p.`id_product` >' . (int) $ebay_sync_last_product . '
						AND p.`id_product` NOT IN (' . EbayProductConfiguration::getBlacklistedProductIdsQuery($ebay_profile->id) . ')
						' . EbaySynchronizer::_addSqlRestrictionOnLang('s') . '
						GROUP BY p.id_product
				)TableRequete';
        } else {
            $sql = '
				SELECT COUNT(`id_product`)
				FROM `' . _DB_PREFIX_ . 'product` AS p';
            if (version_compare(_PS_VERSION_, '1.5', '>')) {
                $sql .= '
					INNER JOIN  `' . _DB_PREFIX_ . 'product_shop` AS ps
					ON p.id_product = ps.id_product 
					AND ps.id_shop = ' . (int) $ebay_profile->id_shop;
            }
            $sql .= '
				WHERE p.`quantity` > 0
				AND p.`active` = 1
				AND p.`id_category_default` IN (
					SELECT `id_category`
					FROM `' . _DB_PREFIX_ . 'ebay_category_configuration`
					WHERE `id_category` > 0
					AND `id_ebay_category` > 0
					AND `id_ebay_profile` = ' . (int) $ebay_profile->id . ($ebay_profile->getConfiguration('EBAY_SYNC_PRODUCTS_MODE') != 'A' ? ' AND `sync` = 1' : '') . '
				)
				' . (Tools::getValue('option') == 1 ? EbaySynchronizer::_addSqlCheckProductInexistence('p') : '') . '
				AND p.`id_product` > ' . (int) $ebay_sync_last_product . '
				AND p.`id_product` NOT IN (' . EbayProductConfiguration::getBlacklistedProductIdsQuery($ebay_profile->id) . ')';
        }
        return Db::getInstance()->getValue($sql);
    }
 public static function getBlacklistedProductIds()
 {
     $res = Db::getInstance()->executeS(EbayProductConfiguration::getBlacklistedProductIdsQuery());
     return array_map(array('EbayProductConfiguration', 'getBlacklistedProductIdsMap'), $res);
 }
    function getContent()
    {
        // Check if the module is configured
        if (!$this->ebay_profile->getConfiguration('EBAY_PAYPAL_EMAIL')) {
            return '<p class="error"><b>' . $this->ebay->l('Please configure the \'General settings\' tab before using this tab') . '</b></p><br /><script type="text/javascript">$("#menuTab5").addClass("wrong")</script>';
        }
        if (!EbayCategoryConfiguration::getTotalCategoryConfigurations($this->ebay_profile->id)) {
            return '<p class="error"><b>' . $this->ebay->l('Please configure the \'Category settings\' tab before using this tab') . '</b></p><br /><script type="text/javascript">$("#menuTab5").addClass("wrong")</script>';
        }
        if (version_compare(_PS_VERSION_, '1.5', '>')) {
            $sql = '
				SELECT COUNT( * ) FROM (
					SELECT COUNT(p.id_product) AS nb
						FROM  `' . _DB_PREFIX_ . 'product` AS p
						INNER JOIN  `' . _DB_PREFIX_ . 'stock_available` AS s 
						ON p.id_product = s.id_product';
            if (version_compare(_PS_VERSION_, '1.5', '>')) {
                $sql .= ' INNER JOIN  `' . _DB_PREFIX_ . 'product_shop` AS ps 
						ON p.id_product = ps.id_product 
						AND ps.id_shop = ' . (int) $this->ebay_profile->id_shop;
            }
            $sql .= ' WHERE s.`quantity` > 0
						AND  p.`active` = 1
						AND  p.`id_category_default`
						IN (
							SELECT  `id_category`
							FROM  `' . _DB_PREFIX_ . 'ebay_category_configuration`
							WHERE  `id_ebay_category` > 0
							AND `id_ebay_profile` = ' . (int) $this->ebay_profile->id . '
						)
						' . $this->ebay->addSqlRestrictionOnLang('s') . '
						AND p.id_product NOT IN (' . EbayProductConfiguration::getBlacklistedProductIdsQuery($this->ebay_profile->id) . ')
						GROUP BY p.id_product
				)TableReponse';
            $nb_products_mode_a = Db::getInstance()->getValue($sql);
            $sql = '
				SELECT COUNT( * ) FROM (
					SELECT COUNT( p.id_product ) AS nb
						FROM  `' . _DB_PREFIX_ . 'product` AS p
						INNER JOIN  `' . _DB_PREFIX_ . 'stock_available` AS s 
						ON p.id_product = s.id_product';
            if (version_compare(_PS_VERSION_, '1.5', '>')) {
                $sql .= ' INNER JOIN  `' . _DB_PREFIX_ . 'product_shop` AS ps
						ON p.id_product = ps.id_product 
						AND ps.id_shop = ' . (int) $this->ebay_profile->id_shop;
            }
            $sql .= ' WHERE s.`quantity` > 0
						AND  p.`active` = 1
						AND  p.`id_category_default`
						IN (
							SELECT  `id_category`
							FROM  `' . _DB_PREFIX_ . 'ebay_category_configuration`
							WHERE  `id_ebay_category` > 0 
							AND `sync` = 1
							AND `id_ebay_profile` = ' . (int) $this->ebay_profile->id . '
						)' . $this->ebay->addSqlRestrictionOnLang('s') . '
						AND p.id_product NOT IN (' . EbayProductConfiguration::getBlacklistedProductIdsQuery($this->ebay_profile->id) . ')
						GROUP BY p.id_product
				)TableReponse';
            $nb_products_mode_b = Db::getInstance()->getValue($sql);
        } else {
            $sql = '
				SELECT COUNT(`id_product`) as nb
				FROM `' . _DB_PREFIX_ . 'product` AS p';
            if (version_compare(_PS_VERSION_, '1.5', '>')) {
                $sql .= ' INNER JOIN  `' . _DB_PREFIX_ . 'product_shop` AS ps
				ON p.id_product = ps.id_product 
				AND ps.id_shop = ' . (int) $this->ebay_profile->id_shop;
            }
            $sql .= ' WHERE p.`quantity` > 0
				AND p.`active` = 1
				AND p.`id_category_default` IN (
					SELECT `id_category`
					FROM `' . _DB_PREFIX_ . 'ebay_category_configuration`
					WHERE `id_ebay_category` > 0
					AND `id_ebay_profile` = ' . (int) $this->ebay_profile->id . ')
				AND p.`id_product` NOT IN (' . EbayProductConfiguration::getBlacklistedProductIdsQuery($this->ebay_profile->id) . ')';
            $nb_products_mode_a = Db::getInstance()->getValue($sql);
            $sql = 'SELECT COUNT(`id_product`) as nb
				FROM `' . _DB_PREFIX_ . 'product` AS p';
            if (version_compare(_PS_VERSION_, '1.5', '>')) {
                $sql .= ' INNER JOIN  `' . _DB_PREFIX_ . 'product_shop` AS ps
				ON p.id_product = ps.id_product 
				AND ps.id_shop = ' . (int) $this->ebay_profile->id_shop;
            }
            $sql .= ' WHERE p.`quantity` > 0
				AND p.`active` = 1
				AND p.`id_category_default` IN (
					SELECT `id_category`
					FROM `' . _DB_PREFIX_ . 'ebay_category_configuration`
					WHERE `id_ebay_category` > 0
					AND `sync` = 1
					AND `id_ebay_profile` = ' . (int) $this->ebay_profile->id . ')
				AND p.`id_product` NOT IN (' . EbayProductConfiguration::getBlacklistedProductIdsQuery($this->ebay_profile->id) . ')';
            $nb_products_mode_b = Db::getInstance()->getValue($sql);
        }
        $nb_products = $this->ebay_profile->getConfiguration('EBAY_SYNC_PRODUCTS_MODE') == 'B' ? $nb_products_mode_b : $nb_products_mode_a;
        $prod_nb = $nb_products < 2 ? $this->ebay->l('product') : $this->ebay->l('products');
        // Display Form
        $url_vars = array('id_tab' => '5', 'section' => 'sync');
        if (version_compare(_PS_VERSION_, '1.5', '>')) {
            $url_vars['controller'] = Tools::getValue('controller');
        } else {
            $url_vars['tab'] = Tools::getValue('tab');
        }
        $action_url = $this->_getUrl($url_vars);
        // Loading categories
        $category_config_list = array();
        foreach (EbayCategoryConfiguration::getEbayCategoryConfigurations($this->ebay_profile->id) as $c) {
            $category_config_list[$c['id_category']] = $c;
        }
        $category_list = $this->ebay->getChildCategories(Category::getCategories($this->context->language->id), 0);
        $categories = array();
        if ($category_list) {
            $alt_row = false;
            foreach ($category_list as $category) {
                if (isset($category_config_list[$category['id_category']]['id_ebay_category']) && $category_config_list[$category['id_category']]['id_ebay_category'] > 0) {
                    $categories[] = array('row_class' => $alt_row ? 'alt_row' : '', 'value' => $category['id_category'], 'checked' => $category_config_list[$category['id_category']]['sync'] == 1 ? 'checked="checked"' : '', 'name' => $category['name']);
                    $alt_row = !$alt_row;
                }
            }
        }
        $nb_products_sync_url = _MODULE_DIR_ . 'ebay/ajax/getNbProductsSync.php?token=' . Configuration::get('EBAY_SECURITY_TOKEN') . '&time=' . pSQL(date('Ymdhis')) . '&profile=' . $this->ebay_profile->id;
        $sync_products_url = _MODULE_DIR_ . 'ebay/ajax/eBaySyncProduct.php?token=' . Configuration::get('EBAY_SECURITY_TOKEN') . '&option=\'+option+\'&profile=' . $this->ebay_profile->id . '&time=' . pSQL(date('Ymdhis'));
        $smarty_vars = array('category_alerts' => $this->_getAlertCategories(), 'path' => $this->path, 'nb_products' => $nb_products ? $nb_products : 0, 'nb_products_mode_a' => $nb_products_mode_a ? $nb_products_mode_a : 0, 'nb_products_mode_b' => $nb_products_mode_b ? $nb_products_mode_b : 0, 'nb_products_sync_url' => $nb_products_sync_url, 'sync_products_url' => $sync_products_url, 'action_url' => $action_url, 'ebay_sync_option_resync' => $this->ebay_profile->getConfiguration('EBAY_SYNC_OPTION_RESYNC'), 'categories' => $categories, 'sync_1' => Tools::getValue('section') == 'sync' && Tools::getValue('ebay_sync_mode') == "1" && Tools::getValue('btnSubmitSyncAndPublish'), 'sync_2' => Tools::getValue('section') == 'sync' && Tools::getValue('ebay_sync_mode') == "2" && Tools::getValue('btnSubmitSyncAndPublish'), 'is_sync_mode_b' => $this->ebay_profile->getConfiguration('EBAY_SYNC_PRODUCTS_MODE') == 'B', 'ebay_sync_mode' => (int) ($this->ebay_profile->getConfiguration('EBAY_SYNC_MODE') ? $this->ebay_profile->getConfiguration('EBAY_SYNC_MODE') : 2), 'prod_str' => $nb_products >= 2 ? $this->ebay->l('products') : $this->ebay->l('product'));
        return $this->display('formEbaySync.tpl', $smarty_vars);
    }
Esempio n. 4
0
    $sql .= ' WHERE s.`quantity` > 0 
		AND p.`active` = 1
		AND p.`id_category_default` IN (
			SELECT `id_category`
			FROM `' . _DB_PREFIX_ . 'ebay_category_configuration`
			WHERE `id_ebay_category` > 0
			AND `sync` = 1
			AND `id_ebay_profile` = ' . (int) $ebay_profile->id . ')
		AND p.id_product NOT IN (' . EbayProductConfiguration::getBlacklistedProductIdsQuery($ebay_profile->id) . ')
		GROUP BY p.id_product) TableRequete';
    $nb_products = Db::getInstance()->getValue($sql);
} else {
    $sql = 'SELECT COUNT(`id_product`) as nb
		FROM `' . _DB_PREFIX_ . 'product` AS p';
    if (version_compare(_PS_VERSION_, '1.5', '>')) {
        $sql .= ' INNER JOIN  `' . _DB_PREFIX_ . 'product_shop` AS ps
		ON p.id_product = ps.id_product 
		AND ps.id_shop = ' . (int) $ebay_profile->id_shop;
    }
    $sql .= ' WHERE p.`quantity` > 0
		AND p.`active` = 1
		AND p.`id_category_default` IN (
			SELECT `id_category`
			FROM `' . _DB_PREFIX_ . 'ebay_category_configuration`
			WHERE `id_ebay_category` > 0
			AND `sync` = 1
			AND `id_ebay_profile` = ' . (int) $ebay_profile->id . ')
		AND p.id_product NOT IN (' . EbayProductConfiguration::getBlacklistedProductIdsQuery($ebay_profile->id) . ')';
    $nb_products = Db::getInstance()->getValue($sql);
}
echo $nb_products;
include dirname(__FILE__) . '/../classes/EbayProductConfiguration.php';
if (!Tools::getValue('token') || Tools::getValue('token') != Configuration::get('EBAY_SECURITY_TOKEN')) {
    die('ERROR: Invalid Token');
}
Db::getInstance()->autoExecute(_DB_PREFIX_ . 'ebay_category_configuration', array('sync' => (int) Tools::getValue('action')), 'UPDATE', '`id_category` = ' . (int) Tools::getValue('id_category'));
if (version_compare(_PS_VERSION_, '1.5', '>')) {
    $nb_products = Db::getInstance()->getValue('SELECT COUNT(*) AS nb FROM(
		SELECT p.id_product
		FROM ' . _DB_PREFIX_ . 'product AS p
		INNER JOIN ' . _DB_PREFIX_ . 'stock_available AS s ON s.id_product = p.id_product
		WHERE s.`quantity` > 0 AND `active` = 1
		AND p.`id_category_default` IN (
			SELECT `id_category`
			FROM `' . _DB_PREFIX_ . 'ebay_category_configuration`
			WHERE `id_ebay_category` > 0
			AND `sync` = 1)
		AND p.id_product NOT IN (' . EbayProductConfiguration::getBlacklistedProductIdsQuery() . ')
		GROUP BY p.id_product) TableRequete');
} else {
    $nb_products = Db::getInstance()->getValue('SELECT COUNT(`id_product`) as nb
		FROM `' . _DB_PREFIX_ . 'product` AS p
		WHERE p.`quantity` > 0
		AND p.`active` = 1
		AND p.`id_category_default` IN (
			SELECT `id_category`
			FROM `' . _DB_PREFIX_ . 'ebay_category_configuration`
			WHERE `id_ebay_category` > 0
			AND `sync` = 1)
		AND p.id_product NOT IN (' . EbayProductConfiguration::getBlacklistedProductIdsQuery() . ')');
}
echo $nb_products;
Esempio n. 6
0
    /**
     * Ebay Sync Form Config Methods
     *
     **/
    private function _displayFormEbaySync()
    {
        // Check if the module is configured
        if (!Configuration::get('EBAY_PAYPAL_EMAIL')) {
            return '<p><b>' . $this->l('Please configure the \'General settings\' tab before using this tab') . '</b></p><br />';
        }
        if (!EbayCategoryConfiguration::getTotalCategoryConfigurations()) {
            return '<p><b>' . $this->l('Please configure the \'Category settings\' tab before using this tab') . '</b></p><br />';
        }
        if (version_compare(_PS_VERSION_, '1.5', '>')) {
            $nb_products_mode_a = Db::getInstance()->getValue('
				SELECT COUNT( * ) FROM (
					SELECT COUNT( p.id_product ) AS nb
						FROM  `' . _DB_PREFIX_ . 'product` AS p
						INNER JOIN  `' . _DB_PREFIX_ . 'stock_available` AS s ON p.id_product = s.id_product
						WHERE s.`quantity` > 0
						AND  `active` = 1
						AND  `id_category_default`
						IN (
							SELECT  `id_category`
							FROM  `' . _DB_PREFIX_ . 'ebay_category_configuration`
							WHERE  `id_ebay_category` > 0
						)
						' . $this->addSqlRestrictionOnLang('s') . '
						AND p.id_product NOT IN (' . EbayProductConfiguration::getBlacklistedProductIdsQuery() . ')
						GROUP BY p.id_product
				)TableReponse');
            $nb_products_mode_b = Db::getInstance()->getValue('
				SELECT COUNT( * ) FROM (
					SELECT COUNT( p.id_product ) AS nb
						FROM  `' . _DB_PREFIX_ . 'product` AS p
						INNER JOIN  `' . _DB_PREFIX_ . 'stock_available` AS s ON p.id_product = s.id_product
						WHERE s.`quantity` > 0
						AND  `active` = 1
						AND  `id_category_default`
						IN (
							SELECT  `id_category`
							FROM  `' . _DB_PREFIX_ . 'ebay_category_configuration`
							WHERE  `id_ebay_category` > 0 AND `sync` = 1
						)' . $this->addSqlRestrictionOnLang('s') . '
						AND p.id_product NOT IN (' . EbayProductConfiguration::getBlacklistedProductIdsQuery() . ')
						GROUP BY p.id_product
				)TableReponse');
        } else {
            $nb_products_mode_a = Db::getInstance()->getValue('
				SELECT COUNT(`id_product`) as nb
				FROM `' . _DB_PREFIX_ . 'product` AS p
				WHERE p.`quantity` > 0
				AND p.`active` = 1
				AND p.`id_category_default` IN (
					SELECT `id_category`
					FROM `' . _DB_PREFIX_ . 'ebay_category_configuration`
					WHERE `id_ebay_category` > 0)
				AND p.`id_product` NOT IN (' . EbayProductConfiguration::getBlacklistedProductIdsQuery() . ')');
            $nb_products_mode_b = Db::getInstance()->getValue('
				SELECT COUNT(`id_product`) as nb
				FROM `' . _DB_PREFIX_ . 'product` AS p
				WHERE p.`quantity` > 0
				AND p.`active` = 1
				AND p.`id_category_default` IN (
					SELECT `id_category`
					FROM `' . _DB_PREFIX_ . 'ebay_category_configuration`
					WHERE `id_ebay_category` > 0
					AND `sync` = 1)
				AND p.`id_product` NOT IN (' . EbayProductConfiguration::getBlacklistedProductIdsQuery() . ')');
        }
        $nb_products = Configuration::get('EBAY_SYNC_MODE') == 'B' ? $nb_products_mode_b : $nb_products_mode_a;
        $prod_nb = $nb_products < 2 ? $this->l('product') : $this->l('products');
        // Display Form
        $url_vars = array('id_tab' => '5', 'section' => 'sync');
        if (version_compare(_PS_VERSION_, '1.5', '>')) {
            $url_vars['controller'] = Tools::safeOutput(Tools::getValue('controller'));
        } else {
            $url_vars['tab'] = Tools::safeOutput(Tools::getValue('tab'));
        }
        $action_url = $this->_getUrl($url_vars);
        // Loading categories
        $category_config_list = array();
        foreach (EbayCategoryConfiguration::getEbayCategoryConfigurations() as $c) {
            $category_config_list[$c['id_category']] = $c;
        }
        $category_list = $this->getChildCategories(Category::getCategories($this->context->language->id), 0);
        $categories = array();
        if ($category_list) {
            $alt_row = false;
            foreach ($category_list as $category) {
                if (isset($category_config_list[$category['id_category']]['id_ebay_category']) && $category_config_list[$category['id_category']]['id_ebay_category'] > 0) {
                    $categories[] = array('row_class' => $alt_row ? 'alt_row' : '', 'value' => $category['id_category'], 'checked' => $category_config_list[$category['id_category']]['sync'] == 1 ? 'checked="checked"' : '', 'name' => $category['name']);
                    $alt_row = !$alt_row;
                }
            }
        }
        $nb_products_sync_url = _MODULE_DIR_ . 'ebay/ajax/getNbProductsSync.php?token=' . Configuration::get('EBAY_SECURITY_TOKEN') . '&time=' . pSQL(date('Ymdhis'));
        $sync_products_url = _MODULE_DIR_ . 'ebay/ajax/eBaySyncProduct.php?token=' . Configuration::get('EBAY_SECURITY_TOKEN') . '&option=\'+option+\'&time=' . pSQL(date('Ymdhis'));
        $smarty_vars = array('path' => $this->_path, 'nb_products' => $nb_products ? $nb_products : 0, 'nb_products_mode_a' => $nb_products_mode_a ? $nb_products_mode_a : 0, 'nb_products_mode_b' => $nb_products_mode_b ? $nb_products_mode_b : 0, 'nb_products_sync_url' => $nb_products_sync_url, 'sync_products_url' => $sync_products_url, 'action_url' => $action_url, 'ebay_sync_option_resync' => Configuration::get('EBAY_SYNC_OPTION_RESYNC'), 'categories' => $categories, 'sync_1' => Tools::getValue('section') == 'sync' && Tools::getValue('submitSave1') != '', 'sync_2' => Tools::getValue('section') == 'sync' && Tools::getValue('submitSave2') != '', 'is_sync_mode_b' => Configuration::get('EBAY_SYNC_MODE') == 'B', 'prod_str' => $nb_products >= 2 ? $this->l('products') : $this->l('product'));
        $this->smarty->assign($smarty_vars);
        return $this->display(dirname(__FILE__), '/views/templates/hook/formEbaySync.tpl');
    }