Combine somehow 2 simple entries from an xml to 1 product at site.

Closed

Import WP Addon - WooCommerce Updated 4 weeks ago 64 Replies

George asked 6 months ago on June 5, 2024 at 2:50 pm

Hi James,

 

I have 1-2 kind of entries that I cannot handle effectively.

 

For example I would like when the xml has two products product with code 1555 that costs 15€ and product with code 6060 tat cost 20€ to merge it at one product that will cost 35€. is it possible? maybe the indentifier would be like \’1555+6060\’ of the mixed product at the site

J

James replied Support Agent

6 months ago on June 6, 2024 at 10:20 pm

Hi George,

What you are looking for may require some custom code to achive.

Can you provide an example xml file, with what the xml base path is, and an example of what records should do this, do you have an importer setup that you have tried to do this, if so can you please export and attach your importer settings to this ticket by going to Tools > Import WP > Settings / Tools > Import / Export and select and export your importer as a JSON file.

James

 

GF

George replied

6 months ago on June 9, 2024 at 1:43 pm

Hi James,

 

This is an xml for example: https://platform.shopranos.eu/api/feeders/feed/Custom/d9c337b6-706d-4f61-b55b-c4e6719e7df5/3b17008b-ac3f-454a-bc87-858fd1f5b324?transformationId=da12d6e2-7075-49c4-a065-40a10598415a

I have this product at the site 

https://fshome.gr/product/armando-vicario-halo-515050-110-34374-110/

 

that is the combination of 2 products from the xml 

<id>214-515050-110</id>

<id>200-34374-110</id>

 

So it is 315 + 210 € 

 

Is there any way to connect the two values from xml at a signle product? so when it reads that it has 214-515050-110 AND 200-34374-110 add them for the price. also the same avaialbilty if one is out of stock return the availabilty of the single product or variation out of stock because the combination cannot be done.

 

I didn't try to set it up because I don;t know how to make the connection

GF

George replied

6 months ago on June 9, 2024 at 2:32 pm

So I guess I need something like a symbol '+' to make the identifier understand that the value between is the sum of the two values of xml?

 

For example identifier (productcode from site): '214-515050-110+200-34374-110' 

GF

George replied

6 months ago on June 9, 2024 at 2:36 pm

This is how I identify products https://prnt.sc/qStj19BU_oJr

J

James replied Support Agent

6 months ago on June 10, 2024 at 8:11 pm

Hi George,

After looking at the two example products in the xml file, i cant see any way to connect the two products using the information given.

This would suggest that you would have to do this manually via code, checking to see if a product with a specific id has been added keeping a sum of the price during the import and at the end applying the final value as the price.

Since you are wanting to combine the two products into one, is it ony the sum of the price, and the stock status that you want to import, the rest of the record will be skipped? Where is the rest of the information of the product coming from: https://fshome.gr/product/armando-vicario-halo-515050-110-34374-110/, is it also on this same feed?

James

 

GF

George replied

6 months ago on June 11, 2024 at 1:24 pm

Hi James, this is not at the feed as a standalone product but 2 separate. 

https://platform.shopranos.eu/api/feeders/feed/Custom/d9c337b6-706d-4f61-b55b-c4e6719e7df5/3b17008b-ac3f-454a-bc87-858fd1f5b324?transformationId=da12d6e2-7075-49c4-a065-40a10598415a

<id>214-515050-110</id>

<id>200-34374-110</id>

I want to update only the price (sum of the two products or 3 if it is like 'xxx+xxxx+xx') and the stock. nothing else.


Actually I upload everything (almost) manually and I want to keep updated through xmls the pricees and stock statues

GF

George replied

6 months ago on June 12, 2024 at 11:34 am

Here is an example xml that I would like to combine:

214-610050-100 

+

200-34376-100

 

for this product:

https://staging.fshome.gr/product/armando-vicario-glam-610050-100-34376-100/

 

J

James replied Support Agent

6 months ago on June 12, 2024 at 9:07 pm

The only way that i can see that this would be possible is if you are importing 1 product and you know the list of ids that you want to sum together to create the price.

in this example lets say you add the following code to your website:

function iwphd_sum($a = '', $b = '')
{
    $a = floatval($a);
    $b = floatval($b);
    return $a + $b;
}

This is a basic function that will add together 2 numbers.

1. Now in the importer you would set the datasource as the remote feed url.
2. Under file settings set the base path as /products
3. You would populate a field to be used to identify the product that you would like to update.
4. Set the product price field to use the sum of the two feed product id's using the custom method shortcode.

[iwphd_sum("{/product[id='214-610050-100']/price}", "{/product[id='200-34376-100']/price}")]

5. Under permissions set the unique identifier to "select a template field to be used", and select the previously mentioned field setup in step 3.
6. Disable the create permission, and restrict the update permission to import "only the following fields" and select only the price field.
7. Run the import.

You should get 1 product updated, during the setup of the importer you may see the error: "Config Index File Not Found: /var/www/html/wp-content/uploads/importwp/temp-config-x.json.file_index-products" this can be ignored as it was not expecting an importer to be setup in this way.

GF

George replied

6 months ago on June 13, 2024 at 8:25 am

4. Set the product price field to use the sum of the two feed product id's using the custom method shortcode.

How I do this step? And I use t he exact shrotcode you have there?

Also I just add  this function?

function iwphd_sum($a = '', $b = '')
{
    $a = floatval($a);
    $b = floatval($b);
    return $a + $b;
}

or a custom plugin like the attached?
J

James replied Support Agent

6 months ago on June 13, 2024 at 9:33 am

All you need to do is add the function to your website, you dont need to register a shortcode or anything like that, just the top of it like you have:

<?php
/*
Plugin Name: IWP Price Sum
Description: Custom plugin to sum product prices based on identifiers and update WooCommerce products.
Version: 1.0
Author: Your Name
*/

// Function to sum two prices
function iwphd_sum($a = '', $b = '')
{
    $a = floatval($a);
    $b = floatval($b);
    return $a + $b;
}

then once the plugin is activated, you paste the following into your template field for the price:

[iwphd_sum("{/product[id='214-610050-100']/price}", "{/product[id='200-34376-100']/price}")]

GF

George replied

6 months ago on June 13, 2024 at 10:27 am

I did all the steps but it doesn;t work

 

https://prnt.sc/NY7hQbAsv2Pa

J

James replied Support Agent

6 months ago on June 13, 2024 at 10:52 am

Ignore the preview as this means the function is working as its showing 0, if you have the base path setup as "/products" if you run the import it should on find 1 record, and set the pricing?

GF

George replied

6 months ago on June 13, 2024 at 11:04 am

I changed the file and now it runs only at 1 product https://prnt.sc/yzLQSNpskRCH

J

James replied Support Agent

6 months ago on June 13, 2024 at 11:05 am

What field / custom field have you setup to connect this price to an existing product?

GF

George replied

6 months ago on June 13, 2024 at 11:08 am

it also gives correct price 

https://prnt.sc/8mUOCdmkbzYN

GF

George replied

6 months ago on June 13, 2024 at 11:08 am

suppliercode from my site with id of xml 

GF

George replied

6 months ago on June 13, 2024 at 11:08 am

J

James replied Support Agent

6 months ago on June 13, 2024 at 11:10 am

If you change the value from {/id} to the actual id of the product you want to update? and then change the permisison unique identifier setting to the suppliercode field.

GF

George replied

6 months ago on June 13, 2024 at 11:16 am

https://staging.fshome.gr/product/armando-vicario-glam-610050-100-34376-100/

 

worked :)

by adding the supliercode value 

GF

George replied

6 months ago on June 13, 2024 at 4:34 pm

So how I make this work also for stockstatus, and all products that are combinated?

J

James replied Support Agent

6 months ago on June 13, 2024 at 4:37 pm

To make it work with all combinated products, can you let me know how the combined product is connected to the products in the feed?

Stock status will require another custom function, to take in two status' and return the correct status based on this, do you need help in writing this function?

James

GF

George replied

6 months ago on June 13, 2024 at 5:05 pm

they are just simple entries like the above example.

Stock status will require another custom function, to take in two status' and return the correct status based on this, do you need help in writing this function?

yes I would like if you can

J

James replied Support Agent

6 months ago on June 13, 2024 at 8:35 pm

 

// Function to return stock status
function iwphd_stock($a = '', $b = '', $check = '')
{
    $a = trim($a);
    $b = trim($b);
    $check = trim($check);

    if ($a == $b && $a == $check) {
        return 'instock';
    }

    return 'outofstock';
}

This can be used as follows:

[iwphd_stock("{/product[id='214-610050-100']/availability}", "{/product[id='200-34376-100']/availability}", "Διαθέσιμο")]

So if both availability values = Διαθέσιμο then they will be marked as instock otherwise they will be marked as outofstock.

GF

George replied

6 months ago on June 14, 2024 at 6:43 am

This works also correct thanks again James!

 

My question is how I make to identify all products that are assigned at this importer and have a + at the suppliercode to auto make the calculation?

the key at the identifier is that it contains + symbol

For example it should work with this logic also for this product combination from the xml

'206-E044275-100' + '206-E106000' 

 

at site is 206-E044275-100+206-E106000 (https://staging.fshome.gr/product/almar-e044275-100-e106000/)

 

also it would be good to work with different placed numbers, 206-E106000+206-E044275-100

or for a combination of 3 number

 

(I covered all possible scenarios)

 

GF

George replied

6 months ago on June 14, 2024 at 9:03 am

To make it guess I will not use these shrotocodes, brcause they are spesific for the product id.

 

GF

George replied

6 months ago on June 14, 2024 at 9:16 am

Also I guess the base path will from 

/products to 

/products/product

 

?

J

James replied Support Agent

6 months ago on June 15, 2024 at 10:15 am

Hi George,

Where in the xml is the main product referenced (the one that has the price and stock status set from other products in the feed, e.g. this product: https://staging.fshome.gr/product/almar-e044275-100-e106000/), and how is it connected to the sub products (206-E044275-100' and '206-E106000) ?

Once i know that i can help you further.

James

GF

George replied

6 months ago on June 15, 2024 at 11:05 am

at the xml there are 2 standalone products.

 

id/ 206-E044275-100

id/ 206-E106000

 

at the site i use acd field > suppliercode 

 for now I have 206-E044275-100+206-E106000

https://staging.fshome.gr/product/almar-e044275-100-e106000/

GF

George replied

6 months ago on June 15, 2024 at 11:28 am

here is the xml

GF

George replied

6 months ago on June 15, 2024 at 11:30 am

At the suppliercode I use '+' symbol but I can change it, I did because in case we can implement a logic that will read the suppliercode (identifie) at the site data and if it contains +, it will serach the values between.

 

J

James replied Support Agent

6 months ago on June 15, 2024 at 12:03 pm

Just to make sure i understand correctly.

1. Loop through all the products on the xml feed, matching each product using the ID node ? {/id}
2. If a product exists matching that ID node, it will then read the value stored in the acf field "suppliercode", then based on the value entered in the suppliercode field it will then search through the xml feed for these products based on the id's and combine there price and stock status.

The suppliercode field is not populated from the xml field and this is manually entered?

GF

George replied

6 months ago on June 15, 2024 at 12:15 pm

1) Correct, loop the products to see if these two values or three exist at the xml

2) Yes, but regarding the search it should be exact match between the + symbols.

 

yes the suppliercode is created by me manually.

 

J

James replied Support Agent

6 months ago on June 15, 2024 at 5:05 pm

To help me create a test environment, can you tell me where this product is referenced in the xml feed: https://staging.fshome.gr/product/almar-e044275-100-e106000/

And can you export and attach your acf field group via the ACF menu.

GF

George replied

6 months ago on June 15, 2024 at 5:59 pm

It is the combination of these 2 entries at the latested attached xml:

line 914 <id>206-E044275-100</id>

line 2150 <id>206-E106000</id>

 

 

it is the suppliercode. also at this product: https://staging.fshome.gr/product/almar-e044275-100-e106000/

 the supplier code is 206-E044275-100+206-E106000 (so is id1+id2)

 

 
 
J

James replied Support Agent

6 months ago on June 15, 2024 at 6:25 pm

So the feed contains the two products: 

1. 206-E044275-100
2. 206-E106000

Sorry, i do not understand how you want this to work, as the importer would be looping though all the xml rows, when the importer reaches each of these products in the xml feed, how does it know to connect them to this product or a similar product (https://staging.fshome.gr/product/almar-e044275-100-e106000/).

GF

George replied

6 months ago on June 15, 2024 at 6:41 pm

I don't know if it possible but a logic could be:

1) add a product tag #combinedproducts at products with + (I can do it manually)

2) then the importer checks that this tag exists

3) after that the importer scans all supplier code values and understands the code beacause each supplier code has a separator + that then can drag each value between + symbols? So when it sees the code  206-E044275-100 then it searches for the next code after + and if there is a 3rd code then the third.

 

can this be done?

J

James replied Support Agent

6 months ago on June 16, 2024 at 8:25 pm

The problem with this is that the importer loops through the rows in the xml file, and what you want to do is loop though the products in wordpress that have the suppliercode and then query the xml file to find the matching product ids.

Out of the box it is not possible.

However a solution that i can think of is creating an importer specifically to handle only this:

1. for the importer to handle the downloading of the xml feed and scheduling
2. during the initialization of the importer we could somehow load all the id's from the suppliercode fields that have a + in them that need to be found.
3. Then loop though each record in the xml file, skipping ids that are not needed, and keeping track of the prices and stock status's.
4. Then when the importer has reached the end of the xml file, then it will update stockstatus and price of the combined products using the previously fetched data (what happens to a product if the price or stock status is not found?)

Does that sound like a possible solution? i am not in the office until the 24th so will not be able to provide the solution until after then, but it would be good to have a solution worked out before then so it will take less time to implement.

James

GF

George replied

6 months ago on June 17, 2024 at 7:42 am

Yes it sounds a very good solution!

Regarding 4) A notice would be nice at my email to understand it and fix it (in this case is more possible somehthing at the ids or code changed, than to not find the price or stock).

A notice email would be nice for 3 scenarios:

-not find the combination of codes (from this 206-E044275-100+206-E106000 it has to find the codes seperately)

-not finding prices

-not finding stock values

 

Also I would like to work to more that 2 codes combinations.

Also no not matter which code comes first or second or third.

 

J

James replied Support Agent

5 months ago on June 25, 2024 at 8:53 pm

Hi George,

I have attached a development build of the importer, and a custom plugin to test the functionality laid out in the previous reply.

Once both plugins are activated:

1. Create a new importer.
2. Attach the xml file.
3. Under file settings set the base path to "/products/product"
4. leave all fields empty as these are not required.
5. under permissions, set the "select data from your import file", and set the indentifier to {/id}
6. once saved, before you run the importer, you need to configure the custom plugin by defining the importer id, by adding the following constant to your wordpress config (changing 11 to the id of your importer, this can be found from the url when editing the importer: http://your.site/wp-admin/tools.php?page=importwp&edit=11&step=4)

define('IWP_COMBINED_IMPORTER_ID', 11);

Now when you run the importer, if everything is setup correctly, no records should be inserted or updated, every record should be skipped.

When a product has found all of the suppliercode prices and stock status the history message will say something like: Updated Products: #15 (stock: outofstock, price: 4732).

At the moment the importer will not send out any emails, as i want to confirm the functionality is there before doing this, the importer will write to the server error log with the status when the importer completes.

All products have been updated:
[25-Jun-2024 20:32:27 UTC] Complete: 1 products.

Not all products with multiple suppliercodes were updated:
[25-Jun-2024 20:32:27 UTC] Incomplete: 1/1 products.

List of products that are missing suppliercodes:
[25-Jun-2024 20:32:27 UTC] missing product: #15

The custom plugin does the following:

1. At the start of import, it finds all products that have a suppliercode custom field that contains + symbol.
2. On each record, it checks to see if the product id matches the list of suppliercodes, if it matches it tracks the stock status and price.
3. the stock status and price will be then be updated of all supplier codes have been found that are required for each product.
4. any products that have not been updated, will be re-checked at the end of the import, and will be marked as incomplete.

Screenshots attached showing the history, and a preview of the edit product screen being updated based on the suppliercodes entered.

J

James replied Support Agent

5 months ago on July 16, 2024 at 7:59 pm

Hello George

This ticket is being marked as closed due to inactivity.

If this is not the case, please reply to this ticket to re-open it.

James

GF

George replied

1 month ago on October 28, 2024 at 4:56 pm

Hi James, 

 

It is time to check this function. Can you please confirm me if I have to download the b04a17c279df6f3fcfe17f89597adc20-jc-importer-v2.14.0-rc1.zip

or the v2.14.4 that you have can work also?

J

James replied Support Agent

1 month ago on October 28, 2024 at 10:01 pm

Hi,

It should work, but i have updated the code to woth updated function calls.

James

GF

George replied

1 month ago on October 31, 2024 at 8:57 pm

Hi,

Where should I do the step 6?

''

once saved, before you run the importer, you need to configure the custom plugin by defining the importer id, by adding the following constant to your wordpress config (changing 11 to the id of your importer, this can be found from the url when editing the importer: http://your.site/wp-admin/tools.php?page=importwp&edit=11&step=4)

define('IWP_COMBINED_IMPORTER_ID', 11);

Now when you run the importer, if everything is setup correctly, no records should be inserted or updated, every record should be skipped.

''

 

 

J

James replied Support Agent

1 month ago on November 1, 2024 at 9:17 am

I would normally add these to your wp-config.php file, however adding it to the plugin file like you have is enough.

James

GF

George replied

1 month ago on November 1, 2024 at 10:07 am

When I add it, it breaks the site

GF

George replied

1 month ago on November 1, 2024 at 10:14 am

Also I had a similar issue with wp-confing and I commented the wp-import code. 

 

 

J

James replied Support Agent

1 month ago on November 1, 2024 at 10:15 am

You need to remove the previously added line from the plugin, as the following line can only be added once per site, otherwise it will break:

define('IWP_COMBINED_IMPORTER_ID', 504116);
GF

George replied

1 month ago on November 1, 2024 at 10:22 am

I had this code only at the iwp-combined-products.php file. Nowhere else

J

James replied Support Agent

1 month ago on November 1, 2024 at 10:26 am

Ok, remove the old plugin "iwp-combined-products" and add the new one where i have set the id for you in the setup.php file.

 

GF

George replied

1 month ago on November 1, 2024 at 11:27 am

It stucks at the first batch

https://prnt.sc/fdlqx8VXei4e

J

James replied Support Agent

1 month ago on November 1, 2024 at 11:49 am

Can you please enable debug log via Tools > ImportWP > Settings / Tools > Enable Debug Mode, refresh the page and go and restart the importer, let it run for a while and then click on show debug button at the bottom right of the importer, then download the import logs and attach.

J

James replied Support Agent

1 month ago on November 1, 2024 at 2:37 pm

Is there any way you can provide access to your wordpress admin area?

GF

George replied privately

1 month ago on November 1, 2024 at 2:38 pm

J

James replied privately Support Agent

1 month ago on November 1, 2024 at 2:51 pm

GF

George replied

1 month ago on November 1, 2024 at 5:18 pm

Fatal error: Uncaught Error: Call to a member function getId() on null
in /home/fshomegr/stage/wp-content/plugins/jc-importer/class/Common/AddonAPI/ImporterAddon.php on line 220

Call stack:

ImportWP\C\A\ImporterAddon::ImportWP\C\A\{closure}()
call_user_func_array()
wp-content/plugins/jc-importer/class/EventHandler.php:41
ImportWP\EventHandler::run()
wp-content/plugins/jc-importer/class/Common/Importer/ImporterManager.php:724
ImportWP\C\I\ImporterManager::import()
wp-content/plugins/jc-importer/class/Common/Rest/RestManager.php:1340
ImportWP\C\R\RestManager::run_import()
wp-includes/rest-api/class-wp-rest-server.php:1230
WP_REST_Server::respond_to_request()
wp-includes/rest-api/class-wp-rest-server.php:1063
WP_REST_Server::dispatch()
wp-includes/rest-api/class-wp-rest-server.php:439
WP_REST_Server::serve_request()
wp-includes/rest-api.php:420
rest_api_loaded()
wp-includes/class-wp-hook.php:324
WP_Hook::apply_filters()
wp-includes/class-wp-hook.php:348
WP_Hook::do_action()
wp-includes/plugin.php:565
do_action_ref_array()
wp-includes/class-wp.php:418
WP::parse_request()
wp-includes/class-wp.php:813
WP::main()
wp-includes/functions.php:1336
wp()
wp-blog-header.php:16
require()
index.php:17
J

James replied Support Agent

1 month ago on November 1, 2024 at 5:34 pm

Thank you, the importer no longer errors and gets past 20 records.

The issue was with the other iwp-custom plugin, it did not return a value when it should.

I have uploaded, and attached it for reference.

James

GF

George replied

1 month ago on November 1, 2024 at 6:33 pm

The price worked at this product, nice! https://staging.fshome.gr/product/almar-e044275-100-e106000/

Does it handle also stock status? 

Also can it handle more than 1 + (to sum 3 products for example or 4)

J

James replied Support Agent

1 month ago on November 1, 2024 at 7:45 pm

Is the stock status using this: https://helpdesk.importwp.com/ticket/283efa1b-da29-4f95-bb75-db281526af12/#reply-2694 ? if not can you explain it in more detail what you require?

Is this in regards to the stock or the price: "Also can it handle more than 1 + (to sum 3 products for example or 4)"

 

GF

George replied

1 month ago on November 1, 2024 at 7:56 pm

Regarding to stock status, can we somehow use text field map: https://prnt.sc/dbDgTwXnCz0b

because maybe at an xml from a different supplier I will need to modify the stock status field map differently.

 

 

About the '+' I would like to work with both price and stock. 

Also at stock I want the weight of the status to go outofstock > onbackorder > instock, what I mean is that i oustofstock exists at one of products then all product is outofstock.

J

James replied Support Agent

4 weeks ago on November 4, 2024 at 5:18 pm

Hi,

If you modify the previously mentioned sum function for prices, to allow an unlimited number of product prices, or stock.

function iwphd_sum(...$numbers)
{
	return array_sum($numbers);
}

If you want to weigh the stock status, you will not be able to use a field map, and instead have to use a custom function.

James

GF

George replied

4 weeks ago on November 4, 2024 at 9:42 pm

In what file should I replace this code? 

function iwphd_sum(...$numbers)
{
	return array_sum($numbers);
}

So if I need the field map, I lose the outofstock>onbackorder>instock?

 

J

James replied Support Agent

4 weeks ago on November 4, 2024 at 9:55 pm

It depends on how you added it the first time (https://helpdesk.importwp.com/ticket/283efa1b-da29-4f95-bb75-db281526af12/#reply-2680) , you just need to replace the previous function with the new contents.

Sorry, i have lost track of what works and how it works since this ticket is 5 months old, Is this how the current stock works / is setup: https://helpdesk.importwp.com/ticket/283efa1b-da29-4f95-bb75-db281526af12/#reply-2694

GF

George replied

4 weeks ago on November 5, 2024 at 8:12 am

Hello, yes you are right.

 

I am opening a new ticket with the plugins attached.