Skip to content

Commit

Permalink
BO: good value for low_stock alert
Browse files Browse the repository at this point in the history
  • Loading branch information
aleeks committed Sep 8, 2017
1 parent 14a95cf commit f28ffc3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
24 changes: 14 additions & 10 deletions src/PrestaShopBundle/Entity/Repository/NormalizeFieldTrait.php
Expand Up @@ -35,7 +35,7 @@ trait NormalizeFieldTrait
protected function castNumericToInt($rows)
{
$castIdentifiersToIntegers = function (&$columnValue, $columnName) {
if ($this->shouldCastToInt($columnName)) {
if ($this->shouldCastToInt($columnName, $columnValue)) {
$columnValue = (int)$columnValue;
}
};
Expand All @@ -52,7 +52,7 @@ protected function castNumericToInt($rows)
protected function castIdsToArray($rows)
{
$castIdentifiersToArray = function (&$columnValue, $columnName) {
if ($this->shouldCastToInt($columnName)) {
if ($this->shouldCastToInt($columnName, $columnValue)) {
$columnValue = array_map('intval', explode(',', $columnValue));
}
};
Expand All @@ -64,16 +64,20 @@ protected function castIdsToArray($rows)

/**
* @param $columnName
* @param $columnValue
* @return bool
*/
private function shouldCastToInt($columnName)
private function shouldCastToInt($columnName, $columnValue)
{
return false !== strpos($columnName, '_id') ||
false !== strpos($columnName, 'id_') ||
false !== strpos($columnName, '_quantity') ||
false !== strpos($columnName, 'sign') ||
false !== strpos($columnName, 'active') ||
false !== strpos($columnName, 'total_') ||
false !== strpos($columnName, 'low_stock_threshold');
return (
false !== strpos($columnName, '_id') ||
false !== strpos($columnName, 'id_') ||
false !== strpos($columnName, '_quantity') ||
false !== strpos($columnName, 'sign') ||
false !== strpos($columnName, 'active') ||
false !== strpos($columnName, 'total_') ||
false !== strpos($columnName, 'product_low_stock_threshold') ||
false !== strpos($columnName, 'low_stock_alert')
) && !is_null($columnValue) && 'N/A' !== $columnValue;
}
}
20 changes: 11 additions & 9 deletions src/PrestaShopBundle/Entity/Repository/StockRepository.php
Expand Up @@ -236,6 +236,7 @@ public function getDataExport(QueryParamsCollection $queryParams)
unset($line['product_thumbnail']);
unset($line['combination_thumbnail']);
unset($line['combinations_product_url']);
unset($line['product_low_stock_alert']);
unset($line['edit_url']);

$formatedData[] = $line;
Expand Down Expand Up @@ -282,17 +283,17 @@ protected function selectSql(
COALESCE(pa.id_product_attribute, 0) = 0,
"N/A",
total_combinations
) as total_combinations,
) AS total_combinations,
IF (
COALESCE(p.reference, "") = "",
"N/A",
p.reference
) as product_reference,
) AS product_reference,
IF (
COALESCE(pa.reference, "") = "",
"N/A",
pa.reference
) as combination_reference,
) AS combination_reference,
pl.name AS product_name,
IF (
COALESCE(pa.id_product_attribute, 0) > 0,
Expand All @@ -305,12 +306,13 @@ protected function selectSql(
p.id_supplier AS supplier_id,
COALESCE(s.name, "N/A") AS supplier_name,
COALESCE(ic.id_image, 0) AS product_cover_id,
COALESCE(i.id_image, 0) as combination_cover_id,
COALESCE(i.id_image, 0) AS combination_cover_id,
p.active,
sa.quantity as product_available_quantity,
sa.physical_quantity as product_physical_quantity,
sa.reserved_quantity as product_reserved_quantity,
ps.low_stock_threshold as product_low_stock_threshold,
sa.quantity AS product_available_quantity,
sa.physical_quantity AS product_physical_quantity,
sa.reserved_quantity AS product_reserved_quantity,
COALESCE(ps.low_stock_threshold, "N/A") AS product_low_stock_threshold,
IF (sa.quantity < ps.low_stock_threshold, 1, 0) AS product_low_stock_alert,
COALESCE(product_attributes.attributes, "") AS product_attributes,
COALESCE(product_features.features, "") AS product_features
FROM {table_prefix}product p
Expand Down Expand Up @@ -345,7 +347,7 @@ protected function selectSql(
",",
1
) image_ids,
pai.id_product_attribute as combination_id
pai.id_product_attribute AS combination_id
FROM {table_prefix}product_attribute_image pai
GROUP BY pai.id_product_attribute
) images_per_combination ON (
Expand Down

0 comments on commit f28ffc3

Please sign in to comment.