Plugin Directory

Changeset 3382150


Ignore:
Timestamp:
10/21/2025 06:53:41 PM (5 months ago)
Author:
minicrmio
Message:

Shipping+billing address handling

Location:
minicrm-woocommerce-sync/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • minicrm-woocommerce-sync/trunk/languages/minicrm-woocommerce-sync.pot

    r3336183 r3382150  
    44"Project-Id-Version: MiniCRM "
    55"WooCommerce Sync plugin "
    6 "v1.7.5\n"
     6"v1.7.6\n"
    77"POT-Creation-Date: 2022-05-30 "
    88"22:22+0200\n"
  • minicrm-woocommerce-sync/trunk/lib/Feed.php

    r3329264 r3382150  
    240240                }
    241241
    242                 // Address
     242                // Address - extract billing and shipping
    243243                $addresses = $business->addChild ('Addresses');
    244                 $address = $addresses->addChild ('Address');
    245 
    246                 // Try to use billing country
    247                 if ($latest_order->get_billing_country () !== '') {
    248                     try {
    249                         $address->CountryId = self::_getCountry (
    250                             $locale,
    251                             $latest_order->get_billing_country ()
    252                         );
    253                     } catch (\Exception $e) {}
    254                 }
    255 
    256                 // Fall back to the shop's base country
    257                 else {
    258                     try {
    259                         $address->CountryId = self::_getCountry (
    260                             $locale,
    261                             \WC ()->countries->get_base_country ()
    262                         );
    263                     } catch (\Exception $e) {}
    264                 }
    265 
    266                 $address->PostalCode = $latest_order->get_billing_postcode ();
    267                 $address->City = $latest_order->get_billing_city ();
    268                 $address->addChild (
    269                     'Address',
    270                     trim (implode (' ', [
    271                         $latest_order->get_billing_address_1 (),
    272                         $latest_order->get_billing_address_2 (),
    273                     ]))
    274                 );
     244                $BillingAddr = self::_extractOrderAddress ($locale, $latest_order, 'billing');
     245                if ($BillingAddr) {
     246                    self::_addAddressToXml ($addresses, $BillingAddr, 'Billing');
     247                }
     248                $ShippingAddr = self::_extractOrderAddress ($locale, $latest_order, 'shipping');
     249                if ($ShippingAddr) {
     250                    self::_addAddressToXml ($addresses, $ShippingAddr, 'Shipping');
     251                }
    275252
    276253                // Email
     
    296273            $phone = $phones->addChild ('Phone');
    297274            $phone->Value = $latest_order->get_billing_phone ();
     275
     276            // Add addresses to Contact if no Business node
     277            if (!$company) {
     278                $addresses = $contact->addChild ('Addresses');
     279                $BillingAddr = self::_extractOrderAddress ($locale, $latest_order, 'billing');
     280                if ($BillingAddr) {
     281                    self::_addAddressToXml ($addresses, $BillingAddr, 'Billing');
     282                }
     283                $ShippingAddr = self::_extractOrderAddress ($locale, $latest_order, 'shipping');
     284                if ($ShippingAddr) {
     285                    self::_addAddressToXml ($addresses, $ShippingAddr, 'Shipping');
     286                }
     287            }
    298288
    299289            // Orders
     
    691681
    692682    /**
     683     * Extracts address data from order billing or shipping fields
     684     *
     685     * @param string $locale MiniCRM locale
     686     * @param \WC_Order $order WooCommerce order
     687     * @param string $type 'billing' or 'shipping'
     688     * @return array|null Address data or null if city is empty
     689     */
     690    protected static function _extractOrderAddress (
     691        string $locale,
     692        \WC_Order $order,
     693        string $type
     694    ): ?array
     695    {
     696        $GetCity = "get_{$type}_city";
     697        $GetCountry = "get_{$type}_country";
     698        $GetPostcode = "get_{$type}_postcode";
     699        $GetAddress1 = "get_{$type}_address_1";
     700        $GetAddress2 = "get_{$type}_address_2";
     701
     702        if ($order->$GetCity () === '') {
     703            return null;
     704        }
     705
     706        $CountryId = '';
     707        if ($order->$GetCountry () !== '') {
     708            try {
     709                $CountryId = self::_getCountry ($locale, $order->$GetCountry ());
     710            } catch (\Exception $e) {}
     711        } else {
     712            try {
     713                $CountryId = self::_getCountry ($locale, \WC ()->countries->get_base_country ());
     714            } catch (\Exception $e) {}
     715        }
     716
     717        if ($CountryId === '') {
     718            return null;
     719        }
     720
     721        return [
     722            'CountryId' => $CountryId,
     723            'PostalCode' => $order->$GetPostcode (),
     724            'City' => $order->$GetCity (),
     725            'Address' => trim (implode (' ', [$order->$GetAddress1 (), $order->$GetAddress2 ()])),
     726        ];
     727    }
     728
     729    /**
     730     * Adds address data to an XML Addresses node
     731     *
     732     * @param \SimpleXMLElement $addresses Parent Addresses node
     733     * @param array $addressData Address data from _extractOrderAddress
     734     * @param string|null $type Optional type label (e.g., 'Billing', 'Shipping')
     735     * @return void
     736     */
     737    protected static function _addAddressToXml (
     738        \SimpleXMLElement $addresses,
     739        array $addressData,
     740        ?string $type = null
     741    ): void
     742    {
     743        $address = $addresses->addChild ('Address');
     744        $address->CountryId = $addressData ['CountryId'];
     745        $address->PostalCode = $addressData ['PostalCode'];
     746        $address->City = $addressData ['City'];
     747        $address->addChild ('Address', $addressData ['Address']);
     748        if ($type !== null) {
     749            $address->Name = $type;
     750        }
     751    }
     752
     753    /**
    693754     * Creates name string from WooCommerce order data array
    694755     *
  • minicrm-woocommerce-sync/trunk/minicrm-woocommerce-sync.php

    r3336183 r3382150  
    77 * License: Expat License
    88 * Plugin Name: MiniCRM Woocommerce Sync
    9  * Requires at least: 4.9
    10  * Requires PHP: 8.0
     9 * Requires at least: 6.0
     10 * Requires PHP: 8.1
    1111 * Text Domain: minicrm-woocommerce-sync
    12  * Version: 1.7.5
    13  * WC requires at least: 4.0.0
    14  * WC tested up to: 7.2
    15  * Tested up to: 6 (non-standard header for latest major WP version supported)
     12 * Version: 1.7.6
     13 * WC requires at least: 9.0
     14 * WC tested up to: 10.2
     15 * Tested up to: 6.8
    1616 *
    1717 * Copyright 2018 Tamás Márton
  • minicrm-woocommerce-sync/trunk/readme.txt

    r3336183 r3382150  
    33License: Expat License
    44License URI: https://directory.fsf.org/wiki/License:Expat
    5 Requires at least: 4.9
    6 Requires PHP: 8.0
    7 Stable tag: 1.7.5
    8 Tested up to: 6.2
    9 WC requires at least: 4.0.0
    10 WC tested up to: 7.2
     5Requires at least: 6.0
     6Requires PHP: 8.1
     7Stable tag: 1.7.6
     8Tested up to: 6.8
     9WC requires at least: 9.0
     10WC tested up to: 10.2
    1111
    1212Synchronizes WooCommerce orders with your MiniCRM webshop module.
Note: See TracChangeset for help on using the changeset viewer.