dovhpmnm31216 2019-01-15 07:39
浏览 32

获取最新的产品ID

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?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大