diff --git a/kreatywnybrand-pl/umam.php b/kreatywnybrand-pl/umam.php new file mode 100644 index 0000000..f085e8a --- /dev/null +++ b/kreatywnybrand-pl/umam.php @@ -0,0 +1,82 @@ +cart->get_cart() as $cart_item) { + $product_id = $cart_item['product_id']; + $variation_id = $cart_item['variation_id']; // ID wariantu, jeśli istnieje + $quantity = $cart_item['quantity']; + + $fee_amount = get_fee_amount($product_id, $variation_id); + if ($fee_amount > 0) { + $fee_total = $fee_amount * $quantity; + $fee_label = __('Opłata za opakowanie') . ' #' . ++$fee_counter; // Tworzenie unikalnej etykiety + WC()->cart->add_fee($fee_label, $fee_total, true); + } + } +} + +function get_fee_amount($product_id, $variation_id = null) { + // Opłaty dla konkretnych produktów lub wariantów + $fee_ids = array( + 8126 => 0.90, + 12399 => 0.90, + 5936 => 0.90, + 7977 => 0.90, + 11178 => 0.90, + 3592 => 0.90, + 7458 => 0.90, + 11174 => 0.90, + 10923 => 0.90, + 3247 => 0.90, + 2801 => 1.80, + 2757 => 1.80, + 2807 => 2.70, + 2760 => 2.70, + 2770 => 5.40, + 2809 => 5.40, + 2811 => 9.90, + 2784 => 9.90, + 2793 => 18.90, + 2814 => 18.90, + 2362 => 0.90, + 4228 => 0.90, + 4259 => 0.90, + 4288 => 0.90, + 2295 => 0.90, + 2574 => 0.90, + 2712 => 0.90, + 2734 => 0.90, + 3158 => 0.90, + 8299 => 0.90 + ); + + // Opłaty dla wybranych wariantów produktów + $variation_fees = array( + 10934 => 0.90, // ID wariantu => opłata + 10936 => 0.90 + // Dodaj więcej wariantów, jeśli to konieczne + ); + + // Sprawdzenie opłaty dla wariantu + if ($variation_id && array_key_exists($variation_id, $variation_fees)) { + return $variation_fees[$variation_id]; + } + + // Sprawdzenie opłaty dla produktu + if (array_key_exists($product_id, $fee_ids)) { + return $fee_ids[$product_id]; + } + + /*// Domyślna opłata dla kategorii + $category_fee = 0.90; + $categories = array('torty', 'ciasta-swiateczne', 'torty_komunijne_umam', 'torty-standardowe', 'inne', 'konfitury-i-pasty', 'makaroniki','wielkanoc-z-umam'); + foreach ($categories as $category) { + if (has_term($category, 'product_cat', $product_id)) { + return $category_fee; + } + }*/ + + return 0; // Brak opłaty domyślnie +} diff --git a/magiczne-perfumy.pl/apilo.js b/magiczne-perfumy.pl/apilo.js new file mode 100644 index 0000000..41a5925 --- /dev/null +++ b/magiczne-perfumy.pl/apilo.js @@ -0,0 +1,519 @@ +const currentUrl = window.location.href; +const patterns = [ + /^https:\/\/mkbiuro\.apilo\.com\/order\/order\/news\/?$/, + /^https:\/\/mkbiuro\.apilo\.com\/order\/order\/in-progress\/?$/, + /^https:\/\/mkbiuro\.apilo\.com\/order\/order\/to-send\/?$/, + /^https:\/\/mkbiuro\.apilo\.com\/order\/order\/completed\/?$/, + /^https:\/\/mkbiuro\.apilo\.com\/order\/order\/all\/?$/ +]; +if (patterns.some(pattern => pattern.test(currentUrl))) { + waitForTableAndSetImage(); + attachTableReloadListener(); +} + +function waitForTableAndSetImage() { + const intervalId = setInterval(() => { + let dataTables_scrollBody = document.getElementsByClassName('dataTables_scrollBody'); + if (dataTables_scrollBody.length > 0) { + let dataTables_tbody = dataTables_scrollBody[0].getElementsByTagName('tbody')[0]; + let rows = dataTables_tbody.getElementsByTagName('tr'); + + if (rows.length > 0) { + clearInterval(intervalId); + setImageToProduct(); + } + } + }, 100); +} + +function attachTableReloadListener() { + const table = document.querySelector('.dataTables_scrollBody table'); + if (table) { + const observer = new MutationObserver((mutationsList, observer) => { + for (const mutation of mutationsList) { + if (mutation.type === 'childList') { + waitForTableAndSetImage(); + break; + } + } + }); + + observer.observe(table.querySelector('tbody'), { childList: true }); + } +} + +function setImageToProduct(img = '') { + let dataTables_scrollBody = document.getElementsByClassName('dataTables_scrollBody'); + if (dataTables_scrollBody.length > 0) { + let dataTables_tbody = dataTables_scrollBody[0].getElementsByTagName('tbody')[0]; + let rows = dataTables_tbody.getElementsByTagName('tr'); + + for (let i = 0; i < rows.length; i++) { + let cells = rows[i].getElementsByTagName('td'); + + if (cells.length > 1) { + let secondCellText = cells[1].textContent.trim(); + let domain; + + if (secondCellText.includes('marianek.pl')) { + domain = 'marianek.pl'; + } else if (secondCellText.includes('pomysloweprezenty.pl')) { + domain = 'pomysloweprezenty.pl'; + } else { + continue; + } + + if (cells.length >= 5) { + let fifthCell = cells[4]; + let divsInFifthCell = fifthCell.children; + + for (let i = 0; i < divsInFifthCell.length; i++) { + let currentDiv = divsInFifthCell[i]; + let imgDiv = currentDiv.getElementsByTagName('div')[0]; + let dataDiv = currentDiv.getElementsByTagName('div')[1]; + + if (dataDiv) { + let skuText = dataDiv.innerHTML.match(/SKU:\s*([A-Za-z0-9-]+)/); + + if (skuText && skuText[1]) { + getProductData(skuText[1], domain).then(data => { + if (!data) { + console.log('Product not found:', skuText[1]); + return; + } + + console.log('Product found:', skuText[1]); + imgDiv.innerHTML = ''; + const imgElement = makeImg(data); + imgDiv.appendChild(imgElement); + + imgElement.addEventListener('mouseover', function() { + showLargeImage(data, imgElement); + }); + + imgElement.addEventListener('mouseout', function() { + hideLargeImage(); + }); + }); + } + } + } + } + } + } + } +} + +function makeImg(src = 'https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png') { + const img = document.createElement('img'); + img.src = src; + img.alt = 'image'; + img.className = 'img-fluid center-block'; + img.style.maxWidth = '48px'; + img.style.maxHeight = '48px'; + + return img; +} + +function showLargeImage(src, imgElement) { + const largeImg = document.createElement('img'); + largeImg.src = src; + largeImg.style.position = 'absolute'; + largeImg.style.maxWidth = '400px'; + largeImg.style.maxHeight = '400px'; + largeImg.style.border = '1px solid #ccc'; + largeImg.style.background = '#fff'; + largeImg.style.zIndex = '1000'; + largeImg.style.top = imgElement.getBoundingClientRect().top + window.scrollY + 'px'; + largeImg.style.left = imgElement.getBoundingClientRect().left + imgElement.offsetWidth + 10 + 'px'; + largeImg.id = 'largeImagePreview'; + + document.body.appendChild(largeImg); +} + +function hideLargeImage() { + const largeImg = document.getElementById('largeImagePreview'); + if (largeImg) { + largeImg.remove(); + } +} + +async function getProductData(sku, domain) { + let url; + if (domain === 'marianek.pl') { + url = `https://marianek.pl/api/v1/product.php?sku=${sku}`; + } else if (domain === 'pomysloweprezenty.pl') { + url = `https://pomysloweprezenty.pl/api/v1/product.php?sku=${sku}`; + } else { + console.error('Unsupported domain:', domain); + return null; + } + + try { + const response = await fetch(url); + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + + const data = await response.json(); console.log(data); + return data.img; + } catch (error) { + console.error('Error fetching product data: ' + url, error); + return null; + } +} + +const currentUrl2 = window.location.href; +const pattern = /^https:\/\/mkbiuro\.apilo\.com\/warehouse\/shipment\/new-for-order\/.+/; + +if (pattern.test(currentUrl2)) { + const portletBody = document.querySelector('.kt-portlet__body'); + if (portletBody) { + const buttonContainer = document.createElement('div'); + buttonContainer.className = 'custom-button-container'; + buttonContainer.style.display = 'flex'; + buttonContainer.style.gap = '10px'; + buttonContainer.style.marginBottom = '15px'; + portletBody.parentNode.insertBefore(buttonContainer, portletBody); + + const buttonKurierDPD = createButton('Kurier DPD', '#ff7800', 'kurier.dpd'); + const buttonInpostPaczkomat = createButton('Inpost Paczkomat', '#007bff', 'inpost.paczkomat'); + const buttonOrlenPaczka = createButton('Orlen Paczka', '#007bff', 'P2P.orlen' ); + // const buttonD2PApaczka = createButton('D2P Apaczka', '#28a745', 'D2P.apaczka'); + // const buttonP2Papaczka = createButton('P2P Apaczka', '#ffc107', 'P2P.apaczka'); + // const buttonOrlen = createButton('Orlen', 'rgb(255, 7, 193)', 'P2P.orlen'); + + // buttonContainer.appendChild(buttonP2D); + buttonContainer.appendChild(buttonKurierDPD); + buttonContainer.appendChild(buttonInpostPaczkomat); + buttonContainer.appendChild(buttonOrlenPaczka); + // buttonContainer.appendChild(buttonD2PApaczka); + // buttonContainer.appendChild(buttonP2Papaczka); + // buttonContainer.appendChild(buttonOrlen); + // buttonContainer.appendChild(buttonD2D); + // buttonContainer.appendChild(buttonD2P); + // buttonContainer.appendChild(buttonP2P); + } +} + +function createButton(text, backgroundColor, method, dropoffPoint = null) { + const button = document.createElement('button'); + button.textContent = text; + button.style.background = backgroundColor; + button.style.display = 'inline-flex'; + button.style.width = '200px'; + button.style.height = '40px'; + button.style.alignItems = 'center'; + button.style.justifyContent = 'center'; + button.style.color = '#FFF'; + button.style.border = 'none'; + button.style.cursor = 'pointer'; + + button.addEventListener('click', () => handleShipment(method, dropoffPoint)); + + return button; +} + +async function handleShipment(method, dropoffPoint = null) { + try { + await selectPackageType(method); + await setShipmentMethod(method); + if (dropoffPoint) { + await setDropoffPoint(dropoffPoint); + } + await setContent( method ); + await setParcelWeight('1'); + await setPackageDimmensions('15', '15', '7'); + await submitShipment(); + } catch (error) { + console.error('Wystąpił błąd: ', error); + } +} + +function retryUntilSuccess(fn, interval = 1000, retries = 10) { + return new Promise((resolve, reject) => { + const attempt = async () => { + try { + const result = await fn(); + resolve(result); + } catch (err) { + if (retries === 0) { + reject(err); + } else { + setTimeout(() => { + retries--; + attempt(); + }, interval); + } + } + }; + attempt(); + }); +} + +function setContent( method ) { + if ( method == 'kurier.dpd' || method == 'inpost.paczkomat' ) { + return new Promise((resolve, reject) => { + resolve(); + }); + } + + if ( method == 'D2D.apaczka' || method == 'D2P.apaczka' || method == 'P2P.apaczka' || method == 'P2P.orlen' ) { + return retryUntilSuccess(() => { + return new Promise((resolve, reject) => { + const selectElement = document.getElementById('warehousebundle_shipment_preferences_content'); + selectElement.value = 'perfumy'; + const event = document.createEvent('HTMLEvents'); + event.initEvent('change', true, false); + selectElement.dispatchEvent(event); + resolve(); + }); + }); + } +} + +function setPackageDimmensions(length, width, height) { + + return retryUntilSuccess(() => { + + return new Promise((resolve, reject) => { + + const lengthElement = document.getElementById('warehousebundle_shipment_preferences_dimensions_length'); + const widthElement = document.getElementById('warehousebundle_shipment_preferences_dimensions_width'); + const heightElement = document.getElementById('warehousebundle_shipment_preferences_dimensions_height'); + if (lengthElement && widthElement && heightElement) { + lengthElement.value = length; + const lengthEvent = document.createEvent('HTMLEvents'); + lengthEvent.initEvent('change', true, false); + lengthElement.dispatchEvent(lengthEvent); + + widthElement.value = width; + const widthEvent = document.createEvent('HTMLEvents'); + widthEvent.initEvent('change', true, false); + widthElement.dispatchEvent(widthEvent); + + heightElement.value = height; + const heightEvent = document.createEvent('HTMLEvents'); + heightEvent.initEvent('change', true, false); + heightElement.dispatchEvent(heightEvent); + } + resolve(); + }); + }); +} + +function selectPackageType(method) { + return retryUntilSuccess(() => { + return new Promise((resolve, reject) => { + + if ( method == 'kurier.dpd' ) + { + //warehousebundle_shipment_carrierAccount + const selectElement = document.getElementById('warehousebundle_shipment_carrierAccount'); + selectElement.value = 3; + const event = document.createEvent('HTMLEvents'); + event.initEvent('change', true, false); + selectElement.dispatchEvent(event); + resolve(); + } + else if ( method == 'inpost.paczkomat' ) + { + //warehousebundle_shipment_carrierAccount + const selectElement = document.getElementById('warehousebundle_shipment_carrierAccount'); + selectElement.value = 6; + const event = document.createEvent('HTMLEvents'); + event.initEvent('change', true, false); + selectElement.dispatchEvent(event); + + // settimeout + setTimeout(() => { + setTimeout(() => { + const selects = Array.from(document.querySelectorAll('select#warehousebundle_shipment_method')) + .filter(select => select.offsetParent !== null); // widoczny, nie aria-hidden + + if (selects.length > 0) { + const activeSelect = selects[0]; + activeSelect.value = 'inpost_locker_standard'; + const event2 = document.createEvent('HTMLEvents'); + event2.initEvent('change', true, false); + activeSelect.dispatchEvent(event2); + } else { + console.warn('Nie znaleziono widocznego selecta shipment_method'); + } + }, 1000); + resolve(); + }, 1000); + } + // else if ( method == 'P2P.orlen' ) { + + // //warehousebundle_shipment_carrierAccount + // const selectElement = document.getElementById('warehousebundle_shipment_carrierAccount'); + // selectElement.value = 17; + // const event = document.createEvent('HTMLEvents'); + // event.initEvent('change', true, false); + // selectElement.dispatchEvent(event); + + // // settimeout + // setTimeout(() => { + // const selectElement2 = document.getElementById('warehousebundle_shipment_method'); + // selectElement2.value = 50; + // const event2 = document.createEvent('HTMLEvents'); + // event2.initEvent('change', true, false); + // selectElement2.dispatchEvent(event2); + + // // settimeout + // setTimeout(() => { + // const selectElement3 = document.getElementById('warehousebundle_shipment_preferences_packageType'); + // selectElement3.value = 'PACZKA'; + // const event3 = document.createEvent('HTMLEvents'); + // event3.initEvent('change', true, false); + // selectElement3.dispatchEvent(event3); + // resolve(); + + // }, 1000); + // }, 1000); + + // } else if ( method == 'D2P.apaczka' || method == 'P2P.apaczka' ) { + + // //warehousebundle_shipment_carrierAccount + // const selectElement = document.getElementById('warehousebundle_shipment_carrierAccount'); + // selectElement.value = 17; + // const event = document.createEvent('HTMLEvents'); + // event.initEvent('change', true, false); + // selectElement.dispatchEvent(event); + + // // settimeout + // setTimeout(() => { + // const selectElement2 = document.getElementById('warehousebundle_shipment_method'); + // selectElement2.value = 41; + // const event2 = document.createEvent('HTMLEvents'); + // event2.initEvent('change', true, false); + // selectElement2.dispatchEvent(event2); + + // // settimeout + // setTimeout(() => { + // const selectElement3 = document.getElementById('warehousebundle_shipment_preferences_packageType'); + // selectElement3.value = 'PACZKA'; + // const event3 = document.createEvent('HTMLEvents'); + // event3.initEvent('change', true, false); + // selectElement3.dispatchEvent(event3); + // resolve(); + + // }, 1000); + // }, 1000); + + + // } else if ( method == 'D2D.apaczka' ) { + + // const selectElement = document.getElementById('warehousebundle_shipment_carrierAccount'); + // selectElement.value = 17; + // const event = document.createEvent('HTMLEvents'); + // event.initEvent('change', true, false); + // selectElement.dispatchEvent(event); + + // // settimeout + // setTimeout(() => { + // const selectElement2 = document.getElementById('warehousebundle_shipment_method'); + // selectElement2.value = 42; + // const event2 = document.createEvent('HTMLEvents'); + // event2.initEvent('change', true, false); + // selectElement2.dispatchEvent(event2); + + // // settimeout + // setTimeout(() => { + // const selectElement3 = document.getElementById('warehousebundle_shipment_preferences_packageType'); + // selectElement3.value = 'PACZKA'; + // const event3 = document.createEvent('HTMLEvents'); + // event3.initEvent('change', true, false); + // selectElement3.dispatchEvent(event3); + // resolve(); + + // }, 1000); + // }, 1000); + + // } else { + // const selectElement = document.getElementById('warehousebundle_shipment_packageType'); + // if (selectElement) { + // selectElement.value = 'package'; + // const event = document.createEvent('HTMLEvents'); + // event.initEvent('change', true, false); + // selectElement.dispatchEvent(event); + // resolve(); + // } else { + // reject('Nie znaleziono elementu packageType'); + // } + // } + }); + }); +} + +function setShipmentMethod(method) { + if ( method == 'kurier.dpd' ) { + return new Promise((resolve, reject) => { + resolve(); + }); + } + return retryUntilSuccess(() => { + return new Promise((resolve, reject) => { + const methodElement = document.getElementById('warehousebundle_shipment_method'); + if (methodElement) { + methodElement.value = method; + const methodEvent = document.createEvent('HTMLEvents'); + methodEvent.initEvent('change', true, false); + methodElement.dispatchEvent(methodEvent); + resolve(); + } else { + reject('Nie znaleziono elementu shipment_method'); + } + }); + }); +} + +function setDropoffPoint(dropoffPoint) { + return retryUntilSuccess(() => { + return new Promise((resolve, reject) => { + const dropoffPointElement = document.getElementById('warehousebundle_shipment_preferences_dropoffPoint'); + if (dropoffPointElement) { + dropoffPointElement.value = dropoffPoint; + const dropoffPointEvent = document.createEvent('HTMLEvents'); + dropoffPointEvent.initEvent('change', true, false); + dropoffPointElement.dispatchEvent(dropoffPointEvent); + resolve(); + } else { + reject('Nie znaleziono elementu dropoffPoint'); + } + }); + }); +} + +function setParcelWeight(weight) { + return retryUntilSuccess(() => { + return new Promise((resolve, reject) => { + const weightElement = document.getElementById('warehousebundle_shipment_shipmentParcels_0_weight'); + if (weightElement) { + weightElement.value = weight; + const weightEvent = document.createEvent('HTMLEvents'); + weightEvent.initEvent('change', true, false); + weightElement.dispatchEvent(weightEvent); + resolve(); + } else { + reject('Nie znaleziono elementu shipmentParcels_0_weight'); + } + }); + }); +} + +function submitShipment() { + return retryUntilSuccess(() => { + return new Promise((resolve, reject) => { + const submitButton = document.getElementById('warehousebundle_shipment_buttons_submit'); + if (submitButton) { + alert( 'submit' ); + // submitButton.click(); + resolve(); + } else { + reject('Nie znaleziono przycisku submit'); + } + }); + }); +} \ No newline at end of file