aggiornamento qta
This commit is contained in:
@@ -1044,7 +1044,7 @@ class ProductUpdateGm extends Command
|
|||||||
|
|
||||||
if ($preorder) {
|
if ($preorder) {
|
||||||
// Controlla se è in preordine
|
// Controlla se è in preordine
|
||||||
$inprevendita = isArticleInPrevendita($article->IdArticolo);
|
$inprevendita = isArticleInPrevendita($article->IdArticolo, true);
|
||||||
if ($inprevendita) {
|
if ($inprevendita) {
|
||||||
setPreOrder($article->IdArticolo, true, false);
|
setPreOrder($article->IdArticolo, true, false);
|
||||||
$log4 .= ' SEtTATO IN PREVENDITA ! <br>';
|
$log4 .= ' SEtTATO IN PREVENDITA ! <br>';
|
||||||
|
|||||||
@@ -87,34 +87,46 @@ class ProductUpdateQta extends Command
|
|||||||
$productsku = Product::where('sku', $stock->Codice)->first();
|
$productsku = Product::where('sku', $stock->Codice)->first();
|
||||||
|
|
||||||
if ($productsku->count() > 0) {
|
if ($productsku->count() > 0) {
|
||||||
$data1 = [
|
$aggiorna = true;
|
||||||
|
|
||||||
'stock_quantity' => $stock->QtaDisponibile,
|
$inprevendita = isArticleInPrevendita($stock->Codice, false);
|
||||||
|
$inprevendita_qtaneg = isArticleInPrevendita($stock->Codice, true);
|
||||||
];
|
$qtyinstock = intval($productsku['stock_quantity']);
|
||||||
$idprodotto = $productsku['parent_id'];
|
$titolo = $productsku['title'];
|
||||||
if ($idprodotto > 0) {
|
// Se il libro è ancora in Prevendita e la quantità è QTA_IN_PREVENDITA, allora non aggiornare la QTA
|
||||||
$variation = Variation::update($idprodotto, $productsku['id'], $data1);
|
// deve rimanere a QTA_IN_PREVENDITA per poter vedere "In Preordine"
|
||||||
} else {
|
if ($inprevendita && $qtyinstock == QTA_IN_PREVENDITA) {
|
||||||
Product::update($productsku['id'], $data1);
|
$aggiorna = false;
|
||||||
}
|
|
||||||
|
|
||||||
$log .= ' *** ' . $stock->Codice . ' QTA=' . $stock->QtaDisponibile . "\n";
|
|
||||||
|
|
||||||
$inprevendita = isArticleInPrevendita($stock->Codice);
|
|
||||||
if ($inprevendita) {
|
|
||||||
setPreOrder($stock->Codice, true, false);
|
|
||||||
$log .= ' SEtTATO IN PREVENDITA ! <br>';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$aggiornato = true;
|
if ($aggiorna) {
|
||||||
|
$data1 = [
|
||||||
|
|
||||||
|
'stock_quantity' => $stock->QtaDisponibile,
|
||||||
|
|
||||||
|
];
|
||||||
|
$idprodotto = $productsku['parent_id'];
|
||||||
|
if ($idprodotto > 0) {
|
||||||
|
$variation = Variation::update($idprodotto, $productsku['id'], $data1);
|
||||||
|
} else {
|
||||||
|
Product::update($productsku['id'], $data1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$log .= ' *** ' . $stock->Codice . ' ' . $titolo . ' QTA=' . $stock->QtaDisponibile . "\n";
|
||||||
|
|
||||||
|
if ($inprevendita_qtaneg && ($qtyinstock != QTA_IN_PREVENDITA)) {
|
||||||
|
setPreOrder($stock->Codice, true, false);
|
||||||
|
$log .= ' SEtTATO IN PREVENDITA ! <br>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$aggiornato = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($log) {
|
if ($log) {
|
||||||
Log::channel('updateproductsqta')->notice($log);
|
Log::channel('updateproductsqta')->notice($log);
|
||||||
$log = "";
|
$log = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
//code error
|
//code error
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -197,13 +197,13 @@ function setPreOrder($sku, $aggiornapreordine, $debug)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function isArticleInPrevendita($id)
|
function isArticleInPrevendita($id, $checkqtanegativa)
|
||||||
{
|
{
|
||||||
return loadArticleByIdArticle($id, true);
|
return loadArticleByIdArticle($id, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function loadArticleByIdArticle($id, $checkprevendita = false)
|
function loadArticleByIdArticle($id, $checkprevendita = false, $checkqtanegativa = false)
|
||||||
{
|
{
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -225,8 +225,10 @@ function loadArticleByIdArticle($id, $checkprevendita = false)
|
|||||||
$qtaneg = $article->QtaDisponibile < 0;
|
$qtaneg = $article->QtaDisponibile < 0;
|
||||||
$inprevendita = false;
|
$inprevendita = false;
|
||||||
if ($article) {
|
if ($article) {
|
||||||
$inprevendita = $qtaneg
|
$inprevendita = ($article->DescrizioneStatoProdotto === 'In prevendita');
|
||||||
&& ($article->DescrizioneStatoProdotto === 'In prevendita');
|
if ($checkqtanegativa) {
|
||||||
|
$inprevendita = $inprevendita && $qtaneg;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ($inprevendita) {
|
if ($inprevendita) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -6195,7 +6195,7 @@ Route::get('/handle-article-action-pao/{id}/{action}', function ($id, $action) {
|
|||||||
setPreOrder($id, "1", true);
|
setPreOrder($id, "1", true);
|
||||||
} elseif ($action == 'checkPrevendita') {
|
} elseif ($action == 'checkPrevendita') {
|
||||||
// Logica per verificare se l'articolo è in preordine
|
// Logica per verificare se l'articolo è in preordine
|
||||||
$inprevendita = isArticleInPrevendita($id);
|
$inprevendita = isArticleInPrevendita($id, false);
|
||||||
if ($inprevendita) {
|
if ($inprevendita) {
|
||||||
return "L'articolo è in prevendita";
|
return "L'articolo è in prevendita";
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user