function convertAndFormatPrice($price, $currency = false)
 {
     if (!$currency) {
         $currency = Currency::getCurrent();
     }
     return Tools::displayPrice(Tools::convertPrice($price, $currency), $currency);
 }
Esempio n. 2
0
 /**
  * Return discount value
  *
  * @param integer $nb_discounts Number of discount currently in cart
  * @param boolean $order_total_products Total cart products amount
  * @return mixed Return a float value or '!' if reduction is 'Shipping free'
  */
 public function getValue($nb_discounts = 0, $order_total_products = 0, $shipping_fees = 0, $idCart = false, $useTax = true)
 {
     $totalAmount = 0;
     $cart = new Cart((int) $idCart);
     if (!Validate::isLoadedObject($cart)) {
         return 0;
     }
     if (!$this->cumulable and (int) $nb_discounts > 1 or !$this->active or !$this->quantity and !$cart->OrderExists()) {
         return 0;
     }
     if ($this->usedByCustomer((int) $cart->id_customer) >= $this->quantity_per_user and !$cart->OrderExists()) {
         return 0;
     }
     $date_start = strtotime($this->date_from);
     $date_end = strtotime($this->date_to);
     if ((time() < $date_start or time() > $date_end) and !$cart->OrderExists()) {
         return 0;
     }
     $products = $cart->getProducts();
     $categories = Discount::getCategories((int) $this->id);
     foreach ($products as $product) {
         if (count($categories) and Product::idIsOnCategoryId($product['id_product'], $categories)) {
             $totalAmount += $this->include_tax ? $product['total_wt'] : $product['total'];
         }
     }
     if ($this->minimal > 0 and $totalAmount < $this->minimal) {
         return 0;
     }
     switch ($this->id_discount_type) {
         /* Relative value (% of the order total) */
         case 1:
             $amount = 0;
             $percentage = $this->value / 100;
             foreach ($products as $product) {
                 if (Product::idIsOnCategoryId($product['id_product'], $categories)) {
                     if ($this->cumulable_reduction or !$product['reduction_applies'] and !$product['on_sale']) {
                         $amount += ($useTax ? $product['total_wt'] : $product['total']) * $percentage;
                     }
                 }
             }
             return $amount;
             /* Absolute value */
         /* Absolute value */
         case 2:
             // An "absolute" voucher is available in one currency only
             $currency = (int) $cart->id_currency ? Currency::getCurrencyInstance($cart->id_currency) : Currency::getCurrent();
             if ($this->id_currency != $currency->id) {
                 return 0;
             }
             $taxDiscount = Cart::getTaxesAverageUsed((int) $cart->id);
             if (!$useTax and isset($taxDiscount) and $taxDiscount != 1) {
                 $this->value = abs($this->value / (1 + $taxDiscount * 0.01));
             }
             // Main return
             $value = 0;
             foreach ($products as $product) {
                 if (Product::idIsOnCategoryId($product['id_product'], $categories)) {
                     $value = $this->value;
                 }
             }
             // Return 0 if there are no applicable categories
             return $value;
             /* Free shipping (does not return a value but a special code) */
         /* Free shipping (does not return a value but a special code) */
         case 3:
             return '!';
     }
     return 0;
 }
Esempio n. 3
0
 /**
  * Return price converted
  *
  * @param float $price Product price
  * @param object $currency Current currency object
  * @param boolean $to_currency convert to currency or from currency to default currency
  */
 public static function convertPrice($price, $currency = NULL, $to_currency = true)
 {
     if ($currency === NULL) {
         $currency = Currency::getCurrent();
     } elseif (is_numeric($currency)) {
         $currency = Currency::getCurrencyInstance($currency);
     }
     $c_id = is_array($currency) ? $currency['id_currency'] : $currency->id;
     $c_rate = is_array($currency) ? $currency['conversion_rate'] : $currency->conversion_rate;
     if ($c_id != (int) Configuration::get('PS_CURRENCY_DEFAULT')) {
         if ($to_currency) {
             $price *= $c_rate;
         } else {
             $price /= $c_rate;
         }
     }
     return $price;
 }
Esempio n. 4
0
    private static function getPriceFilterSubQuery($filterValue)
    {
        if (version_compare(_PS_VERSION_, '1.5', '>')) {
            $idCurrency = (int) Context::getContext()->currency->id;
        } else {
            $idCurrency = (int) Currency::getCurrent()->id;
        }
        $priceFilterQuery = '';
        if (isset($filterValue) && $filterValue) {
            $priceFilterQuery = '
			INNER JOIN `' . _DB_PREFIX_ . 'layered_price_index` psi ON (psi.id_product = p.id_product AND psi.id_currency = ' . (int) $idCurrency . '
			AND psi.price_min <= ' . (int) $filterValue[1] . ' AND psi.price_max >= ' . (int) $filterValue[0] . ') ';
        } else {
            $priceFilterQuery = '
			INNER JOIN `' . _DB_PREFIX_ . 'layered_price_index` psi 
			ON (psi.id_product = p.id_product AND psi.id_currency = ' . (int) $idCurrency . ') ';
        }
        return array('join' => $priceFilterQuery, 'select' => ', psi.price_min, psi.price_max');
    }
Esempio n. 5
0
 /**
  * Return price converted
  *
  * @param float $price Product price
  * @param object $currency Current currency object
  */
 public static function convertPrice($price, $currency = NULL)
 {
     if ($currency === NULL) {
         $currency = Currency::getCurrent();
     }
     $c_id = is_array($currency) ? $currency['id_currency'] : $currency->id;
     $c_rate = is_array($currency) ? $currency['conversion_rate'] : $currency->conversion_rate;
     if ($c_id != intval(Configuration::get('PS_CURRENCY_DEFAULT'))) {
         $price *= $c_rate;
     }
     return $price;
 }
Esempio n. 6
0
*  @copyright 2013 - 2014 PayPlug SAS
*  @license   http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark & Property of PayPlug SAS
*/
require_once dirname(__FILE__) . './../../../../config/config.inc.php';
/** Call init.php to initialize context */
require_once dirname(__FILE__) . '/../../../../init.php';
require_once dirname(__FILE__) . '/../../classes/PayplugLock.php';
/** Tips to include class of module and backward_compatibility */
$payplug = Module::getInstanceByName('payplug');
/** Check PS_VERSION */
if (version_compare(_PS_VERSION_, '1.4', '<')) {
    return;
}
if (version_compare(_PS_VERSION_, '1.5', '<')) {
    $currency = Currency::getCurrent()->iso_code;
    $order_confirmation_url = 'order-confirmation.php?';
} else {
    $context = Context::getContext();
    $currency = $context->currency;
    $order_confirmation_url = 'index.php?controller=order-confirmation&';
}
if (!($cart_id = Tools::getValue('cartid'))) {
    Payplug::redirectForVersion('index.php?controller=order&step=1');
}
$cart = new Cart($cart_id);
/**
 * If no current cart, redirect to order page
 */
if (!$cart->id) {
    Payplug::redirectForVersion('index.php?controller=order&step=1');
Esempio n. 7
0
require_once dirname(__FILE__) . '/../../../../init.php';
/** Tips to include class of module and backward_compatibility */
$payplug = Module::getInstanceByName('payplug');
/** Check PS_VERSION */
if (version_compare(_PS_VERSION_, '1.4', '<')) {
    return;
}
/**
 * Check currency used
 */
$context = Context::getContext();
$cookie = $context->cookie;
$result_currency = array();
$cart = $context->cart;
if (version_compare(_PS_VERSION_, '1.5', '<')) {
    $result_currency['iso_code'] = Currency::getCurrent()->iso_code;
} else {
    $currency = $cart->id_currency;
    $result_currency = Currency::getCurrency($currency);
}
$supported_currencies = explode(';', Configuration::get('PAYPLUG_MODULE_CURRENCIES'));
if (!in_array($result_currency['iso_code'], $supported_currencies)) {
    return false;
}
/**
 *  Check amount
 */
$amount = $context->cart->getOrderTotal(true, Cart::BOTH) * 100;
if ($amount < Configuration::get('PAYPLUG_MODULE_MIN_AMOUNT') * 100 || $amount > Configuration::get('PAYPLUG_MODULE_MAX_AMOUNT') * 100) {
    return false;
}
Esempio n. 8
0
    public static function makeLeftJoinWhereCriterion($fromMethod, $search, $id_lang, $selected_criterion, $selected_criteria_groups_type = array(), $current_id_criterion_group = false, $is_attribute_group = false, $id_currency = false, $id_country = false, $id_group = false, $include_price_table = false, $include_product_table = false, $group_type = false, $criterion_groups = array())
    {
        if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) {
            $context = Context::getContext();
            if (!$id_currency) {
                $id_currency = $context->currency->id;
            }
        } else {
            if (!$id_currency) {
                $id_currency = Currency::getCurrent()->id;
            }
        }
        $join_criterion_tables = array();
        $join_criterion = array();
        $count_criterion = array();
        $where_criterion = array();
        $where_qty = array();
        $field_select = array();
        $attribute_selected = false;
        $lastAttributeCombinationTableId = false;
        $stock_management = (int) Configuration::get('PS_STOCK_MANAGEMENT') ? true : false;
        if (!$stock_management) {
            $search['search_on_stock'] = false;
        }
        if ($group_type == 'stock' && $stock_management) {
            $strict_stock = true;
        } else {
            $strict_stock = false;
        }
        if ($stock_management && AdvancedSearchCoreClass::_isFilledArray($selected_criterion) && AdvancedSearchCoreClass::_isFilledArray($criterion_groups)) {
            foreach ($selected_criterion as $id_criterion_group_tmp => $id_criterion_tmp) {
                foreach ($criterion_groups as $criterion_group) {
                    if ($criterion_group['id_criterion_group'] == $id_criterion_group_tmp && $criterion_group['criterion_group_type'] == 'stock') {
                        $search['search_on_stock'] = true;
                        $strict_stock = true;
                        break;
                    }
                }
            }
        }
        $having = array();
        $where_price_range = array();
        if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) {
            $table_stock_index = 0;
        }
        $idSelectedCriteria = implode('-', self::array_values_recursive($selected_criterion));
        $cacheKey = sha1($fromMethod . $search['id_search'] . $idSelectedCriteria . '-' . implode('-', array_keys($selected_criterion)) . '-' . (int) $current_id_criterion_group . (int) $include_price_table . (int) $include_product_table . (int) $id_lang . (int) $is_attribute_group . (int) $group_type . (int) $strict_stock);
        if (isset(self::$_cacheLeftJoinWhereCriterion[$cacheKey])) {
            return self::$_cacheLeftJoinWhereCriterion[$cacheKey];
        }
        if ($group_type && !$include_product_table && $search['display_empty_criteria']) {
            $make_union = true;
        } else {
            $make_union = false;
        }
        $price_is_included = false;
        if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) {
            $join_criterion[] = 'JOIN `' . _DB_PREFIX_ . 'product_shop` ps ON (' . (AdvancedSearchCoreClass::_isFilledArray(PM_AdvancedSearch4::$productFilterList) ? ' ps.`id_product` IN (' . implode(',', PM_AdvancedSearch4::$productFilterList) . ') AND ' : '') . 'ps.id_shop IN (' . implode(', ', Shop::getContextListShopID()) . ') AND ps.`id_product` = acp.`id_product`)';
            $join_criterion_tables[] = 'ps';
        }
        if (AdvancedSearchCoreClass::_isFilledArray($selected_criterion)) {
            $price_is_included = false;
            $attribute_qty_compare_on_join = array();
            $now = date('Y-m-d H:i:s');
            foreach ($selected_criterion as $id_criterion_group => $id_criterion) {
                if ($selected_criteria_groups_type[$id_criterion_group]['criterion_group_type'] == 'stock') {
                    $strict_stock = true;
                    continue;
                }
                $join_criterion_table = false;
                $join_price_table = false;
                $where_join = array();
                $where_single_value_range = array();
                $where_translatable_value_range = array();
                if (isset($selected_criteria_groups_type[$id_criterion_group]) && ($selected_criteria_groups_type[$id_criterion_group]['display_type'] == 5 || $selected_criteria_groups_type[$id_criterion_group]['range'])) {
                    $id_currency_default = Configuration::get('PS_CURRENCY_DEFAULT');
                    if ($id_currency != $id_currency_default) {
                        $currency = new Currency($id_currency);
                        $conversion_rate = $currency->conversion_rate;
                    } else {
                        $conversion_rate = 0;
                    }
                    $where_price_criterion = array();
                    foreach ($id_criterion as $range) {
                        $range = explode('-', $range);
                        $original_range = $range;
                        if ($conversion_rate > 0) {
                            $range[0] = $range[0] / $conversion_rate;
                            if (isset($range[1])) {
                                $range[1] = $range[1] / $conversion_rate;
                            }
                        }
                        if (in_array($selected_criteria_groups_type[$id_criterion_group]['criterion_group_type'], array('weight', 'width', 'height', 'depth'))) {
                            $where_single_value_range[] = 'ROUND(ac' . (int) $id_criterion_group . '.`single_value`,5) >= ROUND("' . $range[0] . '",5)' . (isset($range[1]) && $range[1] ? ' AND ROUND(ac' . (int) $id_criterion_group . '.`single_value`,5) <= ROUND("' . $range[1] . '",5)' : '');
                        } elseif ($selected_criteria_groups_type[$id_criterion_group]['criterion_group_type'] == 'price') {
                            $price_is_included = true;
                            list($taxConversion, $taxConversionForReduction, $specificPriceCondition, $specificPriceGroupCondition) = self::getPriceRangeConditions($id_group);
                            $specificPriceCondition .= $specificPriceGroupCondition;
                            $priceMinCondition = '
                            IF(app.`is_specific` = 1 AND app.`id_currency` IN (0, ' . $id_currency . '),
                                ' . sprintf($specificPriceCondition . ' >= TRUNCATE(%f' . $taxConversion . ', 2)', (double) $original_range[0]) . ',
                                ' . sprintf($specificPriceCondition . ' >= TRUNCATE(%f' . $taxConversion . ', 2)', (double) $range[0]) . '
                            )';
                            $priceMaxCondition = '';
                            if (isset($range[1]) && $range[1]) {
                                $priceMaxCondition = '
                                AND 
                                IF(app.`is_specific` = 1 AND app.`id_currency` IN (0, ' . $id_currency . '),
                                    ' . sprintf($specificPriceCondition . ' <= ROUND(%f' . $taxConversion . ', 2)', (double) $original_range[1]) . ',
                                    ' . sprintf($specificPriceCondition . ' <= ROUND(%f' . $taxConversion . ', 2)', (double) $range[1]) . '
                                )';
                            }
                            $where_price_criterion[] = ' (
                                /*AS4-PR-Start*/
                                ' . $priceMinCondition . $priceMaxCondition . '
                                /*AS4-PR-End*/
                                AND app.`id_country` IN (0, ' . (int) $id_country . ') 
                                AND app.`id_group` IN (0, ' . (int) $id_group . ')
                                AND ((app.`from` = \'0000-00-00 00:00:00\' OR \'' . $now . '\' >= app.`from`) AND (app.`to` = \'0000-00-00 00:00:00\' OR \'' . $now . '\' <= app.`to`))' . (version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? ' AND app.`id_shop` IN (0, ' . implode(', ', Shop::getContextListShopID()) . ') ' : '') . ') ';
                        } else {
                            $where_translatable_value_range[] = 'ROUND(CAST(REPLACE(acl' . (int) $id_criterion_group . '.`value`, ",", ".") AS DECIMAL(10,2)), 5) >= ROUND("' . $range[0] . '",5)' . (isset($range[1]) && $range[1] ? ' AND ROUND(CAST(REPLACE(acl' . (int) $id_criterion_group . '.`value`, ",", ".") AS DECIMAL(10,2)), 5) <= ROUND("' . $range[1] . '",5)' : '');
                        }
                    }
                    if (isset($where_price_criterion) && AdvancedSearchCoreClass::_isFilledArray($where_price_criterion)) {
                        $where_criterion[] = '( ' . implode(' OR ', $where_price_criterion) . ' )';
                    }
                    $subQueryForRange = '';
                    if (AdvancedSearchCoreClass::_isFilledArray($where_single_value_range) && !AdvancedSearchCoreClass::_isFilledArray($where_translatable_value_range)) {
                        $subQueryForRange = '
						AND acpc' . (int) $id_criterion_group . '.`id_criterion` IN (
							SELECT ac' . (int) $id_criterion_group . '.`id_criterion`
							FROM `' . _DB_PREFIX_ . 'pm_advancedsearch_criterion_' . (int) $search['id_search'] . '` ac' . (int) $id_criterion_group . '
							JOIN `' . _DB_PREFIX_ . 'pm_advancedsearch_criterion_' . (int) $search['id_search'] . '_link` aclink' . (int) $id_criterion_group . ' ON (ac' . (int) $id_criterion_group . '.`id_criterion` = aclink' . (int) $id_criterion_group . '.`id_criterion`)
							WHERE ac' . (int) $id_criterion_group . '.`id_criterion_group` = ' . (int) $id_criterion_group . '
							' . (AdvancedSearchCoreClass::_isFilledArray($where_single_value_range) ? 'AND (' . implode(' OR ', $where_single_value_range) . ')' : '') . '
						)
						';
                    }
                    if (AdvancedSearchCoreClass::_isFilledArray($where_translatable_value_range)) {
                        $subQueryForRange = '
						AND acpc' . (int) $id_criterion_group . '.`id_criterion` IN (
							SELECT ac' . (int) $id_criterion_group . '.`id_criterion`
							FROM `' . _DB_PREFIX_ . 'pm_advancedsearch_criterion_' . (int) $search['id_search'] . '` ac' . (int) $id_criterion_group . '
							JOIN `' . _DB_PREFIX_ . 'pm_advancedsearch_criterion_' . (int) $search['id_search'] . '_link` aclink' . (int) $id_criterion_group . ' ON (ac' . (int) $id_criterion_group . '.`id_criterion` = aclink' . (int) $id_criterion_group . '.`id_criterion`)
							JOIN `' . _DB_PREFIX_ . 'pm_advancedsearch_criterion_' . (int) $search['id_search'] . '_lang` acl' . (int) $id_criterion_group . ' ON (ac' . (int) $id_criterion_group . '.`id_criterion` = acl' . (int) $id_criterion_group . '.`id_criterion` AND acl' . (int) $id_criterion_group . '.`id_lang` = ' . (int) $id_lang . ' AND (' . implode(' OR ', $where_translatable_value_range) . '))
							WHERE ac' . (int) $id_criterion_group . '.`id_criterion_group` = ' . (int) $id_criterion_group . '
							' . (AdvancedSearchCoreClass::_isFilledArray($where_single_value_range) ? 'AND (' . implode(' OR ', $where_single_value_range) . ')' : '') . '
						)
						';
                    }
                    if ($selected_criteria_groups_type[$id_criterion_group]['criterion_group_type'] != 'price') {
                        if (!in_array('acpc' . (int) $id_criterion_group, $join_criterion_tables)) {
                            $join_criterion[] = 'JOIN `' . _DB_PREFIX_ . 'pm_advancedsearch_cache_product_criterion_' . (int) $search['id_search'] . '` acpc' . (int) $id_criterion_group . ' ON ( acp.`id_cache_product` = acpc' . (int) $id_criterion_group . '.`id_cache_product`' . $subQueryForRange . ')';
                            $join_criterion_tables[] = 'acpc' . (int) $id_criterion_group;
                        }
                    }
                } else {
                    if (is_array($id_criterion) && sizeof($id_criterion)) {
                        $customCriterions = AdvancedSearchCriterionClass::getCustomCriterionsLinkIds($search['id_search'], $id_criterion);
                        foreach ($id_criterion as $idCriterionKey => $idCriterion) {
                            if (isset($customCriterions[$idCriterion]) && is_array($customCriterions[$idCriterion]) && sizeof($customCriterions[$idCriterion])) {
                                unset($id_criterion[$idCriterionKey]);
                                $id_criterion = array_unique(array_merge($id_criterion, $customCriterions[$idCriterion]));
                            }
                        }
                    }
                    $current_where = '`id_criterion` IN (' . implode(', ', $id_criterion) . ')';
                    if ($selected_criteria_groups_type[$id_criterion_group]['criterion_group_type'] == 'attribute') {
                        $prev_where_criterion = $current_where;
                    }
                    $where_join[] = 'acpc' . (int) $id_criterion_group . '.' . $current_where;
                    $join_criterion[] = 'JOIN `' . _DB_PREFIX_ . 'pm_advancedsearch_cache_product_criterion_' . (int) $search['id_search'] . '` acpc' . (int) $id_criterion_group . ' ON ( acp.`id_cache_product` = acpc' . (int) $id_criterion_group . '.`id_cache_product`' . (AdvancedSearchCoreClass::_isFilledArray($where_join) ? ' AND ' . implode(' OR ', $where_join) : '') . ')';
                    $join_criterion_tables[] = 'acpc' . (int) $id_criterion_group;
                }
                if ($selected_criteria_groups_type[$id_criterion_group]['criterion_group_type'] != 'price') {
                    $count_criterion[$id_criterion_group] = 'acpc' . (int) $id_criterion_group . '.`id_cache_product`';
                } else {
                    $count_criterion[$id_criterion_group] = 'app.`id_cache_product`';
                }
                if (isset($selected_criteria_groups_type[$id_criterion_group]) && $selected_criteria_groups_type[$id_criterion_group]['criterion_group_type'] == 'attribute') {
                    $attribute_selected = true;
                    $join_criterion['criterion_' . (int) $search['id_search'] . '_' . (int) $id_criterion_group] = 'JOIN `' . _DB_PREFIX_ . 'pm_advancedsearch_criterion_' . (int) $search['id_search'] . '` ac' . (int) $id_criterion_group . ' ON (acpc' . (int) $id_criterion_group . '.`id_criterion` = ac' . (int) $id_criterion_group . '.`id_criterion`)';
                    $join_criterion['criterion_link_' . (int) $search['id_search'] . '_' . (int) $id_criterion_group] = 'JOIN `' . _DB_PREFIX_ . 'pm_advancedsearch_criterion_' . (int) $search['id_search'] . '_link` aclink' . (int) $id_criterion_group . ' ON (ac' . (int) $id_criterion_group . '.`id_criterion` = aclink' . (int) $id_criterion_group . '.`id_criterion`)';
                    if (!isset($previousIdCriterionGroupSelected)) {
                        $previousIdCriterionGroupSelected = null;
                    }
                    $join_criterion['pa' . (int) $id_criterion_group] = 'JOIN `' . _DB_PREFIX_ . 'product_attribute` pa' . (int) $id_criterion_group . ' ON (pa' . (int) $id_criterion_group . '.`id_product` = acp.`id_product`)';
                    $join_criterion[] = 'JOIN `' . _DB_PREFIX_ . 'product_attribute_combination` pac' . (int) $id_criterion_group . ' ON (pa' . (int) $id_criterion_group . '.`id_product_attribute` = pac' . (int) $id_criterion_group . '.`id_product_attribute` AND pac' . (int) $id_criterion_group . '.`id_attribute` = aclink' . (int) $id_criterion_group . '.`id_criterion_linked`' . ($previousIdCriterionGroupSelected != null ? ' AND pa' . (int) $previousIdCriterionGroupSelected . '.`id_product_attribute` = pa' . (int) $id_criterion_group . '.`id_product_attribute` ' : '') . ')';
                    $join_criterion_tables[] = 'ac' . (int) $id_criterion_group;
                    $join_criterion_tables[] = 'pa' . (int) $id_criterion_group;
                    $join_criterion_tables[] = 'pac' . (int) $id_criterion_group;
                    $lastAttributeCombinationTableId = 'pac' . (int) $id_criterion_group;
                    $previousIdCriterionGroupSelected = (int) $id_criterion_group;
                    if (!isset($attribute_check_table) && (!$include_product_table && !$search['display_empty_criteria'])) {
                        $attribute_check_table = $id_criterion_group;
                    } elseif (!isset($attribute_check_table)) {
                        $attribute_check_table = $id_criterion_group;
                        if ($search['priority_on_combination_image'] && $include_product_table) {
                            $join_criterion[] = 'LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute_image` pai ON (pac' . (int) $attribute_check_table . '.`id_product_attribute` = pai.`id_product_attribute`)';
                            $join_criterion_tables[] = 'pai';
                            $field_select[] = 'pai.id_image as attribute_image';
                        }
                    }
                    $attribute_qty_compare_on_join[] = 'pa' . (int) $attribute_check_table . '.`id_product_attribute` = pac' . (int) $id_criterion_group . '.`id_product_attribute`';
                }
            }
            if ($strict_stock || $search['search_on_stock'] || $include_product_table || $price_is_included) {
                if ($strict_stock) {
                    $join_criterion[] = 'LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON (' . (AdvancedSearchCoreClass::_isFilledArray(PM_AdvancedSearch4::$productFilterList) ? ' p.`id_product` IN (' . implode(',', PM_AdvancedSearch4::$productFilterList) . ') AND ' : '') . ' p.`id_product` = acp.`id_product`)';
                    $join_criterion_tables[] = 'p';
                    if (version_compare(_PS_VERSION_, '1.5.0.0', '<')) {
                        $where_qty[] = 'p.`quantity` > 0';
                    }
                } else {
                    $join_criterion[] = 'LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON (' . (AdvancedSearchCoreClass::_isFilledArray(PM_AdvancedSearch4::$productFilterList) ? ' p.`id_product` IN (' . implode(',', PM_AdvancedSearch4::$productFilterList) . ') AND ' : '') . ' p.`id_product` = acp.`id_product`)';
                    $join_criterion_tables[] = 'p';
                    if ($search['search_on_stock'] && version_compare(_PS_VERSION_, '1.5.0.0', '<')) {
                        $where_qty[] = 'IF(p.`quantity` > 0, 1, IF(p.`out_of_stock` = 2, ' . Configuration::get('PS_ORDER_OUT_OF_STOCK') . ' = 1, p.`out_of_stock` = 1))';
                    }
                }
            }
            if ($price_is_included || $include_product_table) {
                $join_criterion[] = 'LEFT JOIN `' . _DB_PREFIX_ . 'tax_rule` tr ON (' . (version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? 'ps' : 'p') . '.`id_tax_rules_group` = tr.`id_tax_rules_group`
				AND tr.`id_country` = ' . (int) (version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? Context::getContext()->country->id : Country::getDefaultCountryId()) . '
				AND tr.`id_state` = 0)';
                $join_criterion[] = ' LEFT JOIN `' . _DB_PREFIX_ . 'tax` t ON (t.`id_tax` = tr.`id_tax`)';
                $join_criterion_tables[] = 'tr';
                $join_criterion_tables[] = 't';
                $join_criterion[] = 'LEFT JOIN `' . _DB_PREFIX_ . 'group_reduction` grc ON (grc.`id_group`=' . (int) $id_group . ' AND ' . (version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? 'ps' : 'p') . '.`id_category_default` = grc.`id_category`)';
                $join_criterion_tables[] = 'grc';
            }
            if ($price_is_included) {
                $field_select[] = self::_getScoreQuery(version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? Context::getContext()->shop->id : 0, $id_currency, $id_country, $id_group);
                $join_criterion[] = 'JOIN `' . _DB_PREFIX_ . 'pm_advancedsearch_product_price_' . (int) $search['id_search'] . '` app ON ( acp.`id_cache_product` = app.`id_cache_product` AND ((app.`valid_id_specific_price`=1 AND app.`is_specific`=1) OR app.`has_no_specific`=1) ' . (version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? ' AND app.`id_shop` IN (0, ' . implode(', ', Shop::getContextListShopID()) . ') ' : '') . ')';
                $join_price_table = true;
            }
            if ($search['search_on_stock'] || $strict_stock && !$group_type && !isset($attribute_check_table)) {
                if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) {
                    $table_stock_index++;
                    if ($strict_stock) {
                        $join_criterion[] = 'LEFT JOIN `' . _DB_PREFIX_ . 'stock_available` sa' . $table_stock_index . ' ON ( sa' . $table_stock_index . '.`id_product` = acp.`id_product` AND sa' . $table_stock_index . '.`id_product_attribute`=0 ' . self::_addSqlShopRestrictionStockAvailable('sa' . $table_stock_index) . ')';
                        $join_criterion_tables[] = 'sa' . $table_stock_index;
                        $where_qty[] = 'IF (sa' . $table_stock_index . '.`quantity` > 0, 1, IF (sa' . $table_stock_index . '.`out_of_stock` = 2, ' . Configuration::get('PS_ORDER_OUT_OF_STOCK') . ' = 1, sa' . $table_stock_index . '.`out_of_stock` = 1))';
                    } else {
                        if (!(($group_type || $include_product_table) && isset($attribute_check_table) && sizeof($attribute_qty_compare_on_join))) {
                            $join_criterion[] = 'LEFT JOIN `' . _DB_PREFIX_ . 'stock_available` sa' . $table_stock_index . ' ON ( sa' . $table_stock_index . '.`id_product` = acp.`id_product` AND sa' . $table_stock_index . '.`id_product_attribute`=0 ' . self::_addSqlShopRestrictionStockAvailable('sa' . $table_stock_index) . ')';
                            $join_criterion_tables[] = 'sa' . $table_stock_index;
                            $where_qty[] = 'IF (sa' . $table_stock_index . '.`quantity` > 0, 1, IF (sa' . $table_stock_index . '.`out_of_stock` = 2, ' . Configuration::get('PS_ORDER_OUT_OF_STOCK') . ' = 1, sa' . $table_stock_index . '.`out_of_stock` = 1))';
                        }
                    }
                }
            }
            if ($current_id_criterion_group && isset($attribute_check_table) && $group_type) {
                if ($is_attribute_group) {
                    if (!isset($previousIdCriterionGroupSelected)) {
                        $previousIdCriterionGroupSelected = null;
                    }
                    if (!in_array('pa' . (int) $current_id_criterion_group, $join_criterion_tables)) {
                        $join_criterion[] = 'JOIN `' . _DB_PREFIX_ . 'product_attribute` pa' . (int) $current_id_criterion_group . ' ON (pa' . (int) $current_id_criterion_group . '.`id_product` = acp.`id_product`)';
                        $join_criterion_tables[] = 'pa' . (int) $current_id_criterion_group;
                    }
                    $join_criterion[] = 'JOIN `' . _DB_PREFIX_ . 'product_attribute_combination` pac' . (int) $current_id_criterion_group . ' ON (pa' . (int) $current_id_criterion_group . '.`id_product_attribute` = pac' . (int) $current_id_criterion_group . '.`id_product_attribute` AND pac' . (int) $current_id_criterion_group . '.`id_attribute` = aclink.`id_criterion_linked`' . ($previousIdCriterionGroupSelected != null ? ' AND pa' . (int) $previousIdCriterionGroupSelected . '.`id_product_attribute` = pa' . (int) $current_id_criterion_group . '.`id_product_attribute` ' : '') . ')';
                    $join_criterion_tables[] = 'pac' . (int) $current_id_criterion_group;
                    $lastAttributeCombinationTableId = 'pac' . (int) $current_id_criterion_group;
                    $attribute_qty_compare_on_join[] = 'pa' . (int) $attribute_check_table . '.`id_product_attribute` = pac' . (int) $current_id_criterion_group . '.`id_product_attribute`';
                    $previousIdCriterionGroupSelected = (int) $current_id_criterion_group;
                }
            } else {
                if (($search['search_on_stock'] || $strict_stock) && $group_type && !isset($attribute_check_table)) {
                    if ($strict_stock && version_compare(_PS_VERSION_, '1.5.0.0', '<')) {
                        $join_criterion[] = 'LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute` pa' . (int) $current_id_criterion_group . ' ON (pa' . (int) $current_id_criterion_group . '.`id_product` = acp.`id_product` ' . ($fromMethod != 'getCriterionsForSearchBloc' ? ' AND pa' . (int) $current_id_criterion_group . '.id_product_attribute = aclink.id_criterion_linked ' : '') . ')';
                        $join_criterion_tables[] = 'pa' . (int) $current_id_criterion_group;
                        $where_qty[] = 'IF (pa' . (int) $current_id_criterion_group . '.`quantity` = NULL, IF (p.`quantity` > 0, 1, IF (p.`out_of_stock` = 2, ' . Configuration::get('PS_ORDER_OUT_OF_STOCK') . ' = 1, p.`out_of_stock` = 1)), pa' . (int) $current_id_criterion_group . '.`quantity` > 0)';
                    } else {
                        $join_criterion[] = 'LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute` pa' . (int) $current_id_criterion_group . ' ON (pa' . (int) $current_id_criterion_group . '.`id_product` = acp.`id_product` ' . ($fromMethod != 'getCriterionsForSearchBloc' ? ' AND pa' . (int) $current_id_criterion_group . '.id_product_attribute = aclink.id_criterion_linked ' : '') . ')';
                        $join_criterion_tables[] = 'pa' . (int) $current_id_criterion_group;
                        if ($search['search_on_stock'] && version_compare(_PS_VERSION_, '1.5.0.0', '<')) {
                            $where_qty[] = 'IF (pa' . (int) $current_id_criterion_group . '.`quantity` = NULL, IF (p.`quantity` > 0, 1, IF (p.`out_of_stock` = 2, ' . Configuration::get('PS_ORDER_OUT_OF_STOCK') . ' = 1, p.`out_of_stock` = 1)), IF (pa' . (int) $current_id_criterion_group . '.`quantity` > 0, 1, IF (p.`out_of_stock` = 2, ' . Configuration::get('PS_ORDER_OUT_OF_STOCK') . ' = 1, p.`out_of_stock` = 1)))';
                        }
                    }
                    if (version_compare(_PS_VERSION_, '1.5.0.0', '>=') && $search['search_on_stock']) {
                        $table_stock_index++;
                        if ($strict_stock) {
                            $join_criterion[] = 'LEFT JOIN `' . _DB_PREFIX_ . 'stock_available` sa' . $table_stock_index . ' ON ( sa' . $table_stock_index . '.`id_product` = acp.`id_product` AND sa' . $table_stock_index . '.`id_product_attribute` = pa' . (int) $current_id_criterion_group . '.`id_product_attribute` ' . self::_addSqlShopRestrictionStockAvailable('sa' . $table_stock_index) . ')';
                            $join_criterion_tables[] = 'sa' . $table_stock_index;
                            $where_qty[] = 'IF (sa' . $table_stock_index . '.`quantity` > 0,1, IF (sa' . $table_stock_index . '.`out_of_stock` = 2, ' . Configuration::get('PS_ORDER_OUT_OF_STOCK') . ' = 1, sa' . $table_stock_index . '.`out_of_stock` = 1))';
                        } else {
                            $join_criterion[] = 'LEFT JOIN `' . _DB_PREFIX_ . 'stock_available` sa' . $table_stock_index . ' ON ( sa' . $table_stock_index . '.`id_product` = acp.`id_product` AND sa' . $table_stock_index . '.`id_product_attribute` = pa' . (int) $current_id_criterion_group . '.`id_product_attribute` ' . self::_addSqlShopRestrictionStockAvailable('sa' . $table_stock_index) . ')';
                            $join_criterion_tables[] = 'sa' . $table_stock_index;
                            $where_qty[] = 'IF (sa' . $table_stock_index . '.`quantity` > 0,1, IF (sa' . $table_stock_index . '.`out_of_stock` = 2, ' . Configuration::get('PS_ORDER_OUT_OF_STOCK') . ' = 1, sa' . $table_stock_index . '.`out_of_stock` = 1))';
                        }
                    }
                    if ($is_attribute_group) {
                        if (!in_array('pa' . (int) $current_id_criterion_group, $join_criterion_tables)) {
                            $join_criterion['pa' . (int) $current_id_criterion_group] = 'JOIN `' . _DB_PREFIX_ . 'product_attribute` pa' . (int) $current_id_criterion_group . ' ON (pa' . (int) $current_id_criterion_group . '.`id_product` = acp.`id_product`)';
                            $join_criterion_tables[] = 'pa' . (int) $current_id_criterion_group;
                        }
                        $join_criterion[] = 'JOIN `' . _DB_PREFIX_ . 'product_attribute_combination` pac' . (int) $current_id_criterion_group . ' ON (' . ($is_attribute_group ? 'pa' . (int) $current_id_criterion_group . '.`id_product_attribute` = pac' . (int) $current_id_criterion_group . '.`id_product_attribute` AND ' : '') . 'pac' . (int) $current_id_criterion_group . '.`id_attribute` = aclink.`id_criterion_linked`)';
                        $join_criterion_tables[] = 'pac' . (int) $current_id_criterion_group;
                        $lastAttributeCombinationTableId = 'pac' . (int) $current_id_criterion_group;
                    }
                }
            }
            if (($group_type || $include_product_table) && isset($attribute_check_table) && sizeof($attribute_qty_compare_on_join)) {
                if ($strict_stock && version_compare(_PS_VERSION_, '1.5.0.0', '<')) {
                    if (!in_array('pa' . (int) $attribute_check_table, $join_criterion_tables)) {
                        $join_criterion['pa' . (int) $attribute_check_table] = 'JOIN `' . _DB_PREFIX_ . 'product_attribute` pa' . (int) $attribute_check_table . ' ON (' . implode(' AND ', $attribute_qty_compare_on_join) . ' AND pa' . (int) $attribute_check_table . '.`id_product` = acp.`id_product`)';
                        $join_criterion_tables[] = 'pa' . (int) $attribute_check_table;
                    }
                    $where_qty[] = 'pa' . (int) $attribute_check_table . '.`quantity` > 0';
                } else {
                    if (!in_array('pa' . (int) $attribute_check_table, $join_criterion_tables)) {
                        $join_criterion['pa' . (int) $attribute_check_table] = 'JOIN `' . _DB_PREFIX_ . 'product_attribute` pa' . (int) $attribute_check_table . ' ON (' . implode(' AND ', $attribute_qty_compare_on_join) . ' AND pa' . (int) $attribute_check_table . '.`id_product` = acp.`id_product`)';
                        $join_criterion_tables[] = 'pa' . (int) $attribute_check_table;
                    }
                    if ($search['search_on_stock'] && version_compare(_PS_VERSION_, '1.5.0.0', '<')) {
                        $where_qty[] = 'IF (pa' . (int) $attribute_check_table . '.`quantity` > 0, 1, IF(p.`out_of_stock` = 2, ' . Configuration::get('PS_ORDER_OUT_OF_STOCK') . ' = 1, p.`out_of_stock` = 1))';
                    } elseif (version_compare(_PS_VERSION_, '1.5.0.0', '<')) {
                        $where_qty[] = 'pa' . (int) $attribute_check_table . '.`quantity` IS NOT NULL';
                    }
                }
                if (version_compare(_PS_VERSION_, '1.5.0.0', '>=') && ($search['search_on_stock'] || $strict_stock)) {
                    $table_stock_index++;
                    if ($strict_stock) {
                        $join_criterion[] = 'LEFT JOIN `' . _DB_PREFIX_ . 'stock_available` sa' . $table_stock_index . ' ON ( sa' . $table_stock_index . '.`id_product` = acp.`id_product` AND sa' . $table_stock_index . '.`id_product_attribute` = pa' . (int) $attribute_check_table . '.`id_product_attribute` ' . self::_addSqlShopRestrictionStockAvailable('sa' . $table_stock_index) . ')';
                        $join_criterion_tables[] = 'sa' . $table_stock_index;
                        $where_qty[] = 'IF (sa' . $table_stock_index . '.`quantity` > 0, 1, IF(sa' . $table_stock_index . '.`out_of_stock` = 2, ' . Configuration::get('PS_ORDER_OUT_OF_STOCK') . ' = 1, sa' . $table_stock_index . '.`out_of_stock` = 1))';
                    } else {
                        $join_criterion[] = 'LEFT JOIN `' . _DB_PREFIX_ . 'stock_available` sa' . $table_stock_index . ' ON ( sa' . $table_stock_index . '.`id_product` = acp.`id_product` AND sa' . $table_stock_index . '.`id_product_attribute` = pa' . (int) $attribute_check_table . '.`id_product_attribute` ' . self::_addSqlShopRestrictionStockAvailable('sa' . $table_stock_index) . ')';
                        $join_criterion_tables[] = 'sa' . $table_stock_index;
                        $where_qty[] = 'IF (sa' . $table_stock_index . '.`quantity` > 0, 1, IF(sa' . $table_stock_index . '.`out_of_stock` = 2, ' . Configuration::get('PS_ORDER_OUT_OF_STOCK') . ' = 1, sa' . $table_stock_index . '.`out_of_stock` = 1))';
                    }
                }
            }
        } else {
            if (($search['search_on_stock'] || $strict_stock) && version_compare(_PS_VERSION_, '1.5.0.0', '<') || $include_product_table && $include_price_table) {
                if ($strict_stock) {
                    $join_criterion[] = 'JOIN `' . _DB_PREFIX_ . 'product` p ON ( ' . (AdvancedSearchCoreClass::_isFilledArray(PM_AdvancedSearch4::$productFilterList) ? ' p.`id_product` IN (' . implode(',', PM_AdvancedSearch4::$productFilterList) . ') AND ' : '') . ' p.`id_product` = acp.`id_product`)';
                    $join_criterion_tables[] = 'p';
                    if (version_compare(_PS_VERSION_, '1.5.0.0', '<')) {
                        $where_qty[] = 'p.`quantity` > 0';
                    }
                } else {
                    $join_criterion[] = 'JOIN `' . _DB_PREFIX_ . 'product` p ON ( ' . (AdvancedSearchCoreClass::_isFilledArray(PM_AdvancedSearch4::$productFilterList) ? ' p.`id_product` IN (' . implode(',', PM_AdvancedSearch4::$productFilterList) . ') AND ' : '') . ' p.`id_product` = acp.`id_product`)';
                    $join_criterion_tables[] = 'p';
                    if ($search['search_on_stock'] && version_compare(_PS_VERSION_, '1.5.0.0', '<')) {
                        $where_qty[] = 'IF (p.`quantity` > 0, 1, IF (p.`out_of_stock` = 2, ' . Configuration::get('PS_ORDER_OUT_OF_STOCK') . ' = 1, p.`out_of_stock` = 1))';
                    }
                }
            }
            if ($include_product_table && $include_price_table) {
                $join_criterion[] = 'LEFT JOIN `' . _DB_PREFIX_ . 'tax_rule` tr ON (' . (version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? 'ps' : 'p') . '.`id_tax_rules_group` = tr.`id_tax_rules_group`
				AND tr.`id_country` = ' . (int) (version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? Context::getContext()->country->id : Country::getDefaultCountryId()) . '
				AND tr.`id_state` = 0)';
                $join_criterion[] = ' LEFT JOIN `' . _DB_PREFIX_ . 'tax` t ON (t.`id_tax` = tr.`id_tax`)';
                $join_criterion_tables[] = 'tr';
                $join_criterion_tables[] = 't';
                $join_criterion[] = 'LEFT JOIN `' . _DB_PREFIX_ . 'group_reduction` grc ON (grc.`id_group`=' . (int) $id_group . ' AND ' . (version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? 'ps' : 'p') . '.`id_category_default` = grc.`id_category`)';
                $join_criterion_tables[] = 'grc';
            }
            if ($is_attribute_group && ($search['search_on_stock'] || $strict_stock)) {
                if ($strict_stock && version_compare(_PS_VERSION_, '1.5.0.0', '<')) {
                    if (!in_array('pa' . (int) $current_id_criterion_group, $join_criterion_tables)) {
                        $join_criterion['pa' . (int) $current_id_criterion_group] = 'JOIN `' . _DB_PREFIX_ . 'product_attribute` pa' . (int) $current_id_criterion_group . ' ON (pa' . (int) $current_id_criterion_group . '.`id_product` = acp.`id_product`)';
                        $join_criterion_tables[] = 'pa' . (int) $current_id_criterion_group;
                    }
                    $where_qty[] = 'pa' . (int) $current_id_criterion_group . '.`quantity` > 0';
                } else {
                    if (!in_array('pa' . (int) $current_id_criterion_group, $join_criterion_tables)) {
                        $join_criterion['pa' . (int) $current_id_criterion_group] = 'JOIN `' . _DB_PREFIX_ . 'product_attribute` pa' . (int) $current_id_criterion_group . ' ON (pa' . (int) $current_id_criterion_group . '.`id_product` = acp.`id_product`)';
                        $join_criterion_tables[] = 'pa' . (int) $current_id_criterion_group;
                    }
                    if ($search['search_on_stock'] && version_compare(_PS_VERSION_, '1.5.0.0', '<')) {
                        $where_qty[] = 'IF (pa' . (int) $current_id_criterion_group . '.`quantity` > 0, 1, IF(p.`out_of_stock` = 2, ' . Configuration::get('PS_ORDER_OUT_OF_STOCK') . ' = 1, p.`out_of_stock` = 1))';
                    }
                }
                if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) {
                    $table_stock_index++;
                    if ($strict_stock) {
                        $join_criterion[] = 'LEFT JOIN `' . _DB_PREFIX_ . 'stock_available` sa' . $table_stock_index . ' ON ( sa' . $table_stock_index . '.`id_product` = acp.`id_product` AND sa' . $table_stock_index . '.`id_product_attribute` = pa' . (int) $current_id_criterion_group . '.`id_product_attribute` ' . self::_addSqlShopRestrictionStockAvailable('sa' . $table_stock_index) . ')';
                        $join_criterion_tables[] = 'sa' . $table_stock_index;
                        $where_qty[] = 'IF (sa' . $table_stock_index . '.`quantity` > 0, 1, IF (sa' . $table_stock_index . '.`out_of_stock` = 2, ' . Configuration::get('PS_ORDER_OUT_OF_STOCK') . ' = 1, sa' . $table_stock_index . '.`out_of_stock` = 1))';
                    } else {
                        $join_criterion[] = 'LEFT JOIN `' . _DB_PREFIX_ . 'stock_available` sa' . $table_stock_index . ' ON ( sa' . $table_stock_index . '.`id_product` = acp.`id_product` AND sa' . $table_stock_index . '.`id_product_attribute` = pa' . (int) $current_id_criterion_group . '.`id_product_attribute` ' . self::_addSqlShopRestrictionStockAvailable('sa' . $table_stock_index) . ')';
                        $join_criterion_tables[] = 'sa' . $table_stock_index;
                        $where_qty[] = 'IF (sa' . $table_stock_index . '.`quantity` > 0, 1, IF (sa' . $table_stock_index . '.`out_of_stock` = 2, ' . Configuration::get('PS_ORDER_OUT_OF_STOCK') . ' = 1, sa' . $table_stock_index . '.`out_of_stock` = 1))';
                    }
                }
                if ($is_attribute_group) {
                    $join_criterion[] = 'JOIN `' . _DB_PREFIX_ . 'product_attribute_combination` pac' . (int) $current_id_criterion_group . ' ON (' . ($is_attribute_group ? 'pa' . (int) $current_id_criterion_group . '.`id_product_attribute` = pac' . (int) $current_id_criterion_group . '.`id_product_attribute` AND ' : '') . 'pac' . (int) $current_id_criterion_group . '.`id_attribute` = aclink.`id_criterion_linked`)';
                    $join_criterion_tables[] = 'pac' . (int) $current_id_criterion_group;
                    $lastAttributeCombinationTableId = 'pac' . (int) $current_id_criterion_group;
                }
            } elseif ($search['search_on_stock'] || $strict_stock) {
                if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) {
                    $table_stock_index++;
                    if ($strict_stock) {
                        $join_criterion[] = 'LEFT JOIN `' . _DB_PREFIX_ . 'stock_available` sa' . $table_stock_index . ' ON ( sa' . $table_stock_index . '.`id_product` = acp.`id_product` AND sa' . $table_stock_index . '.`id_product_attribute`=0 ' . self::_addSqlShopRestrictionStockAvailable('sa' . $table_stock_index) . ')';
                        $join_criterion_tables[] = 'sa' . $table_stock_index;
                        $where_qty[] = 'sa' . $table_stock_index . '.`quantity`';
                    } else {
                        $join_criterion[] = 'LEFT JOIN `' . _DB_PREFIX_ . 'stock_available` sa' . $table_stock_index . ' ON ( sa' . $table_stock_index . '.`id_product` = acp.`id_product` AND sa' . $table_stock_index . '.`id_product_attribute`=0 ' . self::_addSqlShopRestrictionStockAvailable('sa' . $table_stock_index) . ')';
                        $join_criterion_tables[] = 'sa' . $table_stock_index;
                        $where_qty[] = 'IF(sa' . $table_stock_index . '.`quantity` > 0,1,IF(sa' . $table_stock_index . '.`out_of_stock` = 2, ' . Configuration::get('PS_ORDER_OUT_OF_STOCK') . ' = 1, sa' . $table_stock_index . '.`out_of_stock` = 1))';
                    }
                }
            }
        }
        if ($include_product_table || $fromMethod == 'getCriterionsForSearchBloc') {
            if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) {
                $where_criterion[] = 'ps.`active` = 1';
                $where_criterion[] = 'ps.`visibility` IN ("both", "search")';
            } else {
                if (AdvancedSearchCoreClass::_isFilledArray(PM_AdvancedSearch4::$productFilterList)) {
                    $where_criterion[] = ' p.`id_product` IN (' . implode(',', PM_AdvancedSearch4::$productFilterList) . ') ';
                }
                $where_criterion[] = 'p.`active` = 1';
            }
        }
        if (!$include_product_table && AdvancedSearchCoreClass::_isFilledArray(PM_AdvancedSearch4::$productFilterList)) {
            $where_criterion[] = ' acp.`id_product` IN (' . implode(',', PM_AdvancedSearch4::$productFilterList) . ') ';
        }
        if (AdvancedSearchCoreClass::_isFilledArray($where_qty)) {
            if ($is_attribute_group || $attribute_selected) {
                $where_criterion[] = '(' . implode(' AND ', $where_qty) . ')';
            } else {
                $where_criterion[] = '(' . implode(' OR ', $where_qty) . ')';
            }
        }
        if ($price_is_included && ($fromMethod == 'getCriterionsForSearchBloc' || $fromMethod == 'getQueryCountResults' || $fromMethod == 'getProductsSearched' || $fromMethod == 'getPriceRangeForSearchBloc')) {
            $idCacheProductMaxScoreQuery = 'SELECT DISTINCT app.id_cache_product FROM `' . _DB_PREFIX_ . 'pm_advancedsearch_cache_product_' . (int) $search['id_search'] . '` acp ';
            if ($join_criterion && AdvancedSearchCoreClass::_isFilledArray($join_criterion)) {
                foreach ($join_criterion as $tmp_join_criterion) {
                    if (version_compare(_PS_VERSION_, '1.5.0.0', '>=') && preg_match('#stock_available#', $tmp_join_criterion)) {
                        continue;
                    }
                    if (preg_match('#product_attribute_combination|product_attribute_image#', $tmp_join_criterion)) {
                        continue;
                    }
                    $idCacheProductMaxScoreQuery .= ' ' . $tmp_join_criterion;
                }
            }
            if (AdvancedSearchCoreClass::_isFilledArray($where_qty)) {
                $where_criterion_price_included = array_slice($where_criterion, 0, sizeof($where_criterion) - 1);
            } else {
                $where_criterion_price_included = $where_criterion;
            }
            if ($where_criterion_price_included && AdvancedSearchCoreClass::_isFilledArray($where_criterion_price_included)) {
                $add_where = false;
                foreach ($where_criterion_price_included as $where) {
                    if (preg_match('#' . preg_quote('/*AS4-PR-Start*/') . '#', $where) && preg_match('#' . preg_quote('/*AS4-PR-End*/') . '#', $where)) {
                        while (strpos($where, '/*AS4-PR-Start*/') !== false) {
                            $where_tmp = substr($where, 0, strpos($where, '/*AS4-PR-Start*/'));
                            $where_tmp .= 'app.`id_currency` IN (0, ' . $id_currency . ')';
                            $where_tmp .= substr($where, strpos($where, '/*AS4-PR-End*/') + strlen('/*AS4-PR-End*/'), strlen($where));
                            $where = $where_tmp;
                        }
                    }
                    if (!$add_where) {
                        $idCacheProductMaxScoreQuery .= ' WHERE ' . $where;
                        $add_where = true;
                    } else {
                        $idCacheProductMaxScoreQuery .= ' AND ' . $where;
                    }
                }
            }
            $idCacheProductMaxScoreSQLResult = Db::getInstance()->ExecuteS($idCacheProductMaxScoreQuery);
            if (AdvancedSearchCoreClass::_isFilledArray($idCacheProductMaxScoreSQLResult)) {
                $idCacheProductMaxScoreResult = array();
                foreach ($idCacheProductMaxScoreSQLResult as $idCacheProductMaxScore) {
                    $idCacheProductMaxScoreResult[] = (int) $idCacheProductMaxScore['id_cache_product'];
                }
                $where_criterion[] = 'app.id_cache_product IN (' . implode(',', $idCacheProductMaxScoreResult) . ')';
            }
        }
        $return = array('count' => $count_criterion, 'join' => $join_criterion, 'where' => $where_criterion, 'select' => $field_select, 'make_union' => $make_union, 'whereUnion' => array(), 'joinUnion' => array(), 'nbSelectedCriterions' => sizeof($selected_criterion), 'priceIncluded' => $price_is_included, 'productTableIncluded' => $include_product_table, 'lastAttributeCombinationTableId' => $lastAttributeCombinationTableId);
        self::$_cacheLeftJoinWhereCriterion[$cacheKey] = $return;
        return $return;
    }
Esempio n. 9
0
 private function getLocalCodeForSimplePath()
 {
     $currency = Currency::getCurrent();
     if ($currency->iso_code == 'EUR') {
         return 'EUR';
     } elseif ($currency->iso_code == 'GBP') {
         return 'GBP';
     } elseif ($currency->iso_code == 'USD') {
         return 'USD';
     }
     return 'USD';
 }
Esempio n. 10
0
 /**
  * Return price converted
  *
  * @param float $price Product price
  * @param object $currency Current currency object
  * @param boolean $to_currency convert to currency or from currency to default currency
  */
 public static function convertPrice($price, $currency = null, $to_currency = true)
 {
     if ($currency === null) {
         $currency = Currency::getCurrent();
     } elseif (is_numeric($currency)) {
         $currency = Currency::getCurrencyInstance($currency);
     }
     if (isset($currency->id)) {
         $c_id = $currency->id;
         $c_rate = $currency->conversion_rate;
     } else {
         $c_id = $currency['id_currency'];
         $c_rate = $currency['conversion_rate'];
     }
     if ($c_id != (int) _PS_CURRENCY_DEFAULT_) {
         $price = $to_currency ? $price * $c_rate : $price / $c_rate;
     }
     return $price;
 }