|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($model->file && $model->validate()) { |
|
|
if ($model->file && $model->validate()) { |
|
|
$productPriceCsvArray = array_map(function($data) { return str_getcsv($data,";");}, file($model->file->tempName)); |
|
|
$productPriceCsvArray = array_map(function($data) { return str_getcsv($data,";");}, file($model->file->tempName)); |
|
|
unset($productPriceCsvArray[0]); |
|
|
|
|
|
$countUpdate = 0; |
|
|
|
|
|
foreach($productPriceCsvArray as $productPriceCsv) { |
|
|
|
|
|
$productName = $productPriceCsv[0]; |
|
|
|
|
|
$userArray = explode('#', $productPriceCsv[1]); |
|
|
|
|
|
$userGroupName = $productPriceCsv[2]; |
|
|
|
|
|
$pointSaleName = $productPriceCsv[3]; |
|
|
|
|
|
$quantityFrom = (float) $productPriceCsv[4]; |
|
|
|
|
|
$price = (float) $productPriceCsv[5]; |
|
|
|
|
|
|
|
|
|
|
|
$product = $productName ? $productManager->findOneProductByName($productName) : null; |
|
|
|
|
|
$user = (count($userArray) > 1) ? $userManager->findOneUserById((int) $userArray[1]) : null; |
|
|
|
|
|
$userGroup = $userGroupName ? $userGroupManager->findOneUserGroupByName($userGroupName) : null; |
|
|
|
|
|
$pointSale = $pointSaleName ? $pointSaleManager->findOnePointSaleByName($pointSaleName) : null; |
|
|
|
|
|
|
|
|
|
|
|
if($product) { |
|
|
|
|
|
// prix de base |
|
|
|
|
|
if(!$user && !$userGroup && !$pointSale && !$quantityFrom) { |
|
|
|
|
|
$product->price = $price; |
|
|
|
|
|
$productManager->saveUpdate($product); |
|
|
|
|
|
$countUpdate ++; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!$productPriceCsvArray || count($productPriceCsvArray[0]) != 6) { |
|
|
|
|
|
$this->setFlash('error', "Format de fichier invalide. Veuillez vérifier que le séparateur de champs de votre fichier est bien \";\"."); |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
unset($productPriceCsvArray[0]); |
|
|
|
|
|
$countUpdate = 0; |
|
|
|
|
|
$dataNotFound = false; |
|
|
|
|
|
foreach ($productPriceCsvArray as $productPriceCsv) { |
|
|
|
|
|
if (count($productPriceCsv) != 6) { |
|
|
|
|
|
$dataNotFound = true; |
|
|
|
|
|
continue; |
|
|
} |
|
|
} |
|
|
// prix spécifique |
|
|
|
|
|
else { |
|
|
|
|
|
$productPrice = $productPriceManager->findOneProductPriceBy($product, $user, $userGroup, $pointSale, $quantityFrom); |
|
|
|
|
|
if($productPrice) { |
|
|
|
|
|
$productPrice->price = $price; |
|
|
|
|
|
$productPriceManager->saveUpdate($productPrice); |
|
|
|
|
|
$countUpdate ++; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$productName = $productPriceCsv[0]; |
|
|
|
|
|
$userArray = explode('#', $productPriceCsv[1]); |
|
|
|
|
|
$userGroupName = $productPriceCsv[2]; |
|
|
|
|
|
$pointSaleName = $productPriceCsv[3]; |
|
|
|
|
|
$quantityFrom = (float)$productPriceCsv[4]; |
|
|
|
|
|
$price = (float)$productPriceCsv[5]; |
|
|
|
|
|
|
|
|
|
|
|
$product = $productName ? $productManager->findOneProductByName($productName) : null; |
|
|
|
|
|
$user = (count($userArray) > 1) ? $userManager->findOneUserById((int)$userArray[1]) : null; |
|
|
|
|
|
$userGroup = $userGroupName ? $userGroupManager->findOneUserGroupByName($userGroupName) : null; |
|
|
|
|
|
$pointSale = $pointSaleName ? $pointSaleManager->findOnePointSaleByName($pointSaleName) : null; |
|
|
|
|
|
|
|
|
|
|
|
if (($productName && !$product) |
|
|
|
|
|
|| (count($userArray) > 1 && !$user) |
|
|
|
|
|
|| ($userGroupName && !$userGroup) |
|
|
|
|
|
|| ($pointSaleName && !$pointSale)) { |
|
|
|
|
|
|
|
|
|
|
|
$dataNotFound = true; |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ($product) { |
|
|
|
|
|
// prix de base |
|
|
|
|
|
if (!$user && !$userGroup && !$pointSale && !$quantityFrom) { |
|
|
|
|
|
$product->price = $price; |
|
|
|
|
|
$productManager->saveUpdate($product); |
|
|
|
|
|
$countUpdate++; |
|
|
|
|
|
} // prix spécifique |
|
|
|
|
|
else { |
|
|
|
|
|
$productPrice = $productPriceManager->findOneProductPriceBy($product, $user, $userGroup, $pointSale, $quantityFrom); |
|
|
|
|
|
if ($productPrice) { |
|
|
|
|
|
$productPrice->price = $price; |
|
|
|
|
|
$productPriceManager->saveUpdate($productPrice); |
|
|
|
|
|
$countUpdate++; |
|
|
|
|
|
} else { |
|
|
|
|
|
$dataNotFound = true; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if($countUpdate) { |
|
|
|
|
|
$this->setFlash('success', $countUpdate.' prix produits mis à jour.'); |
|
|
|
|
|
|
|
|
if ($dataNotFound) { |
|
|
|
|
|
$this->addFlash('error', "Attention, certaines lignes du fichier n'ont pas été prises en compte. Veuillez réessayer en repartant du fichier d'export.<br />Contacter l'administrateur du site si le problème persiste."); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ($countUpdate) { |
|
|
|
|
|
$this->addFlash('success', $countUpdate . ' prix produits mis à jour.'); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |