From ee58c5db823312381fe6e6cba323cbc72ecacfaf Mon Sep 17 00:00:00 2001 From: Young Vigz Date: Mon, 7 Jul 2025 09:51:16 +0200 Subject: [PATCH] had to marge repos --- .gitignore | 14 + .../pandaGadzety/assets/css/calculator.css | 0 plugins/pandaGadzety/assets/css/delivery.css | 31 ++ .../pandaGadzety/assets/css/description.css | 31 ++ .../assets/css/hidden-add-to-cart.css | 12 + .../assets/css/labeling-description.css | 10 + plugins/pandaGadzety/assets/css/labeling.css | 8 + .../pandaGadzety/assets/js/archive-images.js | 17 + plugins/pandaGadzety/assets/js/calculator.js | 470 ++++++++++++++++++ .../pandaGadzety/assets/js/slider-images.js | 20 + .../panda-calculator-controller.php | 33 ++ .../panda-product-details-loader.php | 34 ++ .../controller/plugins-controller.php | 50 ++ .../plugins-controller-interface.php | 11 + plugins/pandaGadzety/pandaGadzety.php | 61 +++ plugins/pandaGadzety/readmy.md | 3 + .../repository/get_product_info.php | 88 ++++ plugins/pandaGadzety/uninstall.php | 1 + .../pandaGadzety/utils/create-database.php | 0 plugins/pandaGadzety/utils/delivery-tab.php | 104 ++++ .../information-about-labeling-mixed.php | 17 + .../utils/information-about-realization.php | 39 ++ .../utils/labeling-description-tab.php | 329 ++++++++++++ plugins/pandaGadzety/utils/labeling-tab.php | 63 +++ plugins/pandaGadzety/utils/load-file.php | 23 + .../pandaGadzety/utils/logistic-minimum.php | 36 ++ .../utils/modify-product-name.php | 41 ++ plugins/pandaGadzety/utils/notice.php | 38 ++ .../pandaGadzety/utils/product-calculator.php | 374 ++++++++++++++ .../utils/product-description-tab.php | 44 ++ plugins/pandaGadzety/view/calculator.html | 88 ++++ 31 files changed, 2090 insertions(+) create mode 100644 .gitignore create mode 100644 plugins/pandaGadzety/assets/css/calculator.css create mode 100644 plugins/pandaGadzety/assets/css/delivery.css create mode 100644 plugins/pandaGadzety/assets/css/description.css create mode 100644 plugins/pandaGadzety/assets/css/hidden-add-to-cart.css create mode 100644 plugins/pandaGadzety/assets/css/labeling-description.css create mode 100644 plugins/pandaGadzety/assets/css/labeling.css create mode 100644 plugins/pandaGadzety/assets/js/archive-images.js create mode 100644 plugins/pandaGadzety/assets/js/calculator.js create mode 100644 plugins/pandaGadzety/assets/js/slider-images.js create mode 100644 plugins/pandaGadzety/controller/panda-calculator-controller.php create mode 100644 plugins/pandaGadzety/controller/panda-product-details-loader.php create mode 100644 plugins/pandaGadzety/controller/plugins-controller.php create mode 100644 plugins/pandaGadzety/interface/plugins-controller-interface.php create mode 100644 plugins/pandaGadzety/pandaGadzety.php create mode 100644 plugins/pandaGadzety/readmy.md create mode 100644 plugins/pandaGadzety/repository/get_product_info.php create mode 100644 plugins/pandaGadzety/uninstall.php create mode 100644 plugins/pandaGadzety/utils/create-database.php create mode 100644 plugins/pandaGadzety/utils/delivery-tab.php create mode 100644 plugins/pandaGadzety/utils/information-about-labeling-mixed.php create mode 100644 plugins/pandaGadzety/utils/information-about-realization.php create mode 100644 plugins/pandaGadzety/utils/labeling-description-tab.php create mode 100644 plugins/pandaGadzety/utils/labeling-tab.php create mode 100644 plugins/pandaGadzety/utils/load-file.php create mode 100644 plugins/pandaGadzety/utils/logistic-minimum.php create mode 100644 plugins/pandaGadzety/utils/modify-product-name.php create mode 100644 plugins/pandaGadzety/utils/notice.php create mode 100644 plugins/pandaGadzety/utils/product-calculator.php create mode 100644 plugins/pandaGadzety/utils/product-description-tab.php create mode 100644 plugins/pandaGadzety/view/calculator.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a4b31a3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +* + +!.gitignore + +!plugins/ +!themes/ + +plugins/* +!plugins/pandaGadzety/ +!plugins/pandaGadzety/** + +themes/* +!themes/pandaTheme/ +!themes/pandaTheme/** diff --git a/plugins/pandaGadzety/assets/css/calculator.css b/plugins/pandaGadzety/assets/css/calculator.css new file mode 100644 index 0000000..e69de29 diff --git a/plugins/pandaGadzety/assets/css/delivery.css b/plugins/pandaGadzety/assets/css/delivery.css new file mode 100644 index 0000000..05e194c --- /dev/null +++ b/plugins/pandaGadzety/assets/css/delivery.css @@ -0,0 +1,31 @@ +#delivery-tab { + width: 100% +} + +#delivery-tab table { + width: 100% +} + +#delivery-tab table tr { + border: 1px solid #00b4e1; +} + +#delivery-tab table tr th { + background-color: #00b4e1; + color: white; + padding: 5px; +} + +#delivery-tab table tr td { + padding: 5px; +} + +#delivery-tab table tr th, #delivery-tab table tr td { + border: 1px solid #00b4e1; +} + +#delivery-tab h2 { + color: #00b4e1; + font-weight: bold; + margin-top: 20px; +} \ No newline at end of file diff --git a/plugins/pandaGadzety/assets/css/description.css b/plugins/pandaGadzety/assets/css/description.css new file mode 100644 index 0000000..9ee7d7a --- /dev/null +++ b/plugins/pandaGadzety/assets/css/description.css @@ -0,0 +1,31 @@ +#description-tab { + width: 100% +} + +#description-tab table { + width: 100% +} + +#description-tab table tr { + border: 1px solid #00b4e1; +} + +#description-tab table tr th { + background-color: #00b4e1; + color: white; + padding: 5px; +} + +#description-tab table tr td { + padding: 5px; +} + +#description-tab table tr th, #description-tab table tr td { + border: 1px solid #00b4e1; +} + +#description-tab h2 { + color: #00b4e1; + font-weight: bold; + margin-top: 20px; +} \ No newline at end of file diff --git a/plugins/pandaGadzety/assets/css/hidden-add-to-cart.css b/plugins/pandaGadzety/assets/css/hidden-add-to-cart.css new file mode 100644 index 0000000..acf0edf --- /dev/null +++ b/plugins/pandaGadzety/assets/css/hidden-add-to-cart.css @@ -0,0 +1,12 @@ +form.cart { + /* display: none; */ +} + +.wp-block-add-to-cart-form, .wc-block-add-to-cart-form, .wp-block-post-excerpt { + display: none; +} + +.summary > .price { + display: none; +} + diff --git a/plugins/pandaGadzety/assets/css/labeling-description.css b/plugins/pandaGadzety/assets/css/labeling-description.css new file mode 100644 index 0000000..925e28c --- /dev/null +++ b/plugins/pandaGadzety/assets/css/labeling-description.css @@ -0,0 +1,10 @@ +.labeling-description-box { + display: flex; + align-items: center; +} + +.labeling-description-box img { + width: 200px; + height: 200px; + padding: 20px; +} diff --git a/plugins/pandaGadzety/assets/css/labeling.css b/plugins/pandaGadzety/assets/css/labeling.css new file mode 100644 index 0000000..7e77851 --- /dev/null +++ b/plugins/pandaGadzety/assets/css/labeling.css @@ -0,0 +1,8 @@ +#labeling { + +} + +#labeling img { + width: 200px; + margin: 50px; +} \ No newline at end of file diff --git a/plugins/pandaGadzety/assets/js/archive-images.js b/plugins/pandaGadzety/assets/js/archive-images.js new file mode 100644 index 0000000..96d3448 --- /dev/null +++ b/plugins/pandaGadzety/assets/js/archive-images.js @@ -0,0 +1,17 @@ +document.addEventListener("DOMContentLoaded", () => { + if (!archiveImagesData || !archiveImagesData.products) return; + + const products = document.querySelectorAll(".product[data-sku]"); + + products.forEach(product => { + const sku = product.dataset.sku; + const productInfo = archiveImagesData.products[sku]; + + if (productInfo && productInfo.img) { + const img = product.querySelector("img") + img.src = productInfo.img; + img.srcset = productInfo.img; + img.alt = sku; + } + }); +}); diff --git a/plugins/pandaGadzety/assets/js/calculator.js b/plugins/pandaGadzety/assets/js/calculator.js new file mode 100644 index 0000000..daf79e2 --- /dev/null +++ b/plugins/pandaGadzety/assets/js/calculator.js @@ -0,0 +1,470 @@ +/** + * Class to display product labeling and pacing options + */ +class PandaCalculator { + + positions = {}; + productInfo; + productPrice; + + constructor(productInfo) { + this.productInfo = productInfo; + this.productPrice = calculatorScriptVariables.productInfo.productBaseInfo.price; + this.#decodeLabeling(); + + } + + init(optionDiv, technologyDiv, imageDiv, totalPrice) { + + document.querySelector("#attributes").innerHTML = this.#drawAttributes(); + document.querySelector(optionDiv).innerHTML = this.#drawPositionSelect(); + + this.#updatePrice(totalPrice); + + document.querySelector("#select_options").addEventListener("change", () => { + document.querySelector(technologyDiv).innerHTML = this.#drawTechnologySelect(); + + // this.#updatePrice(totalPrice); + + document.querySelector("#select_technology").addEventListener("change", () => { + if (document.querySelector("#select_technology").value != "brak") { + document.querySelector(imageDiv).innerHTML = this.#getImage(); + let value = this.#getSelectedOptions(); + if (value) { + + let maxColors = value.max_colors; + let dimensions = { "width": value.max_width, "height": value.max_height, "radius": value.max_radius } ; + this.#getColorNumber(maxColors); + this.#showDemission(dimensions); + + this.#updatePrice(totalPrice); + + const colorInput = document.querySelector("#color_number_input"); + if (colorInput) { + colorInput.addEventListener("change", () => { + this.#updatePrice(totalPrice); + }); + } + + + } + } + }) + + }) + + + document.querySelector("#quantity").addEventListener("change", (event) => { + this.#updatePrice(totalPrice); + }) + + //this.#updatePriceDefaultBDI(); + } + + #updatePrice(totalPrice) { + let sumPrice = this.#getPricingTable(); + document.querySelector(totalPrice).innerHTML = sumPrice; + document.getElementsByName("total_price")[0].value = sumPrice; + // document.getElementsByName("product_price")[0].value = this.productPrice; + } + + + #decodeLabeling() { + this.productInfo.labeling.forEach(element => { + this.positions[element.name] = this.positions[element.name] ? this.positions[element.name].concat(element) : [element] + }); + } + + #drawPositionSelect() { + var html = ""; + + return html; + } + + #drawTechnologySelect() { + var html = ""; + + var positionKey = document.querySelector("#select_options").value; + + if (positionKey != "brak") { + html += "

Technologia znakowania

"; + html += ""; + } + + return html; + } + + #drawAttributes() { + let html = ""; + + const attributes = this.productInfo.productBaseInfo.attributes || {}; + + if (Object.keys(attributes).length === 0) { + return html; + } + + Object.keys(attributes).forEach(key => { + html += ``; + }); + + return html; + } + + + #getImage() { + + var value = this.#getSelectedOptions(); + + if (value.image) { + var html = ""; + return html; + } + + return ""; + } + + + #getPricingTable() { + + let quantity = document.querySelector("#quantity").value ? document.querySelector("#quantity").value : 1; + let productPrice = this.#getBulkPrice(parseFloat(this.productPrice), quantity); + + document.getElementsByName("product_price")[0].value = productPrice; + document.querySelector("#product_price").innerHTML = productPrice; + + var unitPrice = 0; + var setupCost = 0; + + if (document.querySelector("#select_options") && document.querySelector("#select_technology")) { + + let value = this.#getSelectedOptions(); + + // console.log(value); + + var colorNumber = document.querySelector("#color_number_input") ? document.querySelector("#color_number_input").value : 1; + // console.log(colorNumber); + // console.log(value); + if (value.max_colors == 0 && Object.keys(value.pricing)[0] == "fullcolour") { + colorNumber = "fullcolour"; + } + + if (value.pricing && value.pricing[colorNumber]) { + + var unitPrice = value.pricing[colorNumber].unit_price + var setupCost = value.pricing[colorNumber].setup_cost + value.pricing[colorNumber].forEach((element) => { + if ( + parseInt(element.quantity_from) <= parseInt(quantity) + && parseInt(element.quantity_to) >= parseInt(quantity) + ) { + unitPrice = element.unit_price + setupCost = element.setup_cost + } + }) + + } + + } + + + document.querySelector("#price").innerHTML = unitPrice; + document.querySelector("#setup_price").innerHTML = setupCost; + document.getElementsByName("labeling_price")[0].value = unitPrice; + document.getElementsByName("setup_price")[0].value = setupCost; + let sum = (parseFloat(productPrice) * quantity) + (parseFloat(unitPrice) * quantity) + parseFloat(setupCost); + + return Math.round(sum * 100) / 100; + } + + + #getSelectedOptions() { + var positionKey = document.querySelector("#select_options").value; + var technologyKey = document.querySelector("#select_technology").value; + + // console.log(technologyKey); + // console.log(positionKey); + + if (technologyKey != "brak") { + + var position = this.positions[positionKey]; + + for (let index = 0; index < position.length; index++) { + if (position[index].technology == technologyKey) { + var value = position[index] + } + } + + return value; + } + + return null; + + + } + + #getColorNumber(maxColor) { + + + if (maxColor != 0) { + var html = `"; + } else { + var html = `"; + } + + document.querySelector("#color_number").innerHTML = html; + } + + #showDemission(dimensions) { + let demission = ""; + if (dimensions.radius == "0") { + demission += dimensions.width + "mm x " + dimensions.height + "mm"; + } else { + demission += dimensions.radius + "mm"; + } + + document.querySelector("#dimensions_name").innerHTML = "Wymiary nadruku:"; + document.querySelector("#dimensions").innerHTML = demission; + } + + #updatePriceDefaultBDI() { + let currencySymbol = document.querySelector('.woocommerce-Price-currencySymbol').innerHTML; + let priceBox = document.querySelector('.woocommerce-Price-amount'); + priceBox.innerHTML = " 0.00"; + + } + + #getBulkPrice(price, quantity) { + var newPrice = price; + if (price < 5) { + if (quantity >= 1 && quantity <= 9) { + newPrice = price + price * 0.36; + } else if (quantity >= 10 && quantity <= 249) { + newPrice = price - price * 0.31; + } else if (quantity >= 250 && quantity <= 999) { + newPrice = price - price * 0.37; + } else if (quantity >= 1000 && quantity <= 4999) { + newPrice = price - price * 0.42; + } else if (quantity >= 5000) { + newPrice = price - price * 0.47; + } + } else { + if (quantity >= 1 && quantity <= 9) { + newPrice = price; + } else if (quantity >= 10 && quantity <= 99) { + newPrice = price - price * 0.31; + } else if (quantity >= 100 && quantity <= 249) { + newPrice = price - price * 0.37; + } else if (quantity >= 250 && quantity <= 999) { + newPrice = price - price * 0.42; + } else if (quantity >= 1000) { + newPrice = price - price * 0.47; + } + } + + + newPrice = Math.round(newPrice * 100) / 100; + return newPrice; + } + +} + + +class ShowInformation { + constructor() { + let base = calculatorScriptVariables.productInfo.productBaseInfo + + let price = base.price; + //let currencySymbol = document.querySelector(".woocommerce-Price-currencySymbol").innerHTML; + //document.querySelector("bdi").innerHTML = price + currencySymbol; + + console.log(calculatorScriptVariables.productInfo) + + const invent = calculatorScriptVariables.productInfo.inventory + const attributes = document.getElementById("select_attributes_color") + if(!attributes) { + if(invent.length == 0) { + document.getElementById("stock").innerHTML = "Ilość w magazynie " + 0 + " szt." + document.getElementById("add_to_cart_button").disabled = true; + document.getElementById("add_to_cart_button").value = "Niedostępne"; + document.getElementById("add_to_cart_button").classList.add("unavailable"); + } + + invent.forEach(inv => { + if(inv.type === "central_stock") { + document.getElementById("stock").innerHTML = "Ilość w magazynie " + inv.amount + " szt." + if (inv.amount < 50) { + document.getElementById("add_to_cart_button").disabled = true; + document.getElementById("add_to_cart_button").value = "Niedostępne"; + document.getElementById("add_to_cart_button").classList.add("unavailable"); + } else { + document.getElementById("add_to_cart_button").disabled = false; + document.getElementById("add_to_cart_button").value = "Dodaj do koszyka"; + document.getElementById("add_to_cart_button").classList.remove("unavailable"); + } + + } + }) + } else { + const color = attributes.value; + const selectedColor = calculatorScriptVariables.productInfo.productBaseInfo.attributes.color.find(c => { + return c.attributes === color; + }); + + const sku = selectedColor.image.split('/').at(-1).split('.')[0] + const invent = calculatorScriptVariables.productInfo.inventory + + invent.forEach(inv => { + if(inv.type === "central_stock" && inv.sku == sku) { + document.getElementById("stock").innerHTML = "Ilość w magazynie " + inv.amount + " szt." + if (inv.amount < 50) { + document.getElementById("add_to_cart_button").disabled = true; + document.getElementById("add_to_cart_button").value = "Niedostępne"; + document.getElementById("add_to_cart_button").classList.add("unavailable"); + } else { + document.getElementById("add_to_cart_button").disabled = false; + document.getElementById("add_to_cart_button").value = "Dodaj do koszyka"; + document.getElementById("add_to_cart_button").classList.remove("unavailable"); + } + + } + }) + } + + const gallery = document.querySelector(".single-product__images"); + const images = calculatorScriptVariables.productInfo.productBaseInfo.images + + if(images) { + + images.forEach(img => { + const url = img.url; + + const imageElement = document.createElement("img"); + imageElement.src = url; + imageElement.alt = "Obraz produktu"; + imageElement.classList.add("product-image"); + + imageElement.addEventListener("click", () => { + const thumbnail = document.querySelector(".single-product__thumbnails img"); + thumbnail.src = url; + }) + + gallery.appendChild(imageElement); + }); + + + jQuery(function($) { + $('.single-product__images').slick({ + slidesToShow: images.length, + slidesToScroll: 1, + arrows: true, + infinite: true, + adaptiveHeight: false, + draggable: false, + swipe: false, + prevArrow: '', + nextArrow: '', + + }); + }); + + } + + const photo = base.primary_img; + if (photo) { + const thumbnailContainer = document.querySelector(".single-product__thumbnails"); + + const img = document.createElement("img"); + img.src = photo; + img.alt = "Podgląd produktu"; + img.style.borderRadius = "8px"; + + thumbnailContainer.appendChild(img); + } + + const nameDiv = document.getElementById("product-name") + const infoCard = document.querySelector(".product-info-card__header h2") + nameDiv.innerHTML = infoCard.innerHTML + + const selectColor = document.getElementById("select_attributes_color") + + if(selectColor) { + selectColor.addEventListener("change", this.colorChanged) + } + + } + + + colorChanged(e) { + const color = e.target.value; + + const selectedColor = calculatorScriptVariables.productInfo.productBaseInfo.attributes.color.find(c => { + return c.attributes === color; + }); + + if (!selectedColor) { + console.warn("Nie znaleziono koloru:", color); + return; + } + + const img = document.createElement("img"); + img.src = selectedColor.image; + img.alt = "Podgląd produktu"; + img.style.borderRadius = "8px"; + + const photoContainer = document.getElementById("attributes-photo"); + photoContainer.innerHTML = ""; + photoContainer.appendChild(img); + + const sku = selectedColor.image.split('/').at(-1).split('.')[0] + + const invent = calculatorScriptVariables.productInfo.inventory + + invent.forEach(inv => { + if(inv.type === "central_stock" && inv.sku == sku) { + document.getElementById("stock").innerHTML = "Ilość w magazynie " + inv.amount + " szt." + if (inv.amount < 50) { + document.getElementById("add_to_cart_button").disabled = true; + document.getElementById("add_to_cart_button").value = "Niedostępne"; + document.getElementById("add_to_cart_button").classList.add("unavailable"); + } else { + document.getElementById("add_to_cart_button").disabled = false; + document.getElementById("add_to_cart_button").value = "Dodaj do koszyka"; + document.getElementById("add_to_cart_button").classList.remove("unavailable"); + } + } + }) + } + +} + +document.addEventListener("DOMContentLoaded", function () { + var productCalculator = new PandaCalculator(calculatorScriptVariables.productInfo); + productCalculator.init("#options", "#technology", "#select_image", '#total_price'); + + var information = new ShowInformation(); +}); \ No newline at end of file diff --git a/plugins/pandaGadzety/assets/js/slider-images.js b/plugins/pandaGadzety/assets/js/slider-images.js new file mode 100644 index 0000000..72539d8 --- /dev/null +++ b/plugins/pandaGadzety/assets/js/slider-images.js @@ -0,0 +1,20 @@ +document.addEventListener("DOMContentLoaded", () => { + if (!archiveImagesData || !archiveImagesData.products) return; + + const slides = document.querySelectorAll("[data-sku]"); + + slides.forEach(slide => { + const sku = slide.dataset.sku; + const productInfo = archiveImagesData.products[sku]; + + if (productInfo && productInfo.img) { + const img = slide.querySelector("img"); + + if (img) { + img.src = productInfo.img; + img.srcset = productInfo.img; + img.alt = sku; + } + } + }); +}); diff --git a/plugins/pandaGadzety/controller/panda-calculator-controller.php b/plugins/pandaGadzety/controller/panda-calculator-controller.php new file mode 100644 index 0000000..050b849 --- /dev/null +++ b/plugins/pandaGadzety/controller/panda-calculator-controller.php @@ -0,0 +1,33 @@ +getProductInfo("AP800450"); + + var_dump($results['message']); + + + + } + +} \ No newline at end of file diff --git a/plugins/pandaGadzety/controller/panda-product-details-loader.php b/plugins/pandaGadzety/controller/panda-product-details-loader.php new file mode 100644 index 0000000..3238215 --- /dev/null +++ b/plugins/pandaGadzety/controller/panda-product-details-loader.php @@ -0,0 +1,34 @@ +load(); + // \add_action('woocommerce_before_single_product', [$this, 'load']); + + new Utils\DeliveryTab(); + new Utils\LabelingTab(); + new Utils\LabelingDescriptionTab(); + new Utils\ProductDescriptionTab(); + new Utils\PriceCalculator(); + } + + public function load() { + // global $product; + // $sku = $product->get_sku(); + + // if(!empty($sku)) { + + // } + + } + + + +} \ No newline at end of file diff --git a/plugins/pandaGadzety/controller/plugins-controller.php b/plugins/pandaGadzety/controller/plugins-controller.php new file mode 100644 index 0000000..e957e5b --- /dev/null +++ b/plugins/pandaGadzety/controller/plugins-controller.php @@ -0,0 +1,50 @@ +user = \wp_get_current_user(); + + \register_activation_hook(PLUGIN_URL, [$this, 'activationPlugins']); + \register_deactivation_hook(PLUGIN_URL, [$this, 'disablePlugins']); + \add_action('init', [$this, 'declarePlugins']); + + } + + public function activationPlugins(): void { + // Perform activation tasks if needed + } + + public function declarePlugins(): void { + if(\is_plugin_active(BASE_NAME . "/pandaGadzety.php")) { + + new Utils\InformationAboutLabeling(); + new Utils\InformationAboutLabelingMixed(); + new Controller\CalculatorController(); + new Controller\ProductDetailsController(); + new Utils\LogisticMinimum(350, 45); + new Utils\ShowMinimumPrice(); + + + // var_dump(wc()->session->get_session_cookie()); + } + } + + public function disablePlugins(): void { + // Perform activation tasks if needed + } + + public function updatePlugins(): void { + + } + +} \ No newline at end of file diff --git a/plugins/pandaGadzety/interface/plugins-controller-interface.php b/plugins/pandaGadzety/interface/plugins-controller-interface.php new file mode 100644 index 0000000..e24382b --- /dev/null +++ b/plugins/pandaGadzety/interface/plugins-controller-interface.php @@ -0,0 +1,11 @@ +serverUrl = $serverUrl; + } + + public function getProductInfo($sku) { + $args = [ + 'headers' => [ + 'content-type' => 'application/json', + 'api_key' => API_KEY + ], + 'body' => [ + "sku" => $sku + ] + ]; + $results = wp_remote_get($this->serverUrl . "/api/get_product_details", $args); + $results = json_decode($results['body'], true); + return $results; + } + + public function getDeliveryInfo($sku) { + $args = [ + 'headers' => [ + 'content-type' => 'application/json', + 'api_key' => API_KEY + ], + 'body' => [ + "sku" => $sku + ] + ]; + $results = wp_remote_get($this->serverUrl . "/api/get_product_details", $args); + + $results = json_decode($results['body'], true); + return $results['message']['inventory']; + } + + public function getLabelingInfo($sku) { + $args = [ + 'headers' => [ + 'content-type' => 'application/json', + 'api_key' => API_KEY + ], + 'body' => [ + "sku" => $sku + ] + ]; + $results = wp_remote_get($this->serverUrl . "/api/get_product_details", $args); + $results = json_decode($results['body'], true); + return $results['message']['labeling']; + } + + public function getLowestPrice($price) { + $args = [ + 'headers' => [ + 'content-type' => 'application/json', + 'api_key' => API_KEY + ], + 'body' => [ + "price" => $price + ] + ]; + $results = wp_remote_get($this->serverUrl . "/api/getLowestPrice", $args); + $results = json_decode($results['body'], true); + return $results['message']['lowestPrice']; + } + + public function getProductDescription($sku) { + $args = [ + 'headers' => [ + 'content-type' => 'application/json', + 'api_key' => API_KEY + ], + 'body' => [ + "sku" => $sku + ] + ]; + $results = wp_remote_get($this->serverUrl . "/api/get_product_description", $args); + $results = json_decode($results['body'], true); + return $results['message']; + } + +} diff --git a/plugins/pandaGadzety/uninstall.php b/plugins/pandaGadzety/uninstall.php new file mode 100644 index 0000000..b3d9bbc --- /dev/null +++ b/plugins/pandaGadzety/uninstall.php @@ -0,0 +1 @@ + __('Informacja o dostępności', 'pandaGadzety'), + 'priority' => 50, + 'callback' => [$this, 'customTabData'] + ); + + return $tabs; + + } + + function customTabData() + { + global $product; + $sku = $product->get_sku(); + + \wp_enqueue_style("deliveryStyle", plugins_url("/pandaGadzety/assets/css/delivery.css")); + + $product_repository = new Repository\ProductRepository(SERVER_URL); + $results = $product_repository->getDeliveryInfo($sku); + + $new_tab = []; + foreach ($results as $data) { + if($data['type'] == "central_stock") { + $new_tab[$data['sku']]["central_stock"] = [ + "amount" => $data['amount'], + "arrival_date" => $data['arrival_date'] + ]; + } + if($data['type'] == "external_stock") { + $new_tab[$data['sku']]["external_stock"] = [ + "amount" => $data['amount'], + "arrival_date" => $data['arrival_date'] + ]; + } + if($data['type'] == "incoming_to_central_stock") { + $new_tab[$data['sku']]["incoming_to_central_stock"] = [ + "amount" => $data['amount'], + "arrival_date" => $data['arrival_date'] + ]; + } + if($data['type'] == "incoming_to_external_stock") { + $new_tab[$data['sku']]["incoming_to_external_stock"] = [ + "amount" => $data['amount'], + "arrival_date" => $data['arrival_date'] + ]; + } + + } + + $tab = "
"; + $tab .= ""; + $tab .= ""; + $tab .= ""; + $tab .= ""; + $tab .= ""; + $tab .= ""; + $tab .= ""; + $tab .= ""; + $tab .= ""; + $tab .= ""; + $tab .= ""; + $tab .= ""; + $tab .= ""; + foreach ($new_tab as $key => $value) { + $tab .= ""; + $tab .= ""; + $tab .= ""; + $tab .= ""; + $tab .= ""; + $tab .= ""; + $tab .= ""; + + } + $tab .= "
SKUMagazyn centralnyMagazyn zewnętrzny
SKUNa magazynieNadchodząca dostawa na magazynDostępne w ciągu 6-8 dniNadchodząca dostawa na magazyn
" . $key . "" . $value["central_stock"]['amount'] . " szt."; + $tab .= !empty($value["incoming_to_central_stock"]['amount']) ? $value["incoming_to_central_stock"]['amount'] . "szt.": "0 szt."; + $tab .= "". (!empty($value["incoming_to_central_stock"]['arrival_date']) ? $value["incoming_to_central_stock"]['arrival_date'] : "") .""; + $tab .= ""; + $tab .= !empty($value["external_stock"]['amount']) ? $value["external_stock"]['amount'] . "szt.": "0 szt."; + $tab .= ""; + $tab .= !empty($value["incoming_to_external_stock"]['amount']) ? $value["incoming_to_external_stock"]['amount'] . "szt.": "0 szt."; + $tab .= "" . (!empty($value["incoming_to_external_stock"]['arrival_date']) ? $value["incoming_to_external_stock"]['arrival_date'] : "") . ""; + $tab .= "
"; + + $tab .= "
"; + + + echo $tab; + } + +} \ No newline at end of file diff --git a/plugins/pandaGadzety/utils/information-about-labeling-mixed.php b/plugins/pandaGadzety/utils/information-about-labeling-mixed.php new file mode 100644 index 0000000..61bfd3b --- /dev/null +++ b/plugins/pandaGadzety/utils/information-about-labeling-mixed.php @@ -0,0 +1,17 @@ +' . $title . ''; + + } +} diff --git a/plugins/pandaGadzety/utils/information-about-realization.php b/plugins/pandaGadzety/utils/information-about-realization.php new file mode 100644 index 0000000..5fa72bc --- /dev/null +++ b/plugins/pandaGadzety/utils/information-about-realization.php @@ -0,0 +1,39 @@ +'; + $html .= ' + + Do realizacji zamówienia Foxstudio przystąpi wówczas gdy:
+
+ Klient prześle wiadomość e-mail, poprzez sklep internetowy lub osobiście przekaże pełne zamówienie ze wszystkimi wytycznymi, szczegółami zamówienia dotyczącymi danego produktu (m.in. wypisaną rozmiarówka, wybraną odzieżą wraz z krojami, kolorystyką, wielkością nadruków, umiejscowieniem nadruków) oraz poprawnie przygotowanymi plikami graficznych do znakowania (w przypadku znakowania sitodrukiem, termotransferem, haftem komputerowym, folią flex, flexem lateksowym niezbędne są pliki graficzne zapisane wektorowo),
+
+ W przypadku znakowania Produktu Klient zaakceptuje sposób  i ułożenie znakowania na Produkcie.
+
+ Termin realizacji podany przy wcześniejszej wycenie będzie liczony od momentu spełnienia wszystkich przesłanek określonych w ppkt 3.1. Jeżeli termin realizacji nie został podany to przyjmuje się następujące ramy czasowe trwania w zależności od rodzaju produktu i znakowania:
+ a) Produkty nieznakowane do od 3 do 7 dni roboczych,
+ b) Produkty znakowane do od 7 do 14 dni roboczych.
+ Foxstudio zastrzega możliwość wydłużenia terminów realizacji w przypadku zaistnienia przyczyn niezależnych od Foxstudio.
+
+ Potwierdzenie złożenia oraz przyjęcia do realizacji Zamówienia zostanie przesłane Klientowi przez Foxstudio w formie wiadomości e-mail z poziomu domeny foxstudio.eu lub Pandagadzety.pl.
+
+ Przed złożeniem zamówienia Klient zobowiązany jest do zapoznania się z treścią niniejszego Regulaminu. Złożenie zamówienia w firmie Foxstudio oznacza, iż Klient rozumie i akceptuje wszystkie postanowienia Regulaminu + + '; + + $html .= ''; + + return $html; + + } +} \ No newline at end of file diff --git a/plugins/pandaGadzety/utils/labeling-description-tab.php b/plugins/pandaGadzety/utils/labeling-description-tab.php new file mode 100644 index 0000000..8e7a0e4 --- /dev/null +++ b/plugins/pandaGadzety/utils/labeling-description-tab.php @@ -0,0 +1,329 @@ + __('Opis znakowań', 'pandaGadzety'), + 'priority' => 50, + 'callback' => [$this, 'customTabData'] + ); + + return $tabs; + + } + + public function customTabData() + { + \wp_enqueue_style("descriptionStyle", plugins_url("/pandaGadzety/assets/css/labeling-description.css")); + // https://andapresent.com/pl/pl/pages/printing + echo " +
+ +
+

Haft

+

+ Haft jest używany do zdobienia wyrobów tekstylnych, dzięki czemu uzyskujemy trwałe i wysokiej jakości nadruki za pomocą automatycznej hafciarki, która nakłada nitkę przez ściegi igłowe. Dopasowanie Pantone nie jest możliwe, ze względu na ograniczone kolory nici. +
+ Kod: BR +

+
+
+ + + + +
+ +
+

Nadruk ceramiczny

+

+ Druk ceramiczny służy do oznaczania kubków, szklanek i niektórych przedmiotów metalowych za pomocą specjalnych farb ceramicznych wypalanych w wysokiej temperaturze. Etykieta jest nakładana na produkt podobnie jak druk transferowy, a następnie wypalana w piecu. +
+ Kod: C +

+
+
+ + + + +
+ +
+

Cyfrowa wkładka papierowa

+

+ Druk cyfrowy służy do nadrukowywania produktów papierowych i wkładów papierowych w jakości fotograficznej. Wkładki papierowe mogą być produkowane w różnych rozmiarach i kształtach. +
+ Kod: DG +

+
+
+ + + +
+ +
+

Epoxy

+

+ Epoxy doming jest unikalną technologią druku, z wykorzystaniem pełnokolorowych zadrukowanych naklejek pokrytych 2-składnikową żywicą. W rezultacie obrobiona naklejka będzie miała trójwymiarowy wygląd. Logo z powierzchnią epoksydową może być produkowane w niestandardowych kształtach i jest odporne na promienie UV. +
+ Kod: DO +

+
+
+ + + +
+ +
+

Transfer cyfrowy

+

+ Transfer cyfrowy to nowoczesna, full kolorowa alternatywa dla tradycyjnego druku transferowego. Projekt jest drukowany w jakości fotograficznej na papierze transferowym za pomocą specjalnej drukarki cyfrowej, a następnie nakładany na produkt za pomocą prasy termicznej. Nasza technologia transferu cyfrowego nie ma ograniczeń co do wielkości ani kształtu nadruków. +
+ Kod: DT +

+
+
+ + + +
+ +
+

Transfer cyfrowy na tekstyliach

+

+ Transfer cyfrowy na tekstyliach to odmiana transferu cyfrowego zoptymalizowana pod kątem tworzenia trwałych i odpornych nadruków na odzieży i akcesoriach tekstylnych. Aby zmaksymalizować trwałość nadruku, pierz odzież w temperaturze poniżej 40 stopni Celsjusza. +
+ Kod: DTT +

+
+
+ + +
+ +
+

Grawer

+

+ Grawerowanie wykorzystuje lasery do znakowania produktu. Powierzchnia praktycznie spala się podczas procesu tworzenia logo. Nawet małe logo można wydrukować dokładnie. Grawerowanie ma zastosowanie do metalu, drewna, szkła i niektórych produktów z tworzyw sztucznych. +
+ Kod: E +

+
+
+ + + +
+ +
+

Grawer rotacyjny

+

+ Grawerowanie rotacyjne wykorzystuje laser do znakowania powierzchni produktów cylindrycznych. Za pomocą specjalnego urządzenia rotacyjnego grawerowany produkt jest obracany podczas procesu drukowania, co pozwala na pokrycie dużego nadruku. Grawerowanie rotacyjne ma zastosowanie do metalu, drewna, bambusa, szkła i niektórych wyrobów ceramicznych. +
+ Kod: ER +

+
+
+ + + +
+ +
+

Tłoczenie

+

+ Wytłaczanie to elegancki proces, który zmienia powierzchnię wytłoczonego materiału, tworząc wrażenie 3D. Wrażenie to uzyskuje się poprzez wciśnięcie specjalnie wykonanej matrycy na powierzchnię produktu. +
+ Kod: O +

+
+
+ + + +
+ +
+

Nadruk atramentowy

+

+ Nadruk atramentowy służy do zadrukowywania płaskich powierzchni w pełnym kolorze za pomocą specjalnej szybkiej drukarki atramentowej. Ponieważ nadruk atramentowy nie wykorzystuje białych atramentów, kolory nadruku mogą być efektem koloru bazowego produktu. Druk atramentowy ma zastosowanie na materiałach porowatych, takich jak papier, naturalny bambus i drewno. +
+ Kod: OP +

+
+
+ + + +
+ +
+

Tampodruk

+

+ Tampodruk to najpopularniejsza, tradycyjna metoda znakowania atramentem. Ta technologia wykorzystuje podkładkę silikonową do przenoszenia atramentu na przedmiot z drobnymi detalami i wysoką dokładnością, stosowaną do szerokiej gamy materiałów. Tampodruk umożliwia etykietowanie zakrzywionych powierzchni. +
+ Kod: P +

+
+
+ + + +
+ +
+

Kolorowy grawer

+

+ Kolorowy grawer to specjalna technologia, wykorzystująca promienie laserowe o różnych długościach fali, aby uzyskać kolorowe nadruki na przedmiotach metalowych, bez użycia barwników i chemikaliów. +
+ Kod: RE +

+
+
+ + + +
+ +
+

Cylindryczny sitodruk

+

+ Rotacyjny sitodruk to specjalny rodzaj sitodruku do etykietowania butelek. Rotacyjny maszyna sitodrukowa obraca produkt równolegle z sitem, co powoduje ciągłe drukowanie na całej powierzchni produktu. +
+ Kod: RS +

+
+
+ + + +
+ +
+

Nadruk rotacyjny UV Led

+

+ Druk rotacyjny UV LED to cyfrowy, pełnokolorowy proces znakowania w celu tworzenia nadruków o jakości fotograficznej bezpośrednio na powierzchni przedmiotów cylindrycznych i stożkowych, co pozwala na pokrycie przedmiotu dużym nadrukiem. Rotacyjne nadruki UV LED są pokryte przezroczystym lakierem, co zapewnia wyjątkowy wygląd i dodatkową trwałość. +
+ Kod: RUV +

+
+
+ + + +
+ +
+

Sitodruk

+

+ Sitodruk jest tradycyjnym, opartym na farbach procesem zdobienia (dla produktów płaskich lub spłaszczanych) o wysokiej trwałości i dokładności kolorów. Podczas procesu sitodruku farba jest bezpośrednio rozprowadzana po powierzchni sita, a następnie utrwalana za pomocą obróbki cieplnej. +
+ Kod: S +

+
+
+ + + +
+ +
+

Sublimacja

+

+ Druk sublimacyjny to pełnokolorowa, cyfrowa technika zdobienia z fotograficzną jakością. Wzory drukowane są specjalnym tuszem na papierze transferowym, a następnie wprasowywane na gorąco w powierzchnię produktu. Sublimacja ma zastosowanie do produktów poliestrowych w jasnych kolorach lub powierzchniach przystosowanych pod sublimację. +
+ Kod: SU +

+
+
+ + + +
+ +
+

Transfer

+

+ Druk transferowy opiera się na tradycyjnym sitodruku, jednak zamiast bezpośredniego drukowania na materiale, projekt jest drukowany na papierze transferowym, a następnie wgrzewany za pomocą prasy termicznej. Druk transferowy ma zastosowanie do szerokiej gamy produktów i ma kilka zalet w porównaniu z sitodrukiem. +
+ Kod: T +

+
+
+ + + +
+ +
+

Technologia UV LED

+

+ Druk UV LED jest pełnokolorowym, cyfrowym procesem zdobienia wykorzystującym utwardzane promieniowaniem UV atramenty. Loga są drukowane bezpośrednio na powierzchni produktu w wysokiej rozdzielczości, dając niemalże efekt fotograficzny. +
+ Kod: UV +

+
+
+ + + +
+ +
+

Vision Film druk

+

+ Druk Vision Film jest specjalną techniką druku szkieł okularów przeciwsłonecznych. Podczas tego procesu nakłada się cyfrowo nadrukowaną i perforowaną folię, umożliwiając wysoki stopień personalizacji. +
+ Kod: VF +

+
+
+ + + +
+ +
+

Winylowa naklejka

+

+ Naklejki winylowe są cyfrowo drukowane w full kolorze. Są to naklejki samoprzylepne przeznaczone do różnych w tym trudnych do drukowania produktów. Mogą być produkowane w różnych rozmiarach i kształtach. +
+ Kod: VS +

+
+
+ + + +
+ +
+

Transfer na białej ceramice

+

+ Specjalna technologia znakowania full kolor dla białych, ceramicznych produktów, w oparciu o technologie transferu. +
+ Kod: WPC +

+
+
+ + "; + } + +} \ No newline at end of file diff --git a/plugins/pandaGadzety/utils/labeling-tab.php b/plugins/pandaGadzety/utils/labeling-tab.php new file mode 100644 index 0000000..7d3030f --- /dev/null +++ b/plugins/pandaGadzety/utils/labeling-tab.php @@ -0,0 +1,63 @@ + __('Tabela znakowań', 'pandaGadzety'), + 'priority' => 50, + 'callback' => [$this, 'customTabData'] + ); + + return $tabs; + + } + + function customTabData() + { + global $product; + \wp_enqueue_style("labelingStyle", plugins_url("/pandaGadzety/assets/css/labeling.css")); + $sku = $product->get_sku(); + $product_repository = new Repository\ProductRepository(SERVER_URL); + $results = $product_repository->getLabelingInfo($sku); + // The new tab content + + $html = "
"; + $html .= ""; + foreach ($results as $data) { + $html .= $this->get_labeling_block($data['image'], $data['technology'], $data['name']); + } + $html .= "
"; + $html .= "
"; + + echo $html; + } + + public function get_labeling_block($img, $technology, $position) { + $html = ""; + $html .= ""; + $html .= ""; + $html .= "Technologia: ". $technology."
"; + $html .= "Pozycja: ". $position.""; + $html .= ""; + $html .= ""; + // $html = "
"; + // $html .= "
"; + // $html .= "
"; + // $html .= "

Technologia: ". $technology."

"; + // $html .= "
"; + // $html .= "
"; + + return $html; + } + +} \ No newline at end of file diff --git a/plugins/pandaGadzety/utils/load-file.php b/plugins/pandaGadzety/utils/load-file.php new file mode 100644 index 0000000..a3ab685 --- /dev/null +++ b/plugins/pandaGadzety/utils/load-file.php @@ -0,0 +1,23 @@ +minimumOrderPrice = $minimumOrderPrice; + $this->fee = $fee; + \add_action('woocommerce_cart_calculate_fees', [$this, 'wc_add_surcharge']); + + } + + function wc_add_surcharge($cart) + { + $total_price = 0; + + foreach ($cart->get_cart() as $cart_item) { + if (isset($cart_item['custom_data']['technology'])) { + $price = $cart_item['data']->get_price(); + $quantity = $cart_item['quantity']; + + $total_price += $price * $quantity; + } + } + + if ($total_price < $this->minimumOrderPrice && $total_price > 0): + $cart->add_fee('Minimum logistyczne (dla zamówień poniżej 350 zł)', $this->fee); + endif; + + } +} diff --git a/plugins/pandaGadzety/utils/modify-product-name.php b/plugins/pandaGadzety/utils/modify-product-name.php new file mode 100644 index 0000000..2aef587 --- /dev/null +++ b/plugins/pandaGadzety/utils/modify-product-name.php @@ -0,0 +1,41 @@ +get_sku(); + $price = $product->get_price(); + $price = $this->getLowestPrice($price); + echo '

' . get_the_title() . '

od ' . $price . ' zł

'; + + + } + + private function getLowestPrice($price) { + + $productRepository = new ProductRepository(SERVER_URL); + $price = $productRepository->getLowestPrice($price); + return $price; + } + +} diff --git a/plugins/pandaGadzety/utils/notice.php b/plugins/pandaGadzety/utils/notice.php new file mode 100644 index 0000000..1cd4481 --- /dev/null +++ b/plugins/pandaGadzety/utils/notice.php @@ -0,0 +1,38 @@ +displayNotice('success', $title); + } + + public function noticeWarning($title) + { + return $this->displayNotice('warning', $title); + } + + public function noticeError($title) + { + return $this->displayNotice('error', $title); + } + + public function noticeInfo($title) + { + return $this->displayNotice('info', $title); + } + + private function displayNotice($type, $title) + { + return wc_print_notice($title, $type); + // return ' + //
+ //

'. esc_html($title) .'

+ //
+ // '; + } + +} \ No newline at end of file diff --git a/plugins/pandaGadzety/utils/product-calculator.php b/plugins/pandaGadzety/utils/product-calculator.php new file mode 100644 index 0000000..3dcbb07 --- /dev/null +++ b/plugins/pandaGadzety/utils/product-calculator.php @@ -0,0 +1,374 @@ +productRepository = new Repository\ProductRepository(SERVER_URL); + + + + add_action('woocommerce_init', [$this, 'ensureWooSession']); + + + add_action('wp_enqueue_scripts', [$this, 'loadArchiveImages']); + + + // Calculator + add_filter('woocommerce_single_product_summary', [$this, 'calculatorView']); + + add_action('template_redirect', [$this, 'addToCart']); + add_action('woocommerce_before_single_product', [$this, 'addToCart']); + + add_action('woocommerce_before_calculate_totals', [$this, 'updatePrice'], 10); + + // Show custom data + add_filter('woocommerce_get_item_data', [$this, 'showCustomData'], 10, 3); + add_action('woocommerce_checkout_create_order_line_item', [$this, 'wdm_add_custom_order_line_item_meta'], 10, 4); + + // Remove default add to cart + remove_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart'); + remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30); + + // Add custom styles + \wp_enqueue_style('hidden-add-to-cart', "/wp-content/plugins/pandaGadzety/assets/css/hidden-add-to-cart.css"); + + } + + function wdm_add_custom_order_line_item_meta($item, $cart_item_key, $values, $order) + { + if (array_key_exists('custom_data', $values)) { + + if(!empty($values['custom_data']['option'])) { + $item->add_meta_data('option', $values['custom_data']['option']); + } + + if(!empty($values['custom_data']['technology'])) { + $item->add_meta_data('Technologia', $values['custom_data']['technology']); + } + + if(!empty($values['custom_data']['labeling_price'])) { + $item->add_meta_data('Cena znakowania', $values['custom_data']['labeling_price']); + } + + if(!empty($values['custom_data']['setup_price'])) { + $item->add_meta_data('Cena przygotowania', $values['custom_data']['setup_price']); + } + + if(!empty($values['custom_data']['product_price'])) { + $item->add_meta_data('Cena produktu', $values['custom_data']['product_price']); + } + if(!empty($values['custom_data']['colors'])) { + $item->add_meta_data('Ilość kolorów', $values['custom_data']['colors']); + } + + if(!empty($values['custom_data']['photo'])) { + $item->add_meta_data('Zdjęcie nadruku', \wp_get_attachment_image($values['custom_data']['photo'], array(800, 600))); + } + + } + } + + public function ensureWooSession() { + if (!wc()->session->has_session()) { + wc()->session->set_customer_session_cookie(true); + } + } + + public function loadArchiveImages() { + + $skus = []; + + global $wp_query; + foreach ( $wp_query->posts as $post ) { + $p = wc_get_product( $post->ID ); + if ( $p && $p->get_sku() ) { + $skus[] = $p->get_sku(); + } + } + + + + if ( WC()->cart ) { + foreach ( WC()->cart->get_cart() as $cart_item ) { + $p = $cart_item['data']; + if ( $p && $p->get_sku() ) { + $skus[] = $p->get_sku(); + } + } + } + + + $skus = array_unique( $skus ); + + + $productData = []; + foreach ( $skus as $sku ) { + try { + $info = $this->productRepository->getProductInfo( $sku ); + if ( ! empty( $info['message'] ) ) { + $productData[ $sku ] = [ + 'img' => $info['message']['productBaseInfo']['primary_img'] ?? null, + ]; + } + } catch ( \Throwable $th ) {} + } + + + wp_enqueue_script( + 'archive-images-js', + plugins_url( '/pandaGadzety/assets/js/archive-images.js' ), + [ 'wc-cart-fragments' ], + null, + true + ); + wp_localize_script( 'archive-images-js', 'archiveImagesData', [ + 'products' => $productData, + ] ); + } + + public function addToCart() { + global $post; + + if($_SERVER['REQUEST_METHOD'] == 'POST') { + + // $item_data['custom_data']['new_price'] = 99; + // $item_data['custom_data']['color'] = 'red'; + // $item_data['custom_data']['uuid'] = uniqid(); + + $product = wc_get_product($post->ID); + + if (!$product) { + wc_add_notice('Nie znaleziono produktu', 'error'); + return; + } + + $itemData = []; + + if(!empty($_POST['option'])) { + $itemData['custom_data']['option'] = $_POST['option']; + } + + if(!empty($_POST['technology'])) { + $itemData['custom_data']['technology'] = $_POST['technology']; + } + + if(!empty($_POST['quantity'])) { + $itemData['custom_data']['quantity'] = $_POST['quantity']; + } + + if(!empty($_POST['labeling_price'])) { + $itemData['custom_data']['labeling_price'] = $_POST['labeling_price']; + } else { + $itemData['custom_data']['labeling_price'] = 0; + } + + if(!empty($_POST['setup_price'])) { + $itemData['custom_data']['setup_price'] = $_POST['setup_price']; + } else { + $itemData['custom_data']['setup_price'] = 0; + } + + if(!empty($_POST['colors'])) { + $itemData['custom_data']['colors'] = $_POST['colors']; + } else { + $itemData['custom_data']['colors'] = 0; + } + + if(!empty($_FILES['photo'])) { + $itemData['custom_data']['photo'] = $this->uploadFile('photo', $product->get_id()); + } else { + $itemData['custom_data']['photo'] = null; + } + + + $itemData['custom_data']['product_price'] = $_POST['product_price']; + + $itemData['custom_data']['total_price'] = floatval($_POST['product_price']) + floatval($_POST['labeling_price']); + + $attributes = []; + if(!empty($_POST['attributes'])) { + foreach ($_POST['attributes'] as $key => $value) { + $attributes['attribute_' . $key] = $value; + wc_add_notice('Błąd podczas dodawania do koszyka', 'error'); + } + } + + + try { + $cart_item_key = WC()->cart->add_to_cart( + $product->get_id(), + $_POST['quantity'], + 0, + $attributes, + $itemData + ); + + if ($cart_item_key) { + wp_redirect(wc_get_cart_url()); + exit; + } else { + wc_add_notice('Błąd podczas dodawania do koszyka', 'error'); + } + } catch (\Throwable $th) { + wc_add_notice('Wystąpił błąd: ' . $th->getMessage(), 'error'); + } + + } + } + + public function updatePrice($cart) { + if (is_admin() && !defined('DOING_AJAX')) + return; + + if (did_action('woocommerce_before_calculate_totals') >= 2) + return; + + foreach ($cart->get_cart() as $cart_item) { + if (isset($cart_item['custom_data']['total_price'])) { + $setup_price = !empty($cart_item['custom_data']['setup_price']) ? $cart_item['custom_data']['setup_price']: 0; + $price = $setup_price / $cart_item['quantity'] + $cart_item['custom_data']['total_price']; + // TODO: calculate data after price update; + $cart_item['data']->set_price($price); + } + } + } + + public function showCustomData($item_data, $custom_data) + { + // var_dump($custom_data); + if(!empty($custom_data['custom_data']['option'])) { + $item_data[] = [ + 'key' => "Pozycja znakowania", + 'value' => wc_clean($custom_data['custom_data']['option']), + ]; + } + if(!empty($custom_data['custom_data']['technology'])) { + $item_data[] = [ + 'key' => "Technologia znakowania", + 'value' => wc_clean($custom_data['custom_data']['technology']), + ]; + } + // if(!empty($custom_data['custom_data']['quantity'])) { + // $item_data[] = [ + // 'key' => "Ilość", + // 'value' => wc_clean($custom_data['custom_data']['quantity']), + // ]; + // } + if(!empty($custom_data['custom_data']['labeling_price'])) { + $item_data[] = [ + 'key' => "Cena znakowania", + 'value' => wc_clean($custom_data['custom_data']['labeling_price']), + ]; + } + if(!empty($custom_data['custom_data']['setup_price'])) { + $item_data[] = [ + 'key' => "Koszt przygotowania", + 'value' => wc_clean($custom_data['custom_data']['setup_price']), + ]; + } + + /*if(!empty($custom_data['custom_data']['product_price'])) { + $item_data[] = [ + 'key' => "Cena produktu", + 'value' => wc_clean($custom_data['custom_data']['product_price']), + ]; + }*/ + + if(!empty($custom_data['custom_data']['photo'])) { + $attachment_id = $custom_data['custom_data']['photo']; + + if (is_numeric($attachment_id)) { + $image_html = wp_get_attachment_image($attachment_id, array(800, 600)); + $item_data[] = [ + 'key' => "Zdjęcie nadruku", + 'value' => $image_html, + ]; + } else { + $item_data[] = [ + 'key' => "Zdjęcie nadruku", + 'value' => 'Brak przesłanego pliku', + ]; + } + } + + if(!empty($custom_data['custom_data']['color'])) { + $item_data[] = [ + 'key' => "Kolor", + 'value' => wc_clean($custom_data['custom_data']['color']), + ]; + } + + if(!empty($custom_data['custom_data']['colors'])) { + $item_data[] = [ + 'key' => "Ilość kolorów", + 'value' => wc_clean($custom_data['custom_data']['colors']), + ]; + } + // if(!empty($custom_data['custom_data']['total_price'])) { + // $item_data[] = [ + // 'key' => "Suma", + // 'value' => wc_clean($custom_data['custom_data']['total_price']), + // ]; + // } + + return $item_data; + + } + + + public function calculatorView() + { + global $product; + + $productInfo = $this->productRepository->getProductInfo($product->get_sku()); + if(!empty($productInfo)) { + $productInfo = $productInfo['message']; + + \wp_enqueue_script("calculatorScript", plugins_url("/pandaGadzety/assets/js/calculator.js")); + wp_localize_script('calculatorScript', 'calculatorScriptVariables', array( + 'productInfo' => $productInfo + ) + ); + + \wp_enqueue_style("calculatorStyle", plugins_url("/pandaGadzety/assets/css/calculator.css")); + + $html = file_get_contents("wp-content/plugins/pandaGadzety/view/calculator.html"); + echo $html; + } + + } + + /*private function uploadFile($key, $id) { + // TODO: verify format + require_once (ABSPATH . 'wp-admin/includes/image.php'); + require_once (ABSPATH . 'wp-admin/includes/file.php'); + require_once (ABSPATH . 'wp-admin/includes/media.php'); + return \media_handle_upload($key, $id); + }*/ + + + private function uploadFile($key, $id) { + require_once (ABSPATH . 'wp-admin/includes/image.php'); + require_once (ABSPATH . 'wp-admin/includes/file.php'); + require_once (ABSPATH . 'wp-admin/includes/media.php'); + + $attachment_id = media_handle_upload($key, $id); + + if (is_wp_error($attachment_id)) { + // error_log('Błąd przesyłania pliku: ' . $attachment_id->get_error_message()); + + //wc_add_notice('Błąd przesyłania pliku: ' . $attachment_id->get_error_message(), 'error'); + return null; + } + + return $attachment_id; + } + +} \ No newline at end of file diff --git a/plugins/pandaGadzety/utils/product-description-tab.php b/plugins/pandaGadzety/utils/product-description-tab.php new file mode 100644 index 0000000..a751d64 --- /dev/null +++ b/plugins/pandaGadzety/utils/product-description-tab.php @@ -0,0 +1,44 @@ + __('O produkcie', 'pandaGadzety'), + 'priority' => 50, + 'callback' => [$this, 'customTabData'] + ); + + return $tabs; + + } + + public function customTabData() + { + global $product; + \wp_enqueue_style("descriptionStyle", plugins_url("/pandaGadzety/assets/css/description.css")); + $sku = $product->get_sku(); + $product_repository = new Repository\ProductRepository(SERVER_URL); + $results = $product_repository->getProductDescription($sku); + + echo "
"; + echo $results['short_description']; + echo ""; + foreach ($results['specification'] as $key => $value) { + echo ""; + } + echo "
Informacje o produkcie
".$value['name']."".$value['value']."
"; + echo "
"; + } + +} \ No newline at end of file diff --git a/plugins/pandaGadzety/view/calculator.html b/plugins/pandaGadzety/view/calculator.html new file mode 100644 index 0000000..3452052 --- /dev/null +++ b/plugins/pandaGadzety/view/calculator.html @@ -0,0 +1,88 @@ +
+
+
+
+

Personalizacja produktu

+
+
+ Nazwa produktu +
+
+ +
+
+
+ +
+
+ + +
+
+
+
+
+
+
+
+
+ +
+
+ + + + Do wykonania wizualizacji należy przesłać plik wektorowy w wybranej kolorystyce. Plik z takim logo może mieć rozszerzenie: cdr, eps lub ai (ewentualnie krzywe w pdf). + +
+ +
+

Podsumowanie

+ + + + + + + + + + + + + + + + + + + + + +
Cena nadruku:0.00 zł / szt.
Cena przygotowania:0
Cena produktu:0.00 zł / szt.
Suma:0.00 zł / szt.
+ + +
+ + + + + +
+
+
+
+
+
+
\ No newline at end of file