Aggiornamento per ISBN
This commit is contained in:
@@ -231,7 +231,8 @@ function setPreOrder($sku, $aggiornapreordine, $debug)
|
||||
updateValueByKey($data['meta_data'], '_wpro_amount_price_variable', 'fixed');
|
||||
updateValueByKey($data['meta_data'], '_wpro_date_variable', $datepubblstr);
|
||||
updateValueByKey($data['meta_data'], '_wpro_time_variable', '');
|
||||
updateValueByKey($data['meta_data'], '_rank_math_gtin_code', '');
|
||||
updateValueByKey($data['meta_data'], '_rank_math_gtin_code', $article->Ean13);
|
||||
updateValueByKey($data['meta_data'], '_wc_gla_gtin', $article->Ean13);
|
||||
}
|
||||
|
||||
if ($debug) {
|
||||
@@ -332,6 +333,92 @@ function setPreOrder($sku, $aggiornapreordine, $debug)
|
||||
}
|
||||
}
|
||||
|
||||
function setISBN_GTIN($sku, $article, $debug)
|
||||
{
|
||||
try {
|
||||
$product = Product::where('sku', $sku)->first();
|
||||
|
||||
if ($debug) {
|
||||
echo "Product: " . $sku;
|
||||
showarray($product);
|
||||
}
|
||||
|
||||
if ($product) {
|
||||
$titolo = $product['name'];
|
||||
|
||||
if ($debug)
|
||||
echo "Prodotto trovato: " . $titolo . "<br>";
|
||||
|
||||
$idprodotto = $product['parent_id'];
|
||||
|
||||
$data = [];
|
||||
|
||||
// $article = getArticoloById($sku);
|
||||
|
||||
if ($idprodotto > 0) {
|
||||
|
||||
$variations = Variation::all($product['parent_id']);
|
||||
// if ($debug)
|
||||
// showarray($variations);
|
||||
for ($i = 0; $i < count($variations); $i++) {
|
||||
$variation = $variations[$i];
|
||||
if ($variation->id == $product['id']) {
|
||||
// convert object into array
|
||||
$data = json_decode(json_encode($variation), true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($debug) {
|
||||
echo "Data:";
|
||||
showarray($data);
|
||||
}
|
||||
|
||||
$agg = true;
|
||||
$data['meta_data'] = $product['meta_data'];
|
||||
$aggiornato = false;
|
||||
if ($agg) {
|
||||
$_rank_math_gtin_code = getValueByKey($product['meta_data'], '_rank_math_gtin_code');
|
||||
if (!$_rank_math_gtin_code || $_rank_math_gtin_code != $article->Ean13) {
|
||||
updateValueByKey($data['meta_data'], '_rank_math_gtin_code', $article->Ean13);
|
||||
$aggiornato = true;
|
||||
}
|
||||
|
||||
$_wc_gla_gtin = getValueByKey($product['meta_data'], '_wc_gla_gtin');
|
||||
if (!$_wc_gla_gtin || $_wc_gla_gtin != $article->Ean13) {
|
||||
updateValueByKey($data['meta_data'], '_wc_gla_gtin', $article->Ean13);
|
||||
$aggiornato = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($debug && $aggiornato) {
|
||||
echo "<br>Dati da Salvare:";
|
||||
showarray($data);
|
||||
}
|
||||
|
||||
if ($aggiornato) {
|
||||
|
||||
$variation = Variation::update($idprodotto, $product['id'], $data);
|
||||
|
||||
if ($variation) {
|
||||
if ($debug)
|
||||
echo "Aggiornato ISBN: [ParentId=" . $idprodotto . '] ProdId= ' . $product['id'] . ' ' . $variation['name'] . "<br>";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
if ($debug)
|
||||
echo "Il prodotto non esiste";
|
||||
}
|
||||
return false;
|
||||
|
||||
} catch (Exception $e) {
|
||||
echo "Errore: " . $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
function setDataPubblicazione($sku, $debug)
|
||||
{
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user