Merge branch 'main' of http://91.189.216.43:3000/jacek.pyziak/masimmo.pl
This commit is contained in:
@@ -8,11 +8,12 @@ include(dirname(__FILE__).'/init.php');
|
|||||||
$context = Context::getContext();
|
$context = Context::getContext();
|
||||||
|
|
||||||
// Sprawdzenie trybu działania na podstawie parametrów URL
|
// Sprawdzenie trybu działania na podstawie parametrów URL
|
||||||
$modeAdd = (Tools::getValue('add') === 'true');
|
$modeAdd = (Tools::getValue('add') === 'true');
|
||||||
$modeUpdate = (Tools::getValue('update') === 'true');
|
$modeUpdate = (Tools::getValue('update') === 'true');
|
||||||
|
$modeSynch = (Tools::getValue('synch') === 'true');
|
||||||
|
|
||||||
if (!$modeAdd && !$modeUpdate) {
|
if (!$modeAdd && !$modeUpdate && !$modeSynch) {
|
||||||
die('Brak akcji. Dodaj do adresu ?add=true lub ?update=true');
|
die('Brak akcji. Dodaj do adresu ?add=true lub ?update=true lub ?synch=true');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Plik logu aktualizacji cen
|
// Plik logu aktualizacji cen
|
||||||
@@ -298,6 +299,18 @@ function getTaxRulesGroupIdForRate($rate, $id_country = null) {
|
|||||||
return $id ? (int)$id : 0;
|
return $id ? (int)$id : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Zwraca główny produkt z grupy – pierwszy, którego SKU istnieje w PrestaShop
|
||||||
|
function findMainProductDataFromGroup($products) {
|
||||||
|
foreach ($products as $p) {
|
||||||
|
$ref = (string)$p->sku;
|
||||||
|
if ($ref !== '' && findProductByReference($ref)) {
|
||||||
|
return $p; // to główny produkt
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// === GRUPOWANIE PRODUKTÓW PO SYMBOLU ===
|
// === GRUPOWANIE PRODUKTÓW PO SYMBOLU ===
|
||||||
$productsBySymbol = [];
|
$productsBySymbol = [];
|
||||||
foreach ($xml->product as $productData) {
|
foreach ($xml->product as $productData) {
|
||||||
@@ -337,13 +350,20 @@ if ($modeUpdate) {
|
|||||||
|
|
||||||
$updatedSomething = false;
|
$updatedSomething = false;
|
||||||
|
|
||||||
|
|
||||||
foreach ($productsBySymbol as $symbol => $products) {
|
foreach ($productsBySymbol as $symbol => $products) {
|
||||||
if (empty($products)) {
|
if (empty($products)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Główny produkt – referencja z pierwszego elementu grupy
|
// Główny produkt – referencja z pierwszego elementu grupy
|
||||||
$mainProductData = $products[0];
|
// $mainProductData = $products[0];
|
||||||
|
// $reference = (string)$mainProductData->sku;
|
||||||
|
// $key = 'product_'.$reference;
|
||||||
|
$mainProductData = findMainProductDataFromGroup($products);
|
||||||
|
if (!$mainProductData) {
|
||||||
|
continue; // w grupie nie ma produktu, który istnieje w Presta
|
||||||
|
}
|
||||||
$reference = (string)$mainProductData->sku;
|
$reference = (string)$mainProductData->sku;
|
||||||
$key = 'product_'.$reference;
|
$key = 'product_'.$reference;
|
||||||
|
|
||||||
@@ -491,157 +511,338 @@ if ($modeUpdate) {
|
|||||||
// =======================================
|
// =======================================
|
||||||
// =========== TRYB DODAWANIA ============
|
// =========== TRYB DODAWANIA ============
|
||||||
// =======================================
|
// =======================================
|
||||||
|
if ($modeAdd) {
|
||||||
|
$productAdded = false;
|
||||||
|
$combinationAdded = false;
|
||||||
|
|
||||||
$productAdded = false;
|
// Tworzenie lub aktualizacja produktów z kombinacjami (dodawanie)
|
||||||
$combinationAdded = false;
|
foreach ($productsBySymbol as $symbol => $products) {
|
||||||
|
if (empty($products)) {
|
||||||
// Tworzenie lub aktualizacja produktów z kombinacjami (dodawanie)
|
continue;
|
||||||
foreach ($productsBySymbol as $symbol => $products) {
|
|
||||||
if (empty($products)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Główny produkt – dane z pierwszego w grupie
|
|
||||||
$mainProductData = $products[0];
|
|
||||||
$mainProduct = findProductByReference((string)$mainProductData->sku);
|
|
||||||
|
|
||||||
// BAZA: najtańszy wariant w grupie (brutto i netto)
|
|
||||||
list($grossBase, $netPrice) = getBasePricesFromGroup($products);
|
|
||||||
|
|
||||||
if (!$mainProduct) {
|
|
||||||
// Create a new product if it doesn't exist
|
|
||||||
$mainProduct = new Product();
|
|
||||||
$mainProduct->name = createMultiLangField((string)$mainProductData->title);
|
|
||||||
|
|
||||||
$description = (string)$mainProductData->description;
|
|
||||||
$description = str_replace("\n", "<br>", $description);
|
|
||||||
$mainProduct->description = createMultiLangField($description);
|
|
||||||
|
|
||||||
// Cena BRUTTO z XML -> NETTO (23%) – bazą jest najtańszy wariant
|
|
||||||
$mainProduct->price = $netPrice > 0 ? $netPrice : 0;
|
|
||||||
|
|
||||||
// VAT 23% jeśli dostępny
|
|
||||||
if (!empty($idTaxRulesGroup23)) {
|
|
||||||
$mainProduct->id_tax_rules_group = (int)$idTaxRulesGroup23;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Produkt aktywny + delivery times
|
// ===== Filter item_group_id =====
|
||||||
$mainProduct->active = 1;
|
// $mainProductDataTemp = $products[0];
|
||||||
$mainProduct->delivery_in_stock = createMultiLangField('2-7 dni roboczych');
|
// if ((string)$mainProductDataTemp->item_group_id !== '68590') {
|
||||||
$mainProduct->delivery_out_stock = createMultiLangField('4-10 tygodni');
|
// continue;
|
||||||
|
// }
|
||||||
|
|
||||||
$mainProduct->reference = (string)$mainProductData->sku;
|
// Główny produkt – dane z pierwszego w grupie
|
||||||
$mainProduct->id_category_default = 2; // np. Strona główna
|
// $mainProductData = $products[0];
|
||||||
$mainProduct->link_rewrite = createLinkRewrite((string)$mainProductData->title);
|
// $mainProduct = findProductByReference((string)$mainProductData->sku);
|
||||||
$mainProduct->add();
|
$mainProductData = findMainProductDataFromGroup($products);
|
||||||
|
if (!$mainProductData) {
|
||||||
// Add images to the product
|
$mainProductData = $products[0]; // fallback na etapie dodawania
|
||||||
if (!empty($mainProductData->image)) {
|
|
||||||
addProductImage($mainProduct->id, (string)$mainProductData->image);
|
|
||||||
}
|
}
|
||||||
|
$mainProduct = findProductByReference((string)$mainProductData->sku);
|
||||||
|
|
||||||
for ($i = 1; $i <= 10; $i++) {
|
// BAZA: najtańszy wariant w grupie (brutto i netto)
|
||||||
$imageUrl = (string)$mainProductData->{'images_' . $i};
|
list($grossBase, $netPrice) = getBasePricesFromGroup($products);
|
||||||
if (!empty($imageUrl)) {
|
|
||||||
addProductImage($mainProduct->id, $imageUrl);
|
if (!$mainProduct) {
|
||||||
|
// Create a new product if it doesn't exist
|
||||||
|
$mainProduct = new Product();
|
||||||
|
$mainProduct->name = createMultiLangField((string)$mainProductData->title);
|
||||||
|
|
||||||
|
$description = (string)$mainProductData->description;
|
||||||
|
$description = str_replace("\n", "<br>", $description);
|
||||||
|
$mainProduct->description = createMultiLangField($description);
|
||||||
|
|
||||||
|
// Cena BRUTTO z XML -> NETTO (23%) – bazą jest najtańszy wariant
|
||||||
|
$mainProduct->price = $netPrice > 0 ? $netPrice : 0;
|
||||||
|
|
||||||
|
// VAT 23% jeśli dostępny
|
||||||
|
if (!empty($idTaxRulesGroup23)) {
|
||||||
|
$mainProduct->id_tax_rules_group = (int)$idTaxRulesGroup23;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$productAdded = true;
|
// Produkt aktywny + delivery times
|
||||||
}
|
$mainProduct->active = 1;
|
||||||
|
$mainProduct->delivery_in_stock = createMultiLangField('2-7 dni roboczych');
|
||||||
|
$mainProduct->delivery_out_stock = createMultiLangField('4-10 tygodni');
|
||||||
|
|
||||||
// Ensure the product is saved before adding combinations
|
$mainProduct->reference = (string)$mainProductData->sku;
|
||||||
if (!$mainProduct->id) {
|
$mainProduct->id_category_default = 107; // np. Meble
|
||||||
echo "Failed to create or update main product: " . (string)$mainProductData->title . "\n";
|
$mainProduct->link_rewrite = createLinkRewrite((string)$mainProductData->title);
|
||||||
continue;
|
$mainProduct->add();
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure the combination set is unique for the product
|
// ===== Poprawne przypisanie kategorii =====
|
||||||
$addedCombinations = [];
|
$id_lang = (int)$context->language->id;
|
||||||
|
$defaultCategory = new Category($mainProduct->id_category_default, $id_lang);
|
||||||
|
|
||||||
// Add or update combinations for each product in the group
|
if (Validate::isLoadedObject($defaultCategory) && $defaultCategory->name == 'Strona główna') {
|
||||||
foreach ($products as $productData) {
|
$newCategoryId = 107; // Meble
|
||||||
$attributes = [
|
$mainProduct->id_category_default = (int)$newCategoryId;
|
||||||
'Kolor' => (string)$productData->Kolor,
|
|
||||||
'Dlugosc' => (string)$productData->Dlugosc,
|
|
||||||
'Szerokosc' => (string)$productData->Szerokosc,
|
|
||||||
'Glebokosc' => (string)$productData->Glebokosc,
|
|
||||||
'Wysokosc' => (string)$productData->Wysokosc,
|
|
||||||
];
|
|
||||||
|
|
||||||
$attributeIds = [];
|
// Podmieniamy kategorie produktu (zachowując inne)
|
||||||
foreach ($attributes as $name => $value) {
|
$categories = $mainProduct->getCategories();
|
||||||
if (!empty($value)) {
|
$categories = array_diff($categories, [(int)$defaultCategory->id]);
|
||||||
$attributeGroupId = createAttribute($name, [$value]);
|
$categories[] = (int)$newCategoryId;
|
||||||
$attribute = findAttributeByName($attributeGroupId, $value);
|
$categories = array_unique(array_map('intval', $categories));
|
||||||
if ($attribute) {
|
$mainProduct->updateCategories($categories);
|
||||||
$attributeIds[] = (int)$attribute->id;
|
}
|
||||||
|
// ===== Koniec ustawienia kategorii =====
|
||||||
|
|
||||||
|
// Add images to the product
|
||||||
|
if (!empty($mainProductData->image)) {
|
||||||
|
addProductImage($mainProduct->id, (string)$mainProductData->image);
|
||||||
|
}
|
||||||
|
|
||||||
|
for ($i = 1; $i <= 10; $i++) {
|
||||||
|
$imageUrl = (string)$mainProductData->{'images_' . $i};
|
||||||
|
if (!empty($imageUrl)) {
|
||||||
|
addProductImage($mainProduct->id, $imageUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$productAdded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a unique key for the attribute set
|
// Ensure the product is saved before adding combinations
|
||||||
sort($attributeIds);
|
if (!$mainProduct->id) {
|
||||||
$key = implode('-', $attributeIds);
|
echo "Failed to create or update main product: " . (string)$mainProductData->title . "\n";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Add or update combination if it is unique
|
// Ensure the combination set is unique for the product
|
||||||
if (!empty($attributeIds) && !isset($addedCombinations[$key])) {
|
$addedCombinations = [];
|
||||||
$combination = findCombinationByAttributes($mainProduct->id, $attributeIds);
|
|
||||||
if (!$combination) {
|
// Add or update combinations for each product in the group
|
||||||
// Create new combination
|
foreach ($products as $productData) {
|
||||||
$combination = new Combination();
|
$attributes = [
|
||||||
$combination->id_product = (int)$mainProduct->id;
|
'Kolor' => (string)$productData->Kolor,
|
||||||
$combination->quantity = 100; // startowo, i tak zaraz nadpiszemy StockAvailable
|
'Dlugosc' => (string)$productData->Dlugosc,
|
||||||
$combination->reference = (string)$productData->sku;
|
'Szerokosc' => (string)$productData->Szerokosc,
|
||||||
$combination->add();
|
'Glebokosc' => (string)$productData->Glebokosc,
|
||||||
$combination->setAttributes($attributeIds);
|
'Wysokosc' => (string)$productData->Wysokosc,
|
||||||
$combination->save();
|
];
|
||||||
$combinationAdded = true;
|
|
||||||
} else {
|
$attributeIds = [];
|
||||||
// Update existing combination quantity if necessary
|
foreach ($attributes as $name => $value) {
|
||||||
$combination->quantity = 100; // startowo
|
if (!empty($value)) {
|
||||||
$combination->update();
|
$attributeGroupId = createAttribute($name, [$value]);
|
||||||
|
$attribute = findAttributeByName($attributeGroupId, $value);
|
||||||
|
if ($attribute) {
|
||||||
|
$attributeIds[] = (int)$attribute->id;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark this combination as added
|
// Create a unique key for the attribute set
|
||||||
$addedCombinations[$key] = true;
|
sort($attributeIds);
|
||||||
|
$key = implode('-', $attributeIds);
|
||||||
|
|
||||||
|
// Add or update combination if it is unique
|
||||||
|
if (!empty($attributeIds) && !isset($addedCombinations[$key])) {
|
||||||
|
$combination = findCombinationByAttributes($mainProduct->id, $attributeIds);
|
||||||
|
if (!$combination) {
|
||||||
|
// Create new combination
|
||||||
|
$combination = new Combination();
|
||||||
|
$combination->id_product = (int)$mainProduct->id;
|
||||||
|
$combination->quantity = 100; // startowo, i tak zaraz nadpiszemy StockAvailable
|
||||||
|
$combination->reference = (string)$productData->sku;
|
||||||
|
$combination->add();
|
||||||
|
$combination->setAttributes($attributeIds);
|
||||||
|
$combination->save();
|
||||||
|
$combinationAdded = true;
|
||||||
|
} else {
|
||||||
|
// Update existing combination quantity if necessary
|
||||||
|
$combination->quantity = 100; // startowo
|
||||||
|
$combination->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mark this combination as added
|
||||||
|
$addedCombinations[$key] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($combinationAdded) {
|
||||||
|
break; // Break if a new combination was added
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($combinationAdded) {
|
// --- STANY MAGAZYNOWE PRODUKTU (ID_PRODUCT_ATTRIBUTE = 0) ---
|
||||||
break; // Break if a new combination was added
|
$mainStatus = (string)$mainProductData->Status_magazynowy;
|
||||||
|
$mainQty = ($mainStatus === 'instock') ? 100 : 0;
|
||||||
|
StockAvailable::setQuantity($mainProduct->id, 0, $mainQty);
|
||||||
|
|
||||||
|
// --- STANY MAGAZYNOWE KOMBINACJI ---
|
||||||
|
foreach ($products as $productDataVariant) {
|
||||||
|
$variantRef = (string)$productDataVariant->sku;
|
||||||
|
$variantStatus = (string)$productDataVariant->Status_magazynowy;
|
||||||
|
$variantQty = ($variantStatus === 'instock') ? 100 : 0;
|
||||||
|
|
||||||
|
$combination = findCombinationByReference($mainProduct->id, $variantRef);
|
||||||
|
if ($combination) {
|
||||||
|
StockAvailable::setQuantity($mainProduct->id, $combination->id, $variantQty);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure the product has combinations enabled
|
||||||
|
$mainProduct->checkDefaultAttributes();
|
||||||
|
Product::updateDefaultAttribute($mainProduct->id);
|
||||||
|
|
||||||
|
if ($productAdded || $combinationAdded) {
|
||||||
|
if ($productAdded) {
|
||||||
|
echo "<p>Dodałem produkt: " . htmlspecialchars((string)$mainProductData->title) . "</p>";
|
||||||
|
}
|
||||||
|
if ($combinationAdded) {
|
||||||
|
echo "<p>Dodałem kombinację: " . htmlspecialchars((string)$mainProductData->title) . "</p>";
|
||||||
|
}
|
||||||
|
break; // Break if a new product or combination was added
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// --- STANY MAGAZYNOWE PRODUKTU (ID_PRODUCT_ATTRIBUTE = 0) ---
|
// =======================================
|
||||||
$mainStatus = (string)$mainProductData->Status_magazynowy;
|
// ========= TRYB SYNCHRONIZACJI =========
|
||||||
$mainQty = ($mainStatus === 'instock') ? 100 : 0;
|
// =======================================
|
||||||
StockAvailable::setQuantity($mainProduct->id, 0, $mainQty);
|
if ($modeSynch) {
|
||||||
|
echo '<h2>Rozpoczynam synchronizację produktów...</h2>';
|
||||||
|
|
||||||
// --- STANY MAGAZYNOWE KOMBINACJI ---
|
$db = Db::getInstance();
|
||||||
foreach ($products as $productDataVariant) {
|
|
||||||
$variantRef = (string)$productDataVariant->sku;
|
|
||||||
$variantStatus = (string)$productDataVariant->Status_magazynowy;
|
|
||||||
$variantQty = ($variantStatus === 'instock') ? 100 : 0;
|
|
||||||
|
|
||||||
$combination = findCombinationByReference($mainProduct->id, $variantRef);
|
// 1. Wyczyszczenie tymczasowej tabeli
|
||||||
if ($combination) {
|
$db->execute('TRUNCATE TABLE `'._DB_PREFIX_.'drewmax_products_temp`');
|
||||||
StockAvailable::setQuantity($mainProduct->id, $combination->id, $variantQty);
|
|
||||||
}
|
// 1.1 Wczytywanie SKU z XML i dodawanie do tymczasowej tabeli
|
||||||
|
$skusInXml = [];
|
||||||
|
foreach ($xml->product as $productData) {
|
||||||
|
$sku = trim((string)$productData->sku);
|
||||||
|
if ($sku === '') continue;
|
||||||
|
|
||||||
|
$skusInXml[] = $sku;
|
||||||
|
|
||||||
|
$db->execute('
|
||||||
|
INSERT INTO `'._DB_PREFIX_.'drewmax_products_temp` (`sku`, `date_checked`)
|
||||||
|
VALUES (\''.pSQL($sku).'\', NOW())
|
||||||
|
');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure the product has combinations enabled
|
// 2. Praca z historią
|
||||||
$mainProduct->checkDefaultAttributes();
|
if (!empty($skusInXml)) {
|
||||||
Product::updateDefaultAttribute($mainProduct->id);
|
// Utworzenie listy SKU dla SQL
|
||||||
|
$skusList = "'" . implode("','", array_map('pSQL', $skusInXml)) . "'";
|
||||||
|
|
||||||
if ($productAdded || $combinationAdded) {
|
// 2.1 Dodawanie nowych SKU do historii lub przywracanie aktywności
|
||||||
if ($productAdded) {
|
$sqlInsert = '
|
||||||
echo "<p>Dodałem produkt: " . htmlspecialchars((string)$mainProductData->title) . "</p>";
|
INSERT INTO `'._DB_PREFIX_.'drewmax_products_history` (`sku`, `active`)
|
||||||
}
|
SELECT t.sku, 1
|
||||||
if ($combinationAdded) {
|
FROM `'._DB_PREFIX_.'drewmax_products_temp` t
|
||||||
echo "<p>Dodałem kombinację: " . htmlspecialchars((string)$mainProductData->title) . "</p>";
|
LEFT JOIN `'._DB_PREFIX_.'drewmax_products_history` h ON h.sku = t.sku
|
||||||
}
|
WHERE h.sku IS NULL
|
||||||
break; // Break if a new product or combination was added
|
';
|
||||||
|
$db->execute($sqlInsert);
|
||||||
|
|
||||||
|
$sqlUpdateActive = '
|
||||||
|
UPDATE `'._DB_PREFIX_.'drewmax_products_history` h
|
||||||
|
JOIN `'._DB_PREFIX_.'drewmax_products_temp` t ON h.sku = t.sku
|
||||||
|
SET h.active = 1
|
||||||
|
WHERE h.active = 0
|
||||||
|
';
|
||||||
|
$db->execute($sqlUpdateActive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 2.2 Wykluczanie produktów, których nie ma w temp
|
||||||
|
$sqlDeactivate = '
|
||||||
|
UPDATE `'._DB_PREFIX_.'drewmax_products_history` h
|
||||||
|
LEFT JOIN `'._DB_PREFIX_.'drewmax_products_temp` t ON h.sku = t.sku
|
||||||
|
SET h.active = 0
|
||||||
|
WHERE t.sku IS NULL AND h.active = 1
|
||||||
|
';
|
||||||
|
$db->execute($sqlDeactivate);
|
||||||
|
|
||||||
|
// Wyłącz produkty w PrestaShop dla SKU, które mają active=0
|
||||||
|
$skusToDisable = $db->executeS('
|
||||||
|
SELECT sku FROM `'._DB_PREFIX_.'drewmax_products_history`
|
||||||
|
WHERE active = 0
|
||||||
|
');
|
||||||
|
|
||||||
|
// 3. Synchronizacja statusu produktów i kombinacji w PrestaShop
|
||||||
|
// Pobieramy tylko SKU z historii (źródło prawdy)
|
||||||
|
$allHistory = $db->executeS('
|
||||||
|
SELECT sku, active
|
||||||
|
FROM `'._DB_PREFIX_.'drewmax_products_history`
|
||||||
|
');
|
||||||
|
|
||||||
|
foreach ($allHistory as $row) {
|
||||||
|
$sku = trim($row['sku']);
|
||||||
|
$activeStatus = (int)$row['active'];
|
||||||
|
|
||||||
|
if ($sku === '') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* KROK 3.1
|
||||||
|
* Sprawdzenie czy SKU jest GŁÓWNYM PRODUKTEM
|
||||||
|
* (tylko ps_product.reference)
|
||||||
|
*/
|
||||||
|
$idProduct = (int)$db->getValue('
|
||||||
|
SELECT id_product
|
||||||
|
FROM `'._DB_PREFIX_.'product`
|
||||||
|
WHERE reference = \''.pSQL($sku).'\'
|
||||||
|
LIMIT 1
|
||||||
|
');
|
||||||
|
|
||||||
|
if ($idProduct > 0) {
|
||||||
|
// === GŁÓWNY PRODUKT ===
|
||||||
|
$product = new Product($idProduct);
|
||||||
|
|
||||||
|
if (!Validate::isLoadedObject($product)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($activeStatus === 0 && (int)$product->active === 1) {
|
||||||
|
// Wyłącz produkt
|
||||||
|
$product->active = 0;
|
||||||
|
$product->update();
|
||||||
|
echo "Wyłączono PRODUKT: {$sku}<br>";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($activeStatus === 1 && (int)$product->active === 0) {
|
||||||
|
// Włącz produkt
|
||||||
|
$product->active = 1;
|
||||||
|
$product->update();
|
||||||
|
echo "Włączono PRODUKT: {$sku}<br>";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Główny produkt obsłużony → NIE sprawdzamy kombinacji
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* KROK 3.2
|
||||||
|
* Jeśli NIE jest produktem → sprawdzamy czy to KOMBINACJA
|
||||||
|
*/
|
||||||
|
$combinationRow = $db->getRow('
|
||||||
|
SELECT id_product_attribute, id_product
|
||||||
|
FROM `'._DB_PREFIX_.'product_attribute`
|
||||||
|
WHERE reference = \''.pSQL($sku).'\'
|
||||||
|
LIMIT 1
|
||||||
|
');
|
||||||
|
|
||||||
|
if ($combinationRow) {
|
||||||
|
// === KOMBINACJA ===
|
||||||
|
if ($activeStatus === 0) {
|
||||||
|
$idProductAttribute = (int)$combinationRow['id_product_attribute'];
|
||||||
|
|
||||||
|
$combination = new Combination($idProductAttribute);
|
||||||
|
if (Validate::isLoadedObject($combination)) {
|
||||||
|
$combination->delete();
|
||||||
|
echo "Usunięto KOMBINACJĘ: {$sku} (ID: {$idProductAttribute})<br>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Jeśli active = 1 → NIC NIE ROBIMY (kombinacji się nie aktywuje)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* KROK 3.3
|
||||||
|
* SKU nie istnieje w PrestaShop → ignorujemy
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
echo '<h3>Synchronizacja zakończona.</h3>';
|
||||||
}
|
}
|
||||||
|
|
||||||
// reload page after 250ms if product or combination was added (dla trybu add)
|
// reload page after 250ms if product or combination was added (dla trybu add)
|
||||||
@@ -649,4 +850,4 @@ if ($productAdded || $combinationAdded) {
|
|||||||
// echo "<script>setTimeout(function(){location.reload();}, 250);</script>";
|
// echo "<script>setTimeout(function(){location.reload();}, 250);</script>";
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
Reference in New Issue
Block a user