我是一名经验丰富的c#程序员,使用WordPress和PHP。我正在与一个团队合作,为外部销售点API构建一个woocommerce集成。
API调用正在拉动3,500种产品的json(sku,属性,desc,价格,税收等)。 WordPress程序员将其设置为一个cron作业,删除所有相关的WordPress数据,并通过所有产品,分类法等循环使用wp调用逐个重新填充。
最大的问题是该页面每5分钟超时只能通过大约250个项目,所以它不起作用。而且,我们需要一个可以每小时运行一次的解决方案,以使woocommerce网站尽可能地同步到POS系统。
我建议使用woocommerce API,但被告知它有一个项目限制,但仍未解决此问题。经过几天的搜索,我很难找到解决方案。
完整代码很长,所以这里是伪代码:
Delete all related info from:
wp_terms
wp_term_taxonomy
wp_term_relationships
wp_postmeta
wp_postmeta
wp_posts
wp_termmeta
For each product in 3,500 json products {
// build set of 35 attribute variables.. example:
if( !empty($product->on_hand) ){ $on_hand = number_format($product->on_hand, 0); } else { $on_hand = 0; }
... x35
// create/update 12 taxonomies... example:
if(!empty($is_staff_picks)){
$term_is_staff_picks = wp_set_object_terms( $post_id, 'Staff Picks', 'pa_special_requirements', true );
$product_attributes_data['pa_special_requirements'] = Array( 'name' => 'pa_special_requirements', 'value' => 'Staff Picks', 'is_visible' => '1', 'is_variation' => '0', 'is_taxonomy' => '1' );
}
... x12
// add attributes that aren't taxonomies.. example:
update_post_meta( $post_id,'_product_attributes',$product_attributes_data);
// create the simple product type.. example:
wp_set_object_terms( $post_id, 'simple', 'product_type' );
// make 32 function calls to update/add metadata.. example:
update_post_meta( $post_id, 'key', $val );
... x32
}
... x3,500
答案 0 :(得分:0)
我最终改写了很多这个功能。
现在,我们每15分钟运行一次只提取最新库存数量的作业,如果已经更改,则会更新这些作业。这需要不到一分钟。
然后,每天3次我们将所有库存基本上放入3个变量中,用于与当前产品列表进行比较,然后根据需要更新/添加/删除任何项目。此完整更新需要2-5分钟,具体取决于更改的数量。