I have written a Python script to automate the process of adding products. The script scans an organized folder and converts the folder content information into a CSV format. Later, this CSV file is imported. This is working just fine.
I'm using this setup to import only simple (not bundle) products. Now, I'm working on bundle products. They're a bit problematic. Let me elaborate.
This is what a pre-imported CSV looks like:
sku,name,categories,images
EXP0101,"Pio Kitaplık","Aksesuarlar > Kitaplıklar","url, url, url"
SKU column is optional. When I import this csv/products, products get assigned an ID on the system. If I do an export on one site, the output CSV contains ID column. When I import the same CSV on another site, the new system doesn't respect the IDs on the import. There is one option about IDs/SKUs, but in this case it's irrevelant, because I'm not doing an update on existing products:
☐ Existing products that match by ID or SKU will be updated. Products that do not exist will be skipped.
In short, the system assigns a new (incremented) ID to each product whether you define IDs on your CSV or not. This is where the problem begins. The bundle plugin that is being used is WPC Product Bundles for WooCommerce. The way the plugin associates (bundles) products together is through IDs. For example:
id,type,sku,name,categories,images,"Meta: woosb_ids"
418,woosb,EXP0118,"Çırağan Yemek Odası Takımı","Yemek Odası > Yemek Odası Takımları","url, url, url","416/1,414/1,415/1"
The sub-products, when imported, won't be assigned IDs on the CSV file. They will have different IDs. So the association on the product (#418) "416/1,414/1,415/1"
(id/quantity) won't work.
To get around this, I need to know what the last id on the system is. If I know the last id, I can modify the IDs on my script, make it continue from the last id.
To get the last ID, I could get the products on the system, find the last added, check its ID, but this will work only if there are any products on the system. If I add 100 products, the last one is 100. If I delete them, and then check for the last id, I'll get 0, because there's no product.
Woocommerce must be keeping an internal record of these IDs. So when a new product is added, it assigns a new incremented ID. I need to know what that internal ID is. How/where can I get it?