=== ORLEN Paczka for WooCommerce ===
Contributors: sm32studio
Tags: shipping, pickup points, orlen paczka, delivery, woocommerce
Requires at least: 6.8
Tested up to: 7.1
Requires PHP: 8.1
Stable tag: 1.4.12
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

ORLEN Paczka pickup points delivery for WooCommerce: point selection map in checkout, shipping labels, parcel statuses and consumer returns.

== Description ==

Official ORLEN Paczka integration for WooCommerce stores:

* pickup point selection map in the checkout (classic, block-based and CheckoutWC checkouts; popup or embedded map),
* shipping label generation (single and bulk, from the order list and the "Shipping history" page),
* courier pickup ordering and collective pickup protocols,
* parcel status tracking with optional automatic WooCommerce order status mapping,
* consumer returns: return label PDF or drop-off code, e-mailed to the customer,
* pricing by parcel size (S/M/L), weight or cart value, with a free shipping threshold.

A partner account (PartnerID and PartnerKey) and a map widget token from ORLEN Paczka are required. To obtain them, contact integracje@orlenpaczka.pl.

== External services ==

This plugin connects to the ORLEN Paczka services operated by ORLEN Paczka (Poland):

1. ORLEN Paczka SOAP API (`api.orlenpaczka.pl`, test: `api-test.orlenpaczka.pl`) - used to generate shipping labels, order courier pickups, generate pickup protocols, fetch parcel statuses and create consumer returns. The data sent includes the shop's PartnerID/PartnerKey, recipient name, address, phone number and e-mail address of the order being shipped, parcel size and the selected pickup point code. Data is sent when the shop administrator generates a label, protocol, return or status refresh, and periodically (hourly) for parcel status updates of open shipments.
2. ORLEN Paczka map widget (`mapa.orlenpaczka.pl/widget.js`) - an interactive pickup point map loaded in the checkout so the customer can choose a pickup point. The widget is loaded in the customer's browser with the shop's map token; the customer's typed delivery address may be passed to the widget to centre the map. This script is an integral part of the ORLEN Paczka service and cannot be bundled with the plugin.

Terms of service and privacy policy of the service provider:
https://www.orlenpaczka.pl/regulaminy/ and https://www.orlenpaczka.pl/polityka-prywatnosci/

== Frequently Asked Questions ==

= Do I need an ORLEN Paczka account? =

Yes. The plugin requires an ORLEN Paczka business contract, API credentials (PartnerID, PartnerKey) and a map widget token. To obtain them, contact integracje@orlenpaczka.pl.

= Which checkouts are supported? =

The classic WooCommerce checkout, the block-based checkout and CheckoutWC - with a popup or an embedded map.

= Is the plugin compatible with HPOS? =

Yes, the plugin fully supports High-Performance Order Storage.

= How do I show the selected pickup point in a custom template? =

The pickup point is added automatically to the order summary (thank-you page, "My account", WooCommerce e-mails). Adding it to e-mails can be switched off in ORLEN Paczka -> Dane autoryzacyjne ("Punkt odbioru w e-mailach"). For templates that do not use the standard order summary:

* shortcode `[orlen_paczka_pickup_point]` - on the thank-you page and in the order view in "My account". Optional attributes: `order_id` and `label="no"`. The point is shown only to a person allowed to see the order.
* PHP function `orlen_paczka_get_pickup_point_text( $order )` - for PHP templates, also e-mail templates. Returns plain text ("CODE, name and address") or an empty string. Escape it on output, e.g. `echo esc_html( orlen_paczka_get_pickup_point_text( $order ) );`.
* filter `orlen_paczka_show_pickup_point_in_order_totals` - return false to hide the automatic row in the order summary.

= Why is the ORLEN Paczka method not visible in the cart? =

Check the pricing configuration (ORLEN Paczka -> Konfiguracja cen) and the shipping zone. Since version 1.3.0 the exact reason is logged in ORLEN Paczka -> Logi.

== Installation ==

1. Upload the plugin and activate it.
2. Enter your PartnerID, PartnerKey and map widget token in ORLEN Paczka -> Dane autoryzacyjne.
3. Add the "ORLEN Paczka" shipping method to your shipping zone (WooCommerce -> Settings -> Shipping).
4. Configure prices in ORLEN Paczka -> Konfiguracja cen.

== Changelog ==

= 1.4.12 =

* Plugin requirements aligned with the user manual: PHP 8.1, WordPress 6.8, WooCommerce 10.0. Tested up to WooCommerce 11.3.
* Plugin Check findings resolved: database queries in the pickup point data migration, shipping history and uninstall, fallback storage key generation, shipping history screen time limit, annotations for checkout form field reads and count labels of the return order statuses.

= 1.4.11 =

* Block checkout: an order with a shipping method from another plugin recognised by its name as ORLEN Paczka (e.g. Flexible Shipping) passed without a pickup point selected. Validation now recognises the method the same way as the map button.
* Classic checkout: for such a method the missing pickup point message did not appear on themes that do not send the pickup point fields with the checkout form.
* Classic checkout (popup map): the "Wybierz punkt z mapy" button was not added for such a method on themes without the standard order review.

= 1.4.10 =

* An order with ORLEN Paczka delivery and no pickup point selected passed without a message when the shipping method came from another plugin and was recognised by its name, or when the checkout form did not send the shipping method field. Classic checkout validation now covers these cases.

= 1.4.9 =

* The selected ORLEN Paczka pickup point (code and address) is shown to the customer in the order summary: on the thank-you page, in "My account" and in WooCommerce e-mails.
* New setting "Punkt odbioru w e-mailach": adding the pickup point to WooCommerce e-mails, below the shipping line, can be switched off.
* Shops with custom templates can place the pickup point themselves: shortcode `[orlen_paczka_pickup_point]` and function `orlen_paczka_get_pickup_point_text()`.
* Logs, labels and protocols are stored in a directory that is not accessible from the outside. Labels and protocols can be downloaded only by logged-in shop staff. Existing files are moved automatically and links saved in orders keep working.
* The API key is no longer written to the logs or sent to the browser.
* Admin actions for parcels, sender and protocols require the shop management capability.
* Pickup point and parcel data from forms is validated on save and displayed as text.
* The order screen no longer references a missing script file.
* The return e-mail attaches only the return label of the given order.
* Uninstalling also removes the plugin files from the uploads directory and order data stored in HPOS tables.

= 1.4.8 =

* "By parcel size" price configuration: all cart products without dimensions go together into one parcel of the default size (another parcel only above 20 kg), products with dimensions are packed as before. Previously every unit without dimensions counted as a separate parcel.
* New installations default to the "By parcel price range" mode; existing shops keep their mode. Price ranges must be filled in before the method appears in the cart.
* The "Default parcel size" setting describes the new packing rule.
* Declared compatibility with WooCommerce 11.2.
= 1.4.7 =

* "Download labels" action in the shipping history and the "ORLEN Paczka - download labels" bulk action on the WooCommerce orders list: for the selected parcels that already have a label, also from different days and operations, the plugin fetches fresh copies of the labels from the ORLEN Paczka API (LabelPrintDuplicateListTwo) and delivers them as one PDF file. The API accepts up to 50 parcels per call, so a larger selection is fetched in several calls and delivered as one ZIP archive. Parcels without a label and orders without parcels are skipped with a message. When the API does not return the label of a parcel, the message gives its number, order, the likely cause (e.g. a parcel created on another ORLEN Paczka account or in another environment) and the API answer. The result files in uploads/orlen-labels are kept for one day.
* Opening hours of the selected pickup point on the checkout page (classic, block and embedded map) showed a literal "<br />" tag between days instead of a line break.

= 1.4.6 =

* In the "Shipment data" window the pickup point could not be changed: after clicking "Choose another ORLEN Paczka point" the page dimmed, but the map stayed hidden behind the window. Release 1.4.5 gave the window the topmost layer (z-index 100000) and a CSS transform, which put the ORLEN map modal underneath it. The window is back on the layer used before that release (z-index 1000), without the transform, stays centred in the browser window (on narrower screens in the admin content area, clear of the side menu) and scrolls inside when space is short, so the "Save" and "Close" buttons remain reachable.
* The layout of the "Shipment data" window follows the browser window width instead of the width of the panel on the order screen: at 150 % system scaling the window keeps two columns and "Save" and "Close" sit side by side. A single column with stacked buttons only below 783 px.

= 1.4.5 =

* Delivery of a return parcel (consumer return) switches the order to the status mapped for the "Return delivered to sender" event (by default "Return delivered"), as agreed with ORLEN Paczka. Other return parcel events do not change the order status.
* After updating from a release without status tracking (e.g. the 1.3.x fix line) parcels generated in that period were not tracked, because the index seeding ran only once. A supplementary seeding now runs after every plugin version change and skips parcels with a final status.
* The "Shipment data" window fits the browser window also at 150 % system scaling and on smaller screens: it is centred, never extends beyond the viewport and scrolls inside when needed, so the "Save" and "Close" buttons are always reachable. Both buttons in one row, styled as WordPress buttons.

= 1.4.4 =

* Return parcels are listed in "Parcel statuses" with a RETURN badge and "return parcel" note, their status is refreshed together with the other parcels of the order, and each return parcel has its own tab in the parcels section (sender, return delivery address, parcel number or shipping code, label, tracking, resend e-mail). For a return created as a shipping code the parcel number is fetched from the API (GiveShippingCodeStatus) together with the code state (not used, used, cancelled).
* The "Refresh statuses" button in the shipping history fetched the statuses but did not show them in the table until the page was reloaded.
* Consumer return form: the e-mail field accepts up to 60 characters (previously 30), as per the corrected ORLEN Paczka API documentation. Form fields are laid out in several columns on a wide panel.
* Return parcel statuses do not change the order status.
* The ORLEN Paczka panel on the order screen is back to its two-column layout (parcel data on the left, parcel number and buttons on the right, the action buttons in one row) and the "Shipment data" window to its two-column layout. Since 1.3.0 the panel stylesheet forced a single column at every width, although the single-column layout was meant only for the panel moved to the narrow side column.
* Map tab: removed the "Requires map widget 1.3." note.
* Plugin pages no longer show notices of other plugins (ads, promotions, warnings), which under the ORLEN Paczka header looked like ORLEN Paczka content. Other admin pages are unchanged.
* Plugin log entries no longer carry the "[HPOS]" prefix, which also appeared on stores storing orders as posts.
* Replacing the plugin files while the store is busy no longer ends with a critical error on the storefront when the shipping method file is momentarily missing.
* The "Go to the order in the shipping history" button on stores with an order numbering plugin (order number different from the ID) opened the right page of the shipping history with an empty list, because it put the ID into the "Order id" filter while the list shows the number. The filter now receives the order number, and a manually typed ID still finds the row.
* Plugin log entries refer to orders by the number shown in the store, with the ID in brackets when they differ (e.g. #158297 (ID 560346)). Previously only the ID was logged, which the user does not know.

= 1.4.3 =

* The "Map" tab (map type, frame isolation, point types visible to customers, filter lock) was reachable only from the WordPress side menu, without an entry in the tab bar of the plugin pages. It is now the second tab on every plugin page, uses the same layout as the other pages, and the authorisation page links to it.

= 1.4.2 =

* Shipping history and courier history listed every order of the store, including orders without ORLEN Paczka (rows showing only "-"), and on stores with many orders the page ended with a WordPress critical error (out of memory). The selected order IDs were passed to WooCommerce with an argument its query does not support, so all orders were loaded. Orders are now loaded only for the selected IDs, regardless of the order storage (HPOS or posts).
* Shipping history: server-side pagination. Each page loads only its own orders (20, 50 or 100 per page, the choice is remembered), so the list covers every ORLEN Paczka order without the 200 limit and without stressing the server. Header filters narrow the current page and the "Shipping history" link from the order screen opens the page containing that order.
* Shipping history: orders without a generated label show the pickup point code, phone and e-mail from the order and a "Generate label" button in the Actions column (previously only "-").
* The "Bulk label generation" action in the shipping history shows a clear message when no orders are selected instead of "Unknown error".
* The order screen and label generation recognise shipping methods of other plugins (Flexible Shipping, Apaczka) by name, like the shipping history does. They used to require the plugin's own shipping method and showed "This order does not use ORLEN Paczka" in such stores.
* The ORLEN Paczka panel on the order screen appears only for ORLEN Paczka orders. It used to appear on every order with a "no shipping method" note.
* Courier history pagination shows arrows, the first and the last page and the neighbouring pages instead of every page number.
* Headers and cells of the lists are no longer broken inside a word, narrow columns no longer overlap the Actions column and on narrow screens the table scrolls horizontally.

= 1.4.1 =

* Checkout validation honours the pickup point saved in the session (themes with custom checkout forms); the session point is cleared after the order is placed.
* Faster pickup point map in isolation mode (preloaded after selecting the method, kept between openings, widget script cached).
* Shipping history: no more critical errors on large stores (line items are no longer loaded per order, refunds are excluded, 200 most recent orders), orders shipped through name-recognised methods of other shipping plugins are listed, and the activation-time meta migration that blocked the admin on large stores now runs in the background in batches.

= 1.4.0 =
* Shipment status dictionary - statuses shown with agreed business names.
* Plugin-provided order statuses "Zwrot w drodze" (return in transit) and "Dostarczono zwrot" (return delivered), available in the status mapping.
* New "Map" settings tab (map type, isolation, point types, filter lock) - consistent with the PrestaShop module. The map layout is fixed to tabs, as required by ORLEN Paczka.
* Consumer returns toggle in settings (service requires an ORLEN Paczka agreement; disabled by default); return parcels listed in the order shipments section with a RETURN badge.
* Manual status refresh limited to one request per 15 minutes; completed/cancelled orders are no longer polled.
* Removed API price presentation (test label price note).
* Order status mapping covers all pickup codes (incl. 1100) and the full set of return codes; ordering a courier is blocked for parcels already in transit.

= 1.3.8 =
* Pickup point data is additionally saved in the format recognized by external order-management systems (delivery_point_* fields and the legacy paczka_w_ruchu_punkt_odbioru key with the full shipping code) - enables pickup point transfer to Apilo and similar integrators.

= 1.3.7 =
* Product weight and dimensions are converted according to the WooCommerce store units. Stores using grams saw a false "over 20 kg" warning and inflated parcel size selection.

= 1.3.6 =
* Integrator-facing pickup point fields and the order address preview now carry the full point shipping code (e.g. WS-443055-AB-50) instead of the short numeric point id.

= 1.3.5 =
* Fixed a PHP warning ("Undefined variable $pickup_name") printed in the order details on servers with PHP error display enabled; the pickup point selector shows the saved point name again.

= 1.3.4 =
* The map widget script on the order edit screen now loads only after clicking the pickup point button - opening an ORLEN order no longer freezes the browser tab.

= 1.3.3 =
* Added an "existing parcel number" field when adding a parcel to an order - restores a parcel entry for an already generated label without calling the API again.
* Fixed ordering and saving a courier pickup from the shipping history page failing with "none of the selected orders has a pack_code" although labels were generated correctly.


= 1.3.2 =
* Fixed HPOS storage for parcel rows, labels, protocols, selected senders and courier pickup orders.
* Preserved access to legacy parcel data saved in the WordPress post-meta store.
* Shipping history now queries recent ORLEN Paczka orders instead of filtering only the 20 newest store orders.
* Added persistence verification and actionable logs after label generation and courier pickup ordering.

= 1.3.1 =
* Fixed a Store API validation error ("physicalNamePsd is not of type string") that could block placing an order in the block-based checkout.
* Fixed the embedded map passing partial pickup point data (point code as the name, no postal code or city) on the first point selection - full point details are now saved on the first click.
* Logs page and per-order log preview now show newest entries first.

= 1.3.0 =
* Parcel status tracking with order status mapping.
* Consumer returns (label PDF or drop-off code) with customer e-mail.
* Bulk label generation from the WooCommerce order list.
* Map widget 1.3 support: point type filters and address scoping.
* Security hardening: nonces, input sanitization and output escaping across the admin panel and AJAX endpoints.

== Upgrade Notice ==

= 1.3.2 =
Required for stores using HPOS. Fixes disappearing parcel records and empty shipping/courier histories after successful label or pickup creation.

= 1.3.1 =
Fixes checkout errors and partial pickup point data with the embedded map in the block-based checkout. Recommended for all 1.3.0 users.

= 1.3.0 =
Major update: parcel status tracking, consumer returns, bulk labels, map widget 1.3 settings and a security hardening pass. Back up before updating and re-check your pricing configuration after the update.
