12425 - fix too slow loading, optimise computation of product price
This commit is contained in:
parent
cfa9472639
commit
7a3a9b161a
@ -359,6 +359,16 @@ class SpecificPriceCore extends ObjectModel
|
||||
$query .= (Configuration::get('PS_QTY_DISCOUNT_ON_COMBINATION') || !$id_cart || !$real_quantity) ? (int)$quantity : max(1, (int)$real_quantity);
|
||||
$query .= ' ORDER BY `id_product_attribute` DESC, `from_quantity` DESC, `id_specific_price_rule` ASC, `score` DESC, `to` DESC, `from` DESC';
|
||||
|
||||
// $authorized_ip = array(
|
||||
// '88.163.22.99',
|
||||
// '90.63.178.63',
|
||||
// '137.74.25.146'
|
||||
// );
|
||||
// if(in_array($_SERVER['REMOTE_ADDR'], $authorized_ip))
|
||||
// {
|
||||
// p($query); die();
|
||||
// }
|
||||
|
||||
SpecificPrice::$_specificPriceCache[$key] = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($query);
|
||||
}
|
||||
|
||||
|
@ -73,4 +73,36 @@ class Customer extends CustomerCore
|
||||
return new Address($id);
|
||||
}
|
||||
|
||||
}
|
||||
private static $_customer_groups_cat_reduc = array();
|
||||
|
||||
public function getGroupsCategoriesReduction()
|
||||
{
|
||||
$id_customer = $this->id;
|
||||
if (isset(self::$_customer_groups_cat_reduc[$id_customer])) {
|
||||
return self::$_customer_groups_cat_reduc[$id_customer];
|
||||
}
|
||||
|
||||
self::$_customer_groups_cat_reduc[$id_customer] = array();
|
||||
|
||||
$result = Db::getInstance()->executeS('
|
||||
SELECT cg.`id_group`, gr.`id_category`
|
||||
FROM '._DB_PREFIX_.'customer_group cg
|
||||
JOIN '._DB_PREFIX_.'group_reduction gr ON gr.id_group = cg.id_group
|
||||
WHERE cg.`id_customer` = '.(int)$this->id
|
||||
);
|
||||
foreach ($result as $group) {
|
||||
if (!isset(self::$_customer_groups_cat_reduc[$id_customer][$group['id_group']])) {
|
||||
self::$_customer_groups_cat_reduc[$id_customer][$group['id_group']] = array();
|
||||
}
|
||||
self::$_customer_groups_cat_reduc[$id_customer][$group['id_group']][] = (int)$group['id_category'];
|
||||
}
|
||||
|
||||
if(!isset(self::$_customer_groups_cat_reduc[$id_customer][Configuration::get('PS_CUSTOMER_GROUP')])) {
|
||||
self::$_customer_groups_cat_reduc[$id_customer][Configuration::get('PS_CUSTOMER_GROUP')] = array();
|
||||
}
|
||||
|
||||
return self::$_customer_groups_cat_reduc[$id_customer];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -5,6 +5,8 @@ class Product extends ProductCore
|
||||
public $id_erp;
|
||||
public $nb_per_box;
|
||||
|
||||
private static $categories_product = array();
|
||||
|
||||
public static $definition = array(
|
||||
'table' => 'product',
|
||||
'primary' => 'id_product',
|
||||
@ -92,7 +94,6 @@ class Product extends ProductCore
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
public static function getPriceStatic($id_product, $usetax = true, $id_product_attribute = null, $decimals = 6, $divisor = null,
|
||||
$only_reduc = false, $usereduc = true, $quantity = 1, $force_associated_tax = false, $id_customer = null, $id_cart = null,
|
||||
$id_address = null, &$specific_price_output = null, $with_ecotax = true, $use_group_reduction = true, Context $context = null,
|
||||
@ -103,6 +104,10 @@ class Product extends ProductCore
|
||||
$context = Context::getContext();
|
||||
}
|
||||
|
||||
if (is_null($id_customer) && Validate::isLoadedObject($context->customer)) {
|
||||
$id_customer = $context->customer->id;
|
||||
}
|
||||
|
||||
$cur_cart = $context->cart;
|
||||
|
||||
if ($divisor !== null) {
|
||||
@ -189,39 +194,50 @@ class Product extends ProductCore
|
||||
$usetax = false;
|
||||
}
|
||||
|
||||
if (is_null($id_customer) && Validate::isLoadedObject($context->customer)) {
|
||||
$id_customer = $context->customer->id;
|
||||
}
|
||||
|
||||
$return = array();
|
||||
if (isset(Context::getContext()->customer)) {
|
||||
$customer = new Customer(Context::getContext()->customer->id);
|
||||
|
||||
foreach ($customer->getGroups() as $key => $id) {
|
||||
$return[] = Product::priceCalculation(
|
||||
$context->shop->id,
|
||||
$id_product,
|
||||
$id_product_attribute,
|
||||
$id_country,
|
||||
$id_state,
|
||||
$zipcode,
|
||||
$id_currency,
|
||||
$id,
|
||||
$quantity,
|
||||
$usetax,
|
||||
$decimals,
|
||||
$only_reduc,
|
||||
$usereduc,
|
||||
$with_ecotax,
|
||||
$specific_price_output,
|
||||
$use_group_reduction,
|
||||
$id_customer,
|
||||
$use_customer_price,
|
||||
$id_cart,
|
||||
$cart_quantity
|
||||
);
|
||||
$group_categories = $customer->getGroupsCategoriesReduction();
|
||||
if(!isset(self::$categories_product[$id_product])) {
|
||||
$categories = Db::getInstance()->executeS(
|
||||
'SELECT `id_category`
|
||||
FROM `'._DB_PREFIX_.'category_product`
|
||||
WHERE `id_product` = '.(int)$id_product
|
||||
);
|
||||
$categories = array_column($categories, 'id_category');
|
||||
self::$categories_product[$id_product] = $categories;
|
||||
} else {
|
||||
$categories = self::$categories_product[$id_product];
|
||||
}
|
||||
|
||||
foreach ($group_categories as $id_group => $list_categories) {
|
||||
if (array_intersect($categories, $list_categories) || $id_group == Configuration::get('PS_CUSTOMER_GROUP')) {
|
||||
$return[] = Product::priceCalculation(
|
||||
$context->shop->id,
|
||||
$id_product,
|
||||
$id_product_attribute,
|
||||
$id_country,
|
||||
$id_state,
|
||||
$zipcode,
|
||||
$id_currency,
|
||||
$id_group,
|
||||
$quantity,
|
||||
$usetax,
|
||||
$decimals,
|
||||
$only_reduc,
|
||||
$usereduc,
|
||||
$with_ecotax,
|
||||
$specific_price_output,
|
||||
$use_group_reduction,
|
||||
$id_customer,
|
||||
$use_customer_price,
|
||||
$id_cart,
|
||||
$cart_quantity
|
||||
);
|
||||
}
|
||||
}
|
||||
return min($return);
|
||||
} else {
|
||||
return Product::priceCalculation(
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
define('ANTADIS_CHECK_GROUPS', true);
|
||||
|
||||
class FrontController extends FrontControllerCore
|
||||
{
|
||||
@ -9,6 +10,30 @@ class FrontController extends FrontControllerCore
|
||||
$cookie->tmp = serialize($this->errors);
|
||||
}
|
||||
|
||||
if (defined('ANTADIS_CHECK_GROUPS') && ANTADIS_CHECK_GROUPS) {
|
||||
$id_customer_group = Configuration::get('PS_CUSTOMER_GROUP');
|
||||
if ($id_customer_group!==FALSE && (int)$id_customer_group>0) {
|
||||
$sql = 'SELECT COUNT(a.id_customer)
|
||||
FROM `'._DB_PREFIX_.'customer` a
|
||||
WHERE a.`id_customer` NOT IN (
|
||||
SELECT b.id_customer
|
||||
FROM `'._DB_PREFIX_.'customer_group` b
|
||||
WHERE b.id_group = '.(int)$id_customer_group.'
|
||||
)';
|
||||
$nb_customer_not_in_default_group = Db::getInstance()->getValue($sql);
|
||||
if ($nb_customer_not_in_default_group!==FALSE && $nb_customer_not_in_default_group>0) {
|
||||
error_log(
|
||||
'roykin check : '.$nb_customer_not_in_default_group.' customers are not associated with default group id : '.$id_customer_group,
|
||||
0
|
||||
);
|
||||
error_log(
|
||||
'roykin check : '.$nb_customer_not_in_default_group.' customers are not associated with default group id : '.$id_customer_group,
|
||||
1,
|
||||
'figaro+roykincheck@antadis.fr'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Force assign template
|
||||
|
Loading…
Reference in New Issue
Block a user