Plugin Directory

Changeset 3755233


Ignore:
Timestamp:
10/19/2026 04:51:59 PM (40 hours ago)
Author:
onetrace
Message:

Update to version 1.9.0 from GitHub

Location:
onetrace-for-woocommerce
Files:
2 added
20 edited
1 copied

Legend:

Unmodified
Added
Removed
  • onetrace-for-woocommerce/tags/1.9.0/languages/onetrace-for-woocommerce-ru_RU.po

    r3753316 r3755233  
    108108
    109109#: src/Admin.php:82
    110 msgid "Placed, paid, cancelled and refunded orders with the customer data"
    111 msgstr "Оформленные, оплаченные, отменённые заказы и возвраты с данными покупателя"
     110msgid "Placed, paid, shipped, delivered, cancelled and refunded orders with the customer data"
     111msgstr "Оформленные, оплаченные, отправленные, доставленные, отменённые заказы и возвраты с данными покупателя"
    112112
    113113#: src/Admin.php:83
  • onetrace-for-woocommerce/tags/1.9.0/languages/onetrace-for-woocommerce.pot

    r3753316 r3755233  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: OneTrace for WooCommerce 1.8.0\n"
     5"Project-Id-Version: OneTrace for WooCommerce 1.9.0\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/onetrace-woocommerce\n"
    77"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
    … …  
    114114
    115115#: src/Admin.php:82
    116 msgid "Placed, paid, cancelled and refunded orders with the customer data"
     116msgid "Placed, paid, shipped, delivered, cancelled and refunded orders with the customer data"
    117117msgstr ""
    118118
  • onetrace-for-woocommerce/tags/1.9.0/onetrace-woocommerce.php

    r3753316 r3755233  
    44 * Plugin URI:           https://wordpress.org/plugins/onetrace-for-woocommerce/
    55 * Description:          Connects the store to OneTrace.pro, the customer data platform: orders, customers and consents from the server, the website tracker, the product catalog with stock, wishlists, recommendation widgets and Web Push.
    6  * Version:              1.8.0
     6 * Version:              1.9.0
    77 * Requires at least:    6.6
    88 * Requires PHP:         7.4
    … …  
    4343}
    4444
    45 define('ONETRACE_WC_VERSION', '1.8.0');
     45define('ONETRACE_WC_VERSION', '1.9.0');
    4646define('ONETRACE_WC_FILE', __FILE__);
    4747
  • onetrace-for-woocommerce/tags/1.9.0/readme.txt

    r3753316 r3755233  
    77WC requires at least: 9.0
    88WC tested up to: 11.2
    9 Stable tag: 1.8.0
     9Stable tag: 1.9.0
    1010License: GPLv2 or later
    1111License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    2020
    2121* Orders and their statuses from the server, through a queue with retries — not lost to ad blockers, and the store never waits for the platform.
     22* Shipments with the carrier, tracking number and link from WooCommerce Shipment Tracking, Advanced Shipment Tracking and TrackShip, and delivered orders — for "where is my order?" in the online chat and shipping journeys.
    2223* Customers and newsletter consents from registration, the account page and the checkout (classic and block).
    2324* Cart events for abandoned cart journeys; wishlist events from YITH WooCommerce Wishlist and TI WooCommerce Wishlist.
    … …  
    3536= External service =
    3637
    37 The plugin sends data to the OneTrace.pro platform at the address you enter in the settings (your own brand domain or cdp.onetrace.pro): customer data (email, phone, name, city, country, language), consents, orders, cart and wishlist events and the product catalog with stock from the server; with the loyalty program — the customer id and the cart amount to show and hold bonus points, the friend's referral code on registration; with promo codes the plugin reads the codes of the bound pools; page and product views from the visitor's browser. Terms of service: https://onetrace.pro/en/legal/terms, privacy policy: https://onetrace.pro/en/legal/privacy.
     38The plugin sends data to the OneTrace.pro platform at the address you enter in the settings (your own brand domain or cdp.onetrace.pro): customer data (email, phone, name, city, country, language), consents, orders with their shipments (carrier, tracking number and link), cart and wishlist events and the product catalog with stock from the server; with the loyalty program — the customer id and the cart amount to show and hold bonus points, the friend's referral code on registration; with promo codes the plugin reads the codes of the bound pools; page and product views from the visitor's browser. Terms of service: https://onetrace.pro/en/legal/terms, privacy policy: https://onetrace.pro/en/legal/privacy.
    3839
    3940== Installation ==
    … …  
    4849
    4950YITH WooCommerce Wishlist and TI WooCommerce Wishlist: adding and removing products is sent from the server (setting "Wishlist"). With another wishlist, put `data-cdp-wishlist="{product id}"` on the "Add to wishlist" button of the theme and `data-cdp-wishlist-remove="{product id}"` on the "Remove" button — the OneTrace tracker (1.13.0 and later) sends the events on click. The product id is the one of the catalog: the post ID, or the SKU with "Product id → SKU".
     51
     52= Which shipment tracking plugins are supported? =
     53
     54WooCommerce Shipment Tracking, Advanced Shipment Tracking and TrackShip: every tracking item added to the order is sent as order_shipped with the carrier, the tracking number and the link; the "Delivered" status of AST and TrackShip is order_delivered. Without a tracking plugin the "Completed" status is one order_shipped without tracking. Other tracking plugins can pass their parcels with the onetrace_woocommerce_order_shipments filter (see the README on GitHub).
    5055
    5156= How does "Notify when available" work? =
    … …  
    6974
    7075== Changelog ==
     76
     77= 1.9.0 =
     78* Shipments: order_shipped with the carrier, tracking number and tracking link for every tracking item of WooCommerce Shipment Tracking, Advanced Shipment Tracking and TrackShip — once per parcel, a second parcel is a new event. Without tracking, the "Completed" or "Shipped" status is one order_shipped without tracking when no parcel was sent.
     79* Delivered orders: order_delivered from the "Delivered" status of AST and TrackShip, or when TrackShip reports every parcel of the order delivered.
     80* Other tracking plugins: the onetrace_woocommerce_order_shipments filter and the onetrace_woocommerce_sync_shipments action.
    7181
    7282= 1.8.0 =
    … …  
    120130== Upgrade Notice ==
    121131
     132= 1.9.0 =
     133Shipped and delivered orders with tracking numbers from WooCommerce Shipment Tracking, Advanced Shipment Tracking and TrackShip.
     134
    122135= 1.8.0 =
    123136Stock in the catalog, wishlist events of YITH and TI wishlists, the "Notify when available" form on products out of stock.
  • onetrace-for-woocommerce/tags/1.9.0/src/Admin.php

    r3753316 r3755233  
    8080            $field('tracker', ['type' => 'checkbox', 'title' => __('Tracker', 'onetrace-for-woocommerce'), 'desc' => __('Page and product views on the storefront', 'onetrace-for-woocommerce')]),
    8181            $field('wait_for_consent', ['type' => 'checkbox', 'title' => __('Cookie consent', 'onetrace-for-woocommerce'), 'desc' => __('Load the tracker after the visitor agrees to statistics cookies (with a consent plugin that supports the WP Consent API)', 'onetrace-for-woocommerce')]),
    82             $field('orders', ['type' => 'checkbox', 'title' => __('Orders', 'onetrace-for-woocommerce'), 'desc' => __('Placed, paid, cancelled and refunded orders with the customer data', 'onetrace-for-woocommerce')]),
     82            $field('orders', ['type' => 'checkbox', 'title' => __('Orders', 'onetrace-for-woocommerce'), 'desc' => __('Placed, paid, shipped, delivered, cancelled and refunded orders with the customer data', 'onetrace-for-woocommerce')]),
    8383            $field('cart', ['type' => 'checkbox', 'title' => __('Cart', 'onetrace-for-woocommerce'), 'desc' => __('Adding to and removing from the cart, opening the checkout — for abandoned cart journeys', 'onetrace-for-woocommerce')]),
    8484            $field('wishlist', ['type' => 'checkbox', 'title' => __('Wishlist', 'onetrace-for-woocommerce'), 'desc' => __('Adding to and removing from the wishlist of YITH WooCommerce Wishlist or TI WooCommerce Wishlist — for wishlist journeys', 'onetrace-for-woocommerce')]),
  • onetrace-for-woocommerce/tags/1.9.0/src/Orders.php

    r3738426 r3755233  
    169169
    170170        foreach ($order->get_items() as $item) {
    171             if (!$item instanceof \WC_Order_Item_Product) {
     171            if (!$item instanceof \WC_Order_Item_Product || $refund && abs((float) $item->get_total()) === 0.0) {
    172172                continue;
    173173            }
    174174
    175             $quantity = abs((int) $item->get_quantity());
    176             $total = abs((float) $item->get_total());
    177 
    178             if ($quantity === 0 || $refund && $total === 0.0) {
    179                 continue;
     175            $line = self::line($item);
     176
     177            if ($line !== null) {
     178                $lines[] = $line;
    180179            }
    181 
    182             $product = $item->get_product();
    183             $variation = $item->get_variation_id() ? wc_get_product($item->get_variation_id()) : null;
    184             $lines[] = new LineItem(
    185                 Products::id($item->get_product_id()) ?: (string) $item->get_product_id(),
    186                 $item->get_name(),
    187                 $total / max(1, $quantity),
    188                 max(1, $quantity),
    189                 $variation instanceof \WC_Product ? Products::variantId($variation) : ($item->get_variation_id() ?: null),
    190                 $product instanceof \WC_Product ? Catalog::categoryId($product) : null
    191             );
    192180        }
    193181
    194182        return $lines;
     183    }
     184
     185    /**
     186     * A product line of the order; $quantity — a part of it (a parcel of a partial shipment).
     187     */
     188    public static function line(\WC_Order_Item_Product $item, ?int $quantity = null): ?LineItem
     189    {
     190        $ordered = abs((int) $item->get_quantity());
     191
     192        if ($ordered === 0) {
     193            return null;
     194        }
     195
     196        $product = $item->get_product();
     197        $variation = $item->get_variation_id() ? wc_get_product($item->get_variation_id()) : null;
     198
     199        return new LineItem(
     200            Products::id($item->get_product_id()) ?: (string) $item->get_product_id(),
     201            $item->get_name(),
     202            abs((float) $item->get_total()) / $ordered,
     203            $quantity !== null ? max(1, min($quantity, $ordered)) : $ordered,
     204            $variation instanceof \WC_Product ? Products::variantId($variation) : ($item->get_variation_id() ?: null),
     205            $product instanceof \WC_Product ? Catalog::categoryId($product) : null
     206        );
    195207    }
    196208
  • onetrace-for-woocommerce/tags/1.9.0/src/Plugin.php

    r3753316 r3755233  
    4545        Customers::register();
    4646        Orders::register();
     47        Shipments::register();
    4748        Cart::register();
    4849        Wishlist::register();
  • onetrace-for-woocommerce/tags/1.9.0/vendor/onetrace-php/src/Client.php

    r3753316 r3755233  
    4545final class Client
    4646{
    47     public const VERSION = '1.10.0';
     47    public const VERSION = '1.11.0';
    4848
    4949    /**
  • onetrace-for-woocommerce/tags/1.9.0/vendor/onetrace-php/src/Commerce/Messages.php

    r3753316 r3755233  
    3131    public const ORDER_REFUNDED = 'order_refunded';
    3232
     33    public const ORDER_SHIPPED = 'order_shipped';
     34
     35    public const ORDER_DELIVERED = 'order_delivered';
     36
    3337    /** @var string */
    3438    private $platform;
    … …  
    133137
    134138        return $this->order($order, self::ORDER_REFUNDED, $properties, $at ?? $order->placedAt, $refundId !== null ? (string) $refundId : null);
     139    }
     140
     141    /**
     142     * The order (or a part of it) is handed over to delivery. Each parcel is sent once: $shipmentId (the tracking
     143     * number by default) tells several parcels of one order apart. The platform shows the carrier, the tracking
     144     * number and the link to the customer and to the AI of the online chat ("where is my order").
     145     *
     146     * @param string|int|null $shipmentId
     147     * @param list<LineItem> $lines shipped products of a partial shipment, if known
     148     *
     149     * @return array<string, mixed>
     150     */
     151    public function orderShipped(
     152        Order $order,
     153        ?string $carrier = null,
     154        ?string $trackingNumber = null,
     155        ?string $trackingUrl = null,
     156        ?\DateTimeInterface $estimatedDelivery = null,
     157        ?\DateTimeInterface $at = null,
     158        $shipmentId = null,
     159        array $lines = []
     160    ): array {
     161        $properties = array_filter([
     162            'order_id' => $order->id,
     163            'carrier' => self::text($carrier, 100),
     164            'tracking_number' => self::text($trackingNumber, 100),
     165            'tracking_url' => $trackingUrl !== null && filter_var($trackingUrl, FILTER_VALIDATE_URL) !== false ? $trackingUrl : null,
     166            'estimated_delivery' => $estimatedDelivery !== null ? $estimatedDelivery->format('Y-m-d') : null,
     167        ], static function ($value): bool {
     168            return $value !== null;
     169        });
     170
     171        if ($lines !== []) {
     172            $properties['products'] = array_map(static function (LineItem $line): array {
     173                return $line->toArray();
     174            }, $lines);
     175        }
     176
     177        $suffix = $shipmentId !== null ? (string) $shipmentId : ($properties['tracking_number'] ?? null);
     178
     179        return $this->order($order, self::ORDER_SHIPPED, $properties, $at ?? new \DateTimeImmutable(), $suffix !== null ? preg_replace('/[^A-Za-z0-9_-]/', '', $suffix) : null);
     180    }
     181
     182    /**
     183     * The customer received the order.
     184     *
     185     * @return array<string, mixed>
     186     */
     187    public function orderDelivered(Order $order, ?\DateTimeInterface $at = null): array
     188    {
     189        return $this->order($order, self::ORDER_DELIVERED, ['order_id' => $order->id], $at ?? new \DateTimeImmutable());
    135190    }
    136191
    … …  
    250305    }
    251306
     307    private static function text(?string $value, int $max): ?string
     308    {
     309        $value = $value !== null ? trim($value) : '';
     310
     311        if ($value === '') {
     312            return null;
     313        }
     314
     315        return function_exists('mb_substr') ? mb_substr($value, 0, $max) : substr($value, 0, $max);
     316    }
     317
    252318    private static function time(\DateTimeInterface $at): string
    253319    {
  • onetrace-for-woocommerce/trunk/languages/onetrace-for-woocommerce-ru_RU.po

    r3753316 r3755233  
    108108
    109109#: src/Admin.php:82
    110 msgid "Placed, paid, cancelled and refunded orders with the customer data"
    111 msgstr "Оформленные, оплаченные, отменённые заказы и возвраты с данными покупателя"
     110msgid "Placed, paid, shipped, delivered, cancelled and refunded orders with the customer data"
     111msgstr "Оформленные, оплаченные, отправленные, доставленные, отменённые заказы и возвраты с данными покупателя"
    112112
    113113#: src/Admin.php:83
  • onetrace-for-woocommerce/trunk/languages/onetrace-for-woocommerce.pot

    r3753316 r3755233  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: OneTrace for WooCommerce 1.8.0\n"
     5"Project-Id-Version: OneTrace for WooCommerce 1.9.0\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/onetrace-woocommerce\n"
    77"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
    … …  
    114114
    115115#: src/Admin.php:82
    116 msgid "Placed, paid, cancelled and refunded orders with the customer data"
     116msgid "Placed, paid, shipped, delivered, cancelled and refunded orders with the customer data"
    117117msgstr ""
    118118
  • onetrace-for-woocommerce/trunk/onetrace-woocommerce.php

    r3753316 r3755233  
    44 * Plugin URI:           https://wordpress.org/plugins/onetrace-for-woocommerce/
    55 * Description:          Connects the store to OneTrace.pro, the customer data platform: orders, customers and consents from the server, the website tracker, the product catalog with stock, wishlists, recommendation widgets and Web Push.
    6  * Version:              1.8.0
     6 * Version:              1.9.0
    77 * Requires at least:    6.6
    88 * Requires PHP:         7.4
    … …  
    4343}
    4444
    45 define('ONETRACE_WC_VERSION', '1.8.0');
     45define('ONETRACE_WC_VERSION', '1.9.0');
    4646define('ONETRACE_WC_FILE', __FILE__);
    4747
  • onetrace-for-woocommerce/trunk/readme.txt

    r3753316 r3755233  
    77WC requires at least: 9.0
    88WC tested up to: 11.2
    9 Stable tag: 1.8.0
     9Stable tag: 1.9.0
    1010License: GPLv2 or later
    1111License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    2020
    2121* Orders and their statuses from the server, through a queue with retries — not lost to ad blockers, and the store never waits for the platform.
     22* Shipments with the carrier, tracking number and link from WooCommerce Shipment Tracking, Advanced Shipment Tracking and TrackShip, and delivered orders — for "where is my order?" in the online chat and shipping journeys.
    2223* Customers and newsletter consents from registration, the account page and the checkout (classic and block).
    2324* Cart events for abandoned cart journeys; wishlist events from YITH WooCommerce Wishlist and TI WooCommerce Wishlist.
    … …  
    3536= External service =
    3637
    37 The plugin sends data to the OneTrace.pro platform at the address you enter in the settings (your own brand domain or cdp.onetrace.pro): customer data (email, phone, name, city, country, language), consents, orders, cart and wishlist events and the product catalog with stock from the server; with the loyalty program — the customer id and the cart amount to show and hold bonus points, the friend's referral code on registration; with promo codes the plugin reads the codes of the bound pools; page and product views from the visitor's browser. Terms of service: https://onetrace.pro/en/legal/terms, privacy policy: https://onetrace.pro/en/legal/privacy.
     38The plugin sends data to the OneTrace.pro platform at the address you enter in the settings (your own brand domain or cdp.onetrace.pro): customer data (email, phone, name, city, country, language), consents, orders with their shipments (carrier, tracking number and link), cart and wishlist events and the product catalog with stock from the server; with the loyalty program — the customer id and the cart amount to show and hold bonus points, the friend's referral code on registration; with promo codes the plugin reads the codes of the bound pools; page and product views from the visitor's browser. Terms of service: https://onetrace.pro/en/legal/terms, privacy policy: https://onetrace.pro/en/legal/privacy.
    3839
    3940== Installation ==
    … …  
    4849
    4950YITH WooCommerce Wishlist and TI WooCommerce Wishlist: adding and removing products is sent from the server (setting "Wishlist"). With another wishlist, put `data-cdp-wishlist="{product id}"` on the "Add to wishlist" button of the theme and `data-cdp-wishlist-remove="{product id}"` on the "Remove" button — the OneTrace tracker (1.13.0 and later) sends the events on click. The product id is the one of the catalog: the post ID, or the SKU with "Product id → SKU".
     51
     52= Which shipment tracking plugins are supported? =
     53
     54WooCommerce Shipment Tracking, Advanced Shipment Tracking and TrackShip: every tracking item added to the order is sent as order_shipped with the carrier, the tracking number and the link; the "Delivered" status of AST and TrackShip is order_delivered. Without a tracking plugin the "Completed" status is one order_shipped without tracking. Other tracking plugins can pass their parcels with the onetrace_woocommerce_order_shipments filter (see the README on GitHub).
    5055
    5156= How does "Notify when available" work? =
    … …  
    6974
    7075== Changelog ==
     76
     77= 1.9.0 =
     78* Shipments: order_shipped with the carrier, tracking number and tracking link for every tracking item of WooCommerce Shipment Tracking, Advanced Shipment Tracking and TrackShip — once per parcel, a second parcel is a new event. Without tracking, the "Completed" or "Shipped" status is one order_shipped without tracking when no parcel was sent.
     79* Delivered orders: order_delivered from the "Delivered" status of AST and TrackShip, or when TrackShip reports every parcel of the order delivered.
     80* Other tracking plugins: the onetrace_woocommerce_order_shipments filter and the onetrace_woocommerce_sync_shipments action.
    7181
    7282= 1.8.0 =
    … …  
    120130== Upgrade Notice ==
    121131
     132= 1.9.0 =
     133Shipped and delivered orders with tracking numbers from WooCommerce Shipment Tracking, Advanced Shipment Tracking and TrackShip.
     134
    122135= 1.8.0 =
    123136Stock in the catalog, wishlist events of YITH and TI wishlists, the "Notify when available" form on products out of stock.
  • onetrace-for-woocommerce/trunk/src/Admin.php

    r3753316 r3755233  
    8080            $field('tracker', ['type' => 'checkbox', 'title' => __('Tracker', 'onetrace-for-woocommerce'), 'desc' => __('Page and product views on the storefront', 'onetrace-for-woocommerce')]),
    8181            $field('wait_for_consent', ['type' => 'checkbox', 'title' => __('Cookie consent', 'onetrace-for-woocommerce'), 'desc' => __('Load the tracker after the visitor agrees to statistics cookies (with a consent plugin that supports the WP Consent API)', 'onetrace-for-woocommerce')]),
    82             $field('orders', ['type' => 'checkbox', 'title' => __('Orders', 'onetrace-for-woocommerce'), 'desc' => __('Placed, paid, cancelled and refunded orders with the customer data', 'onetrace-for-woocommerce')]),
     82            $field('orders', ['type' => 'checkbox', 'title' => __('Orders', 'onetrace-for-woocommerce'), 'desc' => __('Placed, paid, shipped, delivered, cancelled and refunded orders with the customer data', 'onetrace-for-woocommerce')]),
    8383            $field('cart', ['type' => 'checkbox', 'title' => __('Cart', 'onetrace-for-woocommerce'), 'desc' => __('Adding to and removing from the cart, opening the checkout — for abandoned cart journeys', 'onetrace-for-woocommerce')]),
    8484            $field('wishlist', ['type' => 'checkbox', 'title' => __('Wishlist', 'onetrace-for-woocommerce'), 'desc' => __('Adding to and removing from the wishlist of YITH WooCommerce Wishlist or TI WooCommerce Wishlist — for wishlist journeys', 'onetrace-for-woocommerce')]),
  • onetrace-for-woocommerce/trunk/src/Orders.php

    r3738426 r3755233  
    169169
    170170        foreach ($order->get_items() as $item) {
    171             if (!$item instanceof \WC_Order_Item_Product) {
     171            if (!$item instanceof \WC_Order_Item_Product || $refund && abs((float) $item->get_total()) === 0.0) {
    172172                continue;
    173173            }
    174174
    175             $quantity = abs((int) $item->get_quantity());
    176             $total = abs((float) $item->get_total());
    177 
    178             if ($quantity === 0 || $refund && $total === 0.0) {
    179                 continue;
     175            $line = self::line($item);
     176
     177            if ($line !== null) {
     178                $lines[] = $line;
    180179            }
    181 
    182             $product = $item->get_product();
    183             $variation = $item->get_variation_id() ? wc_get_product($item->get_variation_id()) : null;
    184             $lines[] = new LineItem(
    185                 Products::id($item->get_product_id()) ?: (string) $item->get_product_id(),
    186                 $item->get_name(),
    187                 $total / max(1, $quantity),
    188                 max(1, $quantity),
    189                 $variation instanceof \WC_Product ? Products::variantId($variation) : ($item->get_variation_id() ?: null),
    190                 $product instanceof \WC_Product ? Catalog::categoryId($product) : null
    191             );
    192180        }
    193181
    194182        return $lines;
     183    }
     184
     185    /**
     186     * A product line of the order; $quantity — a part of it (a parcel of a partial shipment).
     187     */
     188    public static function line(\WC_Order_Item_Product $item, ?int $quantity = null): ?LineItem
     189    {
     190        $ordered = abs((int) $item->get_quantity());
     191
     192        if ($ordered === 0) {
     193            return null;
     194        }
     195
     196        $product = $item->get_product();
     197        $variation = $item->get_variation_id() ? wc_get_product($item->get_variation_id()) : null;
     198
     199        return new LineItem(
     200            Products::id($item->get_product_id()) ?: (string) $item->get_product_id(),
     201            $item->get_name(),
     202            abs((float) $item->get_total()) / $ordered,
     203            $quantity !== null ? max(1, min($quantity, $ordered)) : $ordered,
     204            $variation instanceof \WC_Product ? Products::variantId($variation) : ($item->get_variation_id() ?: null),
     205            $product instanceof \WC_Product ? Catalog::categoryId($product) : null
     206        );
    195207    }
    196208
  • onetrace-for-woocommerce/trunk/src/Plugin.php

    r3753316 r3755233  
    4545        Customers::register();
    4646        Orders::register();
     47        Shipments::register();
    4748        Cart::register();
    4849        Wishlist::register();
  • onetrace-for-woocommerce/trunk/vendor/onetrace-php/src/Client.php

    r3753316 r3755233  
    4545final class Client
    4646{
    47     public const VERSION = '1.10.0';
     47    public const VERSION = '1.11.0';
    4848
    4949    /**
  • onetrace-for-woocommerce/trunk/vendor/onetrace-php/src/Commerce/Messages.php

    r3753316 r3755233  
    3131    public const ORDER_REFUNDED = 'order_refunded';
    3232
     33    public const ORDER_SHIPPED = 'order_shipped';
     34
     35    public const ORDER_DELIVERED = 'order_delivered';
     36
    3337    /** @var string */
    3438    private $platform;
    … …  
    133137
    134138        return $this->order($order, self::ORDER_REFUNDED, $properties, $at ?? $order->placedAt, $refundId !== null ? (string) $refundId : null);
     139    }
     140
     141    /**
     142     * The order (or a part of it) is handed over to delivery. Each parcel is sent once: $shipmentId (the tracking
     143     * number by default) tells several parcels of one order apart. The platform shows the carrier, the tracking
     144     * number and the link to the customer and to the AI of the online chat ("where is my order").
     145     *
     146     * @param string|int|null $shipmentId
     147     * @param list<LineItem> $lines shipped products of a partial shipment, if known
     148     *
     149     * @return array<string, mixed>
     150     */
     151    public function orderShipped(
     152        Order $order,
     153        ?string $carrier = null,
     154        ?string $trackingNumber = null,
     155        ?string $trackingUrl = null,
     156        ?\DateTimeInterface $estimatedDelivery = null,
     157        ?\DateTimeInterface $at = null,
     158        $shipmentId = null,
     159        array $lines = []
     160    ): array {
     161        $properties = array_filter([
     162            'order_id' => $order->id,
     163            'carrier' => self::text($carrier, 100),
     164            'tracking_number' => self::text($trackingNumber, 100),
     165            'tracking_url' => $trackingUrl !== null && filter_var($trackingUrl, FILTER_VALIDATE_URL) !== false ? $trackingUrl : null,
     166            'estimated_delivery' => $estimatedDelivery !== null ? $estimatedDelivery->format('Y-m-d') : null,
     167        ], static function ($value): bool {
     168            return $value !== null;
     169        });
     170
     171        if ($lines !== []) {
     172            $properties['products'] = array_map(static function (LineItem $line): array {
     173                return $line->toArray();
     174            }, $lines);
     175        }
     176
     177        $suffix = $shipmentId !== null ? (string) $shipmentId : ($properties['tracking_number'] ?? null);
     178
     179        return $this->order($order, self::ORDER_SHIPPED, $properties, $at ?? new \DateTimeImmutable(), $suffix !== null ? preg_replace('/[^A-Za-z0-9_-]/', '', $suffix) : null);
     180    }
     181
     182    /**
     183     * The customer received the order.
     184     *
     185     * @return array<string, mixed>
     186     */
     187    public function orderDelivered(Order $order, ?\DateTimeInterface $at = null): array
     188    {
     189        return $this->order($order, self::ORDER_DELIVERED, ['order_id' => $order->id], $at ?? new \DateTimeImmutable());
    135190    }
    136191
    … …  
    250305    }
    251306
     307    private static function text(?string $value, int $max): ?string
     308    {
     309        $value = $value !== null ? trim($value) : '';
     310
     311        if ($value === '') {
     312            return null;
     313        }
     314
     315        return function_exists('mb_substr') ? mb_substr($value, 0, $max) : substr($value, 0, $max);
     316    }
     317
    252318    private static function time(\DateTimeInterface $at): string
    253319    {
Note: See TracChangeset for help on using the changeset viewer.