Skip to content

Commit

Permalink
Merge branch '1.6' of github.com:PrestaShop/PrestaShop into 1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Sacha Froment committed Oct 20, 2014
2 parents 438dd59 + f4297b0 commit 5358b6c
Show file tree
Hide file tree
Showing 14 changed files with 1,681 additions and 116 deletions.
10 changes: 4 additions & 6 deletions admin-dev/ajax_products_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@

/*
* In the SQL request the "q" param is used entirely to match result in database.
* In this way if string:"(ref : #ref_pattern#)" is displayed on the return list,
* they are no return values just because string:"(ref : #ref_pattern#)"
* In this way if string:"(ref : #ref_pattern#)" is displayed on the return list,
* they are no return values just because string:"(ref : #ref_pattern#)"
* is not write in the name field of the product.
* So the ref pattern will be cut for the search request.
*/
Expand Down Expand Up @@ -67,9 +67,7 @@

$items = Db::getInstance()->executeS($sql);

$acc = (bool)Tools::isSubmit('excludeIds');

if ($items && $acc)
if ($items && ($excludeIds || strpos($_SERVER['HTTP_REFERER'], 'AdminScenes') !== false))
foreach ($items AS $item)
echo trim($item['name']).(!empty($item['reference']) ? ' (ref: '.$item['reference'].')' : '').'|'.(int)($item['id_product'])."\n";
elseif ($items)
Expand All @@ -89,4 +87,4 @@
echo Tools::jsonEncode($results);
}
else
json_encode(new stdClass);
Tools::jsonEncode(new stdClass);
22 changes: 13 additions & 9 deletions admin-dev/themes/default/template/controllers/products/prices.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,12 @@ $(document).ready(function () {
<label class="control-label col-lg-2" for="priceTE">
<span class="label-tooltip" data-toggle="tooltip" title="{l s='The pre-tax retail price is the price for which you intend sell this product to your customers. It should be higher than the pre-tax wholesale price: the difference between the two will be your margin.'}">{if !$country_display_tax_label || $tax_exclude_taxe_option}{l s='Retail price'}{else}{l s='Pre-tax retail price'}{/if}</span>
</label>
<div class="input-group col-lg-2">
<span class="input-group-addon">{$currency->prefix}{$currency->suffix}</span>
<input type="hidden" id="priceTEReal" name="price" value="{toolsConvertPrice price=$product->price}"/>
<input size="11" maxlength="27" id="priceTE" name="price_displayed" type="text" value="{{toolsConvertPrice price=$product->price}|string_format:'%.6f'}" onchange="noComma('priceTE'); $('#priceTEReal').val(this.value);" onkeyup="$('#priceType').val('TE'); $('#priceTEReal').val(this.value.replace(/,/g, '.')); if (isArrowKey(event)) return; calcPriceTI();" />
<div class="col-lg-2">
<div class="input-group">
<span class="input-group-addon">{$currency->prefix}{$currency->suffix}</span>
<input type="hidden" id="priceTEReal" name="price" value="{toolsConvertPrice price=$product->price}"/>
<input size="11" maxlength="27" id="priceTE" name="price_displayed" type="text" value="{{toolsConvertPrice price=$product->price}|string_format:'%.6f'}" onchange="noComma('priceTE'); $('#priceTEReal').val(this.value);" onkeyup="$('#priceType').val('TE'); $('#priceTEReal').val(this.value.replace(/,/g, '.')); if (isArrowKey(event)) return; calcPriceTI();" />
</div>
</div>
</div>
<div class="form-group">
Expand Down Expand Up @@ -206,11 +208,13 @@ $(document).ready(function () {
<label class="control-label col-lg-2" for="unit_price">
<span class="label-tooltip" data-toggle="tooltip" title="{l s='When selling a pack of items, you can indicate the unit price for each item of the pack. For instance, "per bottle" or "per pound".'}">{l s='Unit price'}</span>
</label>
<div class="input-group col-lg-4">
<span class="input-group-addon">{$currency->prefix}{$currency->suffix}</span>
<input id="unit_price" name="unit_price" type="text" value="{$unit_price|string_format:'%.2f'}" maxlength="27" onkeyup="if (isArrowKey(event)) return ;this.value = this.value.replace(/,/g, '.'); unitPriceWithTax('unit');"/>
<span class="input-group-addon">{l s='per'}</span>
<input id="unity" name="unity" type="text" value="{$product->unity|htmlentitiesUTF8}" maxlength="10" onkeyup="if (isArrowKey(event)) return ;unitySecond();" onchange="unitySecond();"/>
<div class="col-lg-4">
<div class="input-group">
<span class="input-group-addon">{$currency->prefix}{$currency->suffix}</span>
<input id="unit_price" name="unit_price" type="text" value="{$unit_price|string_format:'%.2f'}" maxlength="27" onkeyup="if (isArrowKey(event)) return ;this.value = this.value.replace(/,/g, '.'); unitPriceWithTax('unit');"/>
<span class="input-group-addon">{l s='per'}</span>
<input id="unity" name="unity" type="text" value="{$product->unity|htmlentitiesUTF8}" maxlength="10" onkeyup="if (isArrowKey(event)) return ;unitySecond();" onchange="unitySecond();"/>
</div>
</div>
</div>
{if isset($product->unity) && $product->unity}
Expand Down
24 changes: 14 additions & 10 deletions classes/Manufacturer.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ public static function getProducts($id_manufacturer, $id_lang, $p, $n, $order_by
$alias = 'stock.';
else
$alias = 'p.';

$sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity'.(Combination::isFeatureActive() ? ', MAX(product_attribute_shop.minimal_quantity) AS product_attribute_minimal_quantity' : '').'
, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`,
pl.`meta_title`, pl.`name`, pl.`available_now`, pl.`available_later`, MAX(image_shop.`id_image`) id_image, il.`legend`, m.`name` AS manufacturer_name,
Expand All @@ -341,18 +342,21 @@ public static function getProducts($id_manufacturer, $id_lang, $p, $n, $order_by
ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m
ON (m.`id_manufacturer` = p.`id_manufacturer`)
'.Product::sqlStock('p', 0).'
'.Product::sqlStock('p', 0);

if (Group::isFeatureActive() || $active_category)
{
$sql .= 'JOIN `'._DB_PREFIX_.'category_product` cp ON (p.id_product = cp.id_product)';
if (Group::isFeatureActive())
$sql .= 'JOIN `'._DB_PREFIX_.'category_group` cg ON (cp.`id_category` = cg.`id_category` AND cg.`id_group` '.$sql_groups.')';
if ($active_category)
$sql .= 'JOIN `'._DB_PREFIX_.'category` ca ON cp.`id_category` = ca.`id_category` AND ca.`active` = 1';
}

$sql .= '
WHERE p.`id_manufacturer` = '.(int)$id_manufacturer.'
'.($active ? ' AND product_shop.`active` = 1' : '').'
'.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').'
AND p.`id_product` IN (
SELECT cp.`id_product`
FROM `'._DB_PREFIX_.'category_group` cg
LEFT JOIN `'._DB_PREFIX_.'category_product` cp
ON (cp.`id_category` = cg.`id_category`)'.
($active_category ? ' INNER JOIN `'._DB_PREFIX_.'category` ca ON cp.`id_category` = ca.`id_category` AND ca.`active` = 1' : '').'
WHERE cg.`id_group` '.$sql_groups.'
)
GROUP BY product_shop.id_product
ORDER BY '.$alias.'`'.bqSQL($order_by).'` '.pSQL($order_way).'
LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n;
Expand Down Expand Up @@ -455,4 +459,4 @@ public function setWsAddresses($id_addresses)

return ($result1 && $result2);
}
}
}
74 changes: 23 additions & 51 deletions classes/ProductSale.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,38 +72,15 @@ public static function getBestSales($id_lang, $page_number = 0, $nb_products = 1
$order_table = 'product_shop';
if (is_null($order_way) || $order_by == 'sales') $order_way = 'DESC';

$sql_groups = '';
if (Group::isFeatureActive())
{
$groups = FrontController::getCurrentCustomerGroups();
$sql_groups = 'WHERE cp.`id_product` IS NOT NULL AND cg.`id_group` '.(count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');
}
$interval = Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20;

$products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT cp.`id_product`
FROM `'._DB_PREFIX_.'category_group` cg
INNER JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
'.$sql_groups);

$ids = array();
foreach ($products as $product)
if (Validate::isUnsignedId($product['id_product']))
$ids[$product['id_product']] = 1;
$ids = array_keys($ids);
$ids = array_filter($ids);
sort($ids);
$ids = count($ids) > 0 ? implode(',', $ids) : 'NULL';

//Main query
$sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity,
pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`,
pl.`meta_keywords`, pl.`meta_title`, pl.`name`, pl.`available_now`, pl.`available_later`,
m.`name` AS manufacturer_name, p.`id_manufacturer` as id_manufacturer,
MAX(image_shop.`id_image`) id_image, il.`legend`,
ps.`quantity` AS sales, t.`rate`, pl.`meta_keywords`, pl.`meta_title`, pl.`meta_description`,
DATEDIFF(p.`date_add`, DATE_SUB(NOW(),
INTERVAL '.$interval.' DAY)) > 0 AS new'.(Combination::isFeatureActive() ? ', MAX(product_attribute_shop.minimal_quantity) AS product_attribute_minimal_quantity' : '')
INTERVAL '.(int)$interval.' DAY)) > 0 AS new'.(Combination::isFeatureActive() ? ', MAX(product_attribute_shop.minimal_quantity) AS product_attribute_minimal_quantity' : '')
.' FROM `'._DB_PREFIX_.'product_sale` ps
LEFT JOIN `'._DB_PREFIX_.'product` p ON ps.`id_product` = p.`id_product`
'.Shop::addSqlAssociation('product', 'p', false).'
Expand All @@ -122,10 +99,19 @@ public static function getBestSales($id_lang, $page_number = 0, $nb_products = 1
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (product_shop.`id_tax_rules_group` = tr.`id_tax_rules_group`)
AND tr.`id_country` = '.(int)Context::getContext()->country->id.'
AND tr.`id_state` = 0
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)';

if (Group::isFeatureActive())
{
$groups = FrontController::getCurrentCustomerGroups();
$sql .= '
JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = p.`id_product`)
JOIN `'._DB_PREFIX_.'category_group` cg ON (cp.id_category = cg.id_category AND cg.`id_group` '.(count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1').')';
}

$sql .= '
WHERE product_shop.`active` = 1
AND p.`visibility` != \'none\'
AND p.`id_product` IN ('.$ids.')
GROUP BY product_shop.id_product
ORDER BY '.(!empty($order_table) ? '`'.pSQL($order_table).'`.' : '').'`'.pSQL($order_by).'` '.pSQL($order_way).'
LIMIT '.(int)($page_number * $nb_products).', '.(int)$nb_products;
Expand Down Expand Up @@ -154,29 +140,6 @@ public static function getBestSalesLight($id_lang, $page_number = 0, $nb_product
if ($page_number < 0) $page_number = 0;
if ($nb_products < 1) $nb_products = 10;

$sql_groups = '';
if (Group::isFeatureActive())
{
$groups = FrontController::getCurrentCustomerGroups();
$sql_groups = 'AND cg.`id_group` '.(count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');
}

//Subquery: get product ids in a separate query to (greatly!) improve performances and RAM usage
$products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT cp.`id_product`
FROM `'._DB_PREFIX_.'category_product` cp
LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = cp.`id_category`)
WHERE cg.`id_group` '.$sql_groups);

$ids = array();
foreach ($products as $product)
$ids[$product['id_product']] = 1;

$ids = array_keys($ids);
sort($ids);
$ids = count($ids) > 0 ? implode(',', $ids) : 'NULL';

//Main query
$sql = '
SELECT
p.id_product, MAX(product_attribute_shop.id_product_attribute) id_product_attribute, pl.`link_rewrite`, pl.`name`, pl.`description_short`, product_shop.`id_category_default`,
Expand All @@ -200,10 +163,19 @@ public static function getBestSalesLight($id_lang, $page_number = 0, $nb_product
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl
ON cl.`id_category` = product_shop.`id_category_default`
AND cl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').'
AND cl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl');

if (Group::isFeatureActive())
{
$groups = FrontController::getCurrentCustomerGroups();
$sql .= '
JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = p.`id_product`)
JOIN `'._DB_PREFIX_.'category_group` cg ON (cp.id_category = cg.id_category AND cg.`id_group` '.(count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1').')';
}

$sql.= '
WHERE product_shop.`active` = 1
AND p.`visibility` != \'none\'
AND p.`id_product` IN ('.$ids.')
GROUP BY product_shop.id_product
ORDER BY sales DESC
LIMIT '.(int)($page_number * $nb_products).', '.(int)$nb_products;
Expand Down
22 changes: 13 additions & 9 deletions classes/Supplier.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,17 +280,21 @@ public static function getProducts($id_supplier, $id_lang, $p, $n,
AND il.`id_lang` = '.(int)$id_lang.')
LEFT JOIN `'._DB_PREFIX_.'supplier` s ON s.`id_supplier` = p.`id_supplier`
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer`
'.Product::sqlStock('p', 0).'
'.Product::sqlStock('p', 0);

if (Group::isFeatureActive() || $active_category)
{
$sql .= 'JOIN `'._DB_PREFIX_.'category_product` cp ON (p.id_product = cp.id_product)';
if (Group::isFeatureActive())
$sql .= 'JOIN `'._DB_PREFIX_.'category_group` cg ON (cp.`id_category` = cg.`id_category` AND cg.`id_group` '.(count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1').')';
if ($active_category)
$sql .= 'JOIN `'._DB_PREFIX_.'category` ca ON cp.`id_category` = ca.`id_category` AND ca.`active` = 1';
}

$sql .= '
WHERE ps.`id_supplier` = '.(int)$id_supplier.'
'.($active ? ' AND product_shop.`active` = 1' : '').'
'.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').'
AND p.`id_product` IN (
SELECT cp.`id_product`
FROM `'._DB_PREFIX_.'category_product` cp
'.(Group::isFeatureActive() ? 'LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cp.`id_category` = cg.`id_category`)' : '').'
'.($active_category ? ' INNER JOIN `'._DB_PREFIX_.'category` ca ON cp.`id_category` = ca.`id_category` AND ca.`active` = 1' : '').'
'.$sql_groups.'
)
GROUP BY product_shop.id_product
ORDER BY '.$alias.pSQL($order_by).' '.pSQL($order_way).'
LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n;
Expand Down Expand Up @@ -384,4 +388,4 @@ public static function getProductInformationsBySupplier($id_supplier, $id_produc
if (count($res))
return $res[0];
}
}
}
2 changes: 1 addition & 1 deletion classes/order/OrderInvoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,8 @@ public function getShippingTaxesBreakdown($order)

/**
* Returns the wrapping taxes breakdown
*
* @todo
* @since 1.5
* @return array
*/
Expand Down
Loading

0 comments on commit 5358b6c

Please sign in to comment.