Skip to content

Commit ab80859

Browse files
authored
Merge pull request #160 from BeAPI/ver/7.1.0
Release 7.1.0
2 parents f23ce48 + aa12897 commit ab80859

14 files changed

+823
-62
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": "7.0.0",
2+
"version": "7.1.0",
33
"slug": "shopping-feed"
44
}

readme.md

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
* Contributors: ShoppingFeed, BeAPI
44
* Tags: shoppingfeed, marketplace, woocommerce, products feed, import orders
55
* Description: WordPress connection Controller Plugin for ShoppingFeed – Sell on Amazon, Ebay, Google, and 1000’s of international marketplaces
6-
* Stable tag: 7.0.0
7-
* Version: 7.0.0
6+
* Stable tag: 7.1.0
7+
* Version: 7.1.0
88
* Requires PHP: 7.3
99
* Requires at least: 5.7
10-
* Tested up to: 6.7
10+
* Tested up to: 6.8
1111
* WC requires at least: 7.0
1212
* WC tested up to: 9.6.0
1313
* License: GPL v2 or later
@@ -19,6 +19,16 @@
1919
2020
## Changelog
2121

22+
### 7.1.0
23+
24+
#### Enhancements
25+
26+
* **Feed** : Allow extra attributes to be added to the feed for variations.
27+
28+
#### Fixes
29+
30+
* **Order** : Check for reference alias in itemsReferencesAliases when importing order.
31+
2232
### 7.0.0
2333

2434
Adds support for multilingual product feeds.
@@ -330,16 +340,55 @@ function your_custom_tracking_url_function() {
330340
return ‘your_custom_order_meta_key’
331341
}
332342
```
333-
334343
### Extra Fields
335-
If you want to add an extra fields to your XML Feed, you can use the following snippet
344+
345+
#### Add extra fields for products in product feed
346+
347+
If you want to add an extra fields to products in your XML Feed, you can use the following snippet :
348+
336349
```php
337-
add_filter( 'shopping_feed_extra_fields', 'your_custom_fields_function', 10, 2 );
350+
add_filter( 'shopping_feed_extra_fields', 'sf_product_extra_fields', 10, 2 );
338351

339-
/** @return array */
340-
function your_custom_fields_function($fields, $wc_product) {
341-
$fields[] = array('name'=>'my_field', 'value'=>'my_value');
342-
return $fields;
352+
/**
353+
* Include additional fields for products in product feed.
354+
*
355+
* @param array $fields
356+
* @param \WC_Product $product
357+
*
358+
* @return array
359+
*/
360+
function sf_product_extra_fields( $fields, $product ) {
361+
$fields[] = array(
362+
'name' => 'my_custom_product_field',
363+
'value' => 'my_custom_value',
364+
);
365+
366+
return $fields;
367+
}
368+
```
369+
370+
#### Add extra fields for variations in product feed
371+
372+
If you want to add an extra fields to variations in your XML Feed, you can use the following snippet :
373+
374+
```php
375+
add_filter( 'shopping_feed_variation_extra_fields', 'sf_product_variation_extra_fields', 10, 2 );
376+
377+
/**
378+
* Include additional fields for variation in product feed.
379+
*
380+
* @param array $fields
381+
* @param \WC_Product $variation
382+
*
383+
* @return array
384+
*/
385+
function sf_product_variation_extra_fields( $fields, $variation ) {
386+
$fields[] = array(
387+
'name' => 'my_custom_variation_field',
388+
'value' => 'my_custom_value',
389+
);
390+
391+
return $fields;
343392
}
344393
```
345394

readme.txt

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
Contributors: ShoppingFeed, BeAPI
33
Tags: shoppingfeed, marketplace, woocommerce, products feed, import orders
44
Description: WordPress connection Controller Plugin for ShoppingFeed – Sell on Amazon, Ebay, Google, and 1000’s of international marketplaces
5-
Stable tag: 7.0.0
6-
Version: 7.0.0
5+
Stable tag: 7.1.0
6+
Version: 7.1.0
77
Requires PHP: 7.3
88
Requires at least: 5.7
9-
Tested up to: 6.7
9+
Tested up to: 6.8
1010
WC requires at least: 7.0
1111
WC tested up to: 9.6.0
1212
License: GPL v2 or later
@@ -17,6 +17,16 @@ Version 6.0.0 is a major version, there are several changes and improvements whi
1717

1818
== Changelog ==
1919

20+
= 7.1.0 =
21+
22+
#### Enhancements
23+
24+
* **Feed** : Allow extra attributes to be added to the feed for variations.
25+
26+
#### Fixes
27+
28+
* **Order** : Check for reference alias in itemsReferencesAliases when importing order.
29+
2030
= 7.0.0 =
2131

2232
Adds support for multilingual product feeds.
@@ -336,15 +346,54 @@ function your_custom_tracking_url_function() {
336346
`
337347

338348
### Extra Fields
339-
If you want to add an extra fields to your XML Feed, you can use the following snippet
349+
350+
#### Add extra fields for products in product feed
351+
352+
If you want to add an extra fields to products in your XML Feed, you can use the following snippet :
340353

341354
`
342-
add_filter( 'shopping_feed_extra_fields', 'your_custom_fields_function', 10, 2 );
355+
add_filter( 'shopping_feed_extra_fields', 'sf_product_extra_fields', 10, 2 );
343356

344-
/** @return array */
345-
function your_custom_fields_function($fields, $wc_product) {
346-
$fields[] = array('name'=>'my_field', 'value'=>'my_value');
347-
return $fields;
357+
/**
358+
* Include additional fields for products in product feed.
359+
*
360+
* @param array $fields
361+
* @param \WC_Product $product
362+
*
363+
* @return array
364+
*/
365+
function sf_product_extra_fields( $fields, $product ) {
366+
$fields[] = array(
367+
'name' => 'my_custom_product_field',
368+
'value' => 'my_custom_value',
369+
);
370+
371+
return $fields;
372+
}
373+
`
374+
375+
#### Add extra fields for variations in product feed
376+
377+
If you want to add an extra fields to variations in your XML Feed, you can use the following snippet :
378+
379+
`
380+
add_filter( 'shopping_feed_variation_extra_fields', 'sf_product_variation_extra_fields', 10, 2 );
381+
382+
/**
383+
* Include additional fields for variation in product feed.
384+
*
385+
* @param array $fields
386+
* @param \WC_Product $variation
387+
*
388+
* @return array
389+
*/
390+
function sf_product_variation_extra_fields( $fields, $variation ) {
391+
$fields[] = array(
392+
'name' => 'my_custom_variation_field',
393+
'value' => 'my_custom_value',
394+
);
395+
396+
return $fields;
348397
}
349398
`
350399

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: 7.0.0
10+
* Version: 7.1.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', '7.0.0' );
29+
define( 'SF_VERSION', '7.1.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/Feed/Generator.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ function (
155155
$product->setAttribute( $field['name'], $field['value'] );
156156
}
157157
}
158-
159158
}
160159
);
161160

@@ -206,6 +205,14 @@ function (
206205
if ( ! empty( $sf_product_variation['height'] ) ) {
207206
$variation->setAttribute( 'height', (string) $sf_product_variation['height'] );
208207
}
208+
if ( ! empty( $sf_product_variation['extra'] ) ) {
209+
foreach ( $sf_product_variation['extra'] as $field ) {
210+
if ( empty( $field['name'] ) ) {
211+
continue;
212+
}
213+
$variation->setAttribute( $field['name'], $field['value'] );
214+
}
215+
}
209216
}
210217
}
211218
);

src/Orders/Order/Products.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,16 @@ public function __construct( $sf_order, $include_vat = false ) {
4545
* Set Products
4646
*/
4747
private function set_products() {
48-
$this->products = array();
48+
$this->products = array();
49+
$references_aliases = $this->sf_order->getItemsReferencesAliases();
4950
foreach ( $this->sf_order->getItems() as $sf_product ) {
50-
$product = $this->mapping_product( $sf_product );
51+
$product = $this->mapping_product( $sf_product, $references_aliases );
5152
if ( empty( $product ) ) {
5253
ShoppingFeedHelper::get_logger()->error(
5354
sprintf(
54-
/* translators: %1$1s: Product reference. %2$2s: Order id. */
55-
__( 'cant match product %1$1s => in order %2$2s', 'shopping-feed' ),
55+
/* translators: %1$s: product reference or alias, %2$s: original product reference, %3$s: order id. */
56+
__( 'Can\'t match product "%1$s" (original ref: %2$s) in order %3$s', 'shopping-feed' ),
57+
( $references_aliases[ $sf_product->getReference() ] ?? $sf_product->getReference() ),
5658
$sf_product->getReference(),
5759
$this->sf_order->getId()
5860
),
@@ -62,19 +64,22 @@ private function set_products() {
6264
);
6365
continue;
6466
}
65-
$this->products[] = $this->mapping_product( $sf_product );
67+
68+
$this->products[] = $product;
6669
}
6770
}
6871

6972
/**
70-
* @param $sf_product OrderItem
73+
* Map products in SF order to Woocommerce products.
74+
*
75+
* @param OrderItem $sf_product
76+
* @param array $references_aliases
7177
*
7278
* @return array
7379
*/
74-
private function mapping_product( $sf_product ) {
75-
80+
private function mapping_product( $sf_product, $references_aliases = [] ) {
7681
$product_identifier = ShoppingFeedHelper::get_sf_feed_product_identifier();
77-
$wc_product_id = $sf_product->getReference();
82+
$wc_product_id = $references_aliases[ $sf_product->getReference() ] ?? $sf_product->getReference();
7883

7984
if ( 'sku' === $product_identifier ) {
8085
$wc_product_id = wc_get_product_id_by_sku( $wc_product_id );
@@ -116,6 +121,7 @@ private function mapping_product( $sf_product ) {
116121
'args' => $args,
117122
'is_available' => $wc_product->is_in_stock() && $wc_product->has_enough_stock( $sf_product_quantity ),
118123
'sf_ref' => $sf_product->getReference(),
124+
'wc_ref' => $references_aliases[ $sf_product->getReference() ] ?? $sf_product->getReference(),
119125
);
120126
}
121127

src/Products/Product.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ public function get_variations( $for_feed = false ) {
493493
$variation_data['image_main'] = apply_filters( 'shopping_feed_variation_main_image', $main_image, $variation, $product );
494494

495495
$variation_data['attributes'] = $this->get_variation_attributes( $variation );
496+
$variation_data['extra'] = $this->get_variation_extra_fields( $variation );
496497
$variations[] = $variation_data;
497498
}
498499

@@ -544,6 +545,23 @@ public function get_extra_fields() {
544545
return apply_filters( 'shopping_feed_extra_fields', [], $this->product );
545546
}
546547

548+
/**
549+
* Get variation extra fields
550+
*
551+
* @param \WC_Product_Variation $variation
552+
*
553+
* @return array
554+
*/
555+
public function get_variation_extra_fields( $variation ) {
556+
/**
557+
* Filter extra fields written in the feed for the variation.
558+
*
559+
* @param array $extra_fields
560+
* @param \WC_Product_Variation $variation
561+
*/
562+
return apply_filters( 'shopping_feed_variation_extra_fields', [], $variation );
563+
}
564+
547565
/**
548566
* Get product's stock quantity.
549567
*

0 commit comments

Comments
 (0)