Skip to content

Commit 4ea9943

Browse files
authored
Merge pull request #153 from BeAPI/ver/6.12.0
Release 6.12.0
2 parents 9c2d51a + a57c000 commit 4ea9943

File tree

12 files changed

+564
-75
lines changed

12 files changed

+564
-75
lines changed

.plugin-data

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"version": "6.11.0",
2+
"version": "6.12.0",
33
"slug": "shopping-feed"
44
}

readme.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
11
# ShoppingFeed
22

33
* Contributors: ShoppingFeed, BeAPI
4-
* Tags: shoppingfeed, marketplace, woocommerce, woocommerce shoppingfeed, create woocommerce products shoppingfeed, products feed, generate shoppingfeed, amazon, Jet, Walmart, many marketplace, import orders
5-
* Stable tag: 6.11.0
6-
* Version: 6.11.0
4+
* Tags: shoppingfeed, marketplace, woocommerce, products feed, import orders
5+
* Description: WordPress connection Controller Plugin for ShoppingFeed – Sell on Amazon, Ebay, Google, and 1000’s of international marketplaces
6+
* Stable tag: 6.12.0
7+
* Version: 6.12.0
78
* Requires PHP: 7.3
89
* Requires at least: 5.7
910
* Tested up to: 6.7
10-
* WC requires at least: 5.1.0
11+
* WC requires at least: 7.0
1112
* WC tested up to: 9.6.0
13+
* License: GPL v2 or later
14+
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
1215

1316
## Upgrade Notice
1417

1518
> Version 6.0.0 is a major version, there are several changes and improvements which affect the architecture of the plugin. You will have to re-configure the plugin, all the previous settings will be lost
1619
1720
## Changelog
21+
* 6.12.0
22+
* Shipping (mondialrelay-wordpress) : Support the MondialRelay plugin for orders imported from the API if the carrier is matched with one of the plugin's shipping methods.
23+
* Shipping (woocommerce-gls) : Show GLS shipping methods in the shipping matching selector.
24+
* Feed : Fix case where the feed could appear empty or broken due to plugins using PHP output buffering.
25+
* Order : Improve logs during order import.
26+
* Misc : Update plugin requirements.
1827
* 6.11.0
19-
* Variations : add new filter to modify variation's main image
28+
* Variations : add new filter to modify variation's main image.
2029
* 6.10.0
2130
* Orders : Redesigned the shipment tracking system.
2231
* Orders (beta) : Add option to include VAT when importing orders.
@@ -174,12 +183,12 @@ WordPress connection Controller Plugin for ShoppingFeed - Sell on Amazon, Ebay,
174183
## Requirements
175184

176185
### Server :
177-
- PHP version 7.1 or above
186+
- PHP version 7.3 or above
178187
- PHP cURL extension is activated
179188

180189
### WordPress :
181190
- Core version 5.7 or above
182-
- WooCommerce version 5.1 or above
191+
- WooCommerce version 7.0 or above
183192

184193
## Installation
185194
Sign up for free on ShoppingFeed : https://shopping-feed.com/

readme.txt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
## ShoppingFeed
22
Contributors: ShoppingFeed, BeAPI
3-
Tags: shoppingfeed, marketplace, woocommerce, woocommerce shoppingfeed, create woocommerce products shoppingfeed, products feed, generate shoppingfeed, amazon, Jet, Walmart, many marketplace, import orders
4-
Stable tag: 6.11.0
5-
Version: 6.11.0
3+
Tags: shoppingfeed, marketplace, woocommerce, products feed, import orders
4+
Description: WordPress connection Controller Plugin for ShoppingFeed – Sell on Amazon, Ebay, Google, and 1000’s of international marketplaces
5+
Stable tag: 6.12.0
6+
Version: 6.12.0
67
Requires PHP: 7.3
78
Requires at least: 5.7
89
Tested up to: 6.7
9-
WC requires at least: 5.1.0
10+
WC requires at least: 7.0
1011
WC tested up to: 9.6.0
12+
License: GPL v2 or later
13+
License URI: https://www.gnu.org/licenses/gpl-2.0.html
1114

1215
== Upgrade Notice ==
1316
Version 6.0.0 is a major version, there are several changes and improvements which affect the architecture of the plugin. You will have to re-configure the plugin, all the previous settings will be lost
1417

1518
== Changelog ==
19+
* 6.12.0
20+
* Shipping (mondialrelay-wordpress) : Support the MondialRelay plugin for orders imported from the API if the carrier is matched with one of the plugin's shipping methods.
21+
* Shipping (woocommerce-gls) : Show GLS shipping methods in the shipping matching selector.
22+
* Feed : Fix case where the feed could appear empty or broken due to plugins using PHP output buffering.
23+
* Order : Improve logs during order import.
24+
* Misc : Update plugin requirements.
1625
* 6.11.0
17-
* Variations : add new filter to modify variation's main image
26+
* Variations : add new filter to modify variation's main image.
1827
* 6.10.0
1928
* Orders : Redesigned the shipment tracking system.
2029
* Orders (beta) : Add option to include VAT when importing orders.
@@ -178,7 +187,7 @@ WordPress connection Controller Plugin for ShoppingFeed - Sell on Amazon, Ebay,
178187
### WordPress :
179188

180189
- Core version 5.7 or above
181-
- WooCommerce version 5.1 or above
190+
- WooCommerce version 7.0 or above
182191

183192
## Installation
184193

shoppingfeed.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Author URI: https://www.shopping-feed.com/
88
* Text Domain: shopping-feed
99
* Domain Path: /languages
10-
* Version: 6.11.0
10+
* Version: 6.12.0
1111
* Requires at least: 5.7
1212
* Requires PHP: 7.3
1313
* WC requires at least: 5.1.0
@@ -26,7 +26,7 @@
2626
require_once plugin_dir_path( __FILE__ ) . '/vendor/autoload.php';
2727
}
2828

29-
define( 'SF_VERSION', '6.11.0' );
29+
define( 'SF_VERSION', '6.12.0' );
3030
define( 'SF_DB_VERSION_SLUG', 'SF_DB_VERSION' );
3131
define( 'SF_DB_VERSION', '1.0.0' );
3232
define( 'SF_UPGRADE_RUNNING', 'SF_UPGRADE_RUNNING' );

src/Addons/Addons.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
use ShoppingFeed\ShoppingFeedWC\Addons\Inventory\Inventory;
99
use ShoppingFeed\ShoppingFeedWC\Addons\Marketplaces\Marketplaces;
10-
use ShoppingFeed\ShoppingFeedWC\Addons\Plugins\ASTPlugin\ASTPlugin;
1110
use ShoppingFeed\ShoppingFeedWC\Addons\Plugins\ChainedProductsPlugin\ChainedProducts;
12-
use ShoppingFeed\ShoppingFeedWC\Addons\Plugins\PhWoocommerceShipmentTrackingProPlugin\PhWoocommerceShipmentTrackingProPlugin;
11+
use ShoppingFeed\ShoppingFeedWC\Addons\Plugins\MondialRelayWordpressPlugin\MondialRelayWordpress;
1312
use ShoppingFeed\ShoppingFeedWC\Addons\Shipping\Shipping;
13+
use ShoppingFeed\ShoppingFeedWC\Addons\Plugins\WoocommerceGlsPlugin\WoocommerceGls;
1414

1515
class Addons {
1616

@@ -36,10 +36,22 @@ class Addons {
3636
*/
3737
private $chained_products_plugin;
3838

39+
/**
40+
* @var MondialRelayWordpress
41+
*/
42+
private $mondial_relay_plugin;
43+
44+
/**
45+
* @var WoocommerceGls
46+
*/
47+
private $woocommerce_gls;
48+
3949
public function __construct() {
40-
$this->shipping = new Shipping();
41-
$this->inventory = new Inventory();
42-
$this->marketplaces = new Marketplaces();
43-
$this->chained_products_plugin = new ChainedProducts();
50+
$this->shipping = new Shipping();
51+
$this->inventory = new Inventory();
52+
$this->marketplaces = new Marketplaces();
53+
$this->chained_products_plugin = new ChainedProducts();
54+
$this->mondial_relay_plugin = new MondialRelayWordpress();
55+
$this->woocommerce_gls = new WoocommerceGLS();
4456
}
4557
}
Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
<?php
2+
3+
namespace ShoppingFeed\ShoppingFeedWC\Addons\Plugins\MondialRelayWordpressPlugin;
4+
5+
use ShoppingFeed\ShoppingFeedWC\Dependencies\ShoppingFeed\Sdk\Api\Order\OrderResource;
6+
use ShoppingFeed\ShoppingFeedWC\Orders\Order\Metas;
7+
use ShoppingFeed\ShoppingFeedWC\Orders\Order\Products;
8+
use ShoppingFeed\ShoppingFeedWC\ShoppingFeedHelper;
9+
10+
// Exit on direct access
11+
defined( 'ABSPATH' ) || exit;
12+
13+
/**
14+
* Class MondialRelayWordpress to manage the plugin mondialrelay-wordpress
15+
* @link https://mondialrelay-wp.com/en/home/
16+
* @package ShoppingFeed\ShoppingFeedWC\Addons\Plugins\MondialRelayWordpressPlugin
17+
*/
18+
class MondialRelayWordpress {
19+
20+
private const MONDIAL_RELAY_SHIPPING_METHOD = 'mondialrelay_official_shipping';
21+
22+
public function __construct() {
23+
if ( ! class_exists( \class_MRWP_main::class ) ) {
24+
return;
25+
}
26+
27+
add_action( 'sf_add_metas', [ $this, 'add_meta' ] );
28+
}
29+
30+
/**
31+
* Add metadata used by MondialRelayWordPress plugin to generate labels.
32+
*
33+
* @param Metas $metas
34+
*
35+
* @return void
36+
*/
37+
public function add_meta( $metas ): void {
38+
$carrier = $metas->sf_order->getShipment()['carrier'] ?? false;
39+
if ( ! $carrier ) {
40+
return;
41+
}
42+
43+
// Find matching shipping method name for the carrier
44+
$shipping_method_for_carrier = ShoppingFeedHelper::get_wc_shipping_from_sf_carrier( $carrier );
45+
if (
46+
! is_array( $shipping_method_for_carrier )
47+
|| empty( $shipping_method_for_carrier ) ||
48+
! isset( $shipping_method_for_carrier['method_rate_id'] )
49+
) {
50+
ShoppingFeedHelper::get_logger()->warning(
51+
sprintf(
52+
'[Mondial Relay] Order %s carrier is not associated with a Woocommerce shipping method.',
53+
$metas->sf_order->getReference()
54+
),
55+
array(
56+
'source' => 'shopping-feed',
57+
'carrier' => esc_html( $carrier ),
58+
)
59+
);
60+
61+
return;
62+
}
63+
64+
// Check if shipping method match MondialRelay
65+
if ( self::MONDIAL_RELAY_SHIPPING_METHOD !== $shipping_method_for_carrier['method_rate_id'] ) {
66+
ShoppingFeedHelper::get_logger()->warning(
67+
sprintf(
68+
'[Mondial Relay] Order %s carrier is not associated with Mondial Relay shipping method.',
69+
$metas->sf_order->getReference()
70+
),
71+
array(
72+
'source' => 'shopping-feed',
73+
'carrier' => esc_html( $carrier ),
74+
'shipping_method' => esc_html( $shipping_method_for_carrier['method_rate_id'] ),
75+
)
76+
);
77+
78+
return;
79+
}
80+
81+
ShoppingFeedHelper::get_logger()->info(
82+
sprintf(
83+
'[Mondial Relay] order %s carrier is associated with Mondial Relay shipping method.',
84+
$metas->sf_order->getReference()
85+
),
86+
array(
87+
'source' => 'shopping-feed',
88+
)
89+
);
90+
91+
// Get shipping method instance (use later to check the shipping code)
92+
$shipping_methods = \WC()->shipping()->get_shipping_methods();
93+
$method_name = (string) $shipping_method_for_carrier['method_rate_id'];
94+
$instance_id = (int) $shipping_method_for_carrier['method_id'];
95+
96+
if ( ! isset( $shipping_methods[ $method_name ] ) ) {
97+
ShoppingFeedHelper::get_logger()->error(
98+
'[Mondial Relay] Failed to retrieve shipping method instance.',
99+
array(
100+
'source' => 'shopping-feed',
101+
'shipping_method' => sprintf( '%s:%s', $method_name, $instance_id ),
102+
)
103+
);
104+
105+
return;
106+
}
107+
108+
$classname = get_class( $shipping_methods[ $method_name ] );
109+
/* @var \WC_Shipping_Method $instance */
110+
$instance = new $classname( $instance_id );
111+
112+
// Get the relay id for the order.
113+
$relay_id = $metas->sf_order->getShippingAddress()['relayId'] ?? false;
114+
if ( ! $relay_id ) {
115+
ShoppingFeedHelper::get_logger()->warning(
116+
sprintf( '[Mondial Relay] no relay id found for the order %s', $metas->sf_order->getReference() ),
117+
array(
118+
'source' => 'shopping-feed',
119+
)
120+
);
121+
122+
return;
123+
}
124+
125+
ShoppingFeedHelper::get_logger()->info(
126+
sprintf(
127+
'[Mondial Relay] found relay id %s for order %s',
128+
$relay_id,
129+
$metas->sf_order->getReference()
130+
),
131+
array(
132+
'source' => 'shopping-feed',
133+
)
134+
);
135+
136+
// Prefix relay id with the country code if available
137+
$country = $metas->sf_order->getShippingAddress()['country'] ?? false;
138+
if ( $country ) {
139+
$relay_id = sprintf( '%s-%s', strtoupper( $country ), $relay_id );
140+
}
141+
142+
$metas->add_meta( 'Mondial Relay Parcel Shop ID', $relay_id, true );
143+
144+
$formatted_address = $this->format_address( $metas->sf_order );
145+
$metas->add_meta( 'Mondial Relay Parcel Shop Address', $formatted_address, true );
146+
147+
/**
148+
* Code MED and APM are encoded as 24R
149+
*
150+
* @see \class_MRWP_main::save_mondial_relay_shipping_meta
151+
*/
152+
$shipping_code = $instance->get_instance_option( 'method', '' );
153+
if ( in_array( $shipping_code, [ 'MED', 'APM' ], true ) ) {
154+
$shipping_code = '24R';
155+
}
156+
157+
$metas->add_meta( 'Mondial Relay Shipping Code', $shipping_code, true );
158+
159+
$weight = $this->calculate_products_weight( $metas->sf_order );
160+
$metas->add_meta( 'Mondial Relay Parcel Weight', $weight, true );
161+
162+
ShoppingFeedHelper::get_logger()->info(
163+
'[Mondial Relay] added metadata for MondialRelayWordpress',
164+
array(
165+
'source' => 'shopping-feed',
166+
)
167+
);
168+
}
169+
170+
/**
171+
* Format address to match MondialRelayWP
172+
*
173+
* The plugin use `-MRWP-` to mark line return.
174+
*
175+
* @return string
176+
*/
177+
private function format_address( OrderResource $sf_order ): string {
178+
$address_parts = [];
179+
$address_parts[] = $sf_order->getShippingAddress()['company'] ?? '';
180+
$address_parts[] = $sf_order->getShippingAddress()['street'] ?? '';
181+
$address_parts[] = $sf_order->getShippingAddress()['street2'] ?? '';
182+
$address_parts[] = $sf_order->getShippingAddress()['postalCode'] ?? '';
183+
$address_parts[] = $sf_order->getShippingAddress()['city'] ?? '';
184+
$address_parts[] = $sf_order->getShippingAddress()['country'] ?? '';
185+
186+
return implode( '-MRWP-', $address_parts );
187+
}
188+
189+
/**
190+
* Return the weight in grams for the order.
191+
*
192+
* @param OrderResource $sf_order
193+
*
194+
* @return int
195+
*/
196+
private function calculate_products_weight( OrderResource $sf_order ): int {
197+
$weight = 0;
198+
$products = new Products( $sf_order );
199+
foreach ( $products->get_products() as $product ) {
200+
$product_id = 0 !== (int) $product['args']['variation_id'] ? (int) $product['args']['variation_id'] : $product['args']['product_id'];
201+
$wc_product = wc_get_product( $product_id );
202+
if ( ! $wc_product ) {
203+
continue;
204+
}
205+
206+
$weight += ( (float) $wc_product->get_weight() ) * 1000; // convert weight to grams
207+
}
208+
209+
return (int) $weight;
210+
}
211+
}

0 commit comments

Comments
 (0)